我已经采用了Spring SAML示例(请参阅本指南中的第4.2节),该示例与开源登录页面SSO一起使用,并尝试添加支持以将WSO2 Identity Server用作其他IDP服务.为此,我通过为IS添加元数据xml文件来更改spring SAML示例项目,并将一个IS元数据条目添加到securityContext.xml.
在运行spring应用程序时,我现在可以看到使用IS登录的选项,当我被重定向到它时,我可以成功登录WSO2.但是,spring应用程序会在IS SAML响应上抛出异常,因为它与InResponseToField不匹配.
2015-01-05 09:54:12,845 line="org.springframework.security.saml.log.SAMLDefaultLogger.log(SAMLDefaultLogger.java:127)" thread="http-nio-8080-exec-4" class="org.springframework.security.saml.log.SAMLDefaultLogger" AuthNResponse;FAILURE;0:0:0:0:0:0:0:1;com:vdenotaris:spring:sp;localhost;;;org.opensaml.common.SAMLException: InResponseToField of the Response doesn't correspond to sent message ae2dab0fb8b0g8e49971b91a73e91i
Run Code Online (Sandbox Code Playgroud)
从调试应用程序开始,响应消息似乎不被识别为属于与请求消息相同的会话.我说从这两条日志消息中,第一个是在发送AuthRequest时记录的,第二个是在收到响应时:
2015-01-05 09:53:20,867 line="org.springframework.security.saml.storage.HttpSessionStorage.storeMessage(HttpSessionStorage.java:93)" thread="http-nio-8080-exec-1" class="org.springframework.security.saml.storage.HttpSessionStorage" Storing message ae2dab0fb8b0g8e49971b91a73e91i to session 26D3B7D9E33F26A7A5092BF6909B9D13
...
2015-01-05 09:54:10,731 line="org.springframework.security.saml.storage.HttpSessionStorage.retrieveMessage(HttpSessionStorage.java:117)" thread="http-nio-8080-exec-4" class="org.springframework.security.saml.storage.HttpSessionStorage" Message ae2dab0fb8b0g8e49971b91a73e91i not found in session BBF256F284F55D774E6997600E9B3388
Run Code Online (Sandbox Code Playgroud)
IS SAML响应是:
<?xml version="1.0" encoding="UTF-8"?><saml2p:Response xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" Destination="http://localhost:8080/saml/SSO" ID="adlbklpnldoanfphalcaahhacooinnldcejjjioe" InResponseTo="ae2dab0fb8b0g8e49971b91a73e91i" IssueInstant="2015-01-05T09:53:38.063Z" Version="2.0">
<saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">localhost</saml2:Issuer>
<saml2p:Status>
<saml2p:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
</saml2p:Status>
<saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" ID="ebhfkdhlgbhclcklefjigfddoikklhjlanlbolel" IssueInstant="2015-01-05T09:53:38.065Z" Version="2.0">
<saml2:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">localhost</saml2:Issuer>
<saml2:Subject>
<saml2:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">smit005</saml2:NameID> …
Run Code Online (Sandbox Code Playgroud) 我在多租户应用程序中使用Spring SAML来提供SSO.不同的租户使用不同的URL来访问应用程序,并且每个租户都配置了单独的身份提供程序.在给定用于访问应用程序的URL的情况下,如何自动分配正确的身份提供者?
例:
我看到我可以在url(http://tenant1.myapp.com?idp=my.idp.entityid.com)中添加参数idp,SAMLContextProvider将选择具有该实体ID的身份提供者.我开发了一个数据库支持的MetadataProvider,它将租户主机名作为初始化参数,从该主机中获取链接到该主机名的数据库的元数据.现在我想我需要一些方法来迭代元数据提供程序,以将元数据的entityId链接到主机名.但是,我不知道如何获取元数据的entityId.这将解决我的问题.
我们使用Spring SAML Security Extension在我们的应用程序中实现SAML.我们现在有以下问题:
我们的一位客户正在为其身份提供商提供包含参数的URL.元数据看起来像这样(为简洁起见,大量缩写):
<EntityDescriptor>
<IDPSSODescriptor>
<SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
Location="https://idp.example.com/login?parameter=value"/>
</IDPSSODescriptor>
</EntityDescriptor>
Run Code Online (Sandbox Code Playgroud)
可以看出,有一个名为"parameter"的参数,其值为"value".生成的重定向URL中不存在此参数.我调试了一下,发现从绑定中SAMLProcessorImpl
获取MessageEncoder
(HTTPRedirectDeflateEncoder
用于HTTP重定向)并委托编码消息.编码器依次在其buildRedirectURL
方法中执行以下操作:
// endpointURL is https://idp.example.com/login?parameter=value here
URLBuilder urlBuilder = new URLBuilder(endpointURL);
List<Pair<String, String>> queryParams = urlBuilder.getQueryParams();
queryParams.clear(); // whoops
Run Code Online (Sandbox Code Playgroud)
因此,出于某种原因,有意无条件地剥离参数.
为什么会出现这种情况?如何以最有效的方式解决这个问题?
我使用 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 …
Run Code Online (Sandbox Code Playgroud) 我已经使用 Spring Security SAML 实现了 SSO。这是目前对我有用的内容:
当我尝试访问 SP 上的任何资源时,如果我尚未登录,我将被重定向到我的 IdP(在我的情况下为 idp.ssocircle.com)。在 IDP 成功验证后,我被重定向回 SP 并授权传入的 SAML 响应并为相应的用户创建会话。一切都很酷,直到这里!但是,当我从 IDP 注销(通过从外部单击 idp.ssocircle.com 注销)时,我应该无法访问我的 SP,这在我的情况下没有发生。现在我想做的是编写一个新的过滤器,在处理 SP 上的任何请求之前检查 IDP 上的有效会话。我已经搜索了很多,但找不到任何解决我的问题的方法。
请提供有关如何实现此过滤器的输入,或者是否有其他方法可以做到这一点?任何建议表示赞赏。
有谁知道OpenSaml3是否有任何文档?支付还是其他?我知道曾经有一本15美元的书可用,但我相信它只涵盖OpenSaml2.
我知道这可能会被投票,因为它不是一个特定于编程的问题,但Spring-Saml现在将SO列为主要论坛(http://projects.spring.io/spring-security-saml/).如果没有一个好的库,SAML很难实现,我认为Spring-SAML是在JVM上编写的人最好的东西.因为Spring-Saml看起来被抛弃了,OpenSaml2很快就会终结.我想看看我是否可以更新Spring Saml以使用更新支持的OpenSAML版本,但除了src代码之外似乎没有文档(没有迁移指南,甚至是已发布的javadoc).任何人都可以指出我正确的方向.
我是 SAML 新手,目前有一个 Spring Restful Web 服务器应用程序,它使用带有基本身份验证的 spring security。由于我有多个企业客户,我希望支持 SAML SSO。
尝试查找有关如何设置 SAML 来对不同客户的不同 IDP 进行身份验证的文档,最好是示例,其中 SAML IDP 详细信息是从持久层 (DB) 读取的。
还想知道在 Web 应用程序中支持正确登录的策略。我现在是否需要为每个客户支持不同的 URL,以便我知道针对哪个 IDP 进行身份验证?
例如我有两个客户
客户 A - 使用 SAML IDP 服务器 A'
客户 B - 使用 SAML IDP 服务器 B'
当客户 A 的用户访问我的网站时:我如何知道现在需要针对 SAML IDP A 进行身份验证?是通过 url 还是某个 url 参数?一旦我知道他是谁,我如何设置 spring saml 来通过 IDP A' 进行身份验证(从该客户的数据库设置中读取)。请注意,我无法在春季配置中预先设置 IDP,因为新客户可以稍后使用新的 IDP 加入。
谢谢
在我的应用程序中,到目前为止,我已经使用 OAuth2 密码授予流程为客户端生成 JWT 访问令牌,并使用 Spring Security 和 Spring OAuth 提供用户名和密码。然后,他们在对我的 Spring Boot REST API 的所有请求中使用该令牌。
我的一些客户现在希望改用 SAML 身份验证。我的想法是创建一个单独的端点/saml/accessToken
并使用 Spring SAML 保护它。SAML 身份验证完成后,用户将被重定向回/saml/accessToken
,现在已进行有效身份验证,并获得一个 JWT,客户端可以使用该 JWT 进一步与我的 REST API 进行通信。
我需要一个控制器方法,它接受经过身份验证的 SAMLAuthenticationToken,使用其凭据生成 JWT,并将其返回给客户端:
@RequestMapping(value = "/saml/accessToken")
public String getAccessToken(SAMLAuthenticationToken authentication) {
return accessTokenFactory.create(authentication);
}
Run Code Online (Sandbox Code Playgroud)
这就是accessTokenFactory
上面例子中我需要帮助的地方。我想尽可能遵循 Spring 编码生态系统,避免使用“hack”解决方案,这样我就可以利用已经存在的 TokenEnhancer 等。
从 SAMLAuthenticationToken 创建 JWT 访问令牌的最佳方法是什么?
我想创建一个供多个应用程序使用的 SSO,最好的方法是什么。我正在经历 SAML2.0,但我很困惑,因为我没有\xe2\x80\x99 找到任何创建自己/自定义 SAML IDP 的文章。
\n\n1.创建自己的IDP是否可行。
\n2.What is the best way to implement SSO
我使用spring security Saml 2.0和 spring boot 进行 SSO(单点登录),并使用 azure 作为身份提供者。
Spring security 使用“{baseUrl}/login/saml2/sso/{registrationId}”作为默认“回复 Url”,
但我想使用“{baseUrl}/login/{registrationId}”
所以按照 我写的官方文档
RelyingPartyRegistration relyingPartyRegistration = RelyingPartyRegistrations
.fromMetadataLocation("https://login.microsoftonline.com/<metadata url>")
.registrationId("azure")
.entityId("{baseUrl}")
.assertionConsumerServiceLocation("{baseUrl}/login/{registrationId}")
.build();
Run Code Online (Sandbox Code Playgroud)
通过这个我进入登录页面,但之后有登录的无限循环......
Spring boot 无法 POST 到 /login/azure
o.s.security.web.FilterChainProxy : Securing POST /login/azure
s.s.w.c.SecurityContextPersistenceFilter : Set SecurityContextHolder to empty SecurityContext
o.s.security.web.csrf.CsrfFilter : Invalid CSRF token found for http://localhost:8080/login/azure
o.s.s.w.access.AccessDeniedHandlerImpl : Responding with 403 status code
Run Code Online (Sandbox Code Playgroud)
我试图允许此端点的 CSRF 并允许所有访问,但随后它无法解析元数据。
我发现它是在过滤器“Saml2WebSsoAuthenticationFilter”中实现的
spring spring-security spring-boot spring-saml spring-security-saml2
spring-saml ×10
saml ×4
saml-2.0 ×4
spring ×4
java ×3
opensaml ×2
spring-boot ×2
jwt ×1
wso2 ×1
wso2is ×1