【发布时间】:2014-06-02 17:27:30
【问题描述】:
有没有办法将 SAML 2.0 集成到基于 Spring Boot 的应用程序中? 我想实现自己的 SP 并与远程 IdP 通信。
【问题讨论】:
标签: spring saml-2.0 spring-boot
有没有办法将 SAML 2.0 集成到基于 Spring Boot 的应用程序中? 我想实现自己的 SP 并与远程 IdP 通信。
【问题讨论】:
标签: spring saml-2.0 spring-boot
我实现了一个示例项目,以展示如何将 Spring Security SAML Extension 与 Spring Boot 集成。
源码发布在GitHub上:
【讨论】:
我最近为这个here 发布了一个spring boot 插件。它基本上是 Spring Security SAML 的包装器,允许通过 DSL 或配置属性进行更友好的配置。这是使用 DSL 的示例:
@SpringBootApplication
@EnableSAMLSSO
public class SpringBootSecuritySAMLDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootSecuritySAMLDemoApplication.class, args);
}
@Configuration
public static class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("index");
}
}
@Configuration
public static class MyServiceProviderConfig extends ServiceProviderConfigurerAdapter {
@Override
public void configure(ServiceProviderSecurityBuilder serviceProvider) throws Exception {
serviceProvider
.metadataGenerator()
.entityId("localhost-demo")
.and()
.sso()
.defaultSuccessURL("/home")
.idpSelectionPageURL("/idpselection")
.and()
.logout()
.defaultTargetURL("/")
.and()
.metadataManager()
.metadataLocations("classpath:/idp-ssocircle.xml")
.refreshCheckInterval(0)
.and()
.extendedMetadata()
.idpDiscoveryEnabled(true)
.and()
.keyManager()
.privateKeyDERLocation("classpath:/localhost.key.der")
.publicKeyPEMLocation("classpath:/localhost.cert");
}
}
}
这基本上就是您需要的所有代码。
【讨论】:
您必须在 XML 中完成所有 SAML 工作(惊喜,惊喜)。但其余的不应该妨碍,只是标准的 Springy、Booty 的东西,例如
@EnableAutoConfiguration
@Configuration
@ImportResource("my-crazy-ass-saml.xml")
public class Application implements WebMvcSecurityAdapter {
// set up security filter chain here
}
【讨论】:
我尝试了@vdenotaris 的解决方案,但似乎不适用于当前的 spring-boot,因此放弃了这种方法。
因此,作为替代解决方案,我使用 shibboleth 使用 apache httpd 中的 mod_shib2 模块执行所有 SAML 工作,并在所述 apache 实例后面使用 mod_jk (也可以使用 mod_proxy_ajp)运行 tomcat。 Tomcat 接收所有需要的 SAML 属性作为请求属性,我只需将 idp 和用户 id 存储在常规用户表中即可将内部身份验证连接到外部(我需要 SAML 和基于密码的身份验证)。
【讨论】:
【讨论】: