use of org.apache.cxf.common.security.SimpleGroup in project cxf by apache.
the class DefaultSecurityContextTest method testUserInRole2.
@Test
public void testUserInRole2() {
Subject s = new Subject();
Principal p = new SimplePrincipal("Barry");
s.getPrincipals().add(p);
Group group = new SimpleGroup("Roles", p);
group.addMember(new SimpleGroup("friend"));
s.getPrincipals().add(group);
assertTrue(new DefaultSecurityContext(p, s).isUserInRole("friend"));
}
use of org.apache.cxf.common.security.SimpleGroup in project cxf by apache.
the class DefaultSecurityContextTest method testMultipleRoles.
@Test
public void testMultipleRoles() {
Subject s = new Subject();
Principal p = new SimplePrincipal("Barry");
s.getPrincipals().add(p);
Set<Principal> roles = new HashSet<>();
roles.add(new SimpleGroup("friend", p));
roles.add(new SimpleGroup("admin", p));
s.getPrincipals().addAll(roles);
LoginSecurityContext context = new DefaultSecurityContext(p, s);
assertTrue(context.isUserInRole("friend"));
assertTrue(context.isUserInRole("admin"));
assertFalse(context.isUserInRole("bar"));
Set<Principal> roles2 = context.getUserRoles();
assertEquals(roles2, roles);
}
use of org.apache.cxf.common.security.SimpleGroup in project cxf by apache.
the class SAMLUtils method parseRolesFromClaims.
/**
* Extract roles from the given Claims
*/
public static Set<Principal> parseRolesFromClaims(ClaimCollection claims, String name, String nameFormat) {
String roleAttributeName = name;
if (roleAttributeName == null) {
roleAttributeName = SAMLClaim.SAML_ROLE_ATTRIBUTENAME_DEFAULT;
}
Set<Principal> roles = new HashSet<>();
for (Claim claim : claims) {
if (claim instanceof SAMLClaim && ((SAMLClaim) claim).getName().equals(name) && (nameFormat == null || nameFormat.equals(((SAMLClaim) claim).getNameFormat()))) {
for (Object claimValue : claim.getValues()) {
if (claimValue instanceof String) {
roles.add(new SimpleGroup((String) claimValue));
}
}
if (claim.getValues().size() > 1) {
// Don't search for other attributes with the same name if > 1 claim value
break;
}
}
}
return roles;
}
use of org.apache.cxf.common.security.SimpleGroup in project cxf by apache.
the class CustomUsernameTokenInterceptor method createSubject.
protected Subject createSubject(String name, String password, boolean isDigest, String nonce, String created) throws SecurityException {
Subject subject = new Subject();
// delegate to the external security system if possible
// authenticate the user somehow
subject.getPrincipals().add(new SimplePrincipal(name));
// add roles this user is in
String roleName = "Alice".equals(name) ? "developers" : "pms";
String expectedPassword = "Alice".equals(name) ? "ecilA" : UsernameToken.doPasswordDigest(nonce, created, "invalid-password");
if (!password.equals(expectedPassword)) {
throw new SecurityException("Wrong Password");
}
subject.getPrincipals().add(new SimpleGroup(roleName, name));
subject.setReadOnly();
return subject;
}
use of org.apache.cxf.common.security.SimpleGroup in project cxf by apache.
the class SimpleSubjectCreatingInterceptor method createSubject.
@Override
protected Subject createSubject(String name, String password, boolean isDigest, String nonce, String created) throws SecurityException {
Subject subject = new Subject();
// delegate to the external security system if possible
String roleName = "Alice".equals(name) ? "developers" : "pms";
subject.getPrincipals().add(new SimplePrincipal(name));
subject.getPrincipals().add(new SimpleGroup(roleName, name));
subject.setReadOnly();
return subject;
}
Aggregations