Vin*_*Vin 6 spring-security saml saml-2.0 spring-saml spring-session
我使用 OpenAM 作为我的 IDP,我的 SP(angular2 SPA)基于以下共享的示例:https : //github.com/vdenotaris/spring-boot-security-saml-sample
身份验证后,我的 webapp 应该调用一些 REST 服务,这些服务通过 http-basic 身份验证(使用 spring 安全性)保护,其会话通过Spring Session进行管理。
在用户通过 OpenAM IDP 进行身份验证后,我正在尝试创建基于 spring 会话的会话。我的目的是使用这些会话与我的 http-basic-secured 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("/");
}
Run Code Online (Sandbox Code Playgroud)
并且身份验证工作得很好。在从 IDP (OpenAM) 发出的 POST 中,我可以看到 cookie 被正确设置。例如:Set-Cookie:JSESSIONID=8DD6CDBF8079E83C8F4E7976C970BB27;路径=/;仅Http
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
Run Code Online (Sandbox Code Playgroud)
以下是我尝试将 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);
}
Run Code Online (Sandbox Code Playgroud)
在从 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
Run Code Online (Sandbox Code Playgroud)
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">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>
Run Code Online (Sandbox Code Playgroud)
由于未设置 cookie,我无法获取主体对象。我的 UI 假设用户未通过身份验证,并将用户再次重定向到 IDP 并继续循环运行。
非常感谢您的回复。
| 归档时间: |
|
| 查看次数: |
2790 次 |
| 最近记录: |