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 javax.naming.NamingException;
20 import javax.naming.directory.Attributes;
21 import javax.naming.directory.BasicAttribute;
22 import javax.naming.directory.BasicAttributes;
23
24 import org.apache.commons.lang.StringUtils;
25 import org.apache.jetspeed.security.SecurityException;
26
27 public class InitLdapSchema extends AbstractLdapDao
28 {
29
30 /***
31 * <p>
32 * Default constructor.
33 * </p>
34 *
35 * @throws SecurityException A {@link SecurityException}.
36 */
37 public InitLdapSchema() throws SecurityException
38 {
39 super();
40 }
41
42 /***
43 * <p>
44 * Initializes the LDAP schema.
45 * </p>
46 *
47 * @param ldapConfig Holds the ldap binding configuration.
48 * @throws SecurityException A {@link SecurityException}.
49 */
50 public InitLdapSchema(LdapBindingConfig ldapConfig) throws SecurityException
51 {
52 super(ldapConfig);
53 }
54
55 /***
56 * @see org.apache.jetspeed.security.spi.impl.ldap.AbstractLdapDao#getObjectClass()
57 */
58 protected String getObjectClass()
59 {
60
61 return null;
62 }
63
64 /***
65 * <p>
66 * Inits a given ou.
67 * </p>
68 *
69 * @param ou The org unit.
70 * @throws SecurityException
71 */
72 public void initOu(String ou) throws NamingException
73 {
74 if (!StringUtils.isEmpty(ou))
75 {
76 Attributes attrs = defineLdapAttributes(ou);
77 String dn = "ou=" + ou;
78 ctx.createSubcontext(dn, attrs);
79 }
80 }
81
82 public void initOu(String ou,String folder) throws NamingException
83 {
84 if (!StringUtils.isEmpty(ou))
85 {
86 Attributes attrs = defineLdapAttributes(ou);
87 ctx.createSubcontext("ou=" + ou + "," + folder, attrs);
88 }
89 }
90
91 /***
92 * <p>
93 * A template method for defining the attributes for a particular LDAP class.
94 * </p>
95 *
96 * @param principalUid The principal uid.
97 * @return the LDAP attributes object for the particular class.
98 */
99 protected Attributes defineLdapAttributes(String ou)
100 {
101 Attributes attrs = new BasicAttributes(true);
102 BasicAttribute classes = new BasicAttribute("objectclass");
103
104 classes.add("top");
105 classes.add("organizationalUnit");
106 attrs.put(classes);
107 attrs.put("ou", ou);
108
109 return attrs;
110 }
111
112 protected String getEntryPrefix()
113 {
114 return null;
115 }
116
117 protected String getSearchSuffix() {
118 return null;
119 }
120
121 protected String getSearchDomain() {
122 return null;
123 }
124
125 protected String[] getObjectClasses() {
126 return null;
127 }
128
129 protected String[] getAttributes() {
130 return null;
131 }
132
133 }