spring security 6

@PreAuthorize를 활용한 댓글 수정/삭제 권한 관리 및 코드 개선

기존 문제점: 관리자(Admin) 권한이 있어도 댓글 수정/삭제 불가기존 코드 분석현재 @AuthenticationPrincipal을 이용하여 컨트롤러에서 userId를 추출하고, 이를 서비스 계층에서 권한 검증하고 있다.@PutMapping("/{commentId}")public ResponseEntity updateComment( @AuthenticationPrincipal JwtUserDetails userPrincipal, @PathVariable Long commentId, @Valid @RequestBody CommentRequest request) { return ResponseEntity.ok( commentService.update( ..

Project/Boilerplate 2025.03.10

Spring Boot response로 header가 추가되지 않는 현상

문제:response.addHeader(JwtProperties.HEADER_AUTHORIZATION, JwtProperties.ACCESS_TOKEN_PREFIX + newAccessToken);스프링 서버에서 응답 헤더에 추가한 헤더가 Front 서버에서 출력했을 때, undefined로 출력됨 원인:configuration.setExposedHeaders(Collections.singletonList("Set-Cookie"));configuration.setExposedHeaders(Collections.singletonList("Authorization"));configuration.setExposedHeaders(Collections.singletonList("x-reissue-token"..

Project/Boilerplate 2025.03.06

Spring Security 6.x.x OAuth2.0 JWT 기반 인증 인가

application.properties#registrationspring.security.oauth2.client.registration.서비스명.client-name=서비스명spring.security.oauth2.client.registration.서비스명.client-id=서비스에서 발급 받은 아이디spring.security.oauth2.client.registration.서비스명.client-secret=서비스에서 발급 받은 비밀번호spring.security.oauth2.client.registration.서비스명.redirect-uri=서비스에 등록한 우리쪽 로그인 성공 URIspring.security.oauth2.client.registration.서비스명.authorization-gr..

Web/Spring Security 2025.02.26

Spring Security JWT 인증 인가 순서

🟡 토큰 발급이 안되어있을 경우클라이언트 요청SecurityConfig에 등록된 JwtAuthenticationFilter 호출토큰정보가 없기 때문에 다음 필터 호출🟡 토큰을 발급하는 경우(로그인)클라이언트 요청SecurityConfig에 등록된 JwtAuthenticationFilter 호출토큰정보가 없기 때문에 다음 필터 호출로그인 url은 SecurityConfig에 예외처리 하였기 때문에 필터에 걸리지 않는다.사용자의 로그인id, pw를 사용하여 UsernamePasswordAuthenticationToken 객체 생성authenticationManagerBuilder를 이용하여 CustomUserDetailsService 의 loadUserByUsername 메소드 호출loadUserByUs..

Web/Spring Security 2025.02.14