inflearn logo
강의

Khóa học

Chia sẻ kiến thức

Cuộc chinh phục hoàn toàn bảo mật mùa xuân [Phiên bản sửa đổi 6.x]

Ủy quyền dựa trên yêu cầu - HttpSecurity.securityMatcher()

(공유) 이제는 securityMatcher 지정 안 한 FilterChain 의 순서가 맨 앞에 있으면 에러를 뱉어냅니다.

Đã giải quyết

275

tastybread

56 câu hỏi đã được viết

2

요청 기반 권한 부여 - HttpSecurity.securityMatch 강의 (14분 25초) 를 듣고 코드를 똑같이 따라 치고
실행해보니 에러가 뜨면서 동작을 안 하더군요.

 

spring boot 버전은 3.4.1 + spring security 6.4.2 로 테스트를 해봤습니다.

 

조사를 해보니 에러를 뱉는 건 스프링 시큐리티의 WebSecurity 클래스였고, 아래 빨간 박스 친 부분에서 에러를 뱉습니다.

 

idea64_V9COPA1Q91.png

 

이 코드는 securityMatcher 를 설정 안 한 SecurityFilterChain, 즉 anyRequestFilterChain 이 모든 FilterChain 들 보다 항상 뒤편에 있어야 되는 것을 보장하기 위한 유효성 검사를 위한 것입니다.

 

선생님이 강의를 찍던 당시와 달라진 내용이 아닐까 싶습니다.

 

아무튼 이를 우회해서 테스트를 할 수 있는데,
선생님이 작성하신 코드에서 딱 한줄만 추가해주면 됩니다.

 

@Bean
@Order(1)
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
	
	// !!!!!!!!!!!!!!! 아래 한 줄 추가 !!!!!!!!!!!!!!!
	http.securityMatchers(matcher -> matcher.requestMatchers("/**"));

	http.authorizeHttpRequests(auth -> {
			auth.anyRequest().authenticated();
        })
	.formLogin(Customizer.withDefaults());
	
	return http.build();
}


@Bean
public SecurityFilterChain securityFilterChain2(HttpSecurity http) throws Exception {
	http.securityMatchers(matchers 
             -> matchers.requestMatchers("/api/**", "/oauth/**"));
	http.authorizeHttpRequests(auth -> {
		auth.anyRequest().permitAll();
	});
	return http.build();
}

 

이상으로 내용 공유를 마칩니다.

 

spring spring-boot spring-security security web-security

Câu trả lời 1

0

rhkdqhr080980

감사합니다 안되서 왜 안되는지 의아 했네요

로그아웃-logout()-2 강에서 겟방식 로그아웃 호출 후 화면이동 질문입니다.

0

22

2

단원별 소스코드

0

55

2

CustomAuthenticationProvider 추가 관련 문의

0

65

2

AOP 의존성 명칭 변경

0

59

1

빈 1개 등록 시 다른 해결 방법

0

61

1

@Bean으로 AuthenticationProvider를 등록 시 http.authenticationProvider 함수를 이용해서 추가해줘야되나요?

0

84

2

OIDC의 id token에 담긴 데이터에 대해

0

69

1

loginPage("/loginPage") 질문드립니다.

0

65

1

@EnableWebSecurity

0

142

1

트랜잭션과 롤백

0

96

1

68. 인증 이벤트 - AuthenticationEventPublisher 활용 강좌 음성 문제

0

84

2

AuthenticationManager 사용 방법

0

144

2

HttpSecurity.authorizeHttpRequests() - 2 강의 부분에 대한 질문

0

97

2

spring security 6.3에서는 HttpSecurity가 만들어지기 전 WebSecurity가 먼저 만들어지는게 맞나요??

0

186

1

init(B Builder), configure(B builder) 에 대하여 질문 드립니다.

0

101

2

메타 주석 질문

0

64

1

동시세션제어 기능에서 로그아웃하기

0

140

3

로그인 후, redirect 에서 error

0

136

3

Session 생성 타이밍에 대한 질문

0

78

2

강의 참고 내용을 개발 로그로 작성해도 될지 문의드립니다.

0

129

2

customAuthentication 관련

0

123

2

authenticationManagerBuilder 주입받은거 vs 만든 거

0

106

1

UserDetailsService()에서 UserDetail이 아닌 타입을 반환할 수 있나요?

0

95

1

9:28 패턴 3의 경우 마지막으로 설정한 것만 적용되는 것 같습니다.

0

153

2