Skip to content

Commit

Permalink
Open readPrincipal method
Browse files Browse the repository at this point in the history
  • Loading branch information
DamnClin committed Jun 27, 2022
1 parent c4449fa commit cd31c3a
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 cd31c3a

Please sign in to comment.