有没有办法在基于Spring Boot的应用程序中集成SAML 2.0?我想实现自己的SP并与远程IdP通信。
我实施了一个示例项目,以展示如何将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和基于密码的身份验证)。