use of net.codestory.http.security.User in project datashare by ICIJ.
the class OAuth2CookieFilter method otherUri.
@Override
protected Payload otherUri(String uri, Context context, PayloadSupplier nextFilter) throws Exception {
if (context.currentUser() != null) {
return nextFilter.get();
}
String sessionId = readSessionIdInCookie(context);
if (uri.equals("/") || uri.isEmpty()) {
if (sessionId != null) {
String login = sessionIdStore.getLogin(sessionId);
if (login != null) {
User user = users.find(login);
context.setCurrentUser(user);
}
}
return nextFilter.get();
}
return super.otherUri(uri, context, nextFilter);
}
use of net.codestory.http.security.User in project datashare by ICIJ.
the class YesCookieAuthFilter method otherUri.
@Override
protected Payload otherUri(String uri, Context context, PayloadSupplier nextFilter) throws Exception {
Payload payload = super.otherUri(uri, context, nextFilter);
if (payload.code() == 401) {
User user = createUser(NameGenerator.generate());
context.setCurrentUser(user);
return nextFilter.get().withCookie(this.authCookie(this.buildCookie(user, "/")));
}
return payload;
}
use of net.codestory.http.security.User in project datashare by ICIJ.
the class ApiKeyFilter method apply.
@Override
public Payload apply(String uri, Context context, PayloadSupplier nextFilter) throws Exception {
if (context.cookies().get(dsCookieName()) != null) {
return nextFilter.get();
}
String apiKey = readApiKeyInHeader(context);
if (apiKey != null) {
String login = apiKeyStore.getLogin(apiKey);
if (login != null) {
User user = users.find(login);
context.setCurrentUser(user);
return nextFilter.get().withHeader(CACHE_CONTROL, "must-revalidate");
}
}
return new Payload(UNAUTHORIZED);
}