Spring Boot and SAML 2.0

前端 未结 5 2384
深忆病人
深忆病人 2020-12-24 14:16

Is there a way to integrate SAML 2.0 in a Spring Boot-based application? I\'d like to implement my own SP and communicate with a remote IdP.

5条回答
  •  梦谈多话
    2020-12-24 15:04

    I recently released a spring boot plugin for this here. It is basically a wrapper around Spring Security SAML that allows for friendlier configuration through a DSL or config properties. Here's an example using the 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");
    
            }
        }
    }
    

    That's basically all the code you need.

提交回复
热议问题