001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.security.spi.impl.ldap;
018:
019: import javax.naming.ldap.LdapContext;
020:
021: import org.apache.commons.configuration.ConfigurationException;
022: import org.apache.commons.configuration.PropertiesConfiguration;
023: import org.apache.commons.lang.StringUtils;
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogFactory;
026:
027: /**
028: * <p>
029: * Holds the configuration for ldap binding.
030: * </p>
031: *
032: * @author <a href="mailto:dlestrat@apache.org">David Le Strat</a>
033: */
034: public class LdapBindingConfig {
035: /** The logger. */
036: private static final Log logger = LogFactory
037: .getLog(LdapBindingConfig.class);
038:
039: private LdapContext context;
040:
041: private String initialContextFactory;
042: private String ldapSocketFactory;
043: private String ldapScheme = "ldap";
044: private String ldapServerName;
045: private String ldapServerPort;
046: private String ldapSecurityLevel = "simple";
047: private String ldapSecurityProtocol;
048: private String rootDn;
049: private String rootPassword;
050: private String rootContext;
051:
052: private PropertiesConfiguration props = null;
053:
054: private String groupFilter;
055: private String userFilter;
056:
057: private String userRoleMembershipAttributes;
058:
059: private String groupMembershipAttributes;
060: private String userGroupMembershipAttributes;
061:
062: private String defaultSearchBase;
063:
064: private String groupFilterBase;
065: private String userFilterBase;
066:
067: private String groupIdAttribute;
068: private String userIdAttribute;
069:
070: private String uidAttribute;
071: private String memberShipSearchScope;
072:
073: private String[] groupObjectClasses;
074:
075: private String[] userObjectClasses;
076:
077: private String groupMembershipForRoleAttributes;
078:
079: private String groupUidAttribute;
080: private String userUidAttribute;
081:
082: private String[] groupAttributes;
083: private String[] userAttributes;
084:
085: private String groupObjectRequiredAttributeClasses;
086:
087: private String[] roleObjectClasses;
088: private String roleGroupMembershipForRoleAttributes;
089: private String[] roleAttributes;
090: private String roleObjectRequiredAttributeClasses;
091: private String roleFilter;
092: private String roleFilterBase;
093: private String roleIdAttribute;
094: private String roleUidAttribute;
095: private String roleMembershipAttributes;
096:
097: private String userPasswordAttribute;
098:
099: private String[] knownAttributes;
100:
101: public LdapBindingConfig() {
102: // allow for properties setting configuration instead of through one big ugly constructor call or external properties file
103: }
104:
105: public LdapBindingConfig(String factory, String name, String port,
106: String context, String dn, String password,
107: String roleFilter, String groupFilter, String userFilter,
108: String roleMembershipAttributes,
109: String userRoleMembershipAttributes,
110: String groupMembershipAttributes,
111: String userGroupMembershipAttributes,
112: String groupMembershipForRoleAttributes,
113: String roleGroupMembershipForRoleAttributes,
114: String defaultSearchBase, String roleFilterBase,
115: String groupFilterBase, String userFilterBase,
116: String roleObjectClasses, String groupObjectClasses,
117: String userObjectClasses, String roleIdAttribute,
118: String groupIdAttribute, String userIdAttribute,
119: String uidAttribute, String memberShipSearchScope,
120: String roleUidAttribute, String groupUidAttribute,
121: String userUidAttribute,
122: String roleObjectRequiredAttributeClasses,
123: String groupObjectRequiredAttributeClasses,
124: String userAttributes, String roleAttributes,
125: String groupAttributes, String userPasswordAttribute,
126: String knownAttributes) {
127: initialContextFactory = factory;
128: ldapServerName = name;
129: ldapServerPort = port;
130: rootContext = context;
131: rootDn = dn;
132: rootPassword = password;
133:
134: this .roleFilter = roleFilter;
135: this .groupFilter = groupFilter;
136: this .userFilter = userFilter;
137:
138: this .roleMembershipAttributes = roleMembershipAttributes;
139: this .userRoleMembershipAttributes = userRoleMembershipAttributes;
140:
141: this .groupMembershipAttributes = groupMembershipAttributes;
142: this .userGroupMembershipAttributes = userGroupMembershipAttributes;
143:
144: this .groupMembershipForRoleAttributes = groupMembershipForRoleAttributes;
145: this .roleGroupMembershipForRoleAttributes = roleGroupMembershipForRoleAttributes;
146: this .defaultSearchBase = defaultSearchBase;
147:
148: this .roleFilterBase = roleFilterBase;
149: this .groupFilterBase = groupFilterBase;
150: this .userFilterBase = userFilterBase;
151:
152: this .roleObjectClasses = StringUtils.split(roleObjectClasses,
153: ",");
154: this .groupObjectClasses = StringUtils.split(groupObjectClasses,
155: ",");
156: this .userObjectClasses = StringUtils.split(userObjectClasses,
157: ",");
158:
159: this .roleIdAttribute = roleIdAttribute;
160: this .groupIdAttribute = groupIdAttribute;
161: this .userIdAttribute = userIdAttribute;
162:
163: this .uidAttribute = uidAttribute;
164: this .memberShipSearchScope = memberShipSearchScope;
165:
166: this .roleUidAttribute = roleUidAttribute;
167: this .groupUidAttribute = groupUidAttribute;
168: this .userUidAttribute = userUidAttribute;
169:
170: this .roleObjectRequiredAttributeClasses = roleObjectRequiredAttributeClasses;
171: this .groupObjectRequiredAttributeClasses = groupObjectRequiredAttributeClasses;
172:
173: this .roleAttributes = StringUtils.split(roleAttributes, ",");
174: this .groupAttributes = StringUtils.split(groupAttributes, ",");
175: this .userAttributes = StringUtils.split(userAttributes, ",");
176:
177: this .userPasswordAttribute = userPasswordAttribute;
178:
179: this .knownAttributes = StringUtils.split(knownAttributes, ",");
180: }
181:
182: /**
183: * <p>
184: * Default constructor. By default instantiates LdapBindingConfig from
185: * JETSPEED-INF/ldap/ldap.properties in the classpath.
186: * </p>
187: */
188: public LdapBindingConfig(String ldapType) {
189: try {
190: props = new PropertiesConfiguration(
191: "JETSPEED-INF/directory/config/" + ldapType
192: + "/ldap.properties");
193: initialContextFactory = props
194: .getString("org.apache.jetspeed.ldap.initialContextFactory");
195: ldapServerName = props
196: .getString("org.apache.jetspeed.ldap.ldapServerName");
197: ldapServerPort = props
198: .getString("org.apache.jetspeed.ldap.ldapServerPort");
199: rootContext = props
200: .getString("org.apache.jetspeed.ldap.rootContext");
201: rootDn = props.getString("org.apache.jetspeed.ldap.rootDn");
202: rootPassword = props
203: .getString("org.apache.jetspeed.ldap.rootPassword");
204:
205: roleFilter = props
206: .getString("org.apache.jetspeed.ldap.RoleFilter");
207: groupFilter = props
208: .getString("org.apache.jetspeed.ldap.GroupFilter");
209: userFilter = props
210: .getString("org.apache.jetspeed.ldap.UserFilter");
211:
212: roleMembershipAttributes = props
213: .getString("org.apache.jetspeed.ldap.RoleMembershipAttributes");
214: userRoleMembershipAttributes = props
215: .getString("org.apache.jetspeed.ldap.UserRoleMembershipAttributes");
216:
217: groupMembershipAttributes = props
218: .getString("org.apache.jetspeed.ldap.GroupMembershipAttributes");
219: userGroupMembershipAttributes = props
220: .getString("org.apache.jetspeed.ldap.UserGroupMembershipAttributes");
221:
222: groupMembershipForRoleAttributes = props
223: .getString("org.apache.jetspeed.ldap.GroupMembershipForRoleAttributes");
224: roleGroupMembershipForRoleAttributes = props
225: .getString("org.apache.jetspeed.ldap.RoleGroupMembershipForRoleAttributes");
226:
227: defaultSearchBase = props
228: .getString("org.apache.jetspeed.ldap.DefaultSearchBase");
229:
230: roleFilterBase = props
231: .getString("org.apache.jetspeed.ldap.RoleFilterBase");
232: groupFilterBase = props
233: .getString("org.apache.jetspeed.ldap.GroupFilterBase");
234: userFilterBase = props
235: .getString("org.apache.jetspeed.ldap.UserFilterBase");
236:
237: this .roleObjectClasses = StringUtils
238: .split(
239: props
240: .getString("org.apache.jetspeed.ldap.RoleObjectClasses"),
241: ",");
242: this .groupObjectClasses = StringUtils
243: .split(
244: props
245: .getString("org.apache.jetspeed.ldap.GroupObjectClasses"),
246: ",");
247: this .userObjectClasses = StringUtils
248: .split(
249: props
250: .getString("org.apache.jetspeed.ldap.UserObjectClasses"),
251: ",");
252:
253: roleIdAttribute = props
254: .getString("org.apache.jetspeed.ldap.RoleIdAttribute");
255: groupIdAttribute = props
256: .getString("org.apache.jetspeed.ldap.GroupIdAttribute");
257: userIdAttribute = props
258: .getString("org.apache.jetspeed.ldap.UserIdAttribute");
259:
260: uidAttribute = props
261: .getString("org.apache.jetspeed.ldap.UidAttribute");
262: memberShipSearchScope = props
263: .getString("org.apache.jetspeed.ldap.MemberShipSearchScope");
264:
265: this .roleUidAttribute = props
266: .getString("org.apache.jetspeed.ldap.roleUidAttribute");
267: this .groupUidAttribute = props
268: .getString("org.apache.jetspeed.ldap.groupUidAttribute");
269: this .userUidAttribute = props
270: .getString("org.apache.jetspeed.ldap.userUidAttribute");
271:
272: this .roleObjectRequiredAttributeClasses = props
273: .getString("org.apache.jetspeed.ldap.roleObjectRequiredAttributeClasses");
274: this .groupObjectRequiredAttributeClasses = props
275: .getString("org.apache.jetspeed.ldap.groupObjectRequiredAttributeClasses");
276:
277: this .roleAttributes = StringUtils
278: .split(
279: props
280: .getString("org.apache.jetspeed.ldap.roleAttributes"),
281: ",");
282: this .groupAttributes = StringUtils
283: .split(
284: props
285: .getString("org.apache.jetspeed.ldap.groupAttributes"),
286: ",");
287: this .userAttributes = StringUtils
288: .split(
289: props
290: .getString("org.apache.jetspeed.ldap.userAttributes"),
291: ",");
292: this .userPasswordAttribute = props
293: .getString("org.apache.jetspeed.ldap.userPasswordAttribute");
294:
295: this .knownAttributes = StringUtils
296: .split(
297: props
298: .getString("org.apache.jetspeed.ldap.knownAttributes"),
299: ",");
300: } catch (ConfigurationException ce) {
301: logger
302: .error("Could not configure LdapBindingConfig: "
303: + ce);
304: }
305: }
306:
307: LdapContext getContext() {
308: return context;
309: }
310:
311: void setContext(LdapContext context) {
312: this .context = context;
313: }
314:
315: /**
316: * @return Returns the initialContextFactory.
317: */
318: public String getInitialContextFactory() {
319: return initialContextFactory;
320: }
321:
322: /**
323: * @param initialContextFactory The initialContextFactory to set.
324: */
325: public void setInitialContextFactory(String initialContextFactory) {
326: this .initialContextFactory = initialContextFactory;
327: }
328:
329: /**
330: * @return the ldapScheme
331: */
332: public String getLdapScheme() {
333: return ldapScheme;
334: }
335:
336: /**
337: * @param ldapScheme the ldapScheme to set
338: */
339: public void setLdapScheme(String ldapScheme) {
340: this .ldapScheme = ldapScheme;
341: }
342:
343: /**
344: * @return the ldapSocketFactory
345: */
346: public String getLdapSocketFactory() {
347: return ldapSocketFactory;
348: }
349:
350: /**
351: * @param ldapSocketFactory the ldapSocketFactory to set
352: */
353: public void setLdapSocketFactory(String ldapSocketFactory) {
354: this .ldapSocketFactory = ldapSocketFactory;
355: }
356:
357: /**
358: * @return Returns the ldapServerName.
359: */
360: public String getLdapServerName() {
361: return ldapServerName;
362: }
363:
364: /**
365: * @param ldapServerName The ldapServerName to set.
366: */
367: public void setLdapServerName(String ldapServerName) {
368: this .ldapServerName = ldapServerName;
369: }
370:
371: /**
372: * @return Returns the ldapServerPort.
373: */
374: public String getLdapServerPort() {
375: return ldapServerPort;
376: }
377:
378: /**
379: * @param ldapServerPort The ldapServerPort to set.
380: */
381: public void setLdapServerPort(String ldapServerPort) {
382: this .ldapServerPort = ldapServerPort;
383: }
384:
385: /**
386: * @return the ldapSecurityLevel
387: */
388: public String getLdapSecurityLevel() {
389: return ldapSecurityLevel;
390: }
391:
392: /**
393: * @param ldapSecurityLevel the ldapSecurityLevel to set
394: */
395: public void setLdapSecurityLevel(String ldapSecurityLevel) {
396: this .ldapSecurityLevel = ldapSecurityLevel;
397: }
398:
399: /**
400: * @return the ldapSecurityProtocol
401: */
402: public String getLdapSecurityProtocol() {
403: return ldapSecurityProtocol;
404: }
405:
406: /**
407: * @param ldapSecurityProtocol the ldapSecurityProtocol to set
408: */
409: public void setLdapSecurityProtocol(String ldapSecurityProtocol) {
410: this .ldapSecurityProtocol = ldapSecurityProtocol;
411: }
412:
413: /**
414: * @return Returns the rootContext.
415: */
416: public String getRootContext() {
417: return rootContext;
418: }
419:
420: /**
421: * @param rootContext The rootContext to set.
422: */
423: public void setRootContext(String rootContext) {
424: this .rootContext = rootContext;
425: }
426:
427: /**
428: * @return Returns the rootDn.
429: */
430: public String getRootDn() {
431: return rootDn;
432: }
433:
434: /**
435: * @param rootDn The rootDn to set.
436: */
437: public void setRootDn(String rootDn) {
438: this .rootDn = rootDn;
439: }
440:
441: /**
442: * @return Returns the rootPassword.
443: */
444: public String getRootPassword() {
445: return rootPassword;
446: }
447:
448: /**
449: * @param rootPassword The rootPassword to set.
450: */
451: public void setRootPassword(String rootPassword) {
452: this .rootPassword = rootPassword;
453: }
454:
455: public String getUserFilter() {
456: return userFilter;
457: }
458:
459: public void setUserFilter(String userFilter) {
460: this .userFilter = userFilter;
461: }
462:
463: public String getUserFilterBase() {
464: return userFilterBase;
465: }
466:
467: public void setUserFilterBase(String userFilterBase) {
468: this .userFilterBase = userFilterBase;
469: }
470:
471: public String getUserGroupMembershipAttributes() {
472: return userGroupMembershipAttributes;
473: }
474:
475: public void setUserGroupMembershipAttributes(
476: String userGroupMembershipAttributes) {
477: this .userGroupMembershipAttributes = userGroupMembershipAttributes;
478: }
479:
480: public String getUserRoleMembershipAttributes() {
481: return userRoleMembershipAttributes;
482: }
483:
484: public void setUserRoleMembershipAttributes(
485: String userRoleMembershipAttributes) {
486: this .userRoleMembershipAttributes = userRoleMembershipAttributes;
487: }
488:
489: public String getDefaultSearchBase() {
490: return defaultSearchBase;
491: }
492:
493: public void setDefaultSearchBase(String defaultSearchBase) {
494: this .defaultSearchBase = defaultSearchBase;
495: }
496:
497: public String getGroupFilter() {
498: return groupFilter;
499: }
500:
501: public void setGroupFilter(String groupFilter) {
502: this .groupFilter = groupFilter;
503: }
504:
505: public String getGroupFilterBase() {
506: return groupFilterBase;
507: }
508:
509: public void setGroupFilterBase(String groupFilterBase) {
510: this .groupFilterBase = groupFilterBase;
511: }
512:
513: public String getGroupMembershipAttributes() {
514: return groupMembershipAttributes;
515: }
516:
517: public void setGroupMembershipAttributes(
518: String groupMembershipAttributes) {
519: this .groupMembershipAttributes = groupMembershipAttributes;
520: }
521:
522: public String getGroupIdAttribute() {
523: return groupIdAttribute;
524: }
525:
526: public void setGroupIdAttribute(String groupIdAttribute) {
527: this .groupIdAttribute = groupIdAttribute;
528: }
529:
530: public String getUserIdAttribute() {
531: return userIdAttribute;
532: }
533:
534: public void setUserIdAttribute(String userIdAttribute) {
535: this .userIdAttribute = userIdAttribute;
536: }
537:
538: public String[] getGroupObjectClasses() {
539: return groupObjectClasses;
540: }
541:
542: public void setGroupObjectClasses(String[] groupObjectClasses) {
543: this .groupObjectClasses = groupObjectClasses;
544: }
545:
546: public String[] getUserObjectClasses() {
547: return userObjectClasses;
548: }
549:
550: public void setUserObjectClasses(String[] userObjectClasses) {
551: this .userObjectClasses = userObjectClasses;
552: }
553:
554: public String getGroupMembershipForRoleAttributes() {
555: return this .groupMembershipForRoleAttributes;
556: }
557:
558: public void setGroupMembershipForRoleAttributes(
559: String groupMembershipForRoleAttributes) {
560: this .groupMembershipForRoleAttributes = groupMembershipForRoleAttributes;
561: }
562:
563: public String getUidAttribute() {
564: return uidAttribute;
565: }
566:
567: public void setUidAttribute(String uidAttribute) {
568: this .uidAttribute = uidAttribute;
569: }
570:
571: public String getMemberShipSearchScope() {
572: return memberShipSearchScope;
573: }
574:
575: public void setMemberShipSearchScope(String memberShipSearchScope) {
576: this .memberShipSearchScope = memberShipSearchScope;
577: }
578:
579: public String getGroupUidAttribute() {
580: return this .groupUidAttribute;
581: }
582:
583: public void setGroupUidAttribute(String groupUidAttribute) {
584: this .groupUidAttribute = groupUidAttribute;
585: }
586:
587: public String getUserUidAttribute() {
588: return this .userUidAttribute;
589: }
590:
591: public void setUserUidAttribute(String userUidAttribute) {
592: this .userUidAttribute = userUidAttribute;
593: }
594:
595: public String getGroupObjectRequiredAttributeClasses() {
596: return groupObjectRequiredAttributeClasses;
597: }
598:
599: public void setGroupObjectRequiredAttributeClasses(
600: String groupObjectRequiredAttributeClasses) {
601: this .groupObjectRequiredAttributeClasses = groupObjectRequiredAttributeClasses;
602: }
603:
604: public String[] getGroupAttributes() {
605: return groupAttributes;
606: }
607:
608: public void setGroupAttributes(String[] groupAttributes) {
609: this .groupAttributes = groupAttributes;
610: }
611:
612: public String[] getUserAttributes() {
613: return userAttributes;
614: }
615:
616: public void setUserAttributes(String[] userAttributes) {
617: this .userAttributes = userAttributes;
618: }
619:
620: public String getRoleObjectRequiredAttributeClasses() {
621: return roleObjectRequiredAttributeClasses;
622: }
623:
624: public void setRoleObjectRequiredAttributeClasses(
625: String roleObjectRequiredAttributeClasses) {
626: this .roleObjectRequiredAttributeClasses = roleObjectRequiredAttributeClasses;
627: }
628:
629: public String[] getRoleAttributes() {
630: return roleAttributes;
631: }
632:
633: public void setRoleAttributes(String[] roleAttributes) {
634: this .roleAttributes = roleAttributes;
635: }
636:
637: public String[] getRoleObjectClasses() {
638: return roleObjectClasses;
639: }
640:
641: public void setRoleObjectClasses(String[] roleObjectClasses) {
642: this .roleObjectClasses = roleObjectClasses;
643: }
644:
645: public String getRoleGroupMembershipForRoleAttributes() {
646: return this .roleGroupMembershipForRoleAttributes;
647: }
648:
649: public void setRoleGroupMembershipForRoleAttributes(
650: String roleGroupMembershipForRoleAttributes) {
651: this .roleGroupMembershipForRoleAttributes = roleGroupMembershipForRoleAttributes;
652: }
653:
654: public String getRoleFilter() {
655: return roleFilter;
656: }
657:
658: public void setRoleFilter(String roleFilter) {
659: this .roleFilter = roleFilter;
660: }
661:
662: public String getRoleFilterBase() {
663: return roleFilterBase;
664: }
665:
666: public void setRoleFilterBase(String roleFilterBase) {
667: this .roleFilterBase = roleFilterBase;
668: }
669:
670: public String getRoleMembershipAttributes() {
671: return roleMembershipAttributes;
672: }
673:
674: public void setRoleMembershipAttributes(
675: String roleMembershipAttributes) {
676: this .roleMembershipAttributes = roleMembershipAttributes;
677: }
678:
679: public String getRoleUidAttribute() {
680: return this .roleUidAttribute;
681: }
682:
683: public void setRoleUidAttribute(String roleUidAttribute) {
684: this .roleUidAttribute = roleUidAttribute;
685: }
686:
687: public String getRoleIdAttribute() {
688: return roleIdAttribute;
689: }
690:
691: public void setRoleIdAttribute(String roleIdAttribute) {
692: this .roleIdAttribute = roleIdAttribute;
693: }
694:
695: public String getUserPasswordAttribute() {
696: return userPasswordAttribute;
697: }
698:
699: public void setUserPasswordAttribute(String userPasswordAttribute) {
700: this .userPasswordAttribute = userPasswordAttribute;
701: }
702:
703: public String[] getKnownAttributes() {
704: return this .knownAttributes;
705: }
706:
707: public void setKnownAttributes(String[] knownAttributes) {
708: this.knownAttributes = knownAttributes;
709: }
710:
711: }
|