Skip to content

Commit

Permalink
Switching name to preferred username in AuthFilter (#209)
Browse files Browse the repository at this point in the history
Co-authored-by: Krishnan Subramanian <krishnan.s@aot-technologies.com>
  • Loading branch information
shibin-aot and krishnan-aot authored Jan 18, 2022
1 parent 25e165e commit 18a77a7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
String userId = null;
Map<String, Object> claims;
if (authentication instanceof JwtAuthenticationToken) {
userId = ((JwtAuthenticationToken)authentication).getName();
userId = ((JwtAuthenticationToken) authentication).getToken().getClaimAsString("preferred_username");
claims = ((JwtAuthenticationToken)authentication).getToken().getClaims();
} else if (authentication.getPrincipal() instanceof OidcUser) {
userId = ((OidcUser)authentication.getPrincipal()).getName();
userId = ((OidcUser)authentication.getPrincipal()).getPreferredUsername();
claims = ((OidcUser)authentication.getPrincipal()).getClaims();
} else {
throw new ServletException("Invalid authentication request token");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public void doFilterTest() throws IOException, ServletException {
.thenReturn(oidcUser);
when(oidcUser.getName())
.thenReturn(userId);
when(oidcUser.getPreferredUsername())
.thenReturn(userId);
when(oidcUser.getClaims())
.thenReturn(claims);

Expand Down

0 comments on commit 18a77a7

Please sign in to comment.