如何使用 spring-security-saml2 配置服务提供者以使用 EncryptedAssertions?
Posted
技术标签:
【中文标题】如何使用 spring-security-saml2 配置服务提供者以使用 EncryptedAssertions?【英文标题】:How to configure service provider with spring-security-saml2 to consume EncryptedAssertions? 【发布时间】:2019-08-27 14:09:41 【问题描述】:我正在使用这个优秀的 repo vdenotaris/spring-boot-security-saml-sample 作为指导,我正在尝试设置它来验证和解密包含EncryptedAssertion
的传入 SAML 消息。
idP 的元数据在 XML 中定义签名和加密密钥。这是在服务提供者中设置的。
@Bean
public ExtendedMetadata extendedMetadata()
ExtendedMetadata extendedMetadata = new ExtendedMetadata();
extendedMetadata.setIdpDiscoveryEnabled(false);
extendedMetadata.setSignMetadata(false);
extendedMetadata.setEcpEnabled(true);
return extendedMetadata;
@Bean
@Qualifier("metadata")
public CachingMetadataManager metadata() throws MetadataProviderException
List<MetadataProvider> providers = new ArrayList<MetadataProvider>();
try
ClasspathResource metadata = new ClasspathResource("/metadata/the-idp-metadata.xml");
Timer timer = new Timer(true);
ResourceBackedMetadataProvider provider = new ResourceBackedMetadataProvider(timer, metadata);
provider.setParserPool(ParserPoolHolder.getPool());
provider.initialize();
ExtendedMetadataDelegate exMetadataDelegate = new ExtendedMetadataDelegate(provider, extendedMetadata());
exMetadataDelegate.setMetadataTrustCheck(true);
exMetadataDelegate.setMetadataRequireSignature(false);
providers.add(exMetadataDelegate);
catch(ResourceException ex)
throw new MetadataProviderException(ex.getMessage(), ex);
CachingMetadataManager cmm = new CachingMetadataManager(providers);
cmm.setRefreshCheckInterval(0);
return cmm;
当我手动向它发送具有加密断言的 SAML 消息样本时,它会失败并显示以下消息。
org.springframework.security.authentication.AuthenticationServiceException: Incoming SAML message is invalid
at org.springframework.security.saml.SAMLProcessingFilter.attemptAuthentication(SAMLProcessingFilter.java:91)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:212)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:186)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:74)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.saml.metadata.MetadataGeneratorFilter.doFilter(MetadataGeneratorFilter.java:87)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.opensaml.common.SAMLException: Unsupported request
at org.springframework.security.saml.processor.SAMLProcessorImpl.getBinding(SAMLProcessorImpl.java:265)
at org.springframework.security.saml.processor.SAMLProcessorImpl.retrieveMessage(SAMLProcessorImpl.java:172)
at org.springframework.security.saml.SAMLProcessingFilter.attemptAuthentication(SAMLProcessingFilter.java:80)
... 53 common frames omitted
我在这里读到Metadata Configuration,您可以配置 idp 使用的签名和加密密钥,以便 解密 断言(至少这是我的假设)。
这是让服务使用EncryptedAssertion
s 的正确方法吗?我一直在点击这个无效的消息墙,但没有找到明确描述如何处理这个问题的好的可靠教程或文档。也不确定解决方案是否存在于我必须修改的WebSSOProfileConsumerImpl
类中?
任何帮助或示例将不胜感激。
【问题讨论】:
Afaik 你不需要明确配置断言是加密的。而且你最明确地不需要修改任何类。至于你的例外:很明显你不需要绑定来处理传入的消息,这与加密无关。 您可以发布您要发送的消息吗? 是否有工具可以创建加密断言以测试服务?我目前正在使用 SAMLING (github.com/capriza/samling),这很棒,但它不支持加密断言。 【参考方案1】:我们通常使用 SAML 工具 (https://www.samltool.com/generic_sso_res.php),其中包含一些带有加密断言的示例。
对于自动化测试,我们倾向于动态生成 SAML 请求和响应,自己签署 XML,然后在集成测试中将其提供给应用程序。
【讨论】:
以上是关于如何使用 spring-security-saml2 配置服务提供者以使用 EncryptedAssertions?的主要内容,如果未能解决你的问题,请参考以下文章
使用 spring-security-saml 在 RP 元数据中包含所需的声明
生成 SP 元数据时出现意外的堆栈跟踪表单 Spring-Security-SAML?