Move collectClaims to OidcUserAuthority

Fixes gh-4749
This commit is contained in:
Rob Winch 2017-10-29 20:40:52 -05:00
parent 5fa822d114
commit d9584384c4
3 changed files with 16 additions and 12 deletions

View File

@ -59,7 +59,7 @@ public class DefaultOidcUser extends DefaultOAuth2User implements OidcUser {
public DefaultOidcUser(Set<GrantedAuthority> authorities, OidcIdToken idToken, OidcUserInfo userInfo,
String nameAttributeKey) {
super(authorities, OidcUser.collectClaims(idToken, userInfo), nameAttributeKey);
super(authorities, OidcUserAuthority.collectClaims(idToken, userInfo), nameAttributeKey);
this.idToken = idToken;
this.userInfo = userInfo;
}

View File

@ -55,16 +55,6 @@ public interface OidcUser extends OAuth2User, IdTokenClaimAccessor {
Map<String, Object> getClaims();
static Map<String, Object> collectClaims(OidcIdToken idToken, OidcUserInfo userInfo) {
Assert.notNull(idToken, "idToken cannot be null");
Map<String, Object> claims = new HashMap<>();
if (userInfo != null) {
claims.putAll(userInfo.getClaims());
}
claims.putAll(idToken.getClaims());
return claims;
}
OidcUserInfo getUserInfo();
OidcIdToken getIdToken();

View File

@ -19,6 +19,10 @@ import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.oauth2.core.oidc.OidcUserInfo;
import org.springframework.security.oauth2.core.user.OAuth2UserAuthority;
import org.springframework.security.oauth2.core.oidc.OidcIdToken;
import org.springframework.util.Assert;
import java.util.HashMap;
import java.util.Map;
/**
* A {@link GrantedAuthority} that is associated with an {@link OidcUser}.
@ -40,7 +44,7 @@ public class OidcUserAuthority extends OAuth2UserAuthority {
}
public OidcUserAuthority(String authority, OidcIdToken idToken, OidcUserInfo userInfo) {
super(authority, OidcUser.collectClaims(idToken, userInfo));
super(authority, collectClaims(idToken, userInfo));
this.idToken = idToken;
this.userInfo = userInfo;
}
@ -82,4 +86,14 @@ public class OidcUserAuthority extends OAuth2UserAuthority {
result = 31 * result + (this.getUserInfo() != null ? this.getUserInfo().hashCode() : 0);
return result;
}
static Map<String, Object> collectClaims(OidcIdToken idToken, OidcUserInfo userInfo) {
Assert.notNull(idToken, "idToken cannot be null");
Map<String, Object> claims = new HashMap<>();
if (userInfo != null) {
claims.putAll(userInfo.getClaims());
}
claims.putAll(idToken.getClaims());
return claims;
}
}