/** * Obtains the caller principal from the specified {@link Subject}. This method looks for a group called {@code * CallerPrincipal} and if it finds one it returns the first {@link java.security.Principal} in the group. * * @param subject the {@link javax.security.auth.Subject} to be inspected. * @return the first {@link java.security.Principal} found in the {@code CallerPrincipal} group or {@code null} if * a caller principal couldn't be found. */ private Principal getCallerPrincipal(Subject subject) { Principal callerPrincipal = null; if (subject != null) { Set<Principal> principals = subject.getPrincipals(); if (principals != null && !principals.isEmpty()) { for (Principal principal : principals) { if (principal instanceof Group && principal.getName().equals(CALLER_PRINCIPAL_GROUP)) { Enumeration<? extends Principal> enumeration = ((Group) principal).members(); if (enumeration.hasMoreElements()) { callerPrincipal = enumeration.nextElement(); break; } } } } } return callerPrincipal; } }
/** * Get the Principal given the authenticated Subject. Currently the first principal that is not of type {@code Group} is * considered or the single principal inside the CallerPrincipal group. * * @param subject * @return the authenticated principal */ private Principal getPrincipal(Subject subject) { Principal principal = null; Principal callerPrincipal = null; if (subject != null) { Set<Principal> principals = subject.getPrincipals(); if (principals != null && !principals.isEmpty()) { for (Principal p : principals) { if (!(p instanceof Group) && principal == null) { principal = p; } if (p instanceof Group) { Group g = Group.class.cast(p); if (g.getName().equals(SecurityConstants.CALLER_PRINCIPAL_GROUP) && callerPrincipal == null) { Enumeration<? extends Principal> e = g.members(); if (e.hasMoreElements()) callerPrincipal = e.nextElement(); } } } } } return callerPrincipal == null ? principal : callerPrincipal; }
/** * Get the Principal given the authenticated Subject. Currently the first principal that is not of type {@code Group} is * considered or the single principal inside the CallerPrincipal group. * * @param subject * @return the authenticated principal */ private Principal getPrincipal(Subject subject) { Principal principal = null; Principal callerPrincipal = null; if (subject != null) { Set<Principal> principals = subject.getPrincipals(); if (principals != null && !principals.isEmpty()) { for (Principal p : principals) { if (!(p instanceof Group) && principal == null) { principal = p; } if (p instanceof Group) { Group g = Group.class.cast(p); if (g.getName().equals("CallerPrincipal") && callerPrincipal == null) { Enumeration<? extends Principal> e = g.members(); if (e.hasMoreElements()) callerPrincipal = e.nextElement(); } } } } } return callerPrincipal == null ? principal : callerPrincipal; }
for (Principal principal : principals) { if (principal instanceof Group && rolePrincipleName.equalsIgnoreCase(principal.getName())) { Enumeration<? extends Principal> groups = ((Group) principal).members();
final Enumeration<? extends Principal> enumeration = group.members(); while (enumeration.hasMoreElements()) { groupPrincipals.add(enumeration.nextElement());
@Override public boolean equals(Object obj) { if (obj instanceof Group && super.equals(obj)) { Group that = (Group) obj; Enumeration<? extends Principal> thatEnum = that.members(); int count = 0; while (thatEnum.hasMoreElements()) { Principal thatPrinc = thatEnum.nextElement(); count++; if (! this.members.contains(thatPrinc)) { return false; } } return count == this.members.size(); } else { return false; } }
private static Class<?> getPrincipalClass(Group roles) { //Assume that the roles all belong to the same principal class Class<?> principalClass = SimplePrincipal.class; Enumeration<? extends Principal> en = roles.members(); if(en.hasMoreElements()) { principalClass = roles.members().nextElement().getClass(); } return principalClass; } }
private static Class<?> getPrincipalClass(Group roles) { //Assume that the roles all belong to the same principal class Class<?> principalClass = SimplePrincipal.class; Enumeration<? extends Principal> en = roles.members(); if(en.hasMoreElements()) { principalClass = roles.members().nextElement().getClass(); } return principalClass; } }
IndexEnumeration() { if( rolesStack.size() > 0 ) { Group grp = (Group) rolesStack.get(0); iter = grp.members(); } } public boolean hasMoreElements()
IndexEnumeration() { if( rolesStack.size() > 0 ) { Group grp = (Group) rolesStack.get(0); iter = grp.members(); } } public boolean hasMoreElements()
private boolean isGroupMember(Group group, String member) { Enumeration<? extends Principal> members = group.members(); while(members.hasMoreElements()) { Principal m = members.nextElement(); if (member.equals(m.getName())) { return true; } } return false; }
@Override public Enumeration<? extends Principal> members() { return GroupPrincipals.transform(group.members()); } }
public SimpleRoleGroup(Group rolesGroup) { super(rolesGroup.getName()); Enumeration<? extends Principal> principals = rolesGroup.members(); while (principals.hasMoreElements()) { SimpleRole role = new SimpleRole(principals.nextElement().getName()); addRole(role); } }
public SimpleRoleGroup(Group rolesGroup) { super(rolesGroup.getName()); Enumeration<? extends Principal> principals = rolesGroup.members(); while (principals.hasMoreElements()) { SimpleRole role = new SimpleRole(principals.nextElement().getName()); addRole(role); } }
private RoleGroup getRoleGroup(Group roleGroup) { if(roleGroup == null) throw new IllegalArgumentException("roleGroup is null"); SimpleRoleGroup srg = new SimpleRoleGroup(roleGroup.getName()); Enumeration<? extends Principal> principals = roleGroup.members(); while(principals.hasMoreElements()) { srg.getRoles().add(new SimpleRole(principals.nextElement().getName())); } return srg; }
private static Enumeration<? extends Principal> members(Principal principal) { if (principal instanceof Group) { return ((Group) principal).members(); } if (principal instanceof GroupPrincipal) { return ((GroupPrincipal) principal).members(); } return Collections.emptyEnumeration(); } }
/** * Replace the principals in first group with those in the second * @param fg * @param sg * @return */ public static Group replacePrincipals(Group fg, Group sg) { return addPrincipals( removePrincipals(fg),sg.members()); }
/** * Replace the principals in first group with those in the second * @param fg * @param sg * @return */ public static Group replacePrincipals(Group fg, Group sg) { return addPrincipals( removePrincipals(fg),sg.members()); }
public void addCustomGroups(UserInfo userInfo, Set<Principal> principals) { if (userInfo == null || principals == null) { LOG.error("Userinfo or Principals null"); return; } List<Group> unknownGroups = getUnknownGroups(principals); for (Group prince : unknownGroups) { Principal other = prince.members().nextElement(); userInfo.setClaim(prince.getName(), other.toString()); //json prince } }
private RoleGroup getRoleGroup(Group roleGroup) { if(roleGroup == null) throw PicketBoxMessages.MESSAGES.invalidNullArgument("roleGroup"); SimpleRoleGroup srg = new SimpleRoleGroup(roleGroup.getName()); Enumeration<? extends Principal> principals = roleGroup.members(); while(principals.hasMoreElements()) { srg.addRole(new SimpleRole(principals.nextElement().getName())); } return srg; }