-
Spring boot - 권한공부/Spring 2023. 12. 5. 17:46
Securityconfig 에서
@Override protected void configure(HttpSecurity http) throws Exception { http.csrf().disable() .authorizeRequests() .antMatchers("/*/*").permitAll() .antMatchers("/item/**").hasRole("USER") // 권한수준 등록 .anyRequest().permitAll() .and() .sessionManagement() .sessionCreationPolicy(SessionCreationPolicy.STATELESS) .and() .exceptionHandling() .authenticationEntryPoint(new CustomAuthenticationEntryPoint()); }이렇게 하면 되지만
.antMatchers("/*/*").permitAll() 이걸로 인해 모든 요청이 허락이 되는 현상이 만들어 졌다
권한 수준을 제외하고는 요청을 받을수 있는 방법을 찾아야 겠다
프론트에서의 요청
const response = await axios.get(url, { headers: { Authorization: `Bearer ${role}`, // 토큰을 Authorization 헤더에 포함 }, });헤더에 궈한 수준을 담아서 요청하면 된다
'공부 > Spring' 카테고리의 다른 글
Spring boot - 영속성 전이(cascade) (0) 2023.12.06 Spring boot - 연관 관계 매핑 (0) 2023.12.06 Spring boot - Querydsl (0) 2023.11.27 Spring boot - JPA - 쿼리 메소드, JPQL snippet (0) 2023.11.11 Spring boot - Entity (0) 2023.11.11