/** * Removes a given role from this manager. * * @param role the role to remove, cannot be <code>null</code>. * @return <code>true</code> if the role was removed (i.e., it was managed by this manager), or * <code>false</code> if it was not found. */ public boolean removeRole(String name) { if (name == null) { throw new IllegalArgumentException("Name cannot be null!"); } checkPermissions(); // Cannot remove predefined roles... if (isPredefinedRole(name)) { return false; } try { Role result = m_store.removeRole(name); if (result != null) { // FELIX-3755: Remove the role as (required)member from all groups... removeRoleFromAllGroups(result); unwireChangeListener(result); m_roleChangeReflector.roleRemoved(result); return true; } return false; } catch (Exception e) { throw new BackendException("Failed to remove role " + name + "!", e); } }
/** * Adds a given role to this manager. * * @param role the role to add, cannot be <code>null</code>. If it is already contained by this * manager, this method will not do anything. * @return the given role if added, <code>null</code> otherwise. */ public Role addRole(String name, int type) { if ((name == null) || "".equals(name.trim())) { throw new IllegalArgumentException("Name cannot be null or empty!"); } if (type != Role.GROUP && type != Role.USER) { throw new IllegalArgumentException("Invalid role type!"); } checkPermissions(); try { Role result = m_store.addRole(name, type); if (result != null) { result = wireChangeListener(result); m_roleChangeReflector.roleAdded(result); } return result; } catch (Exception e) { throw new BackendException("Adding role " + name + " failed!", e); } }