Search in sources :

Example 21 with Subject

use of org.opensaml.saml2.core.Subject 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)

Aggregations

Subject (org.opensaml.saml.saml2.core.Subject)13 ZonedDateTime (java.time.ZonedDateTime)5 Assertion (org.opensaml.saml.saml2.core.Assertion)5 AttributeStatement (org.opensaml.saml.saml2.core.AttributeStatement)5 SAMLObjectBuilder (org.opensaml.common.SAMLObjectBuilder)4 NameID (org.opensaml.saml.saml2.core.NameID)4 RegisteredService (org.apereo.cas.services.RegisteredService)3 Assertion (org.opensaml.saml2.core.Assertion)3 NameID (org.opensaml.saml2.core.NameID)3 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)2 SamlAssertionWrapper (org.apache.wss4j.common.saml.SamlAssertionWrapper)2 Credential (org.apache.wss4j.dom.validate.Credential)2 Principal (org.apereo.cas.authentication.principal.Principal)2 UnauthorizedServiceException (org.apereo.cas.services.UnauthorizedServiceException)2 DateTime (org.joda.time.DateTime)2 Subject (org.opensaml.saml.saml1.core.Subject)2 AuthnStatement (org.opensaml.saml.saml2.core.AuthnStatement)2 Conditions (org.opensaml.saml.saml2.core.Conditions)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 IOException (java.io.IOException)1