This project has retired. For details please refer to its Attic page.
LdapRoleMapper xref
View Javadoc

1   package org.apache.archiva.redback.common.ldap.role;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   * http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  import org.apache.archiva.redback.common.ldap.MappingException;
22  
23  import javax.naming.directory.DirContext;
24  import java.util.Collection;
25  import java.util.List;
26  import java.util.Map;
27  
28  /**
29   * will map ldap group to redback role
30   *
31   * @author Olivier Lamy
32   * @since 2.1
33   */
34  public interface LdapRoleMapper
35  {
36  
37      /**
38       * read all groups from ldap
39       *
40       * @return all LDAP groups
41       */
42      List<String> getAllGroups( DirContext context )
43          throws MappingException;
44  
45      /**
46       * read all ldap groups then map to corresponding role (if no mapping found group is ignored)
47       *
48       * @return all roles
49       * @throws Exception
50       */
51      List<String> getAllRoles( DirContext context )
52          throws MappingException;
53  
54      boolean hasRole( DirContext context, String role )
55          throws MappingException;
56  
57  
58      /**
59       * @return the base dn which contains all ldap groups
60       */
61      String getGroupsDn();
62  
63      /**
64       * @return the class used for group usually groupOfUniqueNames
65       */
66      String getLdapGroupClass();
67  
68      /**
69       * @param group ldap group
70       * @return uids of group members
71       * @throws MappingException
72       */
73      List<String> getGroupsMember( String group, DirContext context )
74          throws MappingException;
75  
76      List<String> getGroups( String username, DirContext context )
77          throws MappingException;
78  
79      List<String> getRoles( String username, DirContext context, Collection<String> realRoles )
80          throws MappingException;
81  
82  
83  
84      /**
85       * will save a ldap group corresponding to the mapping.
86       * <b>will do nothing in group already exists.</b>
87       *
88       * @param roleName
89       * @return <code>true</code> if role was added, <code>false</code> if role already exists
90       * @throws MappingException
91       */
92      boolean saveRole( String roleName, DirContext context )
93          throws MappingException;
94  
95      /**
96       * associate role to user in ldap
97       *
98       * @param roleName
99       * @param username
100      * @return <code>true</code> if role was added to user, <code>false</code> if role already exists for the user
101      * @throws MappingException
102      */
103     boolean saveUserRole( String roleName, String username, DirContext context )
104         throws MappingException;
105 
106     boolean removeUserRole( String roleName, String username, DirContext context )
107         throws MappingException;
108 
109     void removeAllRoles( DirContext context )
110         throws MappingException;
111 
112     void removeRole( String roleName, DirContext context )
113         throws MappingException;
114 
115     String getUserIdAttribute();
116 
117     boolean isUseDefaultRoleName();
118 
119 }