Search in sources :

Example 16 with NameID

use of org.opensaml.saml2.core.NameID in project verify-hub by alphagov.

the class AuthnResponseFactory method buildNameID.

private NameID buildNameID(String id) {
    NameID nameId = new OpenSamlXmlObjectFactory().createNameId(id);
    nameId.setFormat(NameIDType.PERSISTENT);
    return nameId;
}
Also used : OpenSamlXmlObjectFactory(uk.gov.ida.saml.core.OpenSamlXmlObjectFactory) NameID(org.opensaml.saml.saml2.core.NameID)

Example 17 with NameID

use of org.opensaml.saml2.core.NameID in project cxf by apache.

the class OnBehalfOfValidator method validate.

@Override
public Credential validate(Credential credential, RequestData data) throws WSSecurityException {
    Credential validatedCredential = super.validate(credential, data);
    SamlAssertionWrapper assertion = validatedCredential.getSamlAssertion();
    Assertion saml2Assertion = assertion.getSaml2();
    if (saml2Assertion == null) {
        throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "invalidSAMLsecurity");
    }
    List<AttributeStatement> attributeStatements = saml2Assertion.getAttributeStatements();
    if (attributeStatements == null || attributeStatements.isEmpty()) {
        throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "invalidSAMLsecurity");
    }
    Subject subject = saml2Assertion.getSubject();
    NameID nameID = subject.getNameID();
    String subjectName = nameID.getValue();
    if ("alice".equals(subjectName) || "bob".equals(subjectName)) {
        return validatedCredential;
    }
    throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "invalidSAMLsecurity");
}
Also used : Credential(org.apache.wss4j.dom.validate.Credential) NameID(org.opensaml.saml.saml2.core.NameID) AttributeStatement(org.opensaml.saml.saml2.core.AttributeStatement) Assertion(org.opensaml.saml.saml2.core.Assertion) SamlAssertionWrapper(org.apache.wss4j.common.saml.SamlAssertionWrapper) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) Subject(org.opensaml.saml.saml2.core.Subject)

Example 18 with NameID

use of org.opensaml.saml2.core.NameID in project cxf by apache.

the class SAMLUtils method getSubject.

public static Subject getSubject(Message message, SamlAssertionWrapper assertionW) {
    if (assertionW.getSaml2() != null) {
        org.opensaml.saml.saml2.core.Subject s = assertionW.getSaml2().getSubject();
        Subject subject = new Subject();
        NameID nameId = s.getNameID();
        subject.setNameQualifier(nameId.getNameQualifier());
        // if format is transient then we may need to use STSClient
        // to request an alternate name from IDP
        subject.setNameFormat(nameId.getFormat());
        subject.setName(nameId.getValue());
        subject.setSpId(nameId.getSPProvidedID());
        subject.setSpQualifier(nameId.getSPNameQualifier());
        return subject;
    } else if (assertionW.getSaml1() != null) {
        org.opensaml.saml.saml1.core.Subject s = getSaml1Subject(assertionW);
        if (s != null) {
            Subject subject = new Subject();
            NameIdentifier nameId = s.getNameIdentifier();
            subject.setNameQualifier(nameId.getNameQualifier());
            // if format is transient then we may need to use STSClient
            // to request an alternate name from IDP
            subject.setNameFormat(nameId.getFormat());
            subject.setName(nameId.getValue());
            return subject;
        }
    }
    return null;
}
Also used : NameID(org.opensaml.saml.saml2.core.NameID) NameIdentifier(org.opensaml.saml.saml1.core.NameIdentifier) Subject(org.apache.cxf.rs.security.saml.assertion.Subject)

Aggregations

NameID (org.opensaml.saml.saml2.core.NameID)12 Subject (org.opensaml.saml.saml2.core.Subject)4 NameID (org.opensaml.saml2.core.NameID)4 LogoutRequest (org.opensaml.saml2.core.LogoutRequest)3 ZonedDateTime (java.time.ZonedDateTime)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 IdPAttribute (net.shibboleth.idp.attribute.IdPAttribute)2 SAML2StringNameIDEncoder (net.shibboleth.idp.saml.attribute.encoding.impl.SAML2StringNameIDEncoder)2 SamlException (org.apereo.cas.support.saml.SamlException)2 DateTime (org.joda.time.DateTime)2 SAMLObjectBuilder (org.opensaml.common.SAMLObjectBuilder)2 Assertion (org.opensaml.saml.saml2.core.Assertion)2 Issuer (org.opensaml.saml2.core.Issuer)2 Response (org.opensaml.saml2.core.Response)2 IssuerBuilder (org.opensaml.saml2.core.impl.IssuerBuilder)2 NameIDBuilder (org.opensaml.saml2.core.impl.NameIDBuilder)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 IOException (java.io.IOException)1 List (java.util.List)1 Optional (java.util.Optional)1