Skip to content

Commit

Permalink
Merge pull request #2255 from DamnClin/open-read-principal
Browse files Browse the repository at this point in the history
Open readPrincipal method
  • Loading branch information
pascalgrimaud authored Jun 28, 2022
2 parents 42259b7 + cd31c3a commit fd88255
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package {{packageName}}.authentication.infrastructure.primary;
import {{packageName}}.authentication.domain.Role;
import {{packageName}}.authentication.domain.Roles;
import {{packageName}}.authentication.domain.Username;
import {{packageName}}.error.domain.Assert;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
Expand Down Expand Up @@ -48,7 +49,18 @@ public final class AuthenticatedUser {
return authentication().map(AuthenticatedUser::readPrincipal).flatMap(Username::of);
}

private static String readPrincipal(Authentication authentication) {
/**
* Read user principal from authentication
*
* @param authentication
* authentication to read the principal from
* @return The user principal
* @throws UnknownAuthenticationException
* if the authentication can't be read (unknown token type)
*/
public static String readPrincipal(Authentication authentication) {
Assert.notNull("authentication", authentication);
if (authentication.getPrincipal() instanceof UserDetails details) {
return details.getUsername();
}
Expand Down

0 comments on commit fd88255

Please sign in to comment.