    001    package org.apache.turbine.services.security.ldap;
    002
    003    /*
    004     * Licensed to the Apache Software Foundation (ASF) under one
    005     * or more contributor license agreements.  See the NOTICE file
    006     * distributed with this work for additional information
    007     * regarding copyright ownership.  The ASF licenses this file
    008     * to you under the Apache License, Version 2.0 (the
    009     * "License"); you may not use this file except in compliance
    010     * with the License.  You may obtain a copy of the License at
    011     *
    012     *   http://www.apache.org/licenses/LICENSE-2.0
    013     *
    014     * Unless required by applicable law or agreed to in writing,
    015     * software distributed under the License is distributed on an
    016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    017     * KIND, either express or implied.  See the License for the
    018     * specific language governing permissions and limitations
    019     * under the License.
    020     */
    021
    022    import java.util.Properties;
    023
    024    import org.apache.turbine.services.security.TurbineSecurity;
    025
    026    /**
    027     * <p>This is a static class for defining the default ldap confiquration
    028     * keys used by core Turbine components.</p>
    029     *
    030     * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
    031     * @author <a href="mailto:hhernandez@itweb.com.mx">Humberto Hernandez</a>
    032     * @version $Id: LDAPSecurityConstants.java 957284 2010-06-23 17:53:31Z tv $
    033     */
    034    public class LDAPSecurityConstants
    035    {
    036        /** Property key */
    037        public static final String LDAP_ADMIN_USERNAME_KEY = "ldap.admin.username";
    038
    039        /** Property key */
    040        public static final String LDAP_ADMIN_PASSWORD_KEY = "ldap.admin.password";
    041
    042        /** Property key */
    043        public static final String LDAP_HOST_KEY = "ldap.host";
    044
    045        /** Property default value */
    046        public static final String LDAP_HOST_DEFAULT = "localhost";
    047
    048        /** Property key */
    049        public static final String LDAP_PORT_KEY = "ldap.port";
    050
    051        /** Property default value */
    052        public static final String LDAP_PORT_DEFAULT = "389";
    053
    054        /** Property key */
    055        public static final String LDAP_PROVIDER_KEY = "ldap.provider";
    056
    057        /** Property default value */
    058        public static final String LDAP_PROVIDER_DEFAULT =
    059                "com.sun.jndi.ldap.LdapCtxFactory";
    060
    061        /** Property key */
    062        public static final String LDAP_BASE_SEARCH_KEY = "ldap.basesearch";
    063
    064        /** Property key */
    065        public static final String LDAP_AUTH_KEY = "ldap.security.authentication";
    066
    067        /** Property default value */
    068        public static final String LDAP_AUTH_DEFAULT = "simple";
    069
    070        /** Property key */
    071        public static final String LDAP_USER_USERID_KEY = "ldap.user.userid";
    072
    073        /** Property default value */
    074        public static final String LDAP_USER_USERID_DEFAULT = "uid";
    075
    076        /** Property key */
    077        public static final String LDAP_USER_USERNAME_KEY = "ldap.user.username";
    078
    079        /** Property default value */
    080        public static final String LDAP_USER_USERNAME_DEFAULT = "turbineUserUniqueId";
    081
    082        /** Property key */
    083        public static final String LDAP_USER_FIRSTNAME_KEY = "ldap.user.firstname";
    084
    085        /** Property default value */
    086        public static final String LDAP_USER_FIRSTNAME_DEFAULT = "turbineUserFirstName";
    087
    088        /** Property key */
    089        public static final String LDAP_USER_LASTNAME_KEY = "ldap.user.lastname";
    090
    091        /** Property default value */
    092        public static final String LDAP_USER_LASTNAME_DEFAULT = "turbineUserLastName";
    093
    094        /** Property key */
    095        public static final String LDAP_USER_EMAIL_KEY = "ldap.user.email";
    096
    097        /** Property default value */
    098        public static final String LDAP_USER_EMAIL_DEFAULT = "turbineUserMailAddress";
    099
    100        /** Property key */
    101        public static final String LDAP_USER_PASSWORD_KEY = "ldap.user.password";
    102
    103        /** Property default value */
    104        public static final String LDAP_USER_PASSWORD_DEFAULT = "userPassword";
    105
    106        /**
    107         * Get all the properties for the security service.
    108         * @return all the properties of the security service.
    109         */
    110        public static Properties getProperties()
    111        {
    112            return TurbineSecurity.getService().getProperties();
    113        }
    114
    115        /**
    116         * Get a property from the LDAP security service.
    117         * @param key The key to access the value of the property.
    118         * @return The value of the property.
    119         */
    120        public static String getProperty(String key)
    121        {
    122            return getProperties().getProperty(key);
    123        }
    124
    125        /**
    126         * Get a property from the LDAP security service.
    127         * @param key The key to access the value of the property.
    128         * @param defaultValue The value that the property takes
    129         *        when it doesn't exist.
    130         * @return The value of the property.
    131         */
    132        public static String getProperty(String key, String defaultValue)
    133        {
    134            return getProperties().getProperty(key, defaultValue);
    135        }
    136
    137        /**
    138         * Get the value of the property for the administration username.
    139         * @return the value of the property.
    140         */
    141        public static String getAdminUsername()
    142        {
    143            String str = getProperty(LDAP_ADMIN_USERNAME_KEY);
    144
    145            /*
    146             * The adminUsername string contains some
    147             * characters that need to be transformed.
    148             */
    149            str = str.replace('/', '=');
    150            str = str.replace('%', ',');
    151            return str;
    152        }
    153
    154        /**
    155         * Get the value of the property for the administration password.
    156         * @return the value of the property.
    157         */
    158        public static String getAdminPassword()
    159        {
    160            return getProperty(LDAP_ADMIN_PASSWORD_KEY);
    161        }
    162
    163        /**
    164         * Get the value of the property for the LDAP Host.
    165         * @return the value of the property.
    166         */
    167        public static String getLDAPHost()
    168        {
    169            return getProperty(LDAP_HOST_KEY, LDAP_HOST_DEFAULT);
    170        }
    171
    172        /**
    173         * Get the value of the property for the LDAP Port.
    174         * @return the value of the property.
    175         */
    176        public static String getLDAPPort()
    177        {
    178            return getProperty(LDAP_PORT_KEY, LDAP_PORT_DEFAULT);
    179        }
    180
    181        /**
    182         * Get the value of the property for the  LDAP Provider.
    183         * @return the value of the property.
    184         */
    185        public static String getLDAPProvider()
    186        {
    187            return getProperty(LDAP_PROVIDER_KEY, LDAP_PROVIDER_DEFAULT);
    188        }
    189
    190        /**
    191         * Get value of the property for the Base Search.
    192         * @return the value of the property.
    193         */
    194        public static String getBaseSearch()
    195        {
    196            String str = getProperty(LDAP_BASE_SEARCH_KEY);
    197
    198            /*
    199             * The userBaseSearch string contains some
    200             * characters that need to be transformed.
    201             */
    202            str = str.replace('/', '=');
    203            str = str.replace('%', ',');
    204            return str;
    205        }
    206
    207        /**
    208         * Get the value of the property for the Authentication
    209         * mechanism. Valid values are: none, simple,
    210         * @return the value of the property.
    211         */
    212        public static String getLDAPAuthentication()
    213        {
    214            return getProperty(LDAP_AUTH_KEY, LDAP_AUTH_DEFAULT);
    215        }
    216
    217        /**
    218         * Get the value of the User id Attribute.
    219         * @return the value of the property.
    220         */
    221        public static String getUserIdAttribute()
    222        {
    223            return getProperty(LDAP_USER_USERID_KEY, LDAP_USER_USERID_DEFAULT);
    224        }
    225
    226        /**
    227         * Get the value of the Username Attribute.
    228         * @return the value of the property.
    229         */
    230        public static String getNameAttribute()
    231        {
    232            return getProperty(LDAP_USER_USERNAME_KEY, LDAP_USER_USERNAME_DEFAULT);
    233        }
    234
    235        /**
    236         * Get the value of the Username Attribute.
    237         * @return the value of the property.
    238         * @deprecated Use getNameAttribute()
    239         */
    240        public static String getUserNameAttribute()
    241        {
    242            return getNameAttribute();
    243        }
    244
    245        /**
    246         * Get the value of the Firstname Attribute.
    247         * @return the value of the property.
    248         */
    249        public static String getFirstNameAttribute()
    250        {
    251            return getProperty(LDAP_USER_FIRSTNAME_KEY,
    252                    LDAP_USER_FIRSTNAME_DEFAULT);
    253        }
    254
    255        /**
    256         * Get the value of the Lastname Attribute.
    257         * @return the value of the property.
    258         */
    259        public static String getLastNameAttribute()
    260        {
    261            return getProperty(LDAP_USER_LASTNAME_KEY, LDAP_USER_LASTNAME_DEFAULT);
    262        }
    263
    264        /**
    265         * Get the value of the Password Attribute.
    266         * @return the value of the property.
    267         */
    268        public static String getPasswordAttribute()
    269        {
    270            return getProperty(LDAP_USER_PASSWORD_KEY, LDAP_USER_PASSWORD_DEFAULT);
    271        }
    272
    273        /**
    274         * Get the value of the E-Mail Attribute.
    275         * @return the value of the property.
    276         */
    277        public static String getEmailAttribute()
    278        {
    279            return getProperty(LDAP_USER_EMAIL_KEY, LDAP_USER_EMAIL_DEFAULT);
    280        }
    281
    282    }