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.NamingException;
020: import javax.naming.directory.Attributes;
021: import javax.naming.directory.BasicAttribute;
022: import javax.naming.directory.BasicAttributes;
023:
024: import org.apache.commons.lang.StringUtils;
025: import org.apache.jetspeed.security.SecurityException;
026:
027: public class InitLdapSchema extends AbstractLdapDao {
028:
029: /**
030: * <p>
031: * Default constructor.
032: * </p>
033: *
034: * @throws SecurityException A {@link SecurityException}.
035: */
036: public InitLdapSchema() throws SecurityException {
037: super ();
038: }
039:
040: /**
041: * <p>
042: * Initializes the LDAP schema.
043: * </p>
044: *
045: * @param ldapConfig Holds the ldap binding configuration.
046: * @throws SecurityException A {@link SecurityException}.
047: */
048: public InitLdapSchema(LdapBindingConfig ldapConfig)
049: throws SecurityException {
050: super (ldapConfig);
051: }
052:
053: /**
054: * @see org.apache.jetspeed.security.spi.impl.ldap.AbstractLdapDao#getObjectClass()
055: */
056: protected String getObjectClass() {
057: // Implementation not required for initializing the ldap schema.
058: return null;
059: }
060:
061: /**
062: * <p>
063: * Inits a given ou.
064: * </p>
065: *
066: * @param ou The org unit.
067: * @throws SecurityException
068: */
069: public void initOu(String ou) throws NamingException {
070: if (!StringUtils.isEmpty(ou)) {
071: Attributes attrs = defineLdapAttributes(ou);
072: String dn = "ou=" + ou; // + "," + getDefaultSearchBase();
073: ctx.createSubcontext(dn, attrs);
074: }
075: }
076:
077: public void initOu(String ou, String folder) throws NamingException {
078: if (!StringUtils.isEmpty(ou)) {
079: Attributes attrs = defineLdapAttributes(ou);
080: ctx.createSubcontext("ou=" + ou + "," + folder, attrs);
081: }
082: }
083:
084: /**
085: * <p>
086: * A template method for defining the attributes for a particular LDAP class.
087: * </p>
088: *
089: * @param principalUid The principal uid.
090: * @return the LDAP attributes object for the particular class.
091: */
092: protected Attributes defineLdapAttributes(String ou) {
093: Attributes attrs = new BasicAttributes(true);
094: BasicAttribute classes = new BasicAttribute("objectclass");
095:
096: classes.add("top");
097: classes.add("organizationalUnit");
098: attrs.put(classes);
099: attrs.put("ou", ou);
100:
101: return attrs;
102: }
103:
104: protected String getEntryPrefix() {
105: return null;
106: }
107:
108: protected String getSearchSuffix() {
109: return null;
110: }
111:
112: protected String getSearchDomain() {
113: return null;
114: }
115:
116: protected String[] getObjectClasses() {
117: return null;
118: }
119:
120: protected String[] getAttributes() {
121: return null;
122: }
123:
124: }
|