Search in sources :

Example 1 with User

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);
}
Also used : User(net.codestory.http.security.User)

Example 2 with User

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;
}
Also used : User(net.codestory.http.security.User) Payload(net.codestory.http.payload.Payload)

Example 3 with User

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);
}
Also used : User(net.codestory.http.security.User) Payload(net.codestory.http.payload.Payload)

Aggregations

User (net.codestory.http.security.User)3 Payload (net.codestory.http.payload.Payload)2