inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

스프링 시큐리티

9) 인가 개념 및 필터 이해 : Authorization, FilterSecurityInterceptor

AbstratSecurityInterceptor에서의 Event의 용도가 궁금합니다

226

김태완

작성한 질문수 1

1

// AbstractSecurityInterceptor.class

	private void attemptAuthorization(Object object, Collection<ConfigAttribute> attributes,
			Authentication authenticated) {
		try {
			this.accessDecisionManager.decide(authenticated, object, attributes);
		}
		catch (AccessDeniedException ex) {
			if (this.logger.isTraceEnabled()) {
				this.logger.trace(LogMessage.format("Failed to authorize %s with attributes %s using %s", object,
						attributes, this.accessDecisionManager));
			}
			else if (this.logger.isDebugEnabled()) {
				this.logger.debug(LogMessage.format("Failed to authorize %s with attributes %s", object, attributes));
			}
			publishEvent(new AuthorizationFailureEvent(object, attributes, authenticated, ex));
			throw ex;
		}
	}


여기서 publishEvent를 진행하는데요, 제가 이해한 바로는 ExceptionTranslationFilter에서 try-catch로 작업을 진행하기 때문에, 해당 로직(예외처리)에는 불필요해보이는 로직이라 생각합니다.

이 부분의 역할에 대해 궁금증이 생겨 질문 남깁니다!

코드를 분석해봤을 때에는, LoggerListener에서 이 이벤트를 로그로 작성해주고 있는데, 해당 부분만을 별도의 로그 관리로 진행하는지?에 대해서도 의문이남네요!


event java Spring Security spring-boot

답변 1

0

정수원

먼저 답변이 늦어 죄송합니다.

말씀하신 것처럼 LoggerListener 에서 로그를 남기는 작업을 하고 있습니다.

public class LoggerListener implements ApplicationListener<AbstractAuthorizationEvent> {

private static final Log logger = LogFactory.getLog(LoggerListener.class);

@Override
public void onApplicationEvent(AbstractAuthorizationEvent event) {
if (event instanceof AuthenticationCredentialsNotFoundEvent) {
onAuthenticationCredentialsNotFoundEvent((AuthenticationCredentialsNotFoundEvent) event);
}
if (event instanceof AuthorizationFailureEvent) {
onAuthorizationFailureEvent((AuthorizationFailureEvent) event);
}
if (event instanceof AuthorizedEvent) {
onAuthorizedEvent((AuthorizedEvent) event);
}
if (event instanceof PublicInvocationEvent) {
onPublicInvocationEvent((PublicInvocationEvent) event);
}
}

즉 이벤트의 유형에 따라 로그를 남기는 작업을 하고 있습니다.

private void onAuthorizationFailureEvent(AuthorizationFailureEvent authEvent) {
logger.warn(LogMessage.format(
"Security authorization failed due to: %s; authenticated principal: %s; secure object: %s; configuration attributes: %s",
authEvent.getAccessDeniedException(), authEvent.getAuthentication(), authEvent.getSource(),
authEvent.getConfigAttributes()));
}

어떻게 보면 로그를 남기는 작업은 비즈니스 로직의 핵심기능은 아닙니다.

그래서 흔히  AOP 를 활용해서 로깅작업만 별도로 하기도 합니다.

AbstractSecurityInterceptor 클래스는 권한 관련 책임만 담당하고 로깅작업은 별도의 이벤트를 통해 처리한다고 보시면 될 것 같습니다.

비단 여기뿐 아니라 시규리티의 다른 곳에서도 이벤트를 활용해서 여러 작업들을 하고 있습니다.

 

 

0

김태완

친절한 설명 감사합니다 :)

시큐리티 공부 버전 질문

0

188

1

[해결 방법] MethodSecurityConfig.customMethodSecurityMetadataSource() 호출하지 않는 이슈

0

196

1

AbstractSecurityInterceptor.class.beforeInvocation()를 2번 실행하는 경우

0

185

1

강의 코드가 왜이렇게 뒤죽박죽인가요...

0

270

1

메인 페이지로 접속해도 login url로 리다이렉트가 되지 않습니다..

0

247

1

파라미터값이 넘어가지 않습니다 ....

0

381

1

security filterChain 설정 질문이 있습니다.

0

336

1

소스 부분 질문 드립니다.

0

211

2

섹션4 7번 강의 문제가 있는거 같네요.

0

351

2

파일이 수시로 이름이 바껴있네요 ㄷㄷ

0

308

1

HttpSessionSecurityContextRepository를 사용안하는 문제

0

563

2

error , exception 이 잘 안됩니다.

0

288

2

thymeleaf tag 질문합니다.

0

200

2

버전업하면서 deprecated된 것들이 너무많아요

0

482

1

spring security 패치 관련

0

442

1

모바일을 사용할때 토큰말고 세션

0

863

2

DB 연동한 인가 부분에 대한 질문입니다!

0

267

1

Ajax방식도 똑같이 Session방식을 사용하는건가요?

0

310

1

Config 파일 생성 시 질문이 있습니다.

0

233

1

강사님 몇일동안 구글 검색만 100개 했는데도 이유를 모르겠습니다..

1

440

2

403 에러 뜹니다.

0

816

2

login_proc의 존재에 대한 간략한 설명입니다

0

279

1

top.html에 로그인 링크를 만들어서 로그인을 해봤습니다

0

289

2

안녕하세요. DB에 저장될 때 이해 안 가는 값이 있어서 질문드립니다!

0

193

1