All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.dropwizard.auth.PrincipalContainerRequestValueFactory Maven / Gradle / Ivy

There is a newer version: 1.3.7
Show newest version
package io.dropwizard.auth;

import org.glassfish.jersey.server.ContainerRequest;
import org.glassfish.jersey.server.internal.inject.AbstractContainerRequestValueFactory;

import java.security.Principal;

/**
 * A value factory which extracts the {@link Principal} from the
 * current {@link ContainerRequest} instance.
 */
class PrincipalContainerRequestValueFactory extends AbstractContainerRequestValueFactory {
    /**
     * @return {@link Principal} stored on the request, or {@code null}
     *         if no object was found.
     */
    public Principal provide() {
        final Principal principal = getContainerRequest().getSecurityContext().getUserPrincipal();
        if (principal == null) {
            throw new IllegalStateException("Cannot inject a custom principal into unauthenticated request");
        }
        return principal;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy