Search in sources :

Example 16 with Attribute

use of org.opensaml.saml.saml2.core.Attribute in project ddf by codice.

the class SecurityAssertionImpl 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 XMLObject obj : attr.getAttributeValues()) {
                    principals.add(new RolePrincipal(((XSString) obj).getValue()));
                }
            }
        }
    }
    return principals;
}
Also used : Attribute(org.opensaml.saml.saml2.core.Attribute) EncryptedAttribute(org.opensaml.saml.saml2.core.EncryptedAttribute) AttributeStatement(org.opensaml.saml.saml2.core.AttributeStatement) XMLObject(org.opensaml.core.xml.XMLObject) XSString(org.opensaml.core.xml.schema.XSString) RolePrincipal(org.apache.karaf.jaas.boot.principal.RolePrincipal) KerberosPrincipal(javax.security.auth.kerberos.KerberosPrincipal) Principal(java.security.Principal) X500Principal(javax.security.auth.x500.X500Principal) GuestPrincipal(ddf.security.principal.GuestPrincipal) RolePrincipal(org.apache.karaf.jaas.boot.principal.RolePrincipal) HashSet(java.util.HashSet)

Example 17 with Attribute

use of org.opensaml.saml.saml2.core.Attribute in project ddf by codice.

the class SubjectUtilsTest method getSubjectWithAttributes.

private Subject getSubjectWithAttributes(Map<String, List<String>> attributes) {
    Subject subject = mock(Subject.class);
    PrincipalCollection pc = mock(PrincipalCollection.class);
    SecurityAssertion assertion = mock(SecurityAssertion.class);
    AttributeStatement as = mock(AttributeStatement.class);
    List<Attribute> attrs = attributes.entrySet().stream().map(this::getAttribute).collect(Collectors.toList());
    doReturn(pc).when(subject).getPrincipals();
    doReturn(assertion).when(pc).oneByType(SecurityAssertion.class);
    doReturn(ImmutableList.of(assertion)).when(pc).byType(SecurityAssertion.class);
    doReturn(Collections.singletonList(as)).when(assertion).getAttributeStatements();
    doReturn(attrs).when(as).getAttributes();
    return subject;
}
Also used : Attribute(org.opensaml.saml.saml2.core.Attribute) AttributeStatement(org.opensaml.saml.saml2.core.AttributeStatement) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SecurityAssertion(ddf.security.assertion.SecurityAssertion)

Example 18 with Attribute

use of org.opensaml.saml.saml2.core.Attribute in project ddf by codice.

the class SubjectUtilsTest method getAttribute.

private Attribute getAttribute(Map.Entry<String, List<String>> attribute) {
    Attribute attr = mock(Attribute.class);
    doReturn(attribute.getKey()).when(attr).getName();
    doReturn(attribute.getValue().stream().map(this::getXSString).collect(Collectors.toList())).when(attr).getAttributeValues();
    return attr;
}
Also used : Attribute(org.opensaml.saml.saml2.core.Attribute)

Aggregations

Attribute (org.opensaml.saml.saml2.core.Attribute)9 AttributeStatement (org.opensaml.saml.saml2.core.AttributeStatement)7 XMLObject (org.opensaml.core.xml.XMLObject)5 Attribute (org.opensaml.saml2.core.Attribute)5 SecurityAssertion (ddf.security.assertion.SecurityAssertion)3 Map (java.util.Map)3 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)3 SAMLObjectBuilder (org.opensaml.common.SAMLObjectBuilder)3 XMLObjectBuilder (org.opensaml.xml.XMLObjectBuilder)3 GuestPrincipal (ddf.security.principal.GuestPrincipal)2 Principal (java.security.Principal)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 KerberosPrincipal (javax.security.auth.kerberos.KerberosPrincipal)2 X500Principal (javax.security.auth.x500.X500Principal)2 XSString (org.opensaml.core.xml.schema.XSString)2 AttributeStatement (org.opensaml.saml2.core.AttributeStatement)2 XSAny (org.opensaml.xml.schema.XSAny)2 Throwables (com.google.common.base.Throwables)1