io.dropwizard.bundles.apikey.RoleAuthorizer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dropwizard-api-key-bundle Show documentation
Show all versions of dropwizard-api-key-bundle Show documentation
Dropwizard bundle that allows your application to support API keys.
package io.dropwizard.bundles.apikey;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.SetMultimap;
import io.dropwizard.auth.Authorizer;
import java.security.Principal;
/**
* Authorizes principals based upon a mapping between {@link Principal#getName()}
* and enabled roles.
*/
public class RoleAuthorizer implements Authorizer
{
private final SetMultimap roles;
public RoleAuthorizer(Multimap roles) {
this.roles = ImmutableSetMultimap.copyOf(roles);
}
@Override
public boolean authorize(P principal, String role) {
return roles.containsEntry(principal.getName(), role);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy