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 {
84 String[] required = getGroupObjectRequiredAttributeClasses().split(",");
85 for (int i=0; i<required.length; i++)
86 attrs.put(required[i], "");
87 }
88 for (int i=0;i<getAttributes().length;i++)
89 attrs.put(parseAttr(getAttributes()[i],principalUid)[0], parseAttr(getAttributes()[i],principalUid)[1]);
90
91 return attrs;
92 }
93
94 /***
95 * @see org.apache.jetspeed.security.spi.impl.ldap.LdapPrincipalDaoImpl#getDnSuffix()
96 */
97 protected String getDnSuffix()
98 {
99 return getGroupFilterBase();
100 }
101
102 /***
103 * <p>
104 * Creates a GroupPrincipal object.
105 * </p>
106 *
107 * @param principalUid The principal uid.
108 * @return A group principal object.
109 */
110 protected Principal makePrincipal(String principalUid)
111 {
112 return new GroupPrincipalImpl(principalUid);
113 }
114
115
116 protected String getEntryPrefix() {
117 return this.getGroupIdAttribute();
118 }
119
120 protected String getSearchSuffix() {
121 return this.getGroupFilter();
122 }
123
124 protected String getSearchDomain() {
125 return this.getGroupFilterBase();
126 }
127
128 protected String[] getObjectClasses() {
129 return this.getGroupObjectClasses();
130 }
131
132 protected String getUidAttributeForPrincipal() {
133 return this.getGroupUidAttribute();
134 }
135
136 protected String[] getAttributes() {
137 return this.getGroupAttributes();
138 }
139
140
141 }