适用于Azure B2C的Spring Security SSO和适用于SSO的Azure AD

时间:2020-03-31 19:24:18

标签: spring-security azure-active-directory azure-ad-b2c

我的spring应用程序需要允许员工和外部客户使用Azure登录。

我正在关注MS Azure B2C教程HERE,并且B2C正在运行。我也需要允许员工登录Azure AD。静态页面将显示“客户”和“员工”登录按钮。

我已添加Azure AD配置文件,但无法使其正常工作。 B2C配置:

@Configuration
@EnableOAuth2Sso
@Order(1)
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {


    private final AADB2COidcLoginConfigurer configurer;


    public WebSecurityConfiguration(AADB2COidcLoginConfigurer configurer) {
        this.configurer = configurer;
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        System.out.println(" Customer is Authenticating ");

        http
                .authorizeRequests()
                .antMatchers("/employee/**").hasRole("USER")
                .antMatchers("/","/login**").permitAll()
                .anyRequest()
                .authenticated()
                .and()
                .apply(configurer)
        ;
    }
}

Azure AD(员工)

    @Configuration
    @EnableOAuth2Sso
    @Order(2)
    public class EmployeeSecurityConfiguration extends WebSecurityConfigurerAdapter {

        @Autowired
        private OAuth2UserService<OidcUserRequest, OidcUser> oidcUserService;

        @Override
        protected void configure(HttpSecurity http) throws Exception {
        System.out.println(" Employee is Authenticating ");

        http
            .authorizeRequests()
            .antMatchers("/auth/**").hasRole("USER")
            .antMatchers("/", "/login**").permitAll()
            .anyRequest().authenticated()
            .and()
            .oauth2Login()
            .userInfoEndpoint()
            .oidcUserService(oidcUserService);
    }
}

但是当我运行该应用程序时,只能识别B2C路径。

这是正确的方法吗?任何帮助将不胜感激。

凯文

0 个答案:

没有答案