Search in sources :

Example 1 with AttributeDefault

use of ddf.security.assertion.impl.AttributeDefault in project ddf by codice.

the class GuestRealm method createPrincipalFromToken.

private SimplePrincipalCollection createPrincipalFromToken(BaseAuthenticationToken token) {
    SimplePrincipalCollection principals = new SimplePrincipalCollection();
    DefaultSecurityAssertionBuilder defaultSecurityAssertionBuilder = new DefaultSecurityAssertionBuilder();
    Set<Map.Entry<URI, List<String>>> entries = claimsMap.entrySet();
    AttributeStatementDefault attributeStatement = new AttributeStatementDefault();
    for (Map.Entry<URI, List<String>> entry : entries) {
        AttributeDefault attribute = new AttributeDefault();
        attribute.setName(entry.getKey().toString());
        for (String value : entry.getValue()) {
            attribute.addValue(value);
        }
        attributeStatement.addAttribute(attribute);
    }
    defaultSecurityAssertionBuilder.addAttributeStatement(attributeStatement);
    defaultSecurityAssertionBuilder.userPrincipal(new GuestPrincipal(token.getIpAddress()));
    defaultSecurityAssertionBuilder.issuer("local");
    defaultSecurityAssertionBuilder.notBefore(new Date());
    // We don't really care how long it is "valid" for
    defaultSecurityAssertionBuilder.notOnOrAfter(new Date(new Date().getTime() + 14400000L));
    defaultSecurityAssertionBuilder.token(token);
    defaultSecurityAssertionBuilder.tokenType(GUEST_TOKEN_TYPE);
    SecurityAssertion securityAssertion = defaultSecurityAssertionBuilder.build();
    Principal principal = securityAssertion.getPrincipal();
    if (principal != null) {
        principals.add(principal.getName(), getName());
    }
    principals.add(securityAssertion, getName());
    return principals;
}
Also used : DefaultSecurityAssertionBuilder(ddf.security.assertion.impl.DefaultSecurityAssertionBuilder) AttributeDefault(ddf.security.assertion.impl.AttributeDefault) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SecurityAssertion(ddf.security.assertion.SecurityAssertion) URI(java.net.URI) Date(java.util.Date) AttributeStatementDefault(ddf.security.assertion.impl.AttributeStatementDefault) GuestPrincipal(ddf.security.principal.impl.GuestPrincipal) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Principal(java.security.Principal) GuestPrincipal(ddf.security.principal.impl.GuestPrincipal)

Example 2 with AttributeDefault

use of ddf.security.assertion.impl.AttributeDefault 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 3 with AttributeDefault

use of ddf.security.assertion.impl.AttributeDefault 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)

Aggregations

AttributeDefault (ddf.security.assertion.impl.AttributeDefault)3 Attribute (ddf.security.assertion.Attribute)2 Claim (ddf.security.claims.Claim)2 SecurityAssertion (ddf.security.assertion.SecurityAssertion)1 AttributeStatementDefault (ddf.security.assertion.impl.AttributeStatementDefault)1 DefaultSecurityAssertionBuilder (ddf.security.assertion.impl.DefaultSecurityAssertionBuilder)1 GuestPrincipal (ddf.security.principal.impl.GuestPrincipal)1 URI (java.net.URI)1 Principal (java.security.Principal)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)1