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