Skip to content

Commit

Permalink
feat:login response Body수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jms0324 committed Aug 6, 2024
1 parent 72ec007 commit 2b65f4c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/java/com/example/babywithus/jwt/LoginFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;

Expand All @@ -29,7 +30,7 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
String password=obtainPassword(request);
System.out.println(username);

//스프링 시큐리티에서 username과 password를 검증하기 위해서는 token에 담아야 함
//스프링 시큐리티에서 username과 password를 검증하기 위해서는 token에 담아야 함
UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(username, password, null);

//token에 담은 검증을 위한 AuthenticationManager로 전달
Expand All @@ -39,7 +40,7 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ

//로그인 성공시 실행하는 메소드 (여기서 JWT를 발급하면 됨)
@Override
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authentication) {
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authentication)throws IOException {

CustomMemberDetails customMemberDetails = (CustomMemberDetails) authentication.getPrincipal();

Expand All @@ -56,6 +57,16 @@ protected void successfulAuthentication(HttpServletRequest request, HttpServletR

response.addHeader("Authorization", "Bearer " + token);

// JSON 형식으로 응답 본문 작성
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");

// JSON 객체 생성
String jsonResponse = String.format("{\"token\": \"%s\"}", token);

// 응답 본문에 JSON 객체 쓰기
response.getWriter().write(jsonResponse);


}

Expand Down

0 comments on commit 2b65f4c

Please sign in to comment.