public class MyCustomDsl extends AbstractHttpConfigurer<MyCustomDsl, HttpSecurity> { @Override public void configure(HttpSecurity http) throws Exception { System.out.println("체크포인트!@@!@!@!@"); AuthenticationManager authenticationManager = http.getSharedObject(AuthenticationManager.class); http .addFilter(new LoginFilter(authenticationManager)) .addFilterAfter(jwtFilter, UsernamePasswordAuthenticationFilter.class); } } 를 구현하고, 로그인이 완료 되었을 때, @Override protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult) throws IOException, ServletException { log.info("successfulAuthentication 함수 실행: 로그인 성공"); PrincipalDetails principalDetails = (PrincipalDetails) authResult.getPrincipal(); /* 로그인 완료, 1. 토큰 생성 2. 쿠키 장착 */ response.setHeader("gd", "gdgd"); // response.sendRedirect("/api/loginTest"); // super.successfulAuthentication(request, response, chain, authResult); } 이 메서드 까지 구현했습니다. 제 원래 로직은 액세스 토큰, 리프레쉬 토큰을 생성하고 리프레쉬 토큰을 DB에 담고 액세스 토큰, 레프레쉬 토큰 두 개를 쿠키에 저장하는 로직입니다. ResponseCookie build = ResponseCookie .from("accessToken", "gd") .path("/") .httpOnly(true) // 시간 .maxAge(JwtUtil.REFRESH_TOKEN_EXPIRE_TIME) .sameSite("Lax") .build(); ResponseEntity.ok().header("Set-Cookie", build.toString()) .body("ok"); 대충 쿠키를 생성해서 그 쿠키를 헤더에 담는 방식을 사용 중인데, 이렇게 로그인 완료 메서드에서 구현할 방법이 없고 헤더에 저장할 방법이 없어서 너무 막막합니다.. Controller에서 그냥 구현하면 ResponseEntity를 이용해서 헤더에 고정적으로 담을 수 있는데 로그인 성공 메서드에서 어떻게 해야 이렇게 똑같이 구현을 할 수 있을까요..ㅠㅠㅜ?
loadUserByUsername 메서드를 구현하지 않아도 로그인 기능, 권한 넘겨주기 다 가능할 거 같은데 이 메서드가 꼭 필요한 이유가 있나요? doFilter를 안 탄다고 말씀해주셨는데 전 JWT를 쿠키에 저장하는데, 쿠키의 값이 없을 때 doFIlter를 그냥 빠져나가는 식으로 구현했습니다. successfulAuthentication이나, 권한을 UsernamePasswordAuthenticationToken authentication // = new UsernamePasswordAuthenticationToken(userId, null, List.of(new SimpleGrantedAuthority("ROLE_USER"))); authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); SecurityContextHolder.getContext().setAuthentication(authentication); 이렇게 넣을 수 있던데 이러한 방식은 뭐가 잘못된 걸까요? 문제가 생기나요?
안녕하세요. 이전 강의와 강의 교안과는 다르게, 개정3판 강의에서는 라우트분리 및 템플릿엔진 사용법과 관련된 강의가 빠져있더라고요. 혹시 해당 강의들에 대해서 이번 개정판에서는 더 이상 학습하지 않아도 괜찮기 때문에 강의 내용에서 빠진 것 일까요? 매번 좋은 강의로 감사합니다.
에러 안나고 결과도 잘 나오는데 LoginDto에 password가 어떻게 user 테이블에 있는 암호화된 비밀번호랑 비교돼서 동일한 결과값으로 판단돼서 토큰이 나오는지 궁금합니다. 제가 아직 부족해서인지 따라가면서 봐도 입력받은 password로 암호화하는 작업이 안보여서요
강사님 안녕하세요. 강의 늘 잘 보고 있습니다. 25강 내용에서, 올바른 id일 경우 password 일치 여부에 따라 404 혹은 401 에러를 응답하는 것은 확인했습니다. 헌데 id 자체가 잘못되었을 경우 서버 에러(500)가 발생하더라구요. 잘못된 ID 입력에 대한 처리를 어떻게 하는게 좋을 지 궁금합니다. Service 계층(loadUserByUsername)에서 한번 검사를 한 후, 통과되었을 시 UserDetails을 return하는 식으로 구현하나요? 이 경우, loadUserByUsername의 return값은 어떤 것이 권장되는지 궁금합니다.
회원가입은 BCryptPasswordEncoder를 통해 패스워드를 암호화를 했었늗데요 @PostMapping("/joinProc") public String joinPorc(User user) { String rawPassword = user.getPassword(); String encPassword = bCryptPasswordEncoder.encode(rawPassword); user.setPassword(encPassword); userRepository.save(user); return "redirect:/login"; } 로그인할 떄 에는 따로 패스워드를 따로 검증하지 않고 username만 확인하더라구요 @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { User userEntity = userRepository.findByUsername(username); if(userEntity != null){ return new PrincipalDetails(userEntity); } return null; } @Bean public BCryptPasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } 어느 부분에서 자동으로 BCryptPasswordEncoder를 통해 matches 하고 검증하는건가요??
/members/:memberId/fortune/:bigNum?/:smallNum? 안녕하세요, 위 api에 대해 아직 이해가 안되서 여쭤봅니다. bigNum이 대운 smalNum은 세운을 뜻하는것 같은데 대운 1~10, 세운 1~10을 선택하면 위 param에 넣어진다는 것은 맞을까요? /members/:memberId/fortune/1/2 이런식으로요! 그런데 대운, 세운을 선택한다는게 무슨뜻인가요? 예컨대 대운 1을 택한다는것과 세운 3을 선택한다면 뭘 선택했다는건지 이해가 안가서요! 아마 제가 프론트 학습(만세력 앱 관련)을 하기전에 서버부터 해서 그런거 같은데 이 의미에 대해 설명해주시면 감사하겠습니다
PS C:\Users\jagit\SSYW\saju-frontend-vuejs-master> npm install npm WARN config global --global , --local are deprecated. Use --location=global instead. npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: vuetify-loader@1.9.2 npm ERR! Found: vue@2.6.11 npm ERR! node_modules/vue npm ERR! vue@"2.6.11" from the root project npm ERR! peerOptional vue@"^2 || ^3.0.0-0" from @vue/babel-preset-app@4.5.17 npm ERR! node_modules/@vue/babel-preset-app npm ERR! @vue/babel-preset-app@"^4.5.17" from @vue/cli-plugin-babel@4.5.17 npm ERR! node_modules/@vue/cli-plugin-babel npm ERR! dev @vue/cli-plugin-babel@"~4.5.15" from the root project npm ERR! 3 more (vue-axios, vuetify, vuex) npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer vue@"^2.7.2" from vuetify-loader@1.9.2 npm ERR! node_modules/vuetify-loader npm ERR! dev vuetify-loader@"^1.7.0" from the root project npm ERR! npm ERR! Conflicting peer dependency: vue@2.7.14 npm ERR! node_modules/vue npm ERR! peer vue@"^2.7.2" from vuetify-loader@1.9.2 npm ERR! node_modules/vuetify-loader npm ERR! dev vuetify-loader@"^1.7.0" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! See C:\Users\jagit\AppData\Local\npm-cache\eresolve-report.txt for a full report. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\jagit\AppData\Local\npm-cache\_logs\2023-01-28T07_03_01_187Z-debug-0.log PS C:\Users\jagit\SSYW\saju-frontend-vuejs-master> npm run serve npm WARN config global --global , --local are deprecated. Use --location=global instead. > saju-frontend-vuejs@0.1.0 serve > vue-cli-service serve 'vue-cli-service'은(는) 내부 또는 외부 명령, 실행할 수 있는 프로그램, 또는 배치 파일이 아닙니다. PS C:\Users\jagit\SSYW\saju-frontend-vuejs-master> 오류납니다. 도와주세요!