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 534527 2007-05-02 16:10:59Z tv $
033: */
034: public class LDAPSecurityConstants {
035: /** Property key */
036: public static final String LDAP_ADMIN_USERNAME_KEY = "ldap.admin.username";
037:
038: /** Property key */
039: public static final String LDAP_ADMIN_PASSWORD_KEY = "ldap.admin.password";
040:
041: /** Property key */
042: public static final String LDAP_HOST_KEY = "ldap.host";
043:
044: /** Property default value */
045: public static final String LDAP_HOST_DEFAULT = "localhost";
046:
047: /** Property key */
048: public static final String LDAP_PORT_KEY = "ldap.port";
049:
050: /** Property default value */
051: public static final String LDAP_PORT_DEFAULT = "389";
052:
053: /** Property key */
054: public static final String LDAP_PROVIDER_KEY = "ldap.provider";
055:
056: /** Property default value */
057: public static final String LDAP_PROVIDER_DEFAULT = "com.sun.jndi.ldap.LdapCtxFactory";
058:
059: /** Property key */
060: public static final String LDAP_BASE_SEARCH_KEY = "ldap.basesearch";
061:
062: /** Property key */
063: public static final String LDAP_AUTH_KEY = "ldap.security.authentication";
064:
065: /** Property default value */
066: public static final String LDAP_AUTH_DEFAULT = "simple";
067:
068: /** Property key */
069: public static final String LDAP_USER_USERID_KEY = "ldap.user.userid";
070:
071: /** Property default value */
072: public static final String LDAP_USER_USERID_DEFAULT = "uid";
073:
074: /** Property key */
075: public static final String LDAP_USER_USERNAME_KEY = "ldap.user.username";
076:
077: /** Property default value */
078: public static final String LDAP_USER_USERNAME_DEFAULT = "turbineUserUniqueId";
079:
080: /** Property key */
081: public static final String LDAP_USER_FIRSTNAME_KEY = "ldap.user.firstname";
082:
083: /** Property default value */
084: public static final String LDAP_USER_FIRSTNAME_DEFAULT = "turbineUserFirstName";
085:
086: /** Property key */
087: public static final String LDAP_USER_LASTNAME_KEY = "ldap.user.lastname";
088:
089: /** Property default value */
090: public static final String LDAP_USER_LASTNAME_DEFAULT = "turbineUserLastName";
091:
092: /** Property key */
093: public static final String LDAP_USER_EMAIL_KEY = "ldap.user.email";
094:
095: /** Property default value */
096: public static final String LDAP_USER_EMAIL_DEFAULT = "turbineUserMailAddress";
097:
098: /** Property key */
099: public static final String LDAP_USER_PASSWORD_KEY = "ldap.user.password";
100:
101: /** Property default value */
102: public static final String LDAP_USER_PASSWORD_DEFAULT = "userPassword";
103:
104: /**
105: * Get all the properties for the security service.
106: * @return all the properties of the security service.
107: */
108: public static Properties getProperties() {
109: return TurbineSecurity.getService().getProperties();
110: }
111:
112: /**
113: * Get a property from the LDAP security service.
114: * @param key The key to access the value of the property.
115: * @return The value of the property.
116: */
117: public static String getProperty(String key) {
118: return getProperties().getProperty(key);
119: }
120:
121: /**
122: * Get a property from the LDAP security service.
123: * @param key The key to access the value of the property.
124: * @param defaultValue The value that the property takes
125: * when it doesn't exist.
126: * @return The value of the property.
127: */
128: public static String getProperty(String key, String defaultValue) {
129: return getProperties().getProperty(key, defaultValue);
130: }
131:
132: /**
133: * Get the value of the property for the administration username.
134: * @return the value of the property.
135: */
136: public static String getAdminUsername() {
137: String str = getProperty(LDAP_ADMIN_USERNAME_KEY);
138:
139: /*
140: * The adminUsername string contains some
141: * characters that need to be transformed.
142: */
143: str = str.replace('/', '=');
144: str = str.replace('%', ',');
145: return str;
146: }
147:
148: /**
149: * Get the value of the property for the administration password.
150: * @return the value of the property.
151: */
152: public static String getAdminPassword() {
153: return getProperty(LDAP_ADMIN_PASSWORD_KEY);
154: }
155:
156: /**
157: * Get the value of the property for the LDAP Host.
158: * @return the value of the property.
159: */
160: public static String getLDAPHost() {
161: return getProperty(LDAP_HOST_KEY, LDAP_HOST_DEFAULT);
162: }
163:
164: /**
165: * Get the value of the property for the LDAP Port.
166: * @return the value of the property.
167: */
168: public static String getLDAPPort() {
169: return getProperty(LDAP_PORT_KEY, LDAP_PORT_DEFAULT);
170: }
171:
172: /**
173: * Get the value of the property for the LDAP Provider.
174: * @return the value of the property.
175: */
176: public static String getLDAPProvider() {
177: return getProperty(LDAP_PROVIDER_KEY, LDAP_PROVIDER_DEFAULT);
178: }
179:
180: /**
181: * Get value of the property for the Base Search.
182: * @return the value of the property.
183: */
184: public static String getBaseSearch() {
185: String str = getProperty(LDAP_BASE_SEARCH_KEY);
186:
187: /*
188: * The userBaseSearch string contains some
189: * characters that need to be transformed.
190: */
191: str = str.replace('/', '=');
192: str = str.replace('%', ',');
193: return str;
194: }
195:
196: /**
197: * Get the value of the property for the Authentication
198: * mechanism. Valid values are: none, simple,
199: * @return the value of the property.
200: */
201: public static String getLDAPAuthentication() {
202: return getProperty(LDAP_AUTH_KEY, LDAP_AUTH_DEFAULT);
203: }
204:
205: /**
206: * Get the value of the User id Attribute.
207: * @return the value of the property.
208: */
209: public static String getUserIdAttribute() {
210: return getProperty(LDAP_USER_USERID_KEY,
211: LDAP_USER_USERID_DEFAULT);
212: }
213:
214: /**
215: * Get the value of the Username Attribute.
216: * @return the value of the property.
217: */
218: public static String getNameAttribute() {
219: return getProperty(LDAP_USER_USERNAME_KEY,
220: LDAP_USER_USERNAME_DEFAULT);
221: }
222:
223: /**
224: * Get the value of the Username Attribute.
225: * @return the value of the property.
226: * @deprecated Use getNameAttribute()
227: */
228: public static String getUserNameAttribute() {
229: return getNameAttribute();
230: }
231:
232: /**
233: * Get the value of the Firstname Attribute.
234: * @return the value of the property.
235: */
236: public static String getFirstNameAttribute() {
237: return getProperty(LDAP_USER_FIRSTNAME_KEY,
238: LDAP_USER_FIRSTNAME_DEFAULT);
239: }
240:
241: /**
242: * Get the value of the Lastname Attribute.
243: * @return the value of the property.
244: */
245: public static String getLastNameAttribute() {
246: return getProperty(LDAP_USER_LASTNAME_KEY,
247: LDAP_USER_LASTNAME_DEFAULT);
248: }
249:
250: /**
251: * Get the value of the Password Attribute.
252: * @return the value of the property.
253: */
254: public static String getPasswordAttribute() {
255: return getProperty(LDAP_USER_PASSWORD_KEY,
256: LDAP_USER_PASSWORD_DEFAULT);
257: }
258:
259: /**
260: * Get the value of the E-Mail Attribute.
261: * @return the value of the property.
262: */
263: public static String getEmailAttribute() {
264: return getProperty(LDAP_USER_EMAIL_KEY, LDAP_USER_EMAIL_DEFAULT);
265: }
266:
267: }
|