use of ddf.security.assertion.Attribute 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.Attribute in project ddf by codice.
the class PKIRealm method mergeClaimsToAttributes.
private void mergeClaimsToAttributes(AttributeStatement attributeStatement, ClaimsCollection claims) {
for (Claim claim : claims) {
Attribute newAttr = new AttributeDefault();
newAttr.setName(claim.getName());
newAttr.setValues(claim.getValues());
boolean found = false;
for (Attribute attribute : attributeStatement.getAttributes()) {
if (attribute.getName().equals(newAttr.getName())) {
found = true;
for (String value : newAttr.getValues()) {
attribute.addValue(value);
}
}
}
if (!found) {
attributeStatement.addAttribute(newAttr);
}
}
}
use of ddf.security.assertion.Attribute in project ddf by codice.
the class UsernamePasswordRealm method mergeClaimsToAttributes.
private void mergeClaimsToAttributes(AttributeStatement attributeStatement, ClaimsCollection claims) {
for (Claim claim : claims) {
Attribute newAttr = new AttributeDefault();
newAttr.setName(claim.getName());
newAttr.setValues(claim.getValues());
boolean found = false;
for (Attribute attribute : attributeStatement.getAttributes()) {
if (attribute.getName().equals(newAttr.getName())) {
found = true;
for (String value : newAttr.getValues()) {
attribute.addValue(value);
}
}
}
if (!found) {
attributeStatement.addAttribute(newAttr);
}
}
}
use of ddf.security.assertion.Attribute 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.Attribute 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