Fix Delegation-based Strategy examples
Fix examples not copying userNameAttributeName Issue gh-12275 Issue gh-12282 Issue gh-14672
This commit is contained in:
parent
e52dd81d03
commit
488901dd4e
|
@ -472,7 +472,13 @@ public class OAuth2LoginSecurityConfig {
|
||||||
// 2) Map the authority information to one or more GrantedAuthority's and add it to mappedAuthorities
|
// 2) Map the authority information to one or more GrantedAuthority's and add it to mappedAuthorities
|
||||||
|
|
||||||
// 3) Create a copy of oidcUser but use the mappedAuthorities instead
|
// 3) Create a copy of oidcUser but use the mappedAuthorities instead
|
||||||
oidcUser = new DefaultOidcUser(mappedAuthorities, oidcUser.getIdToken(), oidcUser.getUserInfo());
|
ProviderDetails providerDetails = userRequest.getClientRegistration().getProviderDetails();
|
||||||
|
String userNameAttributeName = providerDetails.getUserInfoEndpoint().getUserNameAttributeName();
|
||||||
|
if (StringUtils.hasText(userNameAttributeName)) {
|
||||||
|
oidcUser = new DefaultOidcUser(mappedAuthorities, oidcUser.getIdToken(), oidcUser.getUserInfo(), userNameAttributeName);
|
||||||
|
} else {
|
||||||
|
oidcUser = new DefaultOidcUser(mappedAuthorities, oidcUser.getIdToken(), oidcUser.getUserInfo());
|
||||||
|
}
|
||||||
|
|
||||||
return Mono.just(oidcUser);
|
return Mono.just(oidcUser);
|
||||||
});
|
});
|
||||||
|
@ -513,7 +519,12 @@ class OAuth2LoginSecurityConfig {
|
||||||
// 1) Fetch the authority information from the protected resource using accessToken
|
// 1) Fetch the authority information from the protected resource using accessToken
|
||||||
// 2) Map the authority information to one or more GrantedAuthority's and add it to mappedAuthorities
|
// 2) Map the authority information to one or more GrantedAuthority's and add it to mappedAuthorities
|
||||||
// 3) Create a copy of oidcUser but use the mappedAuthorities instead
|
// 3) Create a copy of oidcUser but use the mappedAuthorities instead
|
||||||
val mappedOidcUser = DefaultOidcUser(mappedAuthorities, oidcUser.idToken, oidcUser.userInfo)
|
val providerDetails = userRequest.getClientRegistration().getProviderDetails()
|
||||||
|
val userNameAttributeName = providerDetails.getUserInfoEndpoint().getUserNameAttributeName()
|
||||||
|
val mappedOidcUser = when (StringUtils.hasText(userNameAttributeName)) {
|
||||||
|
true -> DefaultOidcUser(mappedAuthorities, oidcUser.idToken, oidcUser.userInfo, userNameAttributeName)
|
||||||
|
false -> DefaultOidcUser(mappedAuthorities, oidcUser.idToken, oidcUser.userInfo)
|
||||||
|
}
|
||||||
|
|
||||||
Mono.just(mappedOidcUser)
|
Mono.just(mappedOidcUser)
|
||||||
}
|
}
|
||||||
|
|
|
@ -660,7 +660,13 @@ public class OAuth2LoginSecurityConfig {
|
||||||
// 2) Map the authority information to one or more GrantedAuthority's and add it to mappedAuthorities
|
// 2) Map the authority information to one or more GrantedAuthority's and add it to mappedAuthorities
|
||||||
|
|
||||||
// 3) Create a copy of oidcUser but use the mappedAuthorities instead
|
// 3) Create a copy of oidcUser but use the mappedAuthorities instead
|
||||||
oidcUser = new DefaultOidcUser(mappedAuthorities, oidcUser.getIdToken(), oidcUser.getUserInfo());
|
ProviderDetails providerDetails = userRequest.getClientRegistration().getProviderDetails();
|
||||||
|
String userNameAttributeName = providerDetails.getUserInfoEndpoint().getUserNameAttributeName();
|
||||||
|
if (StringUtils.hasText(userNameAttributeName)) {
|
||||||
|
oidcUser = new DefaultOidcUser(mappedAuthorities, oidcUser.getIdToken(), oidcUser.getUserInfo(), userNameAttributeName);
|
||||||
|
} else {
|
||||||
|
oidcUser = new DefaultOidcUser(mappedAuthorities, oidcUser.getIdToken(), oidcUser.getUserInfo());
|
||||||
|
}
|
||||||
|
|
||||||
return oidcUser;
|
return oidcUser;
|
||||||
};
|
};
|
||||||
|
@ -703,7 +709,13 @@ class OAuth2LoginSecurityConfig {
|
||||||
// 1) Fetch the authority information from the protected resource using accessToken
|
// 1) Fetch the authority information from the protected resource using accessToken
|
||||||
// 2) Map the authority information to one or more GrantedAuthority's and add it to mappedAuthorities
|
// 2) Map the authority information to one or more GrantedAuthority's and add it to mappedAuthorities
|
||||||
// 3) Create a copy of oidcUser but use the mappedAuthorities instead
|
// 3) Create a copy of oidcUser but use the mappedAuthorities instead
|
||||||
oidcUser = DefaultOidcUser(mappedAuthorities, oidcUser.idToken, oidcUser.userInfo)
|
val providerDetails = userRequest.getClientRegistration().getProviderDetails()
|
||||||
|
val userNameAttributeName = providerDetails.getUserInfoEndpoint().getUserNameAttributeName()
|
||||||
|
if (StringUtils.hasText(userNameAttributeName)) {
|
||||||
|
oidcUser = DefaultOidcUser(mappedAuthorities, oidcUser.idToken, oidcUser.userInfo, userNameAttributeName)
|
||||||
|
else {
|
||||||
|
oidcUser = DefaultOidcUser(mappedAuthorities, oidcUser.idToken, oidcUser.userInfo)
|
||||||
|
}
|
||||||
|
|
||||||
oidcUser
|
oidcUser
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue