Search in sources :

Example 16 with BasicCredential

use of org.opensaml.security.credential.BasicCredential in project verify-hub by alphagov.

the class IdpAuthnResponseTranslatorResourceTest method handleResponseFromIdp_shouldDecryptAssertionEncryptedWithSecondaryEncryptionCertificates.

@Test
public void handleResponseFromIdp_shouldDecryptAssertionEncryptedWithSecondaryEncryptionCertificates() throws Exception {
    BasicCredential secondaryEncryptionKey = new BasicCredential(new HardCodedKeyStore(HUB_ENTITY_ID).getSecondaryEncryptionKeyForEntity(HUB_ENTITY_ID));
    SamlAuthnResponseTranslatorDto samlResponseDto = getSuccessSamlAuthnResponseTranslatorDto(secondaryEncryptionKey);
    Response clientResponse = postToSamlEngine(samlResponseDto);
    assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
}
Also used : Response(javax.ws.rs.core.Response) HardCodedKeyStore(uk.gov.ida.saml.core.test.HardCodedKeyStore) SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.samlengine.contracts.SamlAuthnResponseTranslatorDto) SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto(uk.gov.ida.integrationtest.hub.samlengine.builders.SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto) BasicCredential(org.opensaml.security.credential.BasicCredential) Test(org.junit.jupiter.api.Test)

Example 17 with BasicCredential

use of org.opensaml.security.credential.BasicCredential in project verify-hub by alphagov.

the class IdpAuthnResponseTranslatorResourceTest method shouldEncryptTheMatchingDatasetAssertionWhenGivenMatchingServiceEntityId.

@Test
public void shouldEncryptTheMatchingDatasetAssertionWhenGivenMatchingServiceEntityId() throws Exception {
    BasicCredential primaryEncryptionKey = new BasicCredential(new HardCodedKeyStore(HUB_ENTITY_ID).getPrimaryEncryptionKeyForEntity(HUB_ENTITY_ID));
    SamlAuthnResponseTranslatorDto samlResponseDto = getSuccessSamlAuthnResponseTranslatorDto(primaryEncryptionKey);
    Response clientResponse = postToSamlEngine(samlResponseDto);
    assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    InboundResponseFromIdpDto inboundResponseFromIdpDto = clientResponse.readEntity(InboundResponseFromIdpDto.class);
    assertThat(inboundResponseFromIdpDto.getEncryptedMatchingDatasetAssertion().isPresent()).isTrue();
}
Also used : Response(javax.ws.rs.core.Response) HardCodedKeyStore(uk.gov.ida.saml.core.test.HardCodedKeyStore) InboundResponseFromIdpDto(uk.gov.ida.hub.samlengine.domain.InboundResponseFromIdpDto) SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.samlengine.contracts.SamlAuthnResponseTranslatorDto) SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto(uk.gov.ida.integrationtest.hub.samlengine.builders.SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto) BasicCredential(org.opensaml.security.credential.BasicCredential) Test(org.junit.jupiter.api.Test)

Example 18 with BasicCredential

use of org.opensaml.security.credential.BasicCredential in project spring-security by spring-projects.

the class OpenSamlSigningUtils method resolveSigningCredentials.

private static List<Credential> resolveSigningCredentials(RelyingPartyRegistration relyingPartyRegistration) {
    List<Credential> credentials = new ArrayList<>();
    for (Saml2X509Credential x509Credential : relyingPartyRegistration.getSigningX509Credentials()) {
        X509Certificate certificate = x509Credential.getCertificate();
        PrivateKey privateKey = x509Credential.getPrivateKey();
        BasicCredential credential = CredentialSupport.getSimpleCredential(certificate, privateKey);
        credential.setEntityId(relyingPartyRegistration.getEntityId());
        credential.setUsageType(UsageType.SIGNING);
        credentials.add(credential);
    }
    return credentials;
}
Also used : BasicCredential(org.opensaml.security.credential.BasicCredential) Credential(org.opensaml.security.credential.Credential) Saml2X509Credential(org.springframework.security.saml2.core.Saml2X509Credential) PrivateKey(java.security.PrivateKey) ArrayList(java.util.ArrayList) Saml2X509Credential(org.springframework.security.saml2.core.Saml2X509Credential) X509Certificate(java.security.cert.X509Certificate) BasicCredential(org.opensaml.security.credential.BasicCredential)

Example 19 with BasicCredential

use of org.opensaml.security.credential.BasicCredential in project spring-security by spring-projects.

the class OpenSamlSigningUtils method resolveSigningCredentials.

private static List<Credential> resolveSigningCredentials(RelyingPartyRegistration relyingPartyRegistration) {
    List<Credential> credentials = new ArrayList<>();
    for (Saml2X509Credential x509Credential : relyingPartyRegistration.getSigningX509Credentials()) {
        X509Certificate certificate = x509Credential.getCertificate();
        PrivateKey privateKey = x509Credential.getPrivateKey();
        BasicCredential credential = CredentialSupport.getSimpleCredential(certificate, privateKey);
        credential.setEntityId(relyingPartyRegistration.getEntityId());
        credential.setUsageType(UsageType.SIGNING);
        credentials.add(credential);
    }
    return credentials;
}
Also used : BasicCredential(org.opensaml.security.credential.BasicCredential) Credential(org.opensaml.security.credential.Credential) Saml2X509Credential(org.springframework.security.saml2.core.Saml2X509Credential) PrivateKey(java.security.PrivateKey) ArrayList(java.util.ArrayList) Saml2X509Credential(org.springframework.security.saml2.core.Saml2X509Credential) X509Certificate(java.security.cert.X509Certificate) BasicCredential(org.opensaml.security.credential.BasicCredential)

Aggregations

BasicCredential (org.opensaml.security.credential.BasicCredential)19 Credential (org.opensaml.security.credential.Credential)6 PrivateKey (java.security.PrivateKey)5 X509Certificate (java.security.cert.X509Certificate)5 ArrayList (java.util.ArrayList)5 Saml2X509Credential (org.springframework.security.saml2.core.Saml2X509Credential)5 Response (javax.ws.rs.core.Response)4 Test (org.junit.jupiter.api.Test)4 lombok.val (lombok.val)3 BasicX509Credential (org.opensaml.security.x509.BasicX509Credential)3 SamlAuthnResponseTranslatorDto (uk.gov.ida.hub.samlengine.contracts.SamlAuthnResponseTranslatorDto)3 SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto (uk.gov.ida.integrationtest.hub.samlengine.builders.SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto)3 HardCodedKeyStore (uk.gov.ida.saml.core.test.HardCodedKeyStore)3 SamlException (org.apereo.cas.support.saml.SamlException)2 DecrypterFactory (uk.gov.ida.saml.security.DecrypterFactory)2 PublicKey (java.security.PublicKey)1 CriteriaSet (net.shibboleth.utilities.java.support.resolver.CriteriaSet)1 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)1 SamlIdPProperties (org.apereo.cas.configuration.model.support.saml.idp.SamlIdPProperties)1 SamlIdPResponseProperties (org.apereo.cas.configuration.model.support.saml.idp.SamlIdPResponseProperties)1