%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.security.spi.impl.ldap.LdapRoleDaoImpl |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * 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 and |
|
15 | * limitations under the License. |
|
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 | 0 | super(); |
49 | 0 | } |
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 | 0 | super(ldapConfig); |
62 | 0 | } |
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 | 0 | Attributes attrs = new BasicAttributes(true); |
75 | 0 | BasicAttribute classes = new BasicAttribute("objectclass"); |
76 | ||
77 | 0 | for (int i=0;i<getObjectClasses().length;i++) |
78 | 0 | classes.add(getObjectClasses()[i]); |
79 | 0 | attrs.put(classes); |
80 | 0 | attrs.put(getEntryPrefix(), principalUid); |
81 | 0 | if(!StringUtils.isEmpty(getRoleObjectRequiredAttributeClasses())) |
82 | { |
|
83 | 0 | String key = getRoleObjectRequiredAttributeClasses(); |
84 | 0 | if ( key.indexOf(',') >= 0 ) |
85 | { |
|
86 | 0 | String[] allKeys = key.split(","); |
87 | 0 | for (int i=0; i<allKeys.length; i++) |
88 | 0 | attrs.put( allKeys[i], "" ); |
89 | 0 | } |
90 | else |
|
91 | { |
|
92 | 0 | attrs.put(getRoleObjectRequiredAttributeClasses(), ""); |
93 | } |
|
94 | } |
|
95 | 0 | for (int i=0;i<getAttributes().length;i++) |
96 | 0 | attrs.put(parseAttr(getAttributes()[i],principalUid)[0], parseAttr(getAttributes()[i],principalUid)[1]); |
97 | 0 | return attrs; |
98 | } |
|
99 | ||
100 | /** |
|
101 | * @see org.apache.jetspeed.security.spi.impl.ldap.LdapPrincipalDaoImpl#getDnSuffix() |
|
102 | */ |
|
103 | protected String getDnSuffix() |
|
104 | { |
|
105 | 0 | 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 | 0 | return new RolePrincipalImpl(principalUid); |
119 | } |
|
120 | ||
121 | protected String getEntryPrefix() { |
|
122 | 0 | return this.getRoleIdAttribute(); |
123 | } |
|
124 | ||
125 | protected String getSearchSuffix() { |
|
126 | 0 | return this.getRoleFilter(); |
127 | } |
|
128 | ||
129 | protected String getSearchDomain() { |
|
130 | 0 | return this.getRoleFilterBase(); |
131 | } |
|
132 | ||
133 | protected String[] getObjectClasses() { |
|
134 | 0 | return this.getRoleObjectClasses(); |
135 | } |
|
136 | ||
137 | protected String getUidAttributeForPrincipal() { |
|
138 | 0 | return this.getRoleUidAttribute(); |
139 | } |
|
140 | ||
141 | protected String[] getAttributes() { |
|
142 | 0 | return getRoleAttributes(); |
143 | } |
|
144 | ||
145 | ||
146 | } |
|
147 |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |