use of org.pac4j.core.context.WebContext in project pac4j by pac4j.
the class CasClientTests method testCallbackUrlResolver.
@Test
public void testCallbackUrlResolver() {
final CasConfiguration configuration = new CasConfiguration();
configuration.setPrefixUrl(CAS);
configuration.setLoginUrl(CAS + LOGIN);
final CasClient casClient = new CasClient(configuration);
casClient.setCallbackUrl(CASBACK);
casClient.setUrlResolver((url, context) -> HOST + url);
casClient.setCallbackUrlResolver(new CallbackUrlResolver() {
@Override
public String compute(final UrlResolver urlResolver, final String url, final String clientName, final WebContext context) {
return null;
}
@Override
public boolean matches(final String clientName, final WebContext context) {
return false;
}
});
casClient.init();
assertEquals(HOST + CAS + LOGIN, configuration.computeFinalLoginUrl(null));
assertEquals(HOST + CAS + "/", configuration.computeFinalPrefixUrl(null));
}
use of org.pac4j.core.context.WebContext in project druid by druid-io.
the class Pac4jSessionStoreTest method testSetAndGet.
@Test
public void testSetAndGet() {
Pac4jSessionStore<WebContext> sessionStore = new Pac4jSessionStore("test-cookie-passphrase");
WebContext webContext1 = EasyMock.mock(WebContext.class);
EasyMock.expect(webContext1.getScheme()).andReturn("https");
Capture<Cookie> cookieCapture = EasyMock.newCapture();
webContext1.addResponseCookie(EasyMock.capture(cookieCapture));
EasyMock.replay(webContext1);
sessionStore.set(webContext1, "key", "value");
Cookie cookie = cookieCapture.getValue();
Assert.assertTrue(cookie.isSecure());
Assert.assertTrue(cookie.isHttpOnly());
Assert.assertTrue(cookie.isSecure());
Assert.assertEquals(900, cookie.getMaxAge());
WebContext webContext2 = EasyMock.mock(WebContext.class);
EasyMock.expect(webContext2.getRequestCookies()).andReturn(Collections.singletonList(cookie));
EasyMock.replay(webContext2);
Assert.assertEquals("value", sessionStore.get(webContext2, "key"));
}
use of org.pac4j.core.context.WebContext in project cas by apereo.
the class OidcPrivateKeyJwtAuthenticator method validate.
@Override
public void validate(final Credentials creds, final WebContext webContext, final SessionStore sessionStore) {
val credentials = (UsernamePasswordCredentials) creds;
val registeredService = verifyCredentials(credentials, webContext);
if (registeredService == null) {
LOGGER.warn("Unable to verify credentials");
return;
}
val clientId = registeredService.getClientId();
val audience = casProperties.getServer().getPrefix().concat('/' + OidcConstants.BASE_OIDC_URL + '/' + OidcConstants.ACCESS_TOKEN_URL);
val keys = OidcJsonWebKeyStoreUtils.getJsonWebKeySet(registeredService, applicationContext, Optional.of(OidcJsonWebKeyUsage.SIGNING));
keys.ifPresent(Unchecked.consumer(jwks -> jwks.getJsonWebKeys().forEach(jsonWebKey -> {
val consumer = new JwtConsumerBuilder().setVerificationKey(jsonWebKey.getKey()).setRequireSubject().setExpectedSubject(clientId).setRequireJwtId().setRequireExpirationTime().setExpectedIssuer(true, clientId).setExpectedAudience(true, audience).build();
determineUserProfile(credentials, consumer);
})));
}
use of org.pac4j.core.context.WebContext in project cas by apereo.
the class SamlIdPUtils method retrieveSamlRequest.
/**
* Retrieve authn request authn request.
*
* @param context the context
* @param sessionStore the session store
* @param openSamlConfigBean the open saml config bean
* @param clazz the clazz
* @return the request
*/
public static Optional<Pair<? extends RequestAbstractType, MessageContext>> retrieveSamlRequest(final WebContext context, final SessionStore sessionStore, final OpenSamlConfigBean openSamlConfigBean, final Class<? extends RequestAbstractType> clazz) {
LOGGER.trace("Retrieving authentication request from scope");
val authnContext = sessionStore.get(context, SamlProtocolConstants.PARAMETER_SAML_REQUEST).map(String.class::cast).map(value -> retrieveSamlRequest(openSamlConfigBean, clazz, value)).flatMap(authnRequest -> sessionStore.get(context, MessageContext.class.getName()).map(String.class::cast).map(result -> SamlIdPAuthenticationContext.decode(result).toMessageContext(authnRequest)));
return authnContext.map(ctx -> Pair.of((AuthnRequest) ctx.getMessage(), ctx));
}
use of org.pac4j.core.context.WebContext in project cas by apereo.
the class DistributedJEESessionStore method set.
@Override
public void set(final WebContext context, final String key, final Object value) {
LOGGER.trace("Setting key: [{}]", key);
val sessionId = getSessionId(context, true).get();
val properties = new HashMap<String, Serializable>();
if (value instanceof Serializable) {
properties.put(key, (Serializable) value);
} else if (value != null) {
LOGGER.warn("Object value [{}] assigned to [{}] is not serializable and may not be part of the ticket [{}]", value, key, sessionId);
}
val ticket = getTransientSessionTicketForSession(context);
if (value == null && ticket != null) {
ticket.getProperties().remove(key);
FunctionUtils.doUnchecked(s -> this.centralAuthenticationService.updateTicket(ticket));
} else if (ticket == null) {
val transientFactory = (TransientSessionTicketFactory) this.ticketFactory.get(TransientSessionTicket.class);
val created = transientFactory.create(sessionId, properties);
FunctionUtils.doUnchecked(s -> this.centralAuthenticationService.addTicket(created));
} else {
ticket.getProperties().putAll(properties);
FunctionUtils.doUnchecked(s -> this.centralAuthenticationService.updateTicket(ticket));
}
}
Aggregations