AccessDecisionManager

이승민·2022년 10월 16일


Access Control 결정을 내리는 인터페이스로, 구현체 3가지를 기본으로 제공한다.

  • AffirmativeBased: 여러 Voter중에 한명이라도 허용하면 허용. 기본 전략
  • ConsensusBased: 다수결
  • UnanimousBased: 만장일치

AccessDecisionVoter

  • 해당 Authentication이 특정한 Object에 접근할 때 필요한 ConfigAttributes를 만족하는지 확인한다.
  • WebExpressionVote: 웹 시큐리티에서 사용하는 구현체, Role_Xxxx가 매치하는지 확인
  • RoleHierarchyVoter: 계층형 ROLE 지원. ADMIN > MANAGER >. USER

AccessDcisionManger Ehsms Voter를 커스터마이징 하는 방법

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    public SecurityExpressionHandler expressionHandler() {
        RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl();
        roleHierarchy.setHierarchy("ROLE_ADMIN > ROLE_USER");
        DefaultWebSecurityExpressionHandler handler = new
                DefaultWebSecurityExpressionHandler();
        handler.setRoleHierarchy(roleHierarchy);
        return handler;
    }
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .mvcMatchers("/", "/info", "/account/**").permitAll()
                .mvcMatchers("/admin").hasRole("ADMIN")
                .mvcMatchers("/user").hasRole("USER")
                .anyRequest().authenticated() 
                .expressionHandler(expressionHandler());
        http.formLogin();
        http.httpBasic(); 
        }
}
profile
💻 끊임없이 성장하는 백엔드 개발자 💻

0개의 댓글