我希望有人能给我一个比我在文档中找到的更具体的例子。
使用 SpringBoot/Spring Security 5.6.0。我正在将基于 SpringSecurity/SAML 的身份验证过程迁移到SAML2。
我需要将根据responseToken信息构建的UserDetails添加到身份验证中。就像我们在文档中可以读到的内容: https: //docs.spring.io/spring-security/reference/5.6.0-RC1/servlet/saml2/index.html#servlet-saml2login-opensamlauthenticationprovider-userdetailsservice
但我不明白第三点:返回包含用户详细信息的自定义身份验证:“return MySaml2Authentication(userDetails,authentication);”
在任何情况下,您都必须执行“return new MySaml2Authentication(userDetails,authentication);” 正确的?
无论如何,当该过程继续时,它会被执行:
身份验证authenticate =provider.authenticate(authentication);
我们可以看到,它用原始值替换了“详细信息”值。
authenticationResponse.setDetails(authentication.getDetails());
/**
* @param authentication the authentication request object, must be of type
* {@link Saml2AuthenticationToken}
* @return {@link Saml2Authentication} if the assertion is valid
* @throws AuthenticationException if a validation exception occurs
*/
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
try {
Saml2AuthenticationToken token = (Saml2AuthenticationToken) authentication;
String serializedResponse = token.getSaml2Response();
Response response …Run Code Online (Sandbox Code Playgroud)