Skip to content

Commit 25f8bec

Browse files
committed
Default AuthenticatedPrincipal.getName implementation
1 parent 464b078 commit 25f8bec

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/DefaultOAuth2AuthenticatedPrincipal.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public DefaultOAuth2AuthenticatedPrincipal(String name, Map<String, Object> attr
6464
this.attributes = Collections.unmodifiableMap(attributes);
6565
this.authorities = (authorities != null) ? Collections.unmodifiableCollection(authorities)
6666
: AuthorityUtils.NO_AUTHORITIES;
67-
this.name = (name != null) ? name : (String) this.attributes.get(this.getNameAttributeKey());
67+
this.name = (name != null) ? name : (String) this.attributes.get("sub");
6868
}
6969

7070
/**

oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/OAuth2AuthenticatedPrincipal.java

+5
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,9 @@ default <A> A getAttribute(String name) {
6464
*/
6565
String getNameAttributeKey();
6666

67+
@Override
68+
default String getName() {
69+
return getAttribute(getNameAttributeKey()).toString();
70+
}
71+
6772
}

oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/user/DefaultOAuth2User.java

-5
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ public DefaultOAuth2User(Collection<? extends GrantedAuthority> authorities, Map
7979
this.nameAttributeKey = nameAttributeKey;
8080
}
8181

82-
@Override
83-
public String getName() {
84-
return this.getAttribute(this.nameAttributeKey).toString();
85-
}
86-
8782
@Override
8883
public Collection<? extends GrantedAuthority> getAuthorities() {
8984
return this.authorities;

0 commit comments

Comments
 (0)