- isAnonymous() : ๋ก๊ทธ์ธํ ๋ ์ฌ์ฉ
- isAuthenticated() : ๋ก๊ทธ์์ํ ๋ ์ฌ์ฉ
์คํ๋ง์์ ์ฌ๊ณตํ๋ AnonymousAuthenticaitonFilter๋ฅผ ๋ณด๋ฉด
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {
if (SecurityContextHolder.getContext().getAuthentication() == null) {
Authentication authentication = createAuthentication((HttpServletRequest) req);
SecurityContext context = SecurityContextHolder.createEmptyContext();
context.setAuthentication(authentication);
SecurityContextHolder.setContext(context);
if (this.logger.isTraceEnabled()) {
this.logger.trace(LogMessage.of(() -> "Set SecurityContextHolder to "
+ SecurityContextHolder.getContext().getAuthentication()));
}
else {
this.logger.debug("Set SecurityContextHolder to anonymous SecurityContext");
}
}
else {
if (this.logger.isTraceEnabled()) {
this.logger.trace(LogMessage.of(() -> "Did not set SecurityContextHolder since already authenticated "
+ SecurityContextHolder.getContext().getAuthentication()));
}
}
chain.doFilter(req, res);
}
ํด๋น ํํฐ์์ ์ผ๋จ securityContext์ ์ธ์ฆ ๊ฐ์ฒด๊ฐ ์๋์ง ํ์ธํ๊ณ ๋์ ์์ผ๋ฉด chain.doFilter๋ก ์ด๋ํ๋ ๊ฒ์ ๋ณผ ์ ์๋ค!
ํด๋น ๊ธ์ ์ธํ๋ฐ์ ์คํ๋ง์ํ๋ฆฌํฐ-Spring Boot ๊ธฐ๋ฐ์ผ๋ก ๊ฐ๋ฐํ๋ Spring Security๋ฅผ ๋ณด๊ณ ์์ฑํ ๊ธ์ ๋๋ค.