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.RolePrincipalImpl;
28
29 /***
30 * <p>
31 * DAO for handling group objects.
32 * </p>
33 *
34 * @author Davy De Waele
35 */
36 public class LdapRoleDaoImpl extends LdapPrincipalDaoImpl
37 {
38
39 /***
40 * <p>
41 * Default constructor.
42 * </p>
43 *
44 * @throws SecurityException A {@link SecurityException}.
45 */
46 public LdapRoleDaoImpl() throws SecurityException
47 {
48 super();
49 }
50
51 /***
52 * <p>
53 * Initializes the dao.
54 * </p>
55 *
56 * @param ldapConfig Holds the ldap binding configuration.
57 * @throws SecurityException A {@link SecurityException}.
58 */
59 public LdapRoleDaoImpl(LdapBindingConfig ldapConfig) throws SecurityException
60 {
61 super(ldapConfig);
62 }
63
64 /***
65 * <p>
66 * A template method for defining the attributes for a particular LDAP class.
67 * </p>
68 *
69 * @param principalUid The principal uid.
70 * @return The LDAP attributes object for the particular class.
71 */
72 protected Attributes defineLdapAttributes(final String principalUid)
73 {
74 Attributes attrs = new BasicAttributes(true);
75 BasicAttribute classes = new BasicAttribute("objectclass");
76
77 for (int i=0;i<getObjectClasses().length;i++)
78 classes.add(getObjectClasses()[i]);
79 attrs.put(classes);
80 attrs.put(getEntryPrefix(), principalUid);
81 if(!StringUtils.isEmpty(getRoleObjectRequiredAttributeClasses()))
82 {
83 String key = getRoleObjectRequiredAttributeClasses();
84 if ( key.indexOf(',') >= 0 )
85 {
86 String[] allKeys = key.split(",");
87 for (int i=0; i<allKeys.length; i++)
88 attrs.put( allKeys[i], "" );
89 }
90 else
91 {
92 attrs.put(getRoleObjectRequiredAttributeClasses(), "");
93 }
94 }
95 for (int i=0;i<getAttributes().length;i++)
96 attrs.put(parseAttr(getAttributes()[i],principalUid)[0], parseAttr(getAttributes()[i],principalUid)[1]);
97 return attrs;
98 }
99
100 /***
101 * @see org.apache.jetspeed.security.spi.impl.ldap.LdapPrincipalDaoImpl#getDnSuffix()
102 */
103 protected String getDnSuffix()
104 {
105 return this.getRoleFilterBase();
106 }
107
108 /***
109 * <p>
110 * Creates a GroupPrincipal object.
111 * </p>
112 *
113 * @param principalUid The principal uid.
114 * @return A group principal object.
115 */
116 protected Principal makePrincipal(String principalUid)
117 {
118 return new RolePrincipalImpl(principalUid);
119 }
120
121 protected String getEntryPrefix() {
122 return this.getRoleIdAttribute();
123 }
124
125 protected String getSearchSuffix() {
126 return this.getRoleFilter();
127 }
128
129 protected String getSearchDomain() {
130 return this.getRoleFilterBase();
131 }
132
133 protected String[] getObjectClasses() {
134 return this.getRoleObjectClasses();
135 }
136
137 protected String getUidAttributeForPrincipal() {
138 return this.getRoleUidAttribute();
139 }
140
141 protected String[] getAttributes() {
142 return getRoleAttributes();
143 }
144
145
146 }
147