Search in sources :

Example 16 with AuthnStatement

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

the class AuthnStatementAssertionValidatorTest method validate_shouldThrowExceptionIfAuthnContextIsAbsent.

@Test
public void validate_shouldThrowExceptionIfAuthnContextIsAbsent() throws Exception {
    AuthnStatement authnStatement = AuthnStatementBuilder.anAuthnStatement().withAuthnContext(null).build();
    Assertion assertion = AssertionBuilder.anAssertion().addAuthnStatement(authnStatement).buildUnencrypted();
    validateFail(() -> validator.validate(assertion), authnContextMissingError());
}
Also used : AuthnStatement(org.opensaml.saml.saml2.core.AuthnStatement) Assertion(org.opensaml.saml.saml2.core.Assertion) Test(org.junit.jupiter.api.Test)

Example 17 with AuthnStatement

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

the class AuthnStatementAssertionValidatorTest method validate_shouldPassValidation.

@Test
public void validate_shouldPassValidation() throws Exception {
    AuthnStatement authnStatement = AuthnStatementBuilder.anAuthnStatement().build();
    Assertion assertion = AssertionBuilder.anAssertion().addAuthnStatement(authnStatement).buildUnencrypted();
    validator.validate(assertion);
}
Also used : AuthnStatement(org.opensaml.saml.saml2.core.AuthnStatement) Assertion(org.opensaml.saml.saml2.core.Assertion) Test(org.junit.jupiter.api.Test)

Example 18 with AuthnStatement

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

the class MatchingServiceAuthnStatementToAuthnStatementTransformer method transform.

public AuthnStatement transform(MatchingServiceAuthnStatement idaAuthnStatement) {
    AuthnStatement authnStatement = openSamlXmlObjectFactory.createAuthnStatement();
    AuthnContext authnContext = openSamlXmlObjectFactory.createAuthnContext();
    authnContext.setAuthnContextClassRef(openSamlXmlObjectFactory.createAuthnContextClassReference(idaAuthnStatement.getAuthnContext().getUri()));
    authnStatement.setAuthnContext(authnContext);
    authnStatement.setAuthnInstant(DateTime.now());
    return authnStatement;
}
Also used : AuthnStatement(org.opensaml.saml.saml2.core.AuthnStatement) MatchingServiceAuthnStatement(uk.gov.ida.saml.core.domain.MatchingServiceAuthnStatement) AuthnContext(org.opensaml.saml.saml2.core.AuthnContext)

Example 19 with AuthnStatement

use of org.opensaml.saml2.core.AuthnStatement in project cloudstack by apache.

the class SAML2LoginAPIAuthenticatorCmdTest method buildMockResponse.

private Response buildMockResponse() throws Exception {
    Response samlMessage = new ResponseBuilder().buildObject();
    samlMessage.setID("foo");
    samlMessage.setVersion(SAMLVersion.VERSION_20);
    samlMessage.setIssueInstant(new DateTime(0));
    Issuer issuer = new IssuerBuilder().buildObject();
    issuer.setValue("MockedIssuer");
    samlMessage.setIssuer(issuer);
    Status status = new StatusBuilder().buildObject();
    StatusCode statusCode = new StatusCodeBuilder().buildObject();
    statusCode.setValue(StatusCode.SUCCESS_URI);
    status.setStatusCode(statusCode);
    samlMessage.setStatus(status);
    Assertion assertion = new AssertionBuilder().buildObject();
    Subject subject = new SubjectBuilder().buildObject();
    NameID nameID = new NameIDBuilder().buildObject();
    nameID.setValue("SOME-UNIQUE-ID");
    nameID.setFormat(NameIDType.PERSISTENT);
    subject.setNameID(nameID);
    assertion.setSubject(subject);
    AuthnStatement authnStatement = new AuthnStatementBuilder().buildObject();
    authnStatement.setSessionIndex("Some Session String");
    assertion.getAuthnStatements().add(authnStatement);
    AttributeStatement attributeStatement = new AttributeStatementBuilder().buildObject();
    assertion.getAttributeStatements().add(attributeStatement);
    samlMessage.getAssertions().add(assertion);
    return samlMessage;
}
Also used : Status(org.opensaml.saml2.core.Status) AttributeStatementBuilder(org.opensaml.saml2.core.impl.AttributeStatementBuilder) StatusCodeBuilder(org.opensaml.saml2.core.impl.StatusCodeBuilder) Issuer(org.opensaml.saml2.core.Issuer) NameID(org.opensaml.saml2.core.NameID) Assertion(org.opensaml.saml2.core.Assertion) AssertionBuilder(org.opensaml.saml2.core.impl.AssertionBuilder) AuthnStatementBuilder(org.opensaml.saml2.core.impl.AuthnStatementBuilder) StatusCode(org.opensaml.saml2.core.StatusCode) DateTime(org.joda.time.DateTime) Subject(org.opensaml.saml2.core.Subject) Response(org.opensaml.saml2.core.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) NameIDBuilder(org.opensaml.saml2.core.impl.NameIDBuilder) AttributeStatement(org.opensaml.saml2.core.AttributeStatement) AuthnStatement(org.opensaml.saml2.core.AuthnStatement) StatusBuilder(org.opensaml.saml2.core.impl.StatusBuilder) IssuerBuilder(org.opensaml.saml2.core.impl.IssuerBuilder) ResponseBuilder(org.opensaml.saml2.core.impl.ResponseBuilder) SubjectBuilder(org.opensaml.saml2.core.impl.SubjectBuilder)

Aggregations

AuthnStatement (org.opensaml.saml.saml2.core.AuthnStatement)17 Assertion (org.opensaml.saml.saml2.core.Assertion)11 Test (org.junit.jupiter.api.Test)5 AttributeStatement (org.opensaml.saml.saml2.core.AttributeStatement)5 AuthnContext (org.opensaml.saml.saml2.core.AuthnContext)5 DateTime (org.joda.time.DateTime)4 Attribute (org.opensaml.saml.saml2.core.Attribute)4 ZonedDateTime (java.time.ZonedDateTime)3 AuthnContextClassRef (org.opensaml.saml.saml2.core.AuthnContextClassRef)3 Conditions (org.opensaml.saml.saml2.core.Conditions)3 NameID (org.opensaml.saml.saml2.core.NameID)3 Subject (org.opensaml.saml.saml2.core.Subject)3 SubjectConfirmation (org.opensaml.saml.saml2.core.SubjectConfirmation)3 SecureRandom (java.security.SecureRandom)2 ArrayList (java.util.ArrayList)2 EncryptedAssertion (org.opensaml.saml.saml2.core.EncryptedAssertion)2 EncryptedAttribute (org.opensaml.saml.saml2.core.EncryptedAttribute)2 Issuer (org.opensaml.saml.saml2.core.Issuer)2 AssertionBuilder (org.opensaml.saml.saml2.core.impl.AssertionBuilder)2 AttributeBuilder (org.opensaml.saml.saml2.core.impl.AttributeBuilder)2