首页 > 解决方案 > 如何避免使用 Spring Ssecurity 和 SAML 登录页面?

问题描述

我正在尝试当用户通过 Saml2 登录到我的系统时,它会根据他的域自动将他重定向到关联的配置,而不必像显示的那样通过登录页面。

比如用户:user1@company1.com,我想自动重定向到域(company1>singlesignon.url)对应的认证页面,而不必经过这个中间。

我曾尝试使用 Saml2SecurityConfig 解决此问题,但我不知道如何正确设置它。

怎么可能做到?

在此处输入图像描述

  security:
    saml2:
      relyingparty:
        registration:
          company1:
            identityprovider:
              entity-id: 
              verification.credentials:
                - certificate-location: 
               singlesignon.url: https://login.microsoftonline.com/XXXX/saml2
              singlesignon.sign-request: 
          company2:
            identityprovider:
              entity-id: 
              verification.credentials:
                - certificate-location: 
              singlesignon.url: 
              singlesignon.sign-request: 

Saml2Config

public class Saml2Config extends WebSecurityConfigurerAdapter {

        @Override
        protected void configure(HttpSecurity http) throws Exception {

            OpenSamlAuthenticationProvider authenticationProvider = new OpenSamlAuthenticationProvider();


            authenticationProvider.setResponseAuthenticationConverter(responseToken -> {

                Saml2Authentication authentication = OpenSamlAuthenticationProvider
                        .createDefaultResponseAuthenticationConverter()
                        .convert(responseToken);

                Assertion assertion = responseToken.getResponse().getAssertions().get(0);

                String username = assertion.getSubject().getNameID().getValue();

                UserDetails userDetails = inMemoryUserDetailsManager().loadUserByUsername(username);

                authentication.setDetails(userDetails);

                return authentication;

            });


            http
                    .requestMatchers()
                    .antMatchers("/login/**","/saml2/**")
                    .and()
                    .authorizeRequests()
                    .anyRequest().authenticated()
                    .and()
                    .saml2Login().authenticationManager(new ProviderManager(authenticationProvider))
                    .and().csrf().disable();
                   
        }
    }

标签: spring-bootspring-securitysaml-2.0

解决方案


customer.service.com我通常看到组织通过用户的电子邮件地址(如 Office 365 门户如何做到这一点)或通过客户特定的 FQDN(如

如果您使用电子邮件地址,则应将其放入 AuthnRequest 的主题中,以便 IdP 可以在登录屏幕中使用它。


推荐阅读