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

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

There is a newer version: 5.0.0-alpha.4
Show newest version
package io.dropwizard.auth;

import org.glassfish.jersey.server.ContainerRequest;

import java.security.Principal;
import java.util.Optional;

/**
 * A value factory which extracts an {@link Optional optional} {@link
 * Principal} from the current {@link ContainerRequest} instance.
 */
class OptionalPrincipalContainerRequestValueFactory {
    private final ContainerRequest request;

    public OptionalPrincipalContainerRequestValueFactory(ContainerRequest request) {
        this.request = request;
    }

    /**
     * @return {@link Optional}{@code <}{@link Principal}{@code >}
     *         stored on the request, or {@code Optional.empty()} if
     *         no object was found.
     */
    public Optional provide() {
        return Optional.ofNullable(request.getSecurityContext().getUserPrincipal());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy