com.brightsparklabs.dropwizard.bundles.auth.external.PrincipalConverter Maven / Gradle / Ivy
Show all versions of dropwizard-external-auth-bundle Show documentation
/*
* Maintained by brightSPARK Labs.
* www.brightsparklabs.com
*
* Refer to LICENSE at repository root for license details.
*/
package com.brightsparklabs.dropwizard.bundles.auth.external;
import jakarta.validation.constraints.NotNull;
import java.security.Principal;
import java.util.Optional;
import org.eclipse.jetty.server.Authentication;
/**
* Interface for converting between {@link InternalUser} and the {@link Principal} used in the
* system.
*
* @param The {@link Principal} type to convert
*/
public interface PrincipalConverter
{
/**
* Convert the principal {@link P} to an {@link InternalUser}.
*
*
For audit logging purposes, the returned {@link InternalUser#getUsername()} should return
* a non-null entry. This value will be passed into {@link
* org.eclipse.jetty.server.Request#setAuthentication(Authentication)} which is captured and
* logged by default in logback.
*
* @param principal principal to convert
* @return the optionally converted {@link InternalUser}, or {@link Optional#empty()} if the
* conversion cannot be done.
*/
Optional convertToInternalUser(P principal);
/**
* Convert the principal {@link InternalUser} to an {@link P}.
*
* @param internalUser internal user to convert
* @return the converted {@link P}
*/
@NotNull
P convertToPrincipal(InternalUser internalUser);
}