@ Override public void removeRole ( String username , String oldrole ) throws RolesException { List < String > users_with_role = new ArrayList < String > ( ) ; if ( user_list . containsKey ( username ) ) { List < String > roles_of_user = user_list . get ( username ) ; if ( roles_of_user . contains ( oldrole ) ) { // Update our user list roles_of_user . remove ( oldrole ) ; user_list . put ( username , roles_of_user ) ; // Update our roles list if ( role_list . containsKey ( oldrole ) ) users_with_role = role_list . get ( oldrole ) ; users_with_role . remove ( username ) ; if ( users_with_role . size ( ) < 1 ) { role_list . remove ( oldrole ) ; } else { role_list . put ( oldrole , users_with_role ) ; } // Don't forget to update our file_store String roles = StringUtils . join ( roles_of_user . toArray ( new String [ 0 ] ) , "," ) ; file_store . setProperty ( username , roles ) ; // And commit the file_store to disk try { saveRoles ( ) ; } catch ( IOException e ) { throw new RolesException ( e ) ; } } else { throw new RolesException ( "User '" + username + "' does not have the role '" + oldrole + "'!" ) ; } } else { throw new RolesException ( "User '" + username + "' does not exist!" ) ; } }
Remove a role from a user .