Search in sources :

Example 11 with Attribute

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"));
}
Also used : AuthenticationToken(org.apache.shiro.authc.AuthenticationToken) BaseAuthenticationToken(org.codice.ddf.security.handler.BaseAuthenticationToken) Attribute(ddf.security.assertion.Attribute) AttributeStatement(ddf.security.assertion.AttributeStatement) AuthenticationTokenFactory(org.codice.ddf.security.handler.AuthenticationTokenFactory) SecurityAssertion(ddf.security.assertion.SecurityAssertion) AuthenticationInfo(org.apache.shiro.authc.AuthenticationInfo) Test(org.junit.Test)

Example 12 with Attribute

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);
        }
    }
}
Also used : Attribute(ddf.security.assertion.Attribute) AttributeDefault(ddf.security.assertion.impl.AttributeDefault) Claim(ddf.security.claims.Claim)

Example 13 with Attribute

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);
        }
    }
}
Also used : Attribute(ddf.security.assertion.Attribute) AttributeDefault(ddf.security.assertion.impl.AttributeDefault) Claim(ddf.security.claims.Claim)

Example 14 with Attribute

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;
}
Also used : Attribute(ddf.security.assertion.Attribute) AttributeStatement(ddf.security.assertion.AttributeStatement) RolePrincipal(org.apache.karaf.jaas.boot.principal.RolePrincipal) RolePrincipal(org.apache.karaf.jaas.boot.principal.RolePrincipal) Principal(java.security.Principal) HashSet(java.util.HashSet)

Example 15 with Attribute

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;
}
Also used : Attribute(ddf.security.assertion.Attribute) AttributeStatement(ddf.security.assertion.AttributeStatement) RolePrincipal(org.apache.karaf.jaas.boot.principal.RolePrincipal) X500Principal(javax.security.auth.x500.X500Principal) KerberosPrincipal(javax.security.auth.kerberos.KerberosPrincipal) RolePrincipal(org.apache.karaf.jaas.boot.principal.RolePrincipal) Principal(java.security.Principal) GuestPrincipal(ddf.security.principal.impl.GuestPrincipal) HashSet(java.util.HashSet)

Aggregations

Attribute (ddf.security.assertion.Attribute)15 AttributeStatement (ddf.security.assertion.AttributeStatement)10 SecurityAssertion (ddf.security.assertion.SecurityAssertion)7 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)5 Principal (java.security.Principal)3 X500Principal (javax.security.auth.x500.X500Principal)3 AuthenticationInfo (org.apache.shiro.authc.AuthenticationInfo)3 BaseAuthenticationToken (org.codice.ddf.security.handler.BaseAuthenticationToken)3 Test (org.junit.Test)3 Subject (ddf.security.Subject)2 AuthenticationStatement (ddf.security.assertion.AuthenticationStatement)2 AttributeDefault (ddf.security.assertion.impl.AttributeDefault)2 Claim (ddf.security.claims.Claim)2 GuestPrincipal (ddf.security.principal.impl.GuestPrincipal)2 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2 KerberosPrincipal (javax.security.auth.kerberos.KerberosPrincipal)2 RolePrincipal (org.apache.karaf.jaas.boot.principal.RolePrincipal)2 AuthenticationToken (org.apache.shiro.authc.AuthenticationToken)2 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)2