use of org.pac4j.core.context.JEEContext in project cas by apereo.
the class DelegatedClientIdentityProviderConfigurationFactoryTests method verifyRedirectUrlCorrectlyEncoded.
@Test
public void verifyRedirectUrlCorrectlyEncoded() {
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
val context = new JEEContext(request, response);
val service = RegisteredServiceTestUtils.getService("example");
service.setOriginalUrl("http://service.original.url.com?response_type=idtoken+token");
val client = new CasClient(new CasConfiguration());
client.setCustomProperties(Map.of(ClientCustomPropertyConstants.CLIENT_CUSTOM_PROPERTY_CSS_CLASS, "custom-class", ClientCustomPropertyConstants.CLIENT_CUSTOM_PROPERTY_AUTO_DISPLAY_NAME, "My Great Client"));
val factory = DelegatedClientIdentityProviderConfigurationFactory.builder().casProperties(casProperties).client(client).service(service).webContext(context).build();
val actual = factory.resolve();
assertTrue(actual.isPresent());
val redirectUrl = actual.get().getRedirectUrl();
assertNotNull(redirectUrl);
assertTrue(redirectUrl.contains(EncodingUtils.urlEncode(service.getOriginalUrl())));
}
use of org.pac4j.core.context.JEEContext in project cas by apereo.
the class BrowserWebStorageSessionStoreTests method verifyOperation.
@Test
public void verifyOperation() {
val store = new BrowserWebStorageSessionStore(webflowCipherExecutor);
val request = new MockHttpServletRequest();
val ctx = new JEEContext(request, new MockHttpServletResponse());
store.set(ctx, "key1", "value1");
store.set(ctx, "key2", List.of("HelloWorld"));
store.set(ctx, "key3", 1234567);
store.set(ctx, "dummy", new Dummy());
var session = store.getTrackableSession(ctx);
assertTrue(session.isPresent());
store.renewSession(ctx);
val trackableSession = (BrowserSessionStorage) session.get();
store.buildFromTrackableSession(ctx, trackableSession.getPayload());
assertTrue(store.get(ctx, "key1").isPresent());
assertTrue(store.get(ctx, "key2").isPresent());
assertTrue(store.get(ctx, "key3").isPresent());
assertTrue(store.get(ctx, "dummy").isPresent());
}
use of org.pac4j.core.context.JEEContext in project cas by apereo.
the class DistributedJEESessionStoreTests method verifyTracking.
@Test
public void verifyTracking() {
val cookie = casProperties.getSessionReplication().getCookie();
val cookieGenerator = CookieUtils.buildCookieRetrievingGenerator(cookie);
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
val store = new DistributedJEESessionStore(centralAuthenticationService, ticketFactory, cookieGenerator);
val context = new JEEContext(request, response);
assertNotNull(request.getSession());
assertFalse(store.renewSession(context));
assertTrue(store.buildFromTrackableSession(context, "trackable-session").isPresent());
assertTrue(store.getTrackableSession(context).isPresent());
}
use of org.pac4j.core.context.JEEContext in project cas by apereo.
the class SamlObjectSignatureValidatorTests method setupTestContextFor.
private void setupTestContextFor(final String spMetadataPath, final String spEntityId) throws Exception {
val idpMetadata = new File("src/test/resources/metadata/idp-metadata.xml").getCanonicalPath();
val keystorePath = new File(FileUtils.getTempDirectory(), "keystore").getCanonicalPath();
saml2ClientConfiguration = new SAML2Configuration(keystorePath, "changeit", "changeit", idpMetadata);
saml2ClientConfiguration.setServiceProviderEntityId(spEntityId);
saml2ClientConfiguration.setServiceProviderMetadataPath(spMetadataPath);
saml2ClientConfiguration.init();
val saml2Client = new SAML2Client(saml2ClientConfiguration);
saml2Client.setCallbackUrl("http://callback.example.org");
saml2Client.init();
samlContext = new MessageContext();
saml2MessageContext = new SAML2MessageContext();
saml2MessageContext.setSaml2Configuration(saml2ClientConfiguration);
saml2MessageContext.setWebContext(new JEEContext(new MockHttpServletRequest(), new MockHttpServletResponse()));
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 idpResolver = SamlIdPUtils.getRoleDescriptorResolver(casSamlIdPMetadataResolver, true);
md.setRoleDescriptor(idpResolver.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 spRes = new InMemoryResourceMetadataResolver(saml2ClientConfiguration.getServiceProviderMetadataResource(), openSamlConfigBean);
spRes.setId(getClass().getSimpleName());
spRes.initialize();
val spResolver = SamlIdPUtils.getRoleDescriptorResolver(spRes, true);
sp.setRoleDescriptor(spResolver.resolveSingle(new CriteriaSet(new EntityIdCriterion(Objects.requireNonNull(self.getEntityId())), new EntityRoleCriterion(SPSSODescriptor.DEFAULT_ELEMENT_NAME))));
val service = new SamlRegisteredService();
service.setName("Sample");
service.setServiceId(saml2ClientConfiguration.getServiceProviderEntityId());
service.setId(100);
service.setDescription("SAML Service");
service.setMetadataLocation(spMetadataPath);
val facade = SamlRegisteredServiceServiceProviderMetadataFacade.get(samlRegisteredServiceCachingMetadataResolver, service, service.getServiceId());
this.adaptor = facade.get();
}
use of org.pac4j.core.context.JEEContext in project cas by apereo.
the class SamlIdPDelegatedAuthenticationConfigurationTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val service = getSamlRegisteredServiceFor("https://cassp.example.org");
service.setId(2000);
val authnRequest = SamlIdPTestUtils.getAuthnRequest(openSamlConfigBean, service);
authnRequest.setForceAuthn(true);
authnRequest.setIsPassive(true);
var builder = (SAMLObjectBuilder) openSamlConfigBean.getBuilderFactory().getBuilder(AuthnContextClassRef.DEFAULT_ELEMENT_NAME);
val classRef = (AuthnContextClassRef) builder.buildObject(AuthnContextClassRef.DEFAULT_ELEMENT_NAME);
classRef.setURI("https://refeds.org/profile/mfa");
builder = (SAMLObjectBuilder) openSamlConfigBean.getBuilderFactory().getBuilder(RequestedAuthnContext.DEFAULT_ELEMENT_NAME);
val reqCtx = (RequestedAuthnContext) builder.buildObject(RequestedAuthnContext.DEFAULT_ELEMENT_NAME);
reqCtx.setComparison(AuthnContextComparisonTypeEnumeration.EXACT);
reqCtx.getAuthnContextClassRefs().add(classRef);
authnRequest.setRequestedAuthnContext(reqCtx);
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
val webContext = new JEEContext(request, response);
val messageContext = new MessageContext();
messageContext.setMessage(authnRequest);
val context = Pair.of(authnRequest, messageContext);
SamlIdPUtils.storeSamlRequest(webContext, openSamlConfigBean, samlIdPDistributedSessionStore, context);
val saml2Client = mock(SAML2Client.class);
assertTrue(customizer.supports(saml2Client, webContext));
customizer.customize(saml2Client, webContext);
assertTrue(webContext.getRequestAttribute(RedirectionActionBuilder.ATTRIBUTE_FORCE_AUTHN).isPresent());
assertTrue(webContext.getRequestAttribute(RedirectionActionBuilder.ATTRIBUTE_PASSIVE).isPresent());
assertTrue(webContext.getRequestAttribute(SAML2ConfigurationContext.REQUEST_ATTR_AUTHN_CONTEXT_CLASS_REFS).isPresent());
assertTrue(webContext.getRequestAttribute(SAML2ConfigurationContext.REQUEST_ATTR_COMPARISON_TYPE).isPresent());
}
Aggregations