Search in sources :

Example 16 with Attribute

use of org.opensaml.saml.saml1.core.Attribute in project OpenAttestation by OpenAttestation.

the class SamlGenerator method createBase64BinaryAttribute.

/**
         * Creates a base64-encoded attribute
         * @param name
         * @param value
         * @return
         * @throws ConfigurationException 
         */
private Attribute createBase64BinaryAttribute(String name, byte[] value) throws ConfigurationException {
    SAMLObjectBuilder attrBuilder = (SAMLObjectBuilder) builderFactory.getBuilder(Attribute.DEFAULT_ELEMENT_NAME);
    Attribute attr = (Attribute) attrBuilder.buildObject();
    attr.setName(name);
    XMLObjectBuilder xmlBuilder = builderFactory.getBuilder(XSBase64Binary.TYPE_NAME);
    XSBase64Binary attrValue = (XSBase64Binary) xmlBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSBase64Binary.TYPE_NAME);
    attrValue.setValue(Base64.encodeBase64String(value));
    attr.getAttributeValues().add(attrValue);
    return attr;
}
Also used : XSBase64Binary(org.opensaml.xml.schema.XSBase64Binary) SAMLObjectBuilder(org.opensaml.common.SAMLObjectBuilder) Attribute(org.opensaml.saml2.core.Attribute) XMLObjectBuilder(org.opensaml.xml.XMLObjectBuilder)

Example 17 with Attribute

use of org.opensaml.saml.saml1.core.Attribute in project OpenAttestation by OpenAttestation.

the class SamlGenerator method createBooleanAttribute.

/**
         * This method builds a single-valued boolean attribute such as isTrusted=true
         * @param name
         * @param value
         * @return
         * @throws ConfigurationException 
         */
private Attribute createBooleanAttribute(String name, boolean value) throws ConfigurationException {
    SAMLObjectBuilder attrBuilder = (SAMLObjectBuilder) builderFactory.getBuilder(Attribute.DEFAULT_ELEMENT_NAME);
    Attribute attr = (Attribute) attrBuilder.buildObject();
    attr.setName(name);
    XMLObjectBuilder xmlBuilder = builderFactory.getBuilder(XSAny.TYPE_NAME);
    XSAny attrValue = (XSAny) xmlBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSAny.TYPE_NAME);
    attrValue.setTextContent(value ? "true" : "false");
    attr.getAttributeValues().add(attrValue);
    return attr;
}
Also used : SAMLObjectBuilder(org.opensaml.common.SAMLObjectBuilder) Attribute(org.opensaml.saml2.core.Attribute) XMLObjectBuilder(org.opensaml.xml.XMLObjectBuilder) XSAny(org.opensaml.xml.schema.XSAny)

Example 18 with Attribute

use of org.opensaml.saml.saml1.core.Attribute in project cloudstack by apache.

the class SAMLUtils method getValueFromAttributeStatements.

public static String getValueFromAttributeStatements(final List<AttributeStatement> attributeStatements, final String attributeKey) {
    if (attributeStatements == null || attributeStatements.size() < 1 || attributeKey == null) {
        return null;
    }
    for (AttributeStatement attributeStatement : attributeStatements) {
        if (attributeStatement == null || attributeStatements.size() < 1) {
            continue;
        }
        for (Attribute attribute : attributeStatement.getAttributes()) {
            if (attribute.getAttributeValues() != null && attribute.getAttributeValues().size() > 0) {
                String value = attribute.getAttributeValues().get(0).getDOM().getTextContent();
                s_logger.debug("SAML attribute name: " + attribute.getName() + " friendly-name:" + attribute.getFriendlyName() + " value:" + value);
                if (attributeKey.equals(attribute.getName()) || attributeKey.equals(attribute.getFriendlyName())) {
                    return value;
                }
            }
        }
    }
    return null;
}
Also used : Attribute(org.opensaml.saml2.core.Attribute) AttributeStatement(org.opensaml.saml2.core.AttributeStatement)

Example 19 with Attribute

use of org.opensaml.saml.saml1.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 20 with Attribute

use of org.opensaml.saml.saml1.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)24 XMLObject (org.opensaml.core.xml.XMLObject)11 AttributeStatement (org.opensaml.saml.saml2.core.AttributeStatement)11 List (java.util.List)8 Test (org.junit.Test)7 AttributeStatementLogData (uk.gov.ida.hub.samlengine.logging.data.AttributeStatementLogData)7 ImmutableList (com.google.common.collect.ImmutableList)6 AttributeValue (org.opensaml.saml.saml2.core.AttributeValue)6 AttributeBuilder (org.opensaml.saml.saml2.core.impl.AttributeBuilder)6 VerifiedAttributeLogData (uk.gov.ida.hub.samlengine.logging.data.VerifiedAttributeLogData)6 Map (java.util.Map)5 HashMap (java.util.HashMap)4 Attribute (org.opensaml.saml2.core.Attribute)4 SecurityAssertion (ddf.security.assertion.SecurityAssertion)3 ClaimCollection (org.apache.cxf.rt.security.claims.ClaimCollection)3 SamlAssertionWrapper (org.apache.wss4j.common.saml.SamlAssertionWrapper)3 Element (org.w3c.dom.Element)3 GuestPrincipal (ddf.security.principal.GuestPrincipal)2 Principal (java.security.Principal)2 ArrayList (java.util.ArrayList)2