use of org.pac4j.core.context.Cookie in project ratpack by ratpack.
the class RatpackWebContext method getRequestCookies.
@Override
public Collection<Cookie> getRequestCookies() {
final List<Cookie> newCookies = new ArrayList<>();
final Set<io.netty.handler.codec.http.cookie.Cookie> cookies = request.getCookies();
for (final io.netty.handler.codec.http.cookie.Cookie cookie : cookies) {
final Cookie newCookie = new Cookie(cookie.name(), cookie.value());
newCookie.setDomain(cookie.domain());
newCookie.setPath(cookie.path());
newCookie.setMaxAge((int) cookie.maxAge());
newCookie.setSecure(cookie.isSecure());
newCookie.setHttpOnly(cookie.isHttpOnly());
newCookies.add(newCookie);
}
return newCookies;
}
use of org.pac4j.core.context.Cookie in project knox by apache.
the class KnoxSessionStore method set.
public void set(WebContext context, String key, Object value) {
logger.debug("Save in session: {} = {}", key, value);
final Cookie cookie = new Cookie(PAC4J_SESSION_PREFIX + key, compressEncryptBase64(value));
try {
String domain = Urls.getDomainName(context.getFullRequestURL(), this.domainSuffix);
if (domain == null) {
domain = context.getServerName();
}
cookie.setDomain(domain);
} catch (final Exception e) {
throw new TechnicalException(e);
}
cookie.setHttpOnly(true);
cookie.setSecure(ContextHelper.isHttpsOrSecure(context));
context.addResponseCookie(cookie);
}
use of org.pac4j.core.context.Cookie in project knox by apache.
the class KnoxSessionStore method get.
public Object get(WebContext context, String key) {
final Cookie cookie = ContextHelper.getCookie(context, PAC4J_SESSION_PREFIX + key);
Object value = null;
if (cookie != null) {
value = uncompressDecryptBase64(cookie.getValue());
}
logger.debug("Get from session: {} = {}", key, value);
return value;
}
use of org.pac4j.core.context.Cookie in project pac4j by pac4j.
the class CookieClientTests method testAuthentication.
@Test
public void testAuthentication() {
final CookieClient client = new CookieClient(USERNAME, new SimpleTestTokenAuthenticator());
final MockWebContext context = MockWebContext.create();
final Cookie c = new Cookie(USERNAME, Base64.getEncoder().encodeToString(getClass().getName().getBytes(StandardCharsets.UTF_8)));
context.getRequestCookies().add(c);
final TokenCredentials credentials = client.getCredentials(context);
final CommonProfile profile = client.getUserProfile(credentials, context);
assertEquals(c.getValue(), profile.getId());
}
use of org.pac4j.core.context.Cookie in project pac4j by pac4j.
the class CsrfTokenGeneratorAuthorizer method isAuthorized.
@Override
public boolean isAuthorized(final WebContext context, final List<CommonProfile> profiles) {
CommonHelper.assertNotNull("csrfTokenGenerator", csrfTokenGenerator);
final String token = csrfTokenGenerator.get(context);
context.setRequestAttribute(Pac4jConstants.CSRF_TOKEN, token);
final Cookie cookie = new Cookie(Pac4jConstants.CSRF_TOKEN, token);
if (domain != null) {
cookie.setDomain(domain);
} else {
cookie.setDomain(context.getServerName());
}
if (path != null) {
cookie.setPath(path);
}
if (httpOnly != null) {
cookie.setHttpOnly(httpOnly.booleanValue());
}
if (secure != null) {
cookie.setSecure(secure.booleanValue());
}
context.addResponseCookie(cookie);
return true;
}
Aggregations