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 java.security.Principal;
020:
021: import javax.naming.directory.Attributes;
022: import javax.naming.directory.BasicAttribute;
023: import javax.naming.directory.BasicAttributes;
024:
025: import org.apache.commons.lang.StringUtils;
026: import org.apache.jetspeed.security.SecurityException;
027: import org.apache.jetspeed.security.impl.GroupPrincipalImpl;
028:
029: /**
030: * <p>
031: * DAO for handling group objects.
032: * </p>
033: *
034: * @author <a href="mailto:mike.long@dataline.com">Mike Long </a>, <a
035: * href="mailto:dlestrat@apache.org">David Le Strat</a>
036: */
037: public class LdapGroupDaoImpl extends LdapPrincipalDaoImpl {
038:
039: /**
040: * <p>
041: * Default constructor.
042: * </p>
043: *
044: * @throws SecurityException A {@link SecurityException}.
045: */
046: public LdapGroupDaoImpl() throws SecurityException {
047: super ();
048: }
049:
050: /**
051: * <p>
052: * Initializes the dao.
053: * </p>
054: *
055: * @param ldapConfig Holds the ldap binding configuration.
056: * @throws SecurityException A {@link SecurityException}.
057: */
058: public LdapGroupDaoImpl(LdapBindingConfig ldapConfig)
059: throws SecurityException {
060: super (ldapConfig);
061: }
062:
063: /**
064: * <p>
065: * A template method for defining the attributes for a particular LDAP class.
066: * </p>
067: *
068: * @param principalUid The principal uid.
069: * @return The LDAP attributes object for the particular class.
070: */
071: protected Attributes defineLdapAttributes(final String principalUid) {
072: Attributes attrs = new BasicAttributes(true);
073: BasicAttribute classes = new BasicAttribute("objectclass");
074:
075: for (int i = 0; i < getObjectClasses().length; i++)
076: classes.add(getObjectClasses()[i]);
077: attrs.put(classes);
078: attrs.put(getEntryPrefix(), principalUid);
079: if (!StringUtils
080: .isEmpty(getGroupObjectRequiredAttributeClasses())) {
081: String[] required = getGroupObjectRequiredAttributeClasses()
082: .split(",");
083: for (int i = 0; i < required.length; i++)
084: attrs.put(required[i], "");
085: }
086: for (int i = 0; i < getAttributes().length; i++)
087: attrs.put(parseAttr(getAttributes()[i], principalUid)[0],
088: parseAttr(getAttributes()[i], principalUid)[1]);
089:
090: return attrs;
091: }
092:
093: /**
094: * @see org.apache.jetspeed.security.spi.impl.ldap.LdapPrincipalDaoImpl#getDnSuffix()
095: */
096: protected String getDnSuffix() {
097: return getGroupFilterBase();
098: }
099:
100: /**
101: * <p>
102: * Creates a GroupPrincipal object.
103: * </p>
104: *
105: * @param principalUid The principal uid.
106: * @return A group principal object.
107: */
108: protected Principal makePrincipal(String principalUid) {
109: return new GroupPrincipalImpl(principalUid);
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: }
|