use of org.pac4j.saml.sso.impl.SAML2AuthnRequestBuilder in project cas by apereo.
the class DefaultDelegatedClientAuthenticationWebflowManagerTests method verifyPassiveAuthnOperation.
@Test
public void verifyPassiveAuthnOperation() throws Exception {
val registeredService = RegisteredServiceTestUtils.getRegisteredService(UUID.randomUUID().toString());
registeredService.setProperties(Map.of(RegisteredServiceProperty.RegisteredServiceProperties.DELEGATED_AUTHN_PASSIVE_AUTHN.getPropertyName(), new DefaultRegisteredServiceProperty("true")));
servicesManager.save(registeredService);
httpServletRequest.setParameter(CasProtocolConstants.PARAMETER_SERVICE, registeredService.getServiceId());
val pair = setupTestContextFor(File.createTempFile("sp-metadata", ".xml").getAbsolutePath(), "cas.example.sp");
val ticket = delegatedClientAuthenticationWebflowManager.store(context, pair.getLeft());
assertNotNull(ticketRegistry.getTicket(ticket.getId()));
assertEquals(ticket.getId(), delegatedClientDistributedSessionStore.get(context, SAML2StateGenerator.SAML_RELAY_STATE_ATTRIBUTE).get());
val builder = new SAML2AuthnRequestBuilder();
val result = builder.build(pair.getRight());
assertTrue(result.isPassive());
httpServletRequest.addParameter("RelayState", ticket.getId());
val service = delegatedClientAuthenticationWebflowManager.retrieve(requestContext, context, pair.getLeft());
assertNotNull(service);
assertNull(ticketRegistry.getTicket(ticket.getId()));
}
use of org.pac4j.saml.sso.impl.SAML2AuthnRequestBuilder in project cas by apereo.
the class DefaultDelegatedClientAuthenticationWebflowManagerTests method verifyForceAuthnOperation.
@Test
public void verifyForceAuthnOperation() throws Exception {
val registeredService = RegisteredServiceTestUtils.getRegisteredService(UUID.randomUUID().toString());
registeredService.setProperties(Map.of(RegisteredServiceProperty.RegisteredServiceProperties.DELEGATED_AUTHN_FORCE_AUTHN.getPropertyName(), new DefaultRegisteredServiceProperty("true")));
servicesManager.save(registeredService);
httpServletRequest.setParameter(CasProtocolConstants.PARAMETER_SERVICE, registeredService.getServiceId());
val pair = setupTestContextFor(File.createTempFile("sp-metadata", ".xml").getAbsolutePath(), "cas.example.sp");
val ticket = delegatedClientAuthenticationWebflowManager.store(context, pair.getLeft());
assertNotNull(ticketRegistry.getTicket(ticket.getId()));
assertEquals(ticket.getId(), delegatedClientDistributedSessionStore.get(context, SAML2StateGenerator.SAML_RELAY_STATE_ATTRIBUTE).get());
val builder = new SAML2AuthnRequestBuilder();
val result = builder.build(pair.getRight());
assertTrue(result.isForceAuthn());
httpServletRequest.addParameter("RelayState", ticket.getId());
val service = delegatedClientAuthenticationWebflowManager.retrieve(requestContext, context, pair.getLeft());
assertNotNull(service);
assertNull(ticketRegistry.getTicket(ticket.getId()));
}
use of org.pac4j.saml.sso.impl.SAML2AuthnRequestBuilder in project cas by apereo.
the class SamlObjectSignatureValidatorTests method verifySamlAuthnRequestSigned.
@Test
public void verifySamlAuthnRequestSigned() 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()));
val handler = new SAMLOutboundProtocolMessageSigningHandler();
handler.initialize();
handler.invoke(messageContext);
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 verifySamlAuthnRequestNotSigned.
@Test
public void verifySamlAuthnRequestNotSigned() 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);
samlObjectSignatureValidator.verifySamlProfileRequestIfNeeded(authnRequest, adaptor, request, samlContext);
}
Aggregations