Search in sources :

Example 1 with SessionScoped

use of com.peterphi.std.guice.web.rest.scoping.SessionScoped in project stdlib by petergeneric.

the class WebappAuthenticationModule method getCurrentUser.

@Provides
@SessionScoped
public CurrentUser getCurrentUser(Injector injector, HttpServletRequest request) {
    for (String providerName : providerNames) {
        final Provider<CurrentUser> provider = injector.getProvider(Key.get(CurrentUser.class, Names.named(providerName)));
        final CurrentUser user = provider.get();
        if (user != null) {
            // Store the user info for logging
            if (user.getUsername() != null) {
                MDC.put(TracingConstants.MDC_USER_ID, user.getUsername());
            }
            return user;
        }
    }
    throw new IllegalArgumentException("No provider could determine a user for HTTP request!");
}
Also used : CurrentUser(com.peterphi.std.guice.common.auth.iface.CurrentUser) SessionScoped(com.peterphi.std.guice.web.rest.scoping.SessionScoped) Provides(com.google.inject.Provides)

Aggregations

Provides (com.google.inject.Provides)1 CurrentUser (com.peterphi.std.guice.common.auth.iface.CurrentUser)1 SessionScoped (com.peterphi.std.guice.web.rest.scoping.SessionScoped)1