##### Coverage Report - org.apache.turbine.services.security.ldap.LDAPSecurityConstants

Classes in this File | Line Coverage | Branch Coverage | Complexity
LDAPSecurityConstants |
0% | 0/24
N/A | N/A
| 1.0;1

1 |  |
     package org.apache.turbine.services.security.ldap;
2 |  |
3 |  |
     /*
4 |  |
      * Licensed to the Apache Software Foundation (ASF) under one
5 |  |
      * or more contributor license agreements.  See the NOTICE file
6 |  |
      * distributed with this work for additional information
7 |  |
      * regarding copyright ownership.  The ASF licenses this file
8 |  |
      * to you under the Apache License, Version 2.0 (the
9 |  |
      * "License"); you may not use this file except in compliance
10 |  |
      * with the License.  You may obtain a copy of the License at
11 |  |
      *
12 |  |
      *   http://www.apache.org/licenses/LICENSE-2.0
13 |  |
      *
14 |  |
      * Unless required by applicable law or agreed to in writing,
15 |  |
      * software distributed under the License is distributed on an
16 |  |
      * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 |  |
      * KIND, either express or implied.  See the License for the
18 |  |
      * specific language governing permissions and limitations
19 |  |
      * under the License.
20 |  |
      */
21 |  |
22 |  |
     import java.util.Properties;
23 |  |
24 |  |
     import org.apache.turbine.services.security.TurbineSecurity;
25 |  |
26 |  |
     /**
27 |  |
      * <p>This is a static class for defining the default ldap confiquration
28 |  |
      * keys used by core Turbine components.</p>
29 |  |
      *
30 |  |
      * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
31 |  |
      * @author <a href="mailto:hhernandez@itweb.com.mx">Humberto Hernandez</a>
32 |  |
      * @version $Id: LDAPSecurityConstants.java 957284 2010-06-23 17:53:31Z tv $
33 |  |
      */
34 | 0 |
     public class LDAPSecurityConstants
35 |  |
     {
36 |  |
         /** Property key */
37 |  |
         public static final String LDAP_ADMIN_USERNAME_KEY = "ldap.admin.username";
38 |  |
39 |  |
         /** Property key */
40 |  |
         public static final String LDAP_ADMIN_PASSWORD_KEY = "ldap.admin.password";
41 |  |
42 |  |
         /** Property key */
43 |  |
         public static final String LDAP_HOST_KEY = "ldap.host";
44 |  |
45 |  |
         /** Property default value */
46 |  |
         public static final String LDAP_HOST_DEFAULT = "localhost";
47 |  |
48 |  |
         /** Property key */
49 |  |
         public static final String LDAP_PORT_KEY = "ldap.port";
50 |  |
51 |  |
         /** Property default value */
52 |  |
         public static final String LDAP_PORT_DEFAULT = "389";
53 |  |
54 |  |
         /** Property key */
55 |  |
         public static final String LDAP_PROVIDER_KEY = "ldap.provider";
56 |  |
57 |  |
         /** Property default value */
58 |  |
         public static final String LDAP_PROVIDER_DEFAULT =
59 |  |
                 "com.sun.jndi.ldap.LdapCtxFactory";
60 |  |
61 |  |
         /** Property key */
62 |  |
         public static final String LDAP_BASE_SEARCH_KEY = "ldap.basesearch";
63 |  |
64 |  |
         /** Property key */
65 |  |
         public static final String LDAP_AUTH_KEY = "ldap.security.authentication";
66 |  |
67 |  |
         /** Property default value */
68 |  |
         public static final String LDAP_AUTH_DEFAULT = "simple";
69 |  |
70 |  |
         /** Property key */
71 |  |
         public static final String LDAP_USER_USERID_KEY = "ldap.user.userid";
72 |  |
73 |  |
         /** Property default value */
74 |  |
         public static final String LDAP_USER_USERID_DEFAULT = "uid";
75 |  |
76 |  |
         /** Property key */
77 |  |
         public static final String LDAP_USER_USERNAME_KEY = "ldap.user.username";
78 |  |
79 |  |
         /** Property default value */
80 |  |
         public static final String LDAP_USER_USERNAME_DEFAULT = "turbineUserUniqueId";
81 |  |
82 |  |
         /** Property key */
83 |  |
         public static final String LDAP_USER_FIRSTNAME_KEY = "ldap.user.firstname";
84 |  |
85 |  |
         /** Property default value */
86 |  |
         public static final String LDAP_USER_FIRSTNAME_DEFAULT = "turbineUserFirstName";
87 |  |
88 |  |
         /** Property key */
89 |  |
         public static final String LDAP_USER_LASTNAME_KEY = "ldap.user.lastname";
90 |  |
91 |  |
         /** Property default value */
92 |  |
         public static final String LDAP_USER_LASTNAME_DEFAULT = "turbineUserLastName";
93 |  |
94 |  |
         /** Property key */
95 |  |
         public static final String LDAP_USER_EMAIL_KEY = "ldap.user.email";
96 |  |
97 |  |
         /** Property default value */
98 |  |
         public static final String LDAP_USER_EMAIL_DEFAULT = "turbineUserMailAddress";
99 |  |
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 | 0 |
             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 | 0 |
             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 | 0 |
             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 | 0 |
             String str = getProperty(LDAP_ADMIN_USERNAME_KEY);
144 |  |
145 |  |
             /*
146 |  |
              * The adminUsername string contains some
147 |  |
              * characters that need to be transformed.
148 |  |
              */
149 | 0 |
             str = str.replace('/', '=');
150 | 0 |
             str = str.replace('%', ',');
151 | 0 |
             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 | 0 |
             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 | 0 |
             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 | 0 |
             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 | 0 |
             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 | 0 |
             String str = getProperty(LDAP_BASE_SEARCH_KEY);
197 |  |
198 |  |
             /*
199 |  |
              * The userBaseSearch string contains some
200 |  |
              * characters that need to be transformed.
201 |  |
              */
202 | 0 |
             str = str.replace('/', '=');
203 | 0 |
             str = str.replace('%', ',');
204 | 0 |
             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 | 0 |
             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 | 0 |
             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 | 0 |
             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 | 0 |
             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 | 0 |
             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 | 0 |
             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 | 0 |
             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 | 0 |
             return getProperty(LDAP_USER_EMAIL_KEY, LDAP_USER_EMAIL_DEFAULT);
280 |  |
         }
281 |  |
282 |  |
     }