use of org.pac4j.saml.sso.impl.SAML2AuthnRequestBuilder in project cas by apereo.
the class SamlObjectSignatureValidatorTests method verifySamlAuthnRequestSignedMultipleCertificates.
@Test
public void verifySamlAuthnRequestSignedMultipleCertificates() throws Exception {
setupTestContextFor("classpath:metadata/sp-metadata-multicerts.xml", "https://bard.zoom.us");
val request = new MockHttpServletRequest();
val builder = new SAML2AuthnRequestBuilder();
saml2ClientConfiguration.setAuthnRequestSigned(true);
val authnRequest = builder.build(saml2MessageContext);
assertDoesNotThrow(new Executable() {
@Override
public void execute() throws Throwable {
samlObjectSignatureValidator.verifySamlProfileRequestIfNeeded(authnRequest, adaptor, request, samlContext);
}
});
}
use of org.pac4j.saml.sso.impl.SAML2AuthnRequestBuilder in project cas by apereo.
the class SamlObjectSignatureValidatorTests method verifySamlAuthnRequestWithoutSig.
@Test
public void verifySamlAuthnRequestWithoutSig() throws Exception {
val spMetadataPath = new File(FileUtils.getTempDirectory(), "sp-metadata.xml").getCanonicalPath();
setupTestContextFor(spMetadataPath, "cas:example:sp");
val request = new MockHttpServletRequest();
val builder = new SAML2AuthnRequestBuilder();
val authnRequest = builder.build(saml2MessageContext);
val messageContext = new MessageContext();
messageContext.setMessage(authnRequest);
val secContext = messageContext.getSubcontext(SecurityParametersContext.class, true);
val provider = new DefaultSignatureSigningParametersProvider(saml2ClientConfiguration);
Objects.requireNonNull(secContext).setSignatureSigningParameters(provider.build(adaptor.getSsoDescriptor()));
assertDoesNotThrow(new Executable() {
@Override
public void execute() throws Throwable {
samlObjectSignatureValidator.verifySamlProfileRequestIfNeeded(authnRequest, adaptor, request, samlContext);
}
});
}
use of org.pac4j.saml.sso.impl.SAML2AuthnRequestBuilder in project cas by apereo.
the class AuthnRequestRequestedAttributesAttributeReleasePolicyTests method verifyAuthnRequestWithExtensionsAllowed.
@Test
public void verifyAuthnRequestWithExtensionsAllowed() throws IOException {
val filter = new AuthnRequestRequestedAttributesAttributeReleasePolicy();
filter.setAllowedAttributes(List.of("eduPersonPrincipalName"));
filter.setUseFriendlyName(false);
val registeredService = SamlIdPTestUtils.getSamlRegisteredService();
registeredService.setAttributeReleasePolicy(filter);
val builder = new SAML2AuthnRequestBuilder();
val authnRequest = builder.build(saml2MessageContext);
val extensions = ((SAMLObjectBuilder<Extensions>) openSamlConfigBean.getBuilderFactory().getBuilder(Extensions.DEFAULT_ELEMENT_NAME)).buildObject();
val attrBuilder = (SAMLObjectBuilder<RequestedAttribute>) openSamlConfigBean.getBuilderFactory().getBuilder(RequestedAttribute.DEFAULT_ELEMENT_NAME);
val requestAttribute = attrBuilder.buildObject(RequestedAttribute.DEFAULT_ELEMENT_NAME);
requestAttribute.setIsRequired(false);
requestAttribute.setName("eduPersonPrincipalName");
extensions.getUnknownXMLObjects().add(requestAttribute);
authnRequest.setExtensions(extensions);
try (val writer = SamlUtils.transformSamlObject(openSamlConfigBean, authnRequest)) {
val samlRequest = EncodingUtils.encodeBase64(writer.toString().getBytes(StandardCharsets.UTF_8));
val request = HttpRequestUtils.getHttpServletRequestFromRequestAttributes();
val response = HttpRequestUtils.getHttpServletResponseFromRequestAttributes();
val context = new JEEContext(request, response);
samlIdPDistributedSessionStore.set(context, SamlProtocolConstants.PARAMETER_SAML_REQUEST, samlRequest);
val messageContext = new MessageContext();
messageContext.setMessage(authnRequest);
samlIdPDistributedSessionStore.set(context, MessageContext.class.getName(), SamlIdPAuthenticationContext.from(messageContext).encode());
val releasePolicyContext = RegisteredServiceAttributeReleasePolicyContext.builder().registeredService(registeredService).service(CoreAuthenticationTestUtils.getService()).principal(getPrincipal("casuser", CollectionUtils.wrap("eduPersonPrincipalName", "casuser", "givenName", "CAS"))).build();
val attributes = filter.getAttributes(releasePolicyContext);
assertTrue(attributes.containsKey("eduPersonPrincipalName"));
val definitions = filter.determineRequestedAttributeDefinitions(releasePolicyContext);
assertTrue(definitions.contains("eduPersonPrincipalName"));
}
}
use of org.pac4j.saml.sso.impl.SAML2AuthnRequestBuilder in project cas by apereo.
the class AuthnRequestRequestedAttributesAttributeReleasePolicyTests method verifyAuthnRequestWithoutExtensions.
@Test
public void verifyAuthnRequestWithoutExtensions() throws IOException {
val filter = new AuthnRequestRequestedAttributesAttributeReleasePolicy();
filter.setAllowedAttributes(List.of("eduPersonPrincipalAttribute"));
filter.setUseFriendlyName(true);
val registeredService = SamlIdPTestUtils.getSamlRegisteredService();
registeredService.setAttributeReleasePolicy(filter);
val builder = new SAML2AuthnRequestBuilder();
val authnRequest = builder.build(saml2MessageContext);
try (val writer = SamlUtils.transformSamlObject(openSamlConfigBean, authnRequest)) {
val samlRequest = EncodingUtils.encodeBase64(writer.toString().getBytes(StandardCharsets.UTF_8));
val request = HttpRequestUtils.getHttpServletRequestFromRequestAttributes();
val response = HttpRequestUtils.getHttpServletResponseFromRequestAttributes();
val context = new JEEContext(request, response);
samlIdPDistributedSessionStore.set(context, SamlProtocolConstants.PARAMETER_SAML_REQUEST, samlRequest);
val messageContext = new MessageContext();
messageContext.setMessage(authnRequest);
samlIdPDistributedSessionStore.set(context, MessageContext.class.getName(), SamlIdPAuthenticationContext.from(messageContext).encode());
val releasePolicyContext = RegisteredServiceAttributeReleasePolicyContext.builder().registeredService(registeredService).service(CoreAuthenticationTestUtils.getService()).principal(getPrincipal("casuser", CollectionUtils.wrap("eduPersonPrincipalName", "casuser"))).build();
val attributes = filter.getAttributes(releasePolicyContext);
assertTrue(attributes.isEmpty());
}
}
use of org.pac4j.saml.sso.impl.SAML2AuthnRequestBuilder in project cas by apereo.
the class AuthnRequestRequestedAttributesAttributeReleasePolicyTests method verifyAuthnRequestWithExtensionsNotAllowed.
@Test
public void verifyAuthnRequestWithExtensionsNotAllowed() throws IOException {
val filter = new AuthnRequestRequestedAttributesAttributeReleasePolicy();
filter.setAllowedAttributes(List.of("eduPersonPrincipalAttribute"));
filter.setUseFriendlyName(false);
val registeredService = SamlIdPTestUtils.getSamlRegisteredService();
registeredService.setAttributeReleasePolicy(filter);
val builder = new SAML2AuthnRequestBuilder();
val authnRequest = builder.build(saml2MessageContext);
val extensions = ((SAMLObjectBuilder<Extensions>) openSamlConfigBean.getBuilderFactory().getBuilder(Extensions.DEFAULT_ELEMENT_NAME)).buildObject();
val attrBuilder = (SAMLObjectBuilder<RequestedAttribute>) openSamlConfigBean.getBuilderFactory().getBuilder(RequestedAttribute.DEFAULT_ELEMENT_NAME);
val requestAttribute = attrBuilder.buildObject(RequestedAttribute.DEFAULT_ELEMENT_NAME);
requestAttribute.setIsRequired(false);
requestAttribute.setName("givenName");
extensions.getUnknownXMLObjects().add(requestAttribute);
authnRequest.setExtensions(extensions);
try (val writer = SamlUtils.transformSamlObject(openSamlConfigBean, authnRequest)) {
val samlRequest = EncodingUtils.encodeBase64(writer.toString().getBytes(StandardCharsets.UTF_8));
val request = HttpRequestUtils.getHttpServletRequestFromRequestAttributes();
val response = HttpRequestUtils.getHttpServletResponseFromRequestAttributes();
val context = new JEEContext(request, response);
samlIdPDistributedSessionStore.set(context, SamlProtocolConstants.PARAMETER_SAML_REQUEST, samlRequest);
val messageContext = new MessageContext();
messageContext.setMessage(authnRequest);
samlIdPDistributedSessionStore.set(context, MessageContext.class.getName(), SamlIdPAuthenticationContext.from(messageContext).encode());
val releasePolicyContext = RegisteredServiceAttributeReleasePolicyContext.builder().registeredService(registeredService).service(CoreAuthenticationTestUtils.getService()).principal(getPrincipal("casuser", CollectionUtils.wrap("eduPersonPrincipalName", "casuser", "givenName", "CAS"))).build();
val attributes = filter.getAttributes(releasePolicyContext);
assertTrue(attributes.isEmpty());
}
}
Aggregations