我用urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport工具对其进行了测试,发现我需要身份验证类型:表单和令牌请求: SAML (SAML2.0),但我不知道如何配置spring安全性,以便在SAML请求中将RequestedAuthenticationContext发送为这而不是urn:oasis:names:tc:SAML:2.0:ac:classes:Kerberos。
因此,与之相反:
<samlp:Response ID="..."
Version="2.0"
IssueInstant="..."
Destination="https://adfshelp.microsoft.com/ClaimsXray/TokenResponse"
Consent="urn:oasis:names:tc:SAML:2.0:consent:unspecified"
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
...
<AuthnStatement AuthnInstant="..." SessionIndex="...">
<AuthnContext>
<AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Kerberos</AuthnContextClassRef>
</AuthnContext>
</AuthnStatement>
</Assertion>
</samlp:Response>
我需要这个:
<samlp:Response ID="..."
Version="2.0"
IssueInstant="..."
Destination="https://adfshelp.microsoft.com/ClaimsXray/TokenResponse"
Consent="urn:oasis:names:tc:SAML:2.0:consent:unspecified"
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
...
<AuthnStatement AuthnInstant="..." SessionIndex="...">
<AuthnContext>
<AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</AuthnContextClassRef>
</AuthnContext>
</AuthnStatement>
</Assertion>
</samlp:Response>
更新:我们使用spring 2.5.5
发布于 2021-10-13 18:21:23
你需要的是一个AuthenticationEntryPoint
。AuthenticationEntryPoint
是在需要身份验证时告诉Security在何处重定向的方法。
由于只需要在需要身份验证时重定向,所以可以使用LoginUrlAuthenticationEntryPoint
,如下所示:
@Bean
SecurityFilterChain app(HttpSecurity http) throws Exception {
String url = "https://ospa.company.com/adfs/ls/IdpInitiatedSignOn? LoginToRP=urn:microsoft:adfs:claimsxray& RequestedAuthenticationContext=urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport";
AuthenticationEntryPoint entryPoint =
new LoginUrlAuthenticationEntryPoint(url);
http
.authorizeHttpRequests((authorize) -> authorize
.anyRequest().authenticated()
)
.saml2Login(withDefaults())
.exceptionHandling((exceptions) -> exceptions
.authenticationEntryPoint(entryPoint)
);
return http.build();
}
也请确保您的使用IdP的相应元数据配置应用程序。
https://stackoverflow.com/questions/69465308
复制相似问题