use of org.opensaml.saml2.core.AttributeStatement 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");
}
use of org.opensaml.saml2.core.AttributeStatement in project verify-hub by alphagov.
the class IdpAuthnResponseTranslatorServiceTest method setup.
@BeforeEach
public void setup() {
final String idpEntityId = TestEntityIds.STUB_IDP_ONE;
final String assertionId1 = randomUUID().toString();
final String assertionId2 = randomUUID().toString();
final SignatureAlgorithm signatureAlgorithm = new SignatureRSASHA1();
final DigestAlgorithm digestAlgorithm = new DigestSHA256();
final AttributeStatement matchingDatasetAttributeStatement = MatchingDatasetAttributeStatementBuilder_1_1.aMatchingDatasetAttributeStatement_1_1().build();
final AttributeStatement ipAddress = anAttributeStatement().addAttribute(IPAddressAttributeBuilder.anIPAddress().build()).build();
final Optional<Signature> signature = of(SignatureBuilder.aSignature().build());
final SignatureImpl signatureImpl = ((SignatureImpl) signature.get());
signatureImpl.setXMLSignature(BuilderHelper.createXMLSignature(signatureAlgorithm, digestAlgorithm));
authnStatementAssertion = AssertionBuilder.anAssertion().withId(assertionId1).withIssuer(IssuerBuilder.anIssuer().withIssuerId(idpEntityId).build()).addAttributeStatement(ipAddress).addAuthnStatement(AuthnStatementBuilder.anAuthnStatement().build()).withSignature(SignatureBuilder.aSignature().withSignatureAlgorithm(signatureAlgorithm).withDigestAlgorithm(assertionId1, digestAlgorithm).build()).buildUnencrypted();
matchingDatasetAssertion = AssertionBuilder.anAssertion().withId(assertionId2).withIssuer(IssuerBuilder.anIssuer().withIssuerId(idpEntityId).build()).addAttributeStatement(matchingDatasetAttributeStatement).withSignature(SignatureBuilder.aSignature().withSignatureAlgorithm(signatureAlgorithm).withDigestAlgorithm(assertionId2, digestAlgorithm).build()).buildUnencrypted();
when(responseContainer.getSamlResponse()).thenReturn(saml);
when(assertionBlobEncrypter.encryptAssertionBlob(any(), eq(authStatementUnderlyingAssertionBlob))).thenReturn(encryptedAuthnAssertion);
when(stringToOpenSamlResponseTransformer.apply(saml)).thenReturn(samlResponse);
when(samlResponseToIdaResponseIssuedByIdpTransformer.apply(samlResponse)).thenReturn(responseFromIdp);
when(authStatementAssertion.getUnderlyingAssertionBlob()).thenReturn(authStatementUnderlyingAssertionBlob);
when(authStatementAssertion.getAuthnContext()).thenReturn(Optional.empty());
when(authStatementAssertion.getFraudDetectedDetails()).thenReturn(Optional.empty());
when(authStatementAssertion.getPrincipalIpAddressAsSeenByIdp()).thenReturn(Optional.of(principalIpAddressSeenByIdp));
when(authnStatementPersistentId.getNameId()).thenReturn("a name id");
when(authnStatementPersistentId.getNameId()).thenReturn(persistentIdName);
when(authStatementAssertion.getPersistentId()).thenReturn(authnStatementPersistentId);
when(responseFromIdp.getIssuer()).thenReturn(responseIssuer);
when(responseFromIdp.getStatus()).thenReturn(status);
when(responseFromIdp.getMatchingDatasetAssertion()).thenReturn(empty());
when(responseFromIdp.getAuthnStatementAssertion()).thenReturn(empty());
when(responseFromIdp.getSignature()).thenReturn(signature);
when(samlResponse.getIssuer()).thenReturn(issuer);
when(stringToAssertionTransformer.apply(authStatementUnderlyingAssertionBlob)).thenReturn(authnStatementAssertion);
when(stringToAssertionTransformer.apply(matchingDatasetUnderlyingAssertionBlob)).thenReturn(matchingDatasetAssertion);
InboundResponseFromIdpDataGenerator inboundResponseFromIdpDataGenerator = new InboundResponseFromIdpDataGenerator(assertionBlobEncrypter);
service = new IdpAuthnResponseTranslatorService(stringToOpenSamlResponseTransformer, stringToAssertionTransformer, samlResponseToIdaResponseIssuedByIdpTransformer, inboundResponseFromIdpDataGenerator, idpAssertionMetricsCollector, transactionsConfigProxy);
}
use of org.opensaml.saml2.core.AttributeStatement in project verify-hub by alphagov.
the class MatchingDatasetAssertionValidatorTest method validate_shouldNotThrowAnExceptionWhenCurrentAddressIsPresent_ProfileV1_1.
@Test
public void validate_shouldNotThrowAnExceptionWhenCurrentAddressIsPresent_ProfileV1_1() {
AttributeStatement attributeStatement = anEmptyMatchingDatasetAttributeStatement_1_1().withCurrentAddress().build();
Assertion matchingDatasetAssertion = anAssertion().addAttributeStatement(attributeStatement).buildUnencrypted();
validator.validate(matchingDatasetAssertion, RESPONSE_ISSUER_ID);
}
use of org.opensaml.saml2.core.AttributeStatement in project verify-hub by alphagov.
the class MatchingDatasetAssertionValidatorTest method validate_shouldThrowExceptionWhenMultipleAttributeStatementsArePresent.
@Test
public void validate_shouldThrowExceptionWhenMultipleAttributeStatementsArePresent() {
AttributeStatement attributeStatement = anEmptyMatchingDatasetAttributeStatement_1_1().build();
Assertion matchingDatasetAssertion = anAssertion().addAttributeStatement(attributeStatement).addAttributeStatement(attributeStatement).buildUnencrypted();
validateFail(() -> validator.validate(matchingDatasetAssertion, RESPONSE_ISSUER_ID), mdsMultipleStatements());
}
use of org.opensaml.saml2.core.AttributeStatement in project verify-hub by alphagov.
the class MatchingDatasetAssertionValidatorTest method validate_shouldNotThrowAnExceptionWhenPreviousAddressIsPresent_ProfileV1_1.
@Test
public void validate_shouldNotThrowAnExceptionWhenPreviousAddressIsPresent_ProfileV1_1() {
AttributeStatement attributeStatement = anEmptyMatchingDatasetAttributeStatement_1_1().addPreviousAddress().build();
Assertion matchingDatasetAssertion = anAssertion().addAttributeStatement(attributeStatement).buildUnencrypted();
validator.validate(matchingDatasetAssertion, RESPONSE_ISSUER_ID);
}
Aggregations