@Bean 과 @Autowired질문입니다 + loginController에서 질문입니다
331
작성한 질문수 26
1번째 질문
이번 강의에서는
@Bean
public AccessDeniedHandler accessDeniedHandler() {
CustomAccessDeniedHandler accessDeniedHandler = new CustomAccessDeniedHandler();
accessDeniedHandler.setErrorPage("/denied");
return accessDeniedHandler;
}
bean으로 등록시켜주고
저번 강의에서는
@Autowired
private AuthenticationFailureHandler customAuthenticationFailureHandler;
이런식으로 @Autowired를 해주셨는데
@Bean으로 한 이유는 exception핸들러에 추가적으로 setter를 사용해야 했기 때문에 @Bean으로 등록한것이고
Authentication핸들러에 @Autowired를 한 이유는 추가작업 없이 의존성 주입만 하면 돼기 때문에 그런건가요???
2번째 질문
@GetMapping("/denied")
public String accessDenied(@RequestParam(value = "exception", required = false) String exception, Model model) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Account account = (Account)authentication.getPrincipal();
model.addAttribute("username", account.getUsername());
model.addAttribute("exception", exception);
return "user/login/denied";
}
이런식으로 Account타입으로 캐스팅 하셨는데 AccountContext타입으로 해도 상관없는건가요???
답변 2
1
1번째 질문 답변입니다.
빈생성은 말씀하신 이유때문입니다.
상황에 따라 맞는 방식으로 생성하시면 됩니다.
2번째 질문 답변입니다.
예를 들어 유저정보를 담을때
UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(
accountContext.getAccount(), null, accountContext.getAuthorities());
이 구문도
UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(
accountContext, null, accountContext.getAuthorities());
해도 무방하기 때문에 이렇게 했을 경우
if(principal != null && principal instanceof AccountContext){
username = ((AccountContext) principal).getAccount().getUsername();
}
이렇게 해도 무방합니다.
결국은 인증에 성공한 이후에 인증필터에 의해 SecurityContext 안에 저장된 Authentication 객체와 Authentication 안에 AccountContext, Account 객체들을 어떤식으로 구성해서 저장할 것인지를 정책에 따라 결정해서 구현하시면 됩니다.
시큐리티 공부 버전 질문
0
175
1
[해결 방법] MethodSecurityConfig.customMethodSecurityMetadataSource() 호출하지 않는 이슈
0
185
1
AbstractSecurityInterceptor.class.beforeInvocation()를 2번 실행하는 경우
0
174
1
강의 코드가 왜이렇게 뒤죽박죽인가요...
0
249
1
메인 페이지로 접속해도 login url로 리다이렉트가 되지 않습니다..
0
235
1
파라미터값이 넘어가지 않습니다 ....
0
374
1
security filterChain 설정 질문이 있습니다.
0
330
1
소스 부분 질문 드립니다.
0
208
2
섹션4 7번 강의 문제가 있는거 같네요.
0
344
2
파일이 수시로 이름이 바껴있네요 ㄷㄷ
0
304
1
HttpSessionSecurityContextRepository를 사용안하는 문제
0
555
2
error , exception 이 잘 안됩니다.
0
278
2
thymeleaf tag 질문합니다.
0
196
2
버전업하면서 deprecated된 것들이 너무많아요
0
478
1
spring security 패치 관련
0
437
1
모바일을 사용할때 토큰말고 세션
0
845
2
DB 연동한 인가 부분에 대한 질문입니다!
0
264
1
Ajax방식도 똑같이 Session방식을 사용하는건가요?
0
307
1
Config 파일 생성 시 질문이 있습니다.
0
225
1
강사님 몇일동안 구글 검색만 100개 했는데도 이유를 모르겠습니다..
1
429
2
403 에러 뜹니다.
0
813
2
login_proc의 존재에 대한 간략한 설명입니다
0
275
1
top.html에 로그인 링크를 만들어서 로그인을 해봤습니다
0
278
2
안녕하세요. DB에 저장될 때 이해 안 가는 값이 있어서 질문드립니다!
0
189
1





