Search in sources :

Example 11 with AttributeStatement

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"));
}
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 AttributeStatement

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;
}
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 13 with AttributeStatement

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;
}
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

AttributeStatement (ddf.security.assertion.AttributeStatement)13 Attribute (ddf.security.assertion.Attribute)10 SecurityAssertion (ddf.security.assertion.SecurityAssertion)9 Principal (java.security.Principal)4 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)4 AuthenticationStatement (ddf.security.assertion.AuthenticationStatement)3 HashSet (java.util.HashSet)3 AuthenticationInfo (org.apache.shiro.authc.AuthenticationInfo)3 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)3 BaseAuthenticationToken (org.codice.ddf.security.handler.BaseAuthenticationToken)3 Subject (ddf.security.Subject)2 AttributeStatementDefault (ddf.security.assertion.impl.AttributeStatementDefault)2 DefaultSecurityAssertionBuilder (ddf.security.assertion.impl.DefaultSecurityAssertionBuilder)2 ClaimsCollection (ddf.security.claims.ClaimsCollection)2 ClaimsHandler (ddf.security.claims.ClaimsHandler)2 ClaimsParametersImpl (ddf.security.claims.impl.ClaimsParametersImpl)2 Instant (java.time.Instant)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2