1 package org.apache.archiva.redback.rbac.ldap;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import com.google.common.base.Function;
23 import com.google.common.collect.Lists;
24 import org.apache.archiva.redback.common.ldap.MappingException;
25 import org.apache.archiva.redback.common.ldap.connection.LdapConnection;
26 import org.apache.archiva.redback.common.ldap.connection.LdapConnectionFactory;
27 import org.apache.archiva.redback.common.ldap.connection.LdapException;
28 import org.apache.archiva.redback.common.ldap.role.LdapRoleMapper;
29 import org.apache.archiva.redback.components.cache.Cache;
30 import org.apache.archiva.redback.configuration.UserConfiguration;
31 import org.apache.archiva.redback.configuration.UserConfigurationKeys;
32 import org.apache.archiva.redback.rbac.AbstractRBACManager;
33 import org.apache.archiva.redback.rbac.AbstractRole;
34 import org.apache.archiva.redback.rbac.Operation;
35 import org.apache.archiva.redback.rbac.Permission;
36 import org.apache.archiva.redback.rbac.RBACManager;
37 import org.apache.archiva.redback.rbac.RBACManagerListener;
38 import org.apache.archiva.redback.rbac.RBACObjectAssertions;
39 import org.apache.archiva.redback.rbac.RbacManagerException;
40 import org.apache.archiva.redback.rbac.RbacObjectInvalidException;
41 import org.apache.archiva.redback.rbac.RbacObjectNotFoundException;
42 import org.apache.archiva.redback.rbac.RbacPermanentException;
43 import org.apache.archiva.redback.rbac.Resource;
44 import org.apache.archiva.redback.rbac.Role;
45 import org.apache.archiva.redback.rbac.UserAssignment;
46 import org.apache.archiva.redback.users.User;
47 import org.apache.archiva.redback.users.UserManager;
48 import org.apache.archiva.redback.users.UserManagerException;
49 import org.apache.archiva.redback.users.ldap.ctl.LdapController;
50 import org.apache.archiva.redback.users.ldap.ctl.LdapControllerException;
51 import org.apache.commons.lang.StringUtils;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
54 import org.springframework.stereotype.Service;
56 import javax.annotation.PostConstruct;
57 import javax.inject.Inject;
58 import javax.inject.Named;
59 import javax.naming.NamingException;
60 import javax.naming.directory.DirContext;
61 import java.util.ArrayList;
62 import java.util.Collection;
63 import java.util.Collections;
64 import java.util.List;
69 * LdapRbacManager will read datas from ldap for mapping groups to role.
70 * Write operations will delegate to cached implementation.
72 * @author Olivier Lamy
74 @Service( "rbacManager#ldap" )
75 public class LdapRbacManager
76 extends AbstractRBACManager
77 implements RBACManager, RBACManagerListener
80 private Logger log = LoggerFactory.getLogger( getClass() );
83 @Named( value = "rbacManager#cached" )
84 private RBACManager rbacImpl;
87 @Named( value = "ldapRoleMapper#default" )
88 private LdapRoleMapper ldapRoleMapper;
91 @Named( value = "userConfiguration#default" )
92 private UserConfiguration userConf;
95 @Named( value = "userManager#ldap" )
96 private UserManager userManager;
99 private LdapConnectionFactory ldapConnectionFactory;
102 private LdapController ldapController;
104 private boolean writableLdap = false;
107 public void initialize()
109 this.writableLdap = userConf.getBoolean( UserConfigurationKeys.LDAP_WRITABLE, this.writableLdap );
113 public void addChildRole( Role role, Role childRole )
114 throws RbacObjectInvalidException, RbacManagerException
116 this.rbacImpl.addChildRole( role, childRole );
119 public void addListener( RBACManagerListener listener )
121 super.addListener( listener );
122 this.rbacImpl.addListener( listener );
125 public Operation createOperation( String name )
126 throws RbacManagerException
128 return this.rbacImpl.createOperation( name );
131 public Permission createPermission( String name )
132 throws RbacManagerException
134 return this.rbacImpl.createPermission( name );
137 public Permission createPermission( String name, String operationName, String resourceIdentifier )
138 throws RbacManagerException
140 return this.rbacImpl.createPermission( name, operationName, resourceIdentifier );
143 public Resource createResource( String identifier )
144 throws RbacManagerException
146 return this.rbacImpl.createResource( identifier );
149 public Role createRole( String name )
151 return this.rbacImpl.createRole( name );
154 public UserAssignment createUserAssignment( String username )
155 throws RbacManagerException
157 // TODO ldap cannot or isWritable ldap ?
158 return this.rbacImpl.createUserAssignment( username );
161 public void eraseDatabase()
165 LdapConnection ldapConnection = null;
166 DirContext context = null;
169 ldapConnection = ldapConnectionFactory.getConnection();
170 context = ldapConnection.getDirContext();
171 ldapRoleMapper.removeAllRoles( context );
173 catch ( MappingException e )
175 log.warn( "skip error removing all roles {}", e.getMessage() );
177 catch ( LdapException e )
179 log.warn( "skip error removing all roles {}", e.getMessage() );
183 closeContext( context );
184 closeLdapConnection( ldapConnection );
187 this.rbacImpl.eraseDatabase();
191 * @see org.apache.archiva.redback.rbac.RBACManager#getAllAssignableRoles()
193 public List<Role> getAllAssignableRoles()
194 throws RbacManagerException
198 Collection<String> roleNames = ldapRoleMapper.getLdapGroupMappings().values();
200 List<Role> roles = new ArrayList<Role>();
202 for ( String name : roleNames )
204 roles.add( new RoleImpl( name ) );
209 catch ( MappingException e )
211 throw new RbacManagerException( e.getMessage(), e );
215 public List<Operation> getAllOperations()
216 throws RbacManagerException
218 return this.rbacImpl.getAllOperations();
221 public List<Permission> getAllPermissions()
222 throws RbacManagerException
224 return this.rbacImpl.getAllPermissions();
227 public List<Resource> getAllResources()
228 throws RbacManagerException
230 return this.rbacImpl.getAllResources();
233 public List<Role> getAllRoles()
234 throws RbacManagerException
236 LdapConnection ldapConnection = null;
237 DirContext context = null;
240 ldapConnection = ldapConnectionFactory.getConnection();
241 context = ldapConnection.getDirContext();
243 List<String> groups = ldapRoleMapper.getAllGroups( context );
244 return mapToRoles( groups );
246 catch ( MappingException e )
248 throw new RbacManagerException( e.getMessage(), e );
250 catch ( LdapException e )
252 throw new RbacManagerException( e.getMessage(), e );
256 closeContext( context );
257 closeLdapConnection( ldapConnection );
259 //return this.rbacImpl.getAllRoles();
262 public List<UserAssignment> getAllUserAssignments()
263 throws RbacManagerException
265 LdapConnection ldapConnection = null;
266 DirContext context = null;
269 ldapConnection = ldapConnectionFactory.getConnection();
270 context = ldapConnection.getDirContext();
271 Map<String, Collection<String>> usersWithRoles = ldapController.findUsersWithRoles( context );
272 List<UserAssignment> userAssignments = new ArrayList<UserAssignment>( usersWithRoles.size() );
274 for ( Map.Entry<String, Collection<String>> entry : usersWithRoles.entrySet() )
276 UserAssignment userAssignment = new UserAssignmentImpl( entry.getKey(), entry.getValue() );
277 userAssignments.add( userAssignment );
280 return userAssignments;
282 catch ( LdapControllerException e )
284 throw new RbacManagerException( e.getMessage(), e );
286 catch ( LdapException e )
288 throw new RbacManagerException( e.getMessage(), e );
292 closeContext( context );
293 closeLdapConnection( ldapConnection );
297 protected void closeLdapConnection( LdapConnection ldapConnection )
299 if ( ldapConnection != null )
301 ldapConnection.close();
305 protected void closeContext( DirContext context )
307 if ( context != null )
313 catch ( NamingException e )
315 log.warn( "skip issue closing context: {}", e.getMessage() );
321 * public Map<String, List<Permission>> getAssignedPermissionMap( String username )
322 * throws RbacManagerException
324 * return this.rbacImpl.getAssignedPermissionMap( username );
328 /*public Set<Permission> getAssignedPermissions( String username )
329 throws RbacObjectNotFoundException, RbacManagerException
332 return this.rbacImpl.getAssignedPermissions( username );
334 private List<Role> mapToRoles( List<String> groups )
335 throws MappingException, RbacManagerException
337 if ( groups == null || groups.isEmpty() )
339 return Collections.emptyList();
342 List<Role> roles = new ArrayList<Role>( groups.size() );
343 Map<String, String> mappedGroups = ldapRoleMapper.getLdapGroupMappings();
344 for ( String group : groups )
346 String roleName = mappedGroups.get( group );
347 if ( roleName != null )
349 Role role = getRole( roleName );
360 public Collection<Role> getAssignedRoles( String username )
361 throws RbacManagerException
364 LdapConnection ldapConnection = null;
365 DirContext context = null;
370 ldapConnection = ldapConnectionFactory.getConnection();
371 context = ldapConnection.getDirContext();
372 List<String> roleNames = ldapRoleMapper.getRoles( username, context );
374 if ( roleNames.isEmpty() )
376 return Collections.emptyList();
379 List<Role> roles = new ArrayList<Role>( roleNames.size() );
381 for ( String name : roleNames )
383 roles.add( this.rbacImpl.getRole( name ) );// new RoleImpl( name ) );
388 catch ( MappingException e )
390 throw new RbacManagerException( e.getMessage(), e );
392 catch ( LdapException e )
394 throw new RbacManagerException( e.getMessage(), e );
398 public Collection<Role> getAssignedRoles( UserAssignment userAssignment )
399 throws RbacManagerException
401 return getAssignedRoles( userAssignment.getPrincipal() );
404 public Map<String, Role> getChildRoles( Role role )
405 throws RbacManagerException
407 return this.rbacImpl.getChildRoles( role );
410 public Map<String, Role> getParentRoles( Role role )
411 throws RbacManagerException
413 return this.rbacImpl.getParentRoles( role );
417 public Collection<Role> getEffectivelyAssignedRoles( String username )
418 throws RbacManagerException
421 return this.rbacImpl.getEffectivelyAssignedRoles( username );
425 * public Collection<Role> getEffectivelyUnassignedRoles( String username )
426 * throws RbacManagerException
429 * return this.rbacImpl.getEffectivelyUnassignedRoles( username );
433 public Set<Role> getEffectiveRoles( Role role )
434 throws RbacManagerException
436 return this.rbacImpl.getEffectiveRoles( role );
439 public Resource getGlobalResource()
440 throws RbacManagerException
442 return this.rbacImpl.getGlobalResource();
445 public Operation getOperation( String operationName )
446 throws RbacManagerException
448 return this.rbacImpl.getOperation( operationName );
451 public Permission getPermission( String permissionName )
452 throws RbacManagerException
454 return this.rbacImpl.getPermission( permissionName );
457 public Resource getResource( String resourceIdentifier )
458 throws RbacManagerException
460 return this.rbacImpl.getResource( resourceIdentifier );
463 public Role getRole( String roleName )
464 throws RbacManagerException
467 LdapConnection ldapConnection = null;
468 DirContext context = null;
469 //verify it's a ldap group
472 ldapConnection = ldapConnectionFactory.getConnection();
473 context = ldapConnection.getDirContext();
474 if ( !ldapRoleMapper.getAllRoles( context ).contains( roleName ) )
479 catch ( MappingException e )
481 throw new RbacManagerException( e.getMessage(), e );
483 catch ( LdapException e )
485 throw new RbacManagerException( e.getMessage(), e );
487 return this.rbacImpl.getRole( roleName );
490 public Map<String, Role> getRoles( Collection<String> roleNames )
491 throws RbacManagerException
493 return this.rbacImpl.getRoles( roleNames );
496 public Collection<Role> getUnassignedRoles( String username )
497 throws RbacManagerException
499 LdapConnection ldapConnection = null;
501 DirContext context = null;
506 ldapConnection = ldapConnectionFactory.getConnection();
508 context = ldapConnection.getDirContext();
510 List<String> allRoles = ldapRoleMapper.getAllRoles( context );
511 final List<String> userRoles = ldapRoleMapper.getRoles( username, context );
513 List<Role> unassignedRoles = new ArrayList<Role>();
515 for ( String roleName : allRoles )
517 if ( !userRoles.contains( roleName ) )
519 unassignedRoles.add( rbacImpl.getRole( roleName ) );
522 return unassignedRoles;
524 catch ( MappingException e )
526 throw new RbacManagerException( e.getMessage(), e );
528 catch ( LdapException e )
530 throw new RbacManagerException( e.getMessage(), e );
534 closeContext( context );
535 closeLdapConnection( ldapConnection );
539 public UserAssignment getUserAssignment( String username )
540 throws RbacManagerException
542 LdapConnection ldapConnection = null;
543 DirContext context = null;
546 ldapConnection = ldapConnectionFactory.getConnection();
547 context = ldapConnection.getDirContext();
548 List<String> roles = ldapRoleMapper.getRoles( username, context );
550 return new UserAssignmentImpl( username, roles );
552 catch ( MappingException e )
554 throw new RbacManagerException( e.getMessage(), e );
556 catch ( LdapException e )
558 throw new RbacManagerException( e.getMessage(), e );
562 closeContext( context );
563 closeLdapConnection( ldapConnection );
566 //return this.rbacImpl.getUserAssignment( username );
569 public List<UserAssignment> getUserAssignmentsForRoles( Collection<String> roleNames )
570 throws RbacManagerException
573 return this.rbacImpl.getUserAssignmentsForRoles( roleNames );
576 public boolean operationExists( Operation operation )
578 return this.rbacImpl.operationExists( operation );
581 public boolean operationExists( String name )
583 return this.rbacImpl.operationExists( name );
586 public boolean permissionExists( Permission permission )
588 return this.rbacImpl.permissionExists( permission );
591 public boolean permissionExists( String name )
593 return this.rbacImpl.permissionExists( name );
596 public void rbacInit( boolean freshdb )
598 if ( rbacImpl instanceof RBACManagerListener )
600 ( (RBACManagerListener) this.rbacImpl ).rbacInit( freshdb );
604 public void rbacPermissionRemoved( Permission permission )
606 if ( rbacImpl instanceof RBACManagerListener )
608 ( (RBACManagerListener) this.rbacImpl ).rbacPermissionRemoved( permission );
613 public void rbacPermissionSaved( Permission permission )
615 if ( rbacImpl instanceof RBACManagerListener )
617 ( (RBACManagerListener) this.rbacImpl ).rbacPermissionSaved( permission );
622 public void rbacRoleRemoved( Role role )
624 if ( rbacImpl instanceof RBACManagerListener )
626 ( (RBACManagerListener) this.rbacImpl ).rbacRoleRemoved( role );
631 public void rbacRoleSaved( Role role )
633 if ( rbacImpl instanceof RBACManagerListener )
635 ( (RBACManagerListener) this.rbacImpl ).rbacRoleSaved( role );
640 public void rbacUserAssignmentRemoved( UserAssignment userAssignment )
642 if ( rbacImpl instanceof RBACManagerListener )
644 ( (RBACManagerListener) this.rbacImpl ).rbacUserAssignmentRemoved( userAssignment );
649 public void rbacUserAssignmentSaved( UserAssignment userAssignment )
651 if ( rbacImpl instanceof RBACManagerListener )
653 ( (RBACManagerListener) this.rbacImpl ).rbacUserAssignmentSaved( userAssignment );
658 public void removeListener( RBACManagerListener listener )
660 this.rbacImpl.removeListener( listener );
663 public void removeOperation( Operation operation )
664 throws RbacManagerException
666 this.rbacImpl.removeOperation( operation );
669 public void removeOperation( String operationName )
670 throws RbacManagerException
672 this.rbacImpl.removeOperation( operationName );
675 public void removePermission( Permission permission )
676 throws RbacManagerException
678 this.rbacImpl.removePermission( permission );
681 public void removePermission( String permissionName )
682 throws RbacManagerException
684 this.rbacImpl.removePermission( permissionName );
687 public void removeResource( Resource resource )
688 throws RbacManagerException
690 this.rbacImpl.removeResource( resource );
693 public void removeResource( String resourceIdentifier )
694 throws RbacManagerException
696 this.rbacImpl.removeResource( resourceIdentifier );
699 public void removeRole( Role role )
700 throws RbacManagerException
702 RBACObjectAssertions.assertValid( role );
704 if ( role.isPermanent() )
706 throw new RbacPermanentException( "Unable to delete permanent role [" + role.getName() + "]" );
710 LdapConnection ldapConnection = null;
711 DirContext context = null;
714 ldapConnection = ldapConnectionFactory.getConnection();
715 context = ldapConnection.getDirContext();
716 ldapRoleMapper.removeRole( role.getName(), context );
718 catch ( MappingException e )
720 throw new RbacManagerException( e.getMessage(), e );
722 catch ( LdapException e )
724 throw new RbacManagerException( e.getMessage(), e );
726 fireRbacRoleRemoved( role );
730 public void removeRole( String roleName )
731 throws RbacManagerException
733 if ( roleName == null )
737 removeRole( new RoleImpl( roleName ) );
740 public void removeUserAssignment( String username )
741 throws RbacManagerException
743 // TODO ldap cannot or isWritable ldap ?
744 this.rbacImpl.removeUserAssignment( username );
747 public void removeUserAssignment( UserAssignment userAssignment )
748 throws RbacManagerException
750 // TODO ldap cannot or isWritable ldap ?
751 this.rbacImpl.removeUserAssignment( userAssignment );
754 public boolean resourceExists( Resource resource )
756 return this.rbacImpl.resourceExists( resource );
759 public boolean resourceExists( String identifier )
761 return this.rbacImpl.resourceExists( identifier );
765 public boolean roleExists( Role role )
766 throws RbacManagerException
772 return roleExists( role.getName() );
775 public boolean roleExists( String name )
776 throws RbacManagerException
778 if ( StringUtils.isEmpty( name ) )
782 LdapConnection ldapConnection = null;
783 DirContext context = null;
786 ldapConnection = ldapConnectionFactory.getConnection();
787 context = ldapConnection.getDirContext();
788 return ldapRoleMapper.getAllRoles( context ).contains( name );
790 catch ( MappingException e )
792 throw new RbacManagerException( e.getMessage(), e );
794 catch ( LdapException e )
796 throw new RbacManagerException( e.getMessage(), e );
800 closeContext( context );
801 closeLdapConnection( ldapConnection );
805 public Operation saveOperation( Operation operation )
806 throws RbacManagerException
808 return this.rbacImpl.saveOperation( operation );
811 public Permission savePermission( Permission permission )
812 throws RbacManagerException
814 return this.rbacImpl.savePermission( permission );
817 public Resource saveResource( Resource resource )
818 throws RbacManagerException
820 return this.rbacImpl.saveResource( resource );
823 public synchronized Role saveRole( Role role )
824 throws RbacManagerException
828 LdapConnection ldapConnection = null;
829 DirContext context = null;
832 ldapConnection = ldapConnectionFactory.getConnection();
833 context = ldapConnection.getDirContext();
834 ldapRoleMapper.saveRole( role.getName(), context );
835 if ( !role.getChildRoleNames().isEmpty() )
837 for ( String roleName : role.getChildRoleNames() )
839 ldapRoleMapper.saveRole( roleName, context );
842 fireRbacRoleSaved( role );
844 catch ( MappingException e )
846 throw new RbacManagerException( e.getMessage(), e );
848 catch ( LdapException e )
850 throw new RbacManagerException( e.getMessage(), e );
853 return this.rbacImpl.saveRole( role );
854 //return new RoleImpl( role.getName(), role.getPermissions() );
857 public synchronized void saveRoles( Collection<Role> roles )
858 throws RbacManagerException
862 LdapConnection ldapConnection = null;
863 DirContext context = null;
867 ldapConnection = ldapConnectionFactory.getConnection();
868 context = ldapConnection.getDirContext();
869 for ( Role role : roles )
871 ldapRoleMapper.saveRole( role.getName(), context );
872 fireRbacRoleSaved( role );
875 catch ( MappingException e )
877 throw new RbacManagerException( e.getMessage(), e );
879 catch ( LdapException e )
881 throw new RbacManagerException( e.getMessage(), e );
884 this.rbacImpl.saveRoles( roles );
888 public UserAssignment saveUserAssignment( UserAssignment userAssignment )
889 throws RbacManagerException
891 LdapConnection ldapConnection = null;
892 DirContext context = null;
895 if ( !userManager.userExists( userAssignment.getPrincipal() ) )
897 User user = userManager.createUser( userAssignment.getPrincipal(), null, null );
898 userManager.addUser( user );
900 ldapConnection = ldapConnectionFactory.getConnection();
901 context = ldapConnection.getDirContext();
902 List<String> allRoles = ldapRoleMapper.getAllRoles( context );
904 List<String> currentUserRoles = ldapRoleMapper.getRoles( userAssignment.getPrincipal(), context );
906 for ( String role : userAssignment.getRoleNames() )
908 if ( !currentUserRoles.contains( role ) && writableLdap )
910 // role exists in ldap ?
911 if ( !allRoles.contains( role ) )
913 ldapRoleMapper.saveRole( role, context );
914 allRoles.add( role );
916 ldapRoleMapper.saveUserRole( role, userAssignment.getPrincipal(), context );
917 currentUserRoles.add( role );
921 for ( String role : currentUserRoles )
923 if ( !userAssignment.getRoleNames().contains( role ) && writableLdap )
925 ldapRoleMapper.removeUserRole( role, userAssignment.getPrincipal(), context );
929 return userAssignment;
931 catch ( UserManagerException e )
933 throw new RbacManagerException( e.getMessage(), e );
935 catch ( MappingException e )
937 throw new RbacManagerException( e.getMessage(), e );
939 catch ( LdapException e )
941 throw new RbacManagerException( e.getMessage(), e );
945 closeContext( context );
946 closeLdapConnection( ldapConnection );
949 //this.rbacImpl.saveUserAssignment( userAssignment );
951 //return userAssignment;
954 public boolean userAssignmentExists( String principal )
957 return this.rbacImpl.userAssignmentExists( principal );
960 public boolean userAssignmentExists( UserAssignment assignment )
963 return this.rbacImpl.userAssignmentExists( assignment );
966 public RBACManager getRbacImpl()
971 public void setRbacImpl( RBACManager rbacImpl )
973 this.rbacImpl = rbacImpl;
976 public boolean isWritableLdap()
981 public void setWritableLdap( boolean writableLdap )
983 this.writableLdap = writableLdap;
986 public LdapRoleMapper getLdapRoleMapper()
988 return ldapRoleMapper;
991 public void setLdapRoleMapper( LdapRoleMapper ldapRoleMapper )
993 this.ldapRoleMapper = ldapRoleMapper;
996 private static class RoleImpl
1001 private String description;
1003 private List<Permission> permissions = new ArrayList<Permission>();
1005 private List<String> childRoleNames = new ArrayList<String>();
1007 private RoleImpl( String name )
1012 private RoleImpl( String name, List<Permission> permissions )
1015 this.permissions = permissions;
1018 public void addPermission( Permission permission )
1020 this.permissions.add( permission );
1023 public void addChildRoleName( String name )
1025 this.childRoleNames.add( name );
1028 public List<String> getChildRoleNames()
1030 return this.childRoleNames;
1033 public String getDescription()
1035 return this.description;
1038 public String getName()
1043 public List<Permission> getPermissions()
1045 return this.permissions;
1048 public boolean isAssignable()
1053 public void removePermission( Permission permission )
1055 this.permissions.remove( permission );
1058 public void setAssignable( boolean assignable )
1063 public void setChildRoleNames( List<String> names )
1065 this.childRoleNames = names;
1068 public void setDescription( String description )
1070 this.description = description;
1073 public void setName( String name )
1078 public void setPermissions( List<Permission> permissions )
1080 this.permissions = permissions;
1083 public boolean isPermanent()
1088 public void setPermanent( boolean permanent )
1094 public String toString()
1096 final StringBuilder sb = new StringBuilder();
1097 sb.append( "RoleImpl" );
1098 sb.append( "{name='" ).append( name ).append( '\'' );
1100 return sb.toString();
1104 public boolean equals( Object o )
1110 if ( o == null || getClass() != o.getClass() )
1115 RoleImpl role = (RoleImpl) o;
1117 if ( name != null ? !name.equals( role.name ) : role.name != null )
1126 public int hashCode()
1128 return name != null ? name.hashCode() : 0;
1132 private static class UserAssignmentImpl
1133 implements UserAssignment
1135 private String username;
1137 private List<String> roleNames;
1139 private boolean permanent;
1141 private UserAssignmentImpl( String username, Collection<String> roleNames )
1143 this.username = username;
1145 if ( roleNames == null )
1147 this.roleNames = new ArrayList<String>();
1151 this.roleNames = new ArrayList<String>( roleNames );
1155 public String getPrincipal()
1157 return this.username;
1160 public List<String> getRoleNames()
1162 return this.roleNames;
1165 public void addRoleName( Role role )
1171 this.roleNames.add( role.getName() );
1174 public void addRoleName( String roleName )
1176 if ( roleName == null )
1180 this.roleNames.add( roleName );
1183 public void removeRoleName( Role role )
1189 this.roleNames.remove( role.getName() );
1192 public void removeRoleName( String roleName )
1194 if ( roleName == null )
1198 this.roleNames.remove( roleName );
1201 public void setPrincipal( String principal )
1203 this.username = principal;
1206 public void setRoleNames( List<String> roles )
1208 this.roleNames = roles;
1211 public boolean isPermanent()
1213 return this.permanent;
1216 public void setPermanent( boolean permanent )
1218 this.permanent = permanent;
1222 public String toString()
1224 final StringBuilder sb = new StringBuilder();
1225 sb.append( "UserAssignmentImpl" );
1226 sb.append( "{username='" ).append( username ).append( '\'' );
1227 sb.append( ", roleNames=" ).append( roleNames );
1228 sb.append( ", permanent=" ).append( permanent );
1230 return sb.toString();