inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

스프링부트 시큐리티 & JWT 강의

스프링부트 시큐리티 27강 - jwt토큰 서버 구축 완료

질문이 있습니당.

392

알파카

작성한 질문수 2

0

질문이 있습니당.
BasicAuthenticationFilter는 인증이 필요한 주소로 요청했을 때만 실행된다고 하셨는데
/home 으로 요청을 해도 doFilterInternal가 실행되는 것 같습니다. 제가 잘 못 이해한것인지 해서 질문드립니다..!
 
@Override
protected void configure(HttpSecurity http) throws Exception {
http.addFilterBefore(new MyFilter3(), SecurityContextPersistenceFilter.class);
http.csrf().disable();
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.addFilter(corsFilter)
.formLogin().disable()
.httpBasic().disable()
.addFilter(new JwtAuthenticationFilter(authenticationManager()))
.addFilter(new JwtAuthorizationFilter(authenticationManager(), userRepository))
.authorizeRequests()
.antMatchers("/api/v1/user/**")
.access("hasRole('ROLE_USER') or hasRole('ROLE_MANAGER') or hasRole('ROLE_ADMIN')")
.antMatchers("/api/v1/manager/**")
.access("hasRole('ROLE_MANAGER') or hasRole('ROLE_ADMIN')")
.antMatchers("/api/v1/admin/**")
.access("hasRole('ROLE_ADMIN')")
.anyRequest().permitAll();
}
@Slf4j
public class JwtAuthorizationFilter extends BasicAuthenticationFilter {

private UserRepository userRepository;

public JwtAuthorizationFilter(AuthenticationManager authenticationManager, UserRepository userRepository) {
super(authenticationManager);
this.userRepository = userRepository;
}

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
log.info("인증이나 권한이 필요한 주소로 요청됨.");
 
 
http://localhost:7979/home 요청 =>
2022-05-13 2022-05-13 15:04:12.889  INFO 9192 --- [nio-7979-exec-5] com.cos.jwt.filter.MyFilter3             : MyFilter3 호출
2022-05-13 15:04:12.889  INFO 9192 --- [nio-7979-exec-5] com.cos.jwt.filter.MyFilter3             : authorization=
2022-05-13 15:04:12.889  INFO 9192 --- [nio-7979-exec-5] c.c.j.config.jwt.JwtAuthorizationFilter  : 인증이나 권한이 필요한 주소로 요청됨.
2022-05-13 15:04:12.889  INFO 9192 --- [nio-7979-exec-5] c.c.j.config.jwt.JwtAuthorizationFilter  : jwtHeader=
2022-05-13 15:04:12.890  INFO 9192 --- [nio-7979-exec-5] com.cos.jwt.filter.MyFilter1             : MyFilter1 호출
2022-05-13 15:04:12.890  INFO 9192 --- [nio-7979-exec-5] com.cos.jwt.filter.MyFilter2             : MyFilter2 호출
 

jwt Spring Security spring

답변 2

0

최주호

이건 인가 필터여서 무조건 거치게 되요.

유저네임패스워드 토큰이 인증필요할때만 거칩니다

0

최민혁

안녕하세요 다름이 아니라 혹시 이 문제에 대해 답을 얻으셨나요??

얻으셨으면 공유를 부탁드려도 될까요?

JWT를 구현한 다음 이 API를 호출해서 사용하는 것은 프론트엔드 쪽에서 하는 역할인가요?

0

96

1

Jwt쓰면 스프링시큐리티는 필수적으로 사용해야하나요?

0

401

1

13:23 system.out 출력문이 다르게 나옵니다.

0

130

1

수료증 문의

0

226

2

9분대에 질문이 있습니다 !

0

114

1

password 비교를 하지 않았는데 어떻게 인증이 통과된 건가요?

0

321

1

이전 강의 참고하라는 말씀

0

253

1

강의 실습하다가 막히는 분들 참고(2024년8월 기준)

2

1116

2

구글 소셜 로그인 302

0

200

1

오류 문의 _ org.springframework.orm.jpa.JpaSystemException: could not deserialize

1

584

1

[자바] 시큐리티 Config 참고

13

953

1

이론강의

0

280

1

SpringSecurity JWT 로그인 URL 2개 설정하는 방법

0

487

1

2024.06기준) 최근 SecurityConfig 설정 문의

0

921

3

구글 로그인시 authentication이 null 값이라고 에러가 발생합니다.

0

678

2

특정 url필터 거는 방법 이슈

0

422

1

강사님께서 말씀하시는 시큐리티세션이 SecurityContext인가요?

0

277

1

25강 마지막 테스트에서 오류

1

1044

2

jwt를 저장하는 위치에 궁금한 점이 있습니다.

0

298

1

mustache를 사용하지 않고 thymeleaf를 사용하려고 하는데

0

697

1

세션 인증방식이 REST 원칙에 위배되는 건가요?

0

340

1

jwt와 실제데이터의 관계

1

243

1

jwt 와 세션ID의 관계

1

313

1

SecurityConfig에서 세션 설정, 인가 설정

0

421

1