cso6005 / Auth_Project

회원 인증, 인가 관련 프로젝트
0 stars 0 forks source link

Role 권한 지정 에러 #1

Open cso6005 opened 1 year ago

cso6005 commented 1 year ago

문제

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
...

        // 인가 권한 허용
        http
        .authorizeRequests()
        .antMatchers("/board/test").hasRole("USER")
            .antMatchers("/auth/**").permitAll()
            .anyRequest().authenticated()
        ;   

    }
cso6005 commented 1 year ago

솔루션

cso6005 commented 1 year ago

}


- 바꾼 코드

@Getter public class AccountDetails extends User{

private final AccountEntity account;

// UserDetails
AccountDetails(AccountEntity account) {
    super(account.getAccountEmail(), account.getAccountPassword(), List.of(new SimpleGrantedAuthority("ROLE_" + account.getAccountType())));
    this.account = account;
}

}