use of org.pac4j.saml.config.SAML2Configuration in project cas by apereo.
the class DefaultDelegatedClientAuthenticationWebflowManagerTests method verifyExpiredTicketOperation.
@Test
public void verifyExpiredTicketOperation() throws Exception {
val config = new SAML2Configuration();
val client = new SAML2Client(config);
val ticket = delegatedClientAuthenticationWebflowManager.store(context, client);
assertNotNull(ticketRegistry.getTicket(ticket.getId()));
assertEquals(ticket.getId(), delegatedClientDistributedSessionStore.get(context, SAML2StateGenerator.SAML_RELAY_STATE_ATTRIBUTE).get());
httpServletRequest.addParameter("RelayState", ticket.getId());
ticket.markTicketExpired();
assertThrows(UnauthorizedServiceException.class, () -> delegatedClientAuthenticationWebflowManager.retrieve(requestContext, context, client));
}
use of org.pac4j.saml.config.SAML2Configuration in project cas by apereo.
the class DefaultDelegatedClientAuthenticationWebflowManagerTests method setupTestContextFor.
private Pair<SAML2Client, SAML2MessageContext> setupTestContextFor(final String spMetadataPath, final String spEntityId) throws Exception {
val idpMetadata = new File("src/test/resources/idp-metadata.xml").getCanonicalPath();
val keystorePath = new File(FileUtils.getTempDirectory(), "keystore").getCanonicalPath();
val saml2ClientConfiguration = new SAML2Configuration(keystorePath, "changeit", "changeit", idpMetadata);
saml2ClientConfiguration.setServiceProviderEntityId(spEntityId);
saml2ClientConfiguration.setServiceProviderMetadataPath(spMetadataPath);
saml2ClientConfiguration.setForceKeystoreGeneration(true);
saml2ClientConfiguration.setForceServiceProviderMetadataGeneration(true);
saml2ClientConfiguration.init();
val saml2Client = new SAML2Client(saml2ClientConfiguration);
saml2Client.setCallbackUrl("http://callback.example.org");
saml2Client.init();
val saml2MessageContext = new SAML2MessageContext();
saml2MessageContext.setSaml2Configuration(saml2ClientConfiguration);
saml2MessageContext.setWebContext(context);
val peer = saml2MessageContext.getMessageContext().getSubcontext(SAMLPeerEntityContext.class, true);
assertNotNull(peer);
peer.setEntityId("https://cas.example.org/idp");
val md = peer.getSubcontext(SAMLMetadataContext.class, true);
assertNotNull(md);
val roleDescriptorResolver = new PredicateRoleDescriptorResolver(saml2Client.getIdpMetadataResolver().resolve());
roleDescriptorResolver.initialize();
md.setRoleDescriptor(roleDescriptorResolver.resolveSingle(new CriteriaSet(new EntityIdCriterion(Objects.requireNonNull(peer.getEntityId())), new EntityRoleCriterion(IDPSSODescriptor.DEFAULT_ELEMENT_NAME))));
val self = saml2MessageContext.getMessageContext().getSubcontext(SAMLSelfEntityContext.class, true);
assertNotNull(self);
self.setEntityId(saml2ClientConfiguration.getServiceProviderEntityId());
val sp = self.getSubcontext(SAMLMetadataContext.class, true);
assertNotNull(sp);
val spResolver = new PredicateRoleDescriptorResolver(saml2Client.getSpMetadataResolver().resolve());
spResolver.initialize();
sp.setRoleDescriptor(spResolver.resolveSingle(new CriteriaSet(new EntityIdCriterion(Objects.requireNonNull(self.getEntityId())), new EntityRoleCriterion(SPSSODescriptor.DEFAULT_ELEMENT_NAME))));
return Pair.of(saml2Client, saml2MessageContext);
}
use of org.pac4j.saml.config.SAML2Configuration in project knox by apache.
the class SAML2ClientConfigurationDecoratorTest method testSaml2ClientConfigurationDecoration.
@Test
public void testSaml2ClientConfigurationDecoration() throws Exception {
final SAML2Configuration saml2Configuration = new SAML2Configuration();
final SAML2Client client = new SAML2Client(saml2Configuration);
final Map<String, String> properties = new HashMap<>();
properties.put("useNameQualifier", "true");
properties.put("forceAuth", "true");
properties.put("passive", "true");
properties.put("nameIdPolicyFormat", "testPolicyFormat");
final SAML2ClientConfigurationDecorator saml2ConfigurationDecorator = new SAML2ClientConfigurationDecorator();
saml2ConfigurationDecorator.decorateClients(Collections.singletonList(client), properties);
assertTrue(saml2Configuration.isUseNameQualifier());
assertTrue(saml2Configuration.isForceAuth());
assertTrue(saml2Configuration.isPassive());
assertEquals("testPolicyFormat", saml2Configuration.getNameIdPolicyFormat());
}
Aggregations