@Override public boolean isMember(Principal member) { if (_members.containsKey(member)) { return true; } for (Principal principal : _members.values()) { if (principal instanceof Group) { Group group = (Group)principal; if (group.isMember(member)) { return true; } } } return false; }
@Override public boolean isMember(Principal member) { return group.isMember(member); }
/** Returns true if the passed principal is a member of the active group. This method does a recursive search, so if a principal belongs to a group which is a member of this group, true is returned. @param member the principal whose membership is to be checked. @return true if the principal is a member of this group, false otherwise. */ public boolean isMember(Principal member) { if( rolesStack.size() == 0 ) return false; Group activeGroup = (Group) rolesStack.getFirst(); boolean isMember = activeGroup.isMember(member); return isMember; }
public boolean isMember(Principal member) { if ( members.contains(member) ) { return true; } else { for (Principal m : members) { if (m instanceof Group && ((Group) m).isMember(member)) { return true; } } } return false; }
/** Returns true if the passed principal is a member of the active group. This method does a recursive search, so if a principal belongs to a group which is a member of this group, true is returned. @param member the principal whose membership is to be checked. @return true if the principal is a member of this group, false otherwise. */ public boolean isMember(Principal member) { if( rolesStack.size() == 0 ) return false; Group activeGroup = (Group) rolesStack.getFirst(); boolean isMember = activeGroup.isMember(member); return isMember; }
public boolean isMember(Principal member) { if (members.contains(member)) { return true; } else { for (Principal m : members) { if (m instanceof Group && ((Group)m).isMember(member)) { return true; } } } return false; }
@Override public boolean isMember(final Principal user) { boolean isMember = this.members.containsKey(user); if (!isMember) { final Collection<Principal> values = this.members.values(); for (final Principal principal : values) { if (principal instanceof Group) { final Group group = (Group) principal; isMember = group.isMember(user); if (isMember) { break; } } } } return isMember; }
@Override public boolean isMember(final Principal user) { boolean isMember = this.members.containsKey(user); if (!isMember) { final Collection<Principal> values = this.members.values(); for (final Principal principal : values) { if (principal instanceof Group) { final Group group = (Group) principal; isMember = group.isMember(user); if (isMember) { break; } } } } return isMember; }
public boolean isMember(Principal member) { boolean isMember = _members.containsKey(member); if (!isMember) { Iterator<Principal> itr = _members.values().iterator(); while (!isMember && itr.hasNext()) { Principal principal = itr.next(); if (principal instanceof Group) { Group group = (Group)principal; isMember = group.isMember(member); } } } return isMember; }
/** * Returns true if the passed principal is a member of the group. * @param principal the principal whose members are being checked. * @param member the principal whose membership is to be checked. * @return true if the principal is a member of this group, false otherwise. */ public static boolean isMember(Principal principal, Principal member) { if (principal instanceof Group) { return ((Group) principal).isMember(member); } if (principal instanceof GroupPrincipal) { return ((GroupPrincipal) principal).isMember(member); } return false; } }
/** * Returns true if the passed principal is a member of the group. * @param principal the principal whose members are being checked. * @param member the principal whose membership is to be checked. * @return true if the principal is a member of this group, false otherwise. */ public static boolean isMember(@NotNull Principal principal, @NotNull Principal member) { if (principal instanceof Group) { return ((Group) principal).isMember(member); } if (principal instanceof GroupPrincipal) { return ((GroupPrincipal) principal).isMember(member); } return false; }
/** * Returns true if the passed principal is a member of the group. * @param principal the principal whose members are being checked. * @param member the principal whose membership is to be checked. * @return true if the principal is a member of this group, false otherwise. */ public static boolean isMember(Principal principal, Principal member) { if (principal instanceof Group) { return ((Group) principal).isMember(member); } if (principal instanceof GroupPrincipal) { return ((GroupPrincipal) principal).isMember(member); } return false; } }
@Override protected void authorize(LoginContext context) throws LoginException { HashSet<String> required = new HashSet<>(requiredRoles); Set<Group> groups = context.getSubject().getPrincipals(Group.class); if (groups != null) { for (Group group : groups) { if ("Roles".equals(group.getName())) { for (String role : requiredRoles) { if (group.isMember(new SimplePrincipal(role))) { required.remove(role); } } } } } if (!required.isEmpty()) throw new LoginException("User does not have required roles: " + required); } }
/** * Process the group with the roles that are mapped in the * properies file * @param group Group that needs to be processed * @param props Properties file */ private void processRoles(Group group,Properties props) throws Exception { Enumeration<?> enumer = props.propertyNames(); while(enumer.hasMoreElements()) { String roleKey = (String)enumer.nextElement(); String comma_separated_roles = props.getProperty(roleKey); Principal pIdentity = createIdentity(roleKey); if(group.isMember(pIdentity)) Util.parseGroupMembers(group,comma_separated_roles,this); if(REPLACE_ROLE) group.removeMember(pIdentity); } } }
protected static boolean isMember(Group subjectRoles, String grantedRole) { if (subjectRoles.isMember(new SimplePrincipal(grantedRole))) { return true; } else { // Try regexps try { Pattern regex = Pattern.compile(grantedRole); for (String role : getRoles(subjectRoles)) { if (regex.matcher(role).matches()) { return true; } } } catch (Throwable t) { // Nothing to do here } List<String> roles = getRoles(subjectRoles); } return false; }
private boolean isMemberRecurse(Principal principal, Vector<Principal> vector) { for(Enumeration<Principal> enumeration = members(); enumeration.hasMoreElements();) { boolean flag = false; Principal principal1 = (Principal)enumeration.nextElement(); if(principal1.equals(principal)) return true; if(principal1 instanceof SecurityGroup) { SecurityGroup groupimpl = (SecurityGroup)principal1; vector.addElement(this); if(!vector.contains(groupimpl)) flag = groupimpl.isMemberRecurse(principal, vector); } else if(principal1 instanceof Group) { Group group1 = (Group)principal1; if(!vector.contains(group1)) flag = group1.isMember(principal); } if(flag) return flag; } return false; }//-------------------------------------------- @Override
/** * Checks if the authenticated user is a member of the specified role. * * @param role String The name of the role to check * @return boolean True if the user is a member of the specified role */ public boolean hasRole(String role) { if (!securityEnabled) return true; if (systemOp != null && Boolean.TRUE.equals(systemOp.get())) return true; tryLogin(); for ( Group sg : getSubject().getPrincipals(Group.class) ) { if ( ROLES_GROUP.equals( sg.getName() ) ) { return sg.isMember( new Role(role) ); } } return false; }
/** * Checks if the authenticated Identity is a member of the specified role. * * @param role String The name of the role to check * @return boolean True if the user is a member of the specified role */ public boolean hasRole(String role) { isLoggedIn(true); for (Group sg : getSubject().getPrincipals(Group.class)) { if (ROLES_GROUP.equals(sg.getName())) { return sg.isMember(new SimplePrincipal(role)); } } return false; }
/** * Process the group with the roles that are mapped in the * properies file * @param group Group that needs to be processed * @param props Properties file */ private void processRoles(Group group,Properties props) //throws Exception { Enumeration<?> enumer = props.propertyNames(); while(enumer.hasMoreElements()) { String roleKey = (String)enumer.nextElement(); String comma_separated_roles = props.getProperty(roleKey); try { Principal pIdentity = createIdentity(roleKey); if (group != null) { if(group.isMember(pIdentity)) Util.parseGroupMembers(group,comma_separated_roles,this); if(REPLACE_ROLE) group.removeMember(pIdentity); } } catch(Exception e) { PicketBoxLogger.LOGGER.debugFailureToCreatePrincipal(roleKey, e); } } } }
@Override protected Group[] getRoleSets() throws LoginException { Group group = new SimpleGroup("Roles"); List<String> roles = OpenIDProcessor.cachedRoles.get(); if (roles != null) { for (String role : roles) { group.addMember(new SimplePrincipal(role)); } } roles = FacebookProcessor.cachedRoles.get(); if (roles != null) { for (String role : roles) { Principal rolePrincipal = new SimplePrincipal(role); if (group.isMember(rolePrincipal) == false) { group.addMember(rolePrincipal); } } } return new Group[] { group }; } }