在春季启动中,基于LDAP组的URL受到限制的访问

时间:2019-04-04 12:14:48

标签: spring-boot ldap http-status-code-403

我正在开发一个Spring Boot应用程序,该应用程序通过ldap使用spring安全性。

在我的一项功能中,如果登录的用户不属于特定的LDAP组,我需要限制对URL的访问,然后将用户重定向到403错误页面。

应用程序已具有SpringSecurityConfig类,该类扩展了WebSecurityConfigurerAdapter。

覆盖的方法如下:

@Autowired
private AccessDeniedHandler accessDeniedHandler;

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

    http.csrf().disable()
            .authorizeRequests()
            .anyRequest().authenticated()
            .and()
            .formLogin()
            .loginPage("/login")
            .permitAll()
            .and()
            .logout()
            .logoutSuccessUrl("/login")
            .permitAll()
            .and()
            .exceptionHandling()
            .accessDeniedHandler(accessDeniedHandler);
}

@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers("/XXX/api/*", "/YYY/**/ZZZ");
}


@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {

    auth
        .ldapAuthentication()
        .userSearchBase("dc=ad,dc=here,dc=com")
        .userSearchFilter("sAMAccountName={0}")
        .groupSearchBase("ou=Groups,dc=ad,dc=XXX,dc=com")
        .groupSearchFilter("member={0}")
        .groupRoleAttribute("cn")
        .userDetailsContextMapper(userContextMapper())
        .contextSource(contextSource());
}

我不知道如何向此代码添加基于LDAP组的限制。 这里有什么建议吗?

0 个答案:

没有答案