Ограниченный доступ к URL-адресу на основе группы LDAP при весенней загрузке - PullRequest
0 голосов
/ 04 апреля 2019

Я работаю над приложением весенней загрузки, которое использует Spring Security с ldap.

В одной из моих функций мне нужно ограничить доступ к URL, если вошедший в систему пользователь не принадлежит определенномуГруппа LDAP и перенаправить пользователя на страницу ошибки 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 к этому коду.Любой вклад будет полезным здесь?

...