use of ddf.security.assertion.AttributeStatement in project ddf by codice.
the class UsernamePasswordRealmTest method testDoGetAuthenticationInfo.
@Test
public void testDoGetAuthenticationInfo() {
AuthenticationTokenFactory authenticationTokenFactory = new AuthenticationTokenFactory();
AuthenticationToken authenticationToken = authenticationTokenFactory.fromUsernamePassword("admin", "pass", "0.0.0.0");
AuthenticationInfo authenticationInfo = upRealm.doGetAuthenticationInfo(authenticationToken);
SecurityAssertion assertion = authenticationInfo.getPrincipals().oneByType(SecurityAssertion.class);
assertNotNull(assertion);
assertThat(assertion.getPrincipal().getName(), is("admin"));
AttributeStatement attributeStatement = assertion.getAttributeStatements().get(0);
assertNotNull(attributeStatement);
assertThat(attributeStatement.getAttributes().size(), greaterThan(0));
Attribute attribute = attributeStatement.getAttributes().get(0);
assertThat(attribute.getName(), is("email"));
assertThat(attribute.getValues().size(), is(2));
assertThat(attribute.getValues(), contains("tester@example.com", "test@example.com"));
}
use of ddf.security.assertion.AttributeStatement in project ddf by codice.
the class SecurityAssertionJwt method getPrincipals.
@Override
public Set<Principal> getPrincipals() {
Set<Principal> principals = new HashSet<>();
Principal primary = getPrincipal();
principals.add(primary);
principals.add(new RolePrincipal(primary.getName()));
for (AttributeStatement attributeStatement : getAttributeStatements()) {
for (Attribute attr : attributeStatement.getAttributes()) {
if (StringUtils.containsIgnoreCase(attr.getName(), "role")) {
for (final String attrValue : attr.getValues()) {
principals.add(new RolePrincipal(attrValue));
}
}
}
}
return principals;
}
use of ddf.security.assertion.AttributeStatement in project ddf by codice.
the class SecurityAssertionSaml method getPrincipals.
@Override
public Set<Principal> getPrincipals() {
Set<Principal> principals = new HashSet<>();
Principal primary = getPrincipal();
principals.add(primary);
principals.add(new RolePrincipal(primary.getName()));
for (AttributeStatement attributeStatement : getAttributeStatements()) {
for (Attribute attr : attributeStatement.getAttributes()) {
if (StringUtils.containsIgnoreCase(attr.getName(), "role")) {
for (final String obj : attr.getValues()) {
principals.add(new RolePrincipal(obj));
}
}
}
}
return principals;
}
Aggregations