List of usage examples for java.security.acl Group isMember
public boolean isMember(Principal member);
From source file:org.betaconceptframework.astroboa.context.SecurityContext.java
public boolean addRole(String role) { if (StringUtils.isBlank(role)) { return false; }//from ww w . j a v a 2 s .com Set<Group> groups = subject.getPrincipals(Group.class); boolean roleGroupFound = false; boolean roleAdded = false; String nameOfGroupWhichContainsTheRoles = AstroboaPrincipalName.Roles.toString(); if (groups != null) { for (Group group : groups) { if (StringUtils.equals(nameOfGroupWhichContainsTheRoles, group.getName())) { roleGroupFound = true; final CmsPrincipal rolePrincipal = new CmsPrincipal(role); if (!group.isMember(rolePrincipal)) { group.addMember(rolePrincipal); roleAdded = true; } break; } } } if (!roleGroupFound) { Group rolesPrincipal = new CmsGroup(nameOfGroupWhichContainsTheRoles); rolesPrincipal.addMember(new CmsPrincipal(role)); subject.getPrincipals().add(rolesPrincipal); roleAdded = true; } if (roleAdded) { this.roles.add(role); } return roleAdded; }
From source file:org.betaconceptframework.astroboa.context.SecurityContext.java
public boolean removeRole(String role) { if (StringUtils.isBlank(role)) { return false; }/*from w w w. j a v a 2 s.c o m*/ boolean roleHasBeenRemoved = false; Set<Group> groups = subject.getPrincipals(Group.class); if (groups != null) { String nameOfGroupWhichContainsTheRoles = AstroboaPrincipalName.Roles.toString(); for (Group group : groups) { if (StringUtils.equals(nameOfGroupWhichContainsTheRoles, group.getName())) { final CmsPrincipal rolePrincipal = new CmsPrincipal(role); if (group.isMember(rolePrincipal)) { roleHasBeenRemoved = group.removeMember(rolePrincipal); break; } } } } //remove role from the list as well if (roleHasBeenRemoved && this.roles.contains(role)) { this.roles.remove(role); } return roleHasBeenRemoved; }