package io.dropwizard.auth;
import org.glassfish.jersey.server.ContainerRequest;
import org.glassfish.jersey.server.internal.inject.AbstractContainerRequestValueFactory;
import java.security.Principal;
class PrincipalContainerRequestValueFactory extends AbstractContainerRequestValueFactory<Principal> {
@Override
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;
}
}