1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.security.spi.impl.ldap;
18
19 import java.security.Principal;
20
21 import javax.naming.directory.Attributes;
22 import javax.naming.directory.BasicAttribute;
23 import javax.naming.directory.BasicAttributes;
24
25 import org.apache.commons.lang.StringUtils;
26 import org.apache.jetspeed.security.SecurityException;
27 import org.apache.jetspeed.security.impl.GroupPrincipalImpl;
28
29 /***
30 * <p>
31 * DAO for handling group objects.
32 * </p>
33 *
34 * @author <a href="mailto:mike.long@dataline.com">Mike Long </a>, <a
35 * href="mailto:dlestrat@apache.org">David Le Strat</a>
36 */
37 public class LdapGroupDaoImpl extends LdapPrincipalDaoImpl
38 {
39
40 /***
41 * <p>
42 * Default constructor.
43 * </p>
44 *
45 * @throws SecurityException A {@link SecurityException}.
46 */
47 public LdapGroupDaoImpl() throws SecurityException
48 {
49 super();
50 }
51
52 /***
53 * <p>
54 * Initializes the dao.
55 * </p>
56 *
57 * @param ldapConfig Holds the ldap binding configuration.
58 * @throws SecurityException A {@link SecurityException}.
59 */
60 public LdapGroupDaoImpl(LdapBindingConfig ldapConfig) throws SecurityException
61 {
62 super(ldapConfig);
63 }
64
65 /***
66 * <p>
67 * A template method for defining the attributes for a particular LDAP class.
68 * </p>
69 *
70 * @param principalUid The principal uid.
71 * @return The LDAP attributes object for the particular class.
72 */
73 protected Attributes defineLdapAttributes(final String principalUid)
74 {
75 Attributes attrs = new BasicAttributes(true);
76 BasicAttribute classes = new BasicAttribute("objectclass");
77
78 for (int i=0 ; i<getObjectClasses().length ; i++)
79 classes.add(getObjectClasses()[i]);
80 attrs.put(classes);
81 attrs.put(getEntryPrefix(), principalUid);
82 if(!StringUtils.isEmpty(getGroupObjectRequiredAttributeClasses()))
83 attrs.put(getGroupObjectRequiredAttributeClasses(), "");
84 for (int i=0;i<getAttributes().length;i++)
85 attrs.put(parseAttr(getAttributes()[i],principalUid)[0], parseAttr(getAttributes()[i],principalUid)[1]);
86
87 return attrs;
88 }
89
90 /***
91 * @see org.apache.jetspeed.security.spi.impl.ldap.LdapPrincipalDaoImpl#getDnSuffix()
92 */
93 protected String getDnSuffix()
94 {
95 return getGroupFilterBase();
96 }
97
98 /***
99 * <p>
100 * Creates a GroupPrincipal object.
101 * </p>
102 *
103 * @param principalUid The principal uid.
104 * @return A group principal object.
105 */
106 protected Principal makePrincipal(String principalUid)
107 {
108 return new GroupPrincipalImpl(principalUid);
109 }
110
111
112 protected String getEntryPrefix() {
113 return this.getGroupIdAttribute();
114 }
115
116 protected String getSearchSuffix() {
117 return this.getGroupFilter();
118 }
119
120 protected String getSearchDomain() {
121 return this.getGroupFilterBase();
122 }
123
124 protected String[] getObjectClasses() {
125 return this.getGroupObjectClasses();
126 }
127
128 protected String getUidAttributeForPrincipal() {
129 return this.getGroupUidAttribute();
130 }
131
132 protected String[] getAttributes() {
133 return this.getGroupAttributes();
134 }
135
136
137 }