Skip to content

Commit

Permalink
Default AuthenticatedPrincipal.getName implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
andreblanke committed Nov 24, 2024
1 parent 464b078 commit 25f8bec
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public DefaultOAuth2AuthenticatedPrincipal(String name, Map<String, Object> attr
this.attributes = Collections.unmodifiableMap(attributes);
this.authorities = (authorities != null) ? Collections.unmodifiableCollection(authorities)
: AuthorityUtils.NO_AUTHORITIES;
this.name = (name != null) ? name : (String) this.attributes.get(this.getNameAttributeKey());
this.name = (name != null) ? name : (String) this.attributes.get("sub");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,9 @@ default <A> A getAttribute(String name) {
*/
String getNameAttributeKey();

@Override
default String getName() {
return getAttribute(getNameAttributeKey()).toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ public DefaultOAuth2User(Collection<? extends GrantedAuthority> authorities, Map
this.nameAttributeKey = nameAttributeKey;
}

@Override
public String getName() {
return this.getAttribute(this.nameAttributeKey).toString();
}

@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return this.authorities;
Expand Down

0 comments on commit 25f8bec

Please sign in to comment.