我使用OpenAM作为我的IDP,我的SP ( angular2 SPA)基于在https://github.com/vdenotaris/spring-boot-security-saml-sample上分享的示例
认证之后,我的webapp应该调用一些通过http-basic认证(使用spring安全)保护的REST服务,这些服务的会话是通过Spring Session管理的。
我正在尝试在用户通过OpenAM身份验证后创建基于spring会话的会话。我的目的是使用这些会话与我的http-basic安全的REST服务对话。
下面是在我尝试集成spring-session和spring-saml之前,我的webapp的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)发出的帖子中,我可以看到cookie被正确设置。例如: Set-Cookie: JSESSIONID=8DD6CDBF8079E83C8F4E7976C970BB27;Path=/;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之后,我的webapp的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)发出的帖子中,我没有看到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
CookiesSAML响应是ok的,因为我可以从IDP post身份验证中看到主题的详细信息。
来自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">vin@example.com
</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,然后继续循环运行。
非常感谢您的回复。
发布于 2020-04-16 17:32:32
尝试在属性文件中添加以下内容:server.session.tracting-modes=cookie。另外,尝试添加SSL。cookie可能被标记为安全的,没有SSL则不可见。
https://stackoverflow.com/questions/38681903
复制相似问题