use of com.datastax.fallout.service.auth.FalloutTokenAuthenticator in project fallout by datastax.
the class FalloutServiceBase method getAuthFilters.
private List<AuthFilter<String, User>> getAuthFilters(FC conf, UserDAO userDAO) {
List<AuthFilter<String, User>> filters = new ArrayList<>();
// This will only be applied to methods/classes annotated with RolesAllowed
final Authorizer<User> adminAuthorizer = (user, role) -> user.isAdmin() && role.equals("ADMIN");
AuthFilter<String, User> oauthCredentialAuthFilter = new OAuthCredentialAuthFilter.Builder<User>().setAuthenticator(new FalloutTokenAuthenticator(userDAO, OAUTH_REALM)).setAuthorizer(adminAuthorizer).setPrefix(OAUTH_BEARER_TOKEN_TYPE).setRealm(OAUTH_REALM).buildAuthFilter();
filters.add(oauthCredentialAuthFilter);
AuthFilter<String, User> uiAuthFilter;
if (conf.getAuthenticationMode() == FalloutConfiguration.AuthenticationMode.SINGLE_USER) {
if (conf.getAdminUserCreds().isEmpty()) {
throw new RuntimeException(String.format("Cannot use %s authentication mode without specifying %s in the environment", FalloutConfiguration.AuthenticationMode.SINGLE_USER, FalloutConfiguration.ADMIN_CREDS_ENV_VAR));
}
uiAuthFilter = new SingleUserAuthFilter(() -> userDAO.getUser(conf.getAdminUserCreds().get().email()));
} else {
uiAuthFilter = new FalloutCookieAuthFilter.Builder().setAuthenticator(new FalloutTokenAuthenticator(userDAO, COOKIE_NAME)).setAuthorizer(adminAuthorizer).setPrefix(OAUTH_BEARER_TOKEN_TYPE).setRealm(OAUTH_REALM).buildAuthFilter();
}
filters.add(uiAuthFilter);
return filters;
}
Aggregations