我使用OpenAM作为我的IDP,而我的SP(angular2 SPA)基于在以下位置共享的示例:https://github.com/vdenotaris/spring-boot-security-saml-sample
[经过身份验证后,我的Web应用程序应该调用一些REST服务,这些服务通过http-basic身份验证(使用spring安全性)来保护,其会话是通过Spring Session管理的。
我正在尝试通过OpenAM IDP对用户进行身份验证后创建基于spring-session的会话。我的意图是使用这些会话来与我的基于HTTP的安全REST服务进行对话。
下面是我尝试将spring-session与spring-saml集成之前,我的Web应用程序的WebSecurityConfig的“ configure()”,这很好用。
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.httpBasic()
.authenticationEntryPoint(samlEntryPoint());
http
.csrf()
.disable();
http
.addFilterBefore(metadataGeneratorFilter(), ChannelProcessingFilter.class)
.addFilterAfter(samlFilter(), BasicAuthenticationFilter.class);
http
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/publicUrl").permitAll()
.antMatchers("/app/**").permitAll()
.antMatchers("/error").permitAll()
.antMatchers("/saml/**").permitAll()
.anyRequest().authenticated();
http
.logout()
.logoutSuccessUrl("/");
}
并且身份验证工作正常。在从IDP(OpenAM)触发的POST中,我可以看到cookie设置正确。例如:Set-Cookie:JSESSIONID = 8DD6CDBF8079E83C8F4E7976C970BB27;路径= /; HttpOnly
Response
Headers
Pragma: no-cache
Date: Sun, 31 Jul 2016 02:12:06 GMT
X-Content-Type-Options: nosniff
Server: Apache-Coyote/1.1
X-Frame-Options: DENY
Location: http://localhost:8097/
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Set-Cookie: JSESSIONID=8DD6CDBF8079E83C8F4E7976C970BB27; Path=/; HttpOnly
Content-Length: 0
X-XSS-Protection: 1; mode=block
Expires: 0
Cookies
JSESSIONID: 8DD6CDBF8079E83C8F4E7976C970BB27
以下是我尝试将spring-session与spring-saml集成后,我的Web应用程序的WebSecurityConfig的“ configure()”,这会破坏身份验证。
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.httpBasic()
.authenticationEntryPoint(samlEntryPoint());
http
.csrf()
.disable();
http
.addFilterBefore(metadataGeneratorFilter(), ChannelProcessingFilter.class)
.addFilterAfter(samlFilter(), BasicAuthenticationFilter.class);
http
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/publicUrl").permitAll()
.antMatchers("/app/**").permitAll()
.antMatchers("/error").permitAll()
.antMatchers("/saml/**").permitAll()
.anyRequest().authenticated();
http
.logout()
.logoutSuccessUrl("/");
http
.addFilterBefore(sessionRepositoryFilter(sessionRepository(), httpSessionStrategy()),
ChannelProcessingFilter.class)
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED);
}
在从IDP(OpenAM)发回的POST中,我看不到cookie被设置。
Response
Headers
Pragma: no-cache
Date: Sun, 31 Jul 2016 02:18:44 GMT
X-Content-Type-Options: nosniff
Server: Apache-Coyote/1.1
X-Frame-Options: DENY
Location: http://localhost:8097/
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
x-auth-token: 666412f1-b293-49fa-bacb-0aa6fc3d2fe0
Content-Length: 0
X-XSS-Protection: 1; mode=block
Expires: 0
Cookies
SAML响应正常,因为我可以从IDP身份验证后看到主题详细信息。
SAML响应中的摘录
<saml:Subject>
<saml:NameID
Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
NameQualifier="http://openam.example.com:8080/OpenAM-13.0.0">[email protected]
</saml:NameID>
<saml:SubjectConfirmation
Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
<saml:SubjectConfirmationData
InResponseTo="a1f07e22gi7db1h425hfj65i5gh0464"
NotOnOrAfter="2016-07-31T02:28:44Z"
Recipient="http://localhost:8097/saml/SSO"/>
</saml:SubjectConfirmation>
</saml:Subject>
由于未设置cookie,因此无法获得主体对象。我的UI假定用户未通过身份验证,然后再次将用户重定向到IDP,并保持循环运行。
非常感谢您的回复。
尝试在属性文件中添加此文件:server.session.tracking-modes = cookie。另外,尝试添加SSL。该cookie可能被标记为安全的,并且没有SSL则不可见。