1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17packageorg.apache.jetspeed.security.spi.impl.ldap;
1819import java.security.Principal;
2021import javax.naming.directory.Attributes;
22import javax.naming.directory.BasicAttribute;
23import javax.naming.directory.BasicAttributes;
2425import org.apache.commons.lang.StringUtils;
26import org.apache.jetspeed.security.SecurityException;
27import org.apache.jetspeed.security.impl.GroupPrincipalImpl;
2829/***30 * <p>31 * DAO for handling group objects.32 * </p>33 * 34 * @author <a href="mailto:mike.long@dataline.com">Mike Long </a>, <a35 * href="mailto:dlestrat@apache.org">David Le Strat</a>36 */37publicclassLdapGroupDaoImplextendsLdapPrincipalDaoImpl38 {
3940/***41 * <p>42 * Default constructor.43 * </p>44 * 45 * @throws SecurityException A {@link SecurityException}.46 */47publicLdapGroupDaoImpl() throws SecurityException
48 {
49super();
50 }
5152/***53 * <p>54 * Initializes the dao.55 * </p>56 * 57 * @param ldapConfig Holds the ldap binding configuration.58 * @throws SecurityException A {@link SecurityException}.59 */60publicLdapGroupDaoImpl(LdapBindingConfig ldapConfig) throws SecurityException
61 {
62super(ldapConfig);
63 }
6465/***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 */73protected Attributes defineLdapAttributes(final String principalUid)
74 {
75 Attributes attrs = new BasicAttributes(true);
76 BasicAttribute classes = new BasicAttribute("objectclass");
7778for (int i=0 ; i<getObjectClasses().length ; i++)
79 classes.add(getObjectClasses()[i]);
80 attrs.put(classes);
81 attrs.put(getEntryPrefix(), principalUid);
82if(!StringUtils.isEmpty(getGroupObjectRequiredAttributeClasses()))
83 {
84 String[] required = getGroupObjectRequiredAttributeClasses().split(",");
85for (int i=0; i<required.length; i++)
86 attrs.put(required[i], "");
87 }
88for (int i=0;i<getAttributes().length;i++)
89 attrs.put(parseAttr(getAttributes()[i],principalUid)[0], parseAttr(getAttributes()[i],principalUid)[1]);
9091return attrs;
92 }
9394/***95 * @see org.apache.jetspeed.security.spi.impl.ldap.LdapPrincipalDaoImpl#getDnSuffix()96 */97protected String getDnSuffix()
98 {
99return getGroupFilterBase();
100 }
101102/***103 * <p>104 * Creates a GroupPrincipal object.105 * </p>106 * 107 * @param principalUid The principal uid.108 * @return A group principal object.109 */110protected Principal makePrincipal(String principalUid)
111 {
112returnnewGroupPrincipalImpl(principalUid);
113 }
114115116protected String getEntryPrefix() {
117returnthis.getGroupIdAttribute();
118 }
119120protected String getSearchSuffix() {
121returnthis.getGroupFilter();
122 }
123124protected String getSearchDomain() {
125returnthis.getGroupFilterBase();
126 }
127128protected String[] getObjectClasses() {
129returnthis.getGroupObjectClasses();
130 }
131132protected String getUidAttributeForPrincipal() {
133returnthis.getGroupUidAttribute();
134 }
135136protected String[] getAttributes() {
137returnthis.getGroupAttributes();
138 }
139140141 }