use of org.jboss.security.SimpleGroup in project keycloak by keycloak.
the class WildflyRequestAuthenticator method propagateKeycloakContext.
@Override
protected void propagateKeycloakContext(KeycloakUndertowAccount account) {
super.propagateKeycloakContext(account);
SecurityInfoHelper.propagateSessionInfo(account);
log.debug("propagate security context to wildfly");
Subject subject = new Subject();
Set<Principal> principals = subject.getPrincipals();
principals.add(account.getPrincipal());
Group[] roleSets = getRoleSets(account.getRoles());
for (int g = 0; g < roleSets.length; g++) {
Group group = roleSets[g];
String name = group.getName();
Group subjectGroup = createGroup(name, principals);
if (subjectGroup instanceof NestableGroup) {
/* A NestableGroup only allows Groups to be added to it so we
need to add a SimpleGroup to subjectRoles to contain the roles
*/
SimpleGroup tmp = new SimpleGroup("Roles");
subjectGroup.addMember(tmp);
subjectGroup = tmp;
}
// Copy the group members to the Subject group
Enumeration<? extends Principal> members = group.members();
while (members.hasMoreElements()) {
Principal role = (Principal) members.nextElement();
subjectGroup.addMember(role);
}
}
// add the CallerPrincipal group if none has been added in getRoleSets
Group callerGroup = new SimpleGroup(SecurityConstants.CALLER_PRINCIPAL_GROUP);
callerGroup.addMember(account.getPrincipal());
principals.add(callerGroup);
org.jboss.security.SecurityContext sc = SecurityContextAssociation.getSecurityContext();
Principal userPrincipal = getPrincipal(subject);
sc.getUtil().createSubjectInfo(userPrincipal, account, subject);
// Roles of subjectInfo are null, because is was constructed by
// org.jboss.security.identity.extensions.CredentialIdentityFactory
// .createIdentity(Principal [=userPrincipal], Object [=account], Role [=null]).
// Therefore the roles are only contained in the authenticatedSubject (member of subjectInfo)
// and subsequent logics do only access subjectInfo#roles instead of authenticatedSubject#roles.
mapGroupMembersOfAuthenticatedSubjectIntoSecurityContext(sc);
}
use of org.jboss.security.SimpleGroup in project keycloak by keycloak.
the class SecurityInfoHelper method createGroup.
protected static Group createGroup(String name, Set<Principal> principals) {
Group roles = null;
Iterator<Principal> iter = principals.iterator();
while (iter.hasNext()) {
Object next = iter.next();
if (!(next instanceof Group))
continue;
Group grp = (Group) next;
if (grp.getName().equals(name)) {
roles = grp;
break;
}
}
// If we did not find a group create one
if (roles == null) {
roles = new SimpleGroup(name);
principals.add(roles);
}
return roles;
}
use of org.jboss.security.SimpleGroup in project keycloak by keycloak.
the class SecurityInfoHelper method getRoleSets.
protected static Group[] getRoleSets(Collection<String> roleSet) {
SimpleGroup roles = new SimpleGroup("Roles");
Group[] roleSets = { roles };
for (String role : roleSet) {
roles.addMember(new SimplePrincipal(role));
}
return roleSets;
}
use of org.jboss.security.SimpleGroup in project wildfly-swarm by wildfly-swarm.
the class JWTLoginModule method commit.
@Override
public boolean commit() throws LoginException {
subject.getPrincipals().add(jwtPrincipal);
SimpleGroup roles = new SimpleGroup("Roles");
for (String name : jwtPrincipal.getGroups()) {
roles.addMember(new SimplePrincipal(name));
}
subject.getPrincipals().add(roles);
sharedState.put("JsonWebToken", jwtPrincipal);
return super.commit();
}
use of org.jboss.security.SimpleGroup in project wildfly by wildfly.
the class JASPICAuthenticationMechanism method updateSubjectRoles.
private void updateSubjectRoles(final org.jboss.security.SecurityContext jbossSct) {
if (jbossSct == null) {
throw UndertowLogger.ROOT_LOGGER.nullParamter("org.jboss.security.SecurityContext");
}
RoleGroup contextRoleGroup = jbossSct.getUtil().getRoles();
if (contextRoleGroup == null) {
return;
}
Collection<Role> contextRoles = contextRoleGroup.getRoles();
if (contextRoles.isEmpty()) {
return;
}
Subject subject = jbossSct.getUtil().getSubject();
Set<Group> groupPrincipals = subject.getPrincipals(Group.class);
Group subjectRoleGroup = null;
for (Group candidate : groupPrincipals) {
if (candidate.getName().equals(ROLES_IDENTIFIER)) {
subjectRoleGroup = candidate;
break;
}
}
if (subjectRoleGroup == null) {
subjectRoleGroup = new SimpleGroup(ROLES_IDENTIFIER);
subject.getPrincipals().add(subjectRoleGroup);
}
for (Role role : contextRoles) {
Principal rolePrincipal = new SimplePrincipal(role.getRoleName());
subjectRoleGroup.addMember(rolePrincipal);
}
}
Aggregations