1

나는 사용자 정의 인증을 구현하려고했지만 인증은 정상적으로 작동하지만 인증에는 문제가 있습니다. JWT 토큰을 사용하고 있습니다. 모든 API에서 403 금지 된 오류가 발생하여 액세스하려고합니다. 나는 무엇이 잘못되었는지 확신하지 못한다. github에 전체 소스 코드가 있습니다. https://github.com/vivdso/SpringAuthentication, 스프링 부트 마술이 작동하지 않습니다. 모든 포인터는 적용됩니다. MongoDb를 내 저장소로 사용하여 사용자 계정 및 역할을 저장합니다. 아래는,
InMemory 인증은 잘 작동하지만 사용자 인증은 항상 403 returs 내 내가 WebSecurityConfigurerAdapter사용자 정의 인증 - 스프링 부트 403 금지 된 오류

확장
@Autowired 
    public void configureAuthentication(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception { 
//  authenticationManagerBuilder.inMemoryAuthentication().withUser("admin").password("admin").roles("ADMIN"); 
//  authenticationManagerBuilder.inMemoryAuthentication().withUser("user").password("user").roles("USER"); 

authenticationManagerBuilder.authenticationProvider (getCustomAuthenticationProvider()); }

@Override 
protected void configure(HttpSecurity http) throws Exception { 
http 
       .authorizeRequests() 
       .antMatchers(HttpMethod.GET, "/customer").hasAuthority("ADMIN") 
       .antMatchers(HttpMethod.GET, "/order").hasAuthority("USER").and() 
       .csrf().disable(); 
    } 

@Bean 
    protected CustomAuthenticationProvider getCustomAuthenticationProvider(){ 
     return new CustomAuthenticationProvider(); 
    } 

나는 인증을위한 사용자 정의 구현이 없습니다.

답변

0

문제가 해결되었으므로 Github 저장소를 업데이트했습니다. 스프링 부트 보안이 제대로 작동했지만 문제는 사용자 컬렉션에 할당 된 역할이 객체 "ROLE_ADMIN"을 찌르는 대신 Json 문자열 객체 (예 : { "role": "ROLE_ADMIN"})였습니다.

감사합니다.