Skip to content

Commit

Permalink
api login dto 전송
Browse files Browse the repository at this point in the history
  • Loading branch information
HeeSung98 committed Nov 24, 2023
1 parent 97f63ce commit ddee9ba
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

@Log4j2
public class ApiLoginFilter extends AbstractAuthenticationProcessingFilter {
Expand All @@ -23,6 +25,8 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
throws IOException, ServletException {
log.info("ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ");

String body = getBody(request);
log.info("body: ", body);
String email = request.getParameter("email");
String password = request.getParameter("password");
log.info("email" + email);
Expand All @@ -31,4 +35,36 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ

return getAuthenticationManager().authenticate(token);
}

public static String getBody(HttpServletRequest request) throws IOException {

String body = null;
StringBuilder stringBuilder = new StringBuilder();
BufferedReader bufferedReader = null;

try {
InputStream inputStream = request.getInputStream();
if (inputStream != null) {
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
char[] charBuffer = new char[128];
int bytesRead = -1;
while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
stringBuilder.append(charBuffer, 0, bytesRead);
}
}
} catch (IOException ex) {
throw ex;
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException ex) {
throw ex;
}
}
}

body = stringBuilder.toString();
return body;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
log.info("ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ");
log.info("인증에 성공했습니다.");

log.info(authentication);

AuthUserDTO authUserDTO = (AuthUserDTO) authentication.getPrincipal();
boolean fromSocial = authUserDTO.isFromSocial();
String name = authUserDTO.getName();

log.info(authUserDTO);

if(fromSocial && name == null) {
redirectStrategy.sendRedirect(request, response, "https://weatherfit-frontend.vercel.app");
} else {
String result = objectMapper.writeValueAsString(authUserDTO);
response.setContentType("application/json;charset=utf-8");
response.getWriter().write(result);
redirectStrategy.sendRedirect(request, response, "https://weatherfit-frontend.vercel.app");
}
}
}

0 comments on commit ddee9ba

Please sign in to comment.