feat: Client 정보 획득 DTO 추가
parent
78f32f9db5
commit
71c07a4b88
@ -0,0 +1,38 @@
|
||||
package kr.xit.core.model;
|
||||
|
||||
import kr.xit.core.spring.config.WebServerConfig;
|
||||
import kr.xit.core.spring.resolver.ClientInfoArgumentResolver;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* description : Client 헤더값 class
|
||||
* 헤더 값 set
|
||||
* -> 1. HandlerMethodArgumentResolver 인터페이스를 구현하여 ClientInfoDTO 객체 생성
|
||||
* 2. WebMvcConfigurer 인터페이스를 구현하여 Resolver 를 등록
|
||||
* 3. Controller 에서 헤더 값을 객체로 받는다.
|
||||
* packageName : kr.xit.core.model
|
||||
* fileName : ClientInfoDTO
|
||||
* author : limju
|
||||
* date : 2023-04-26
|
||||
* ======================================================================
|
||||
* 변경일 변경자 변경 내용
|
||||
* ----------------------------------------------------------------------
|
||||
* 2023-04-26 limju 최초 생성
|
||||
*
|
||||
* </pre>
|
||||
* @see ClientInfoArgumentResolver
|
||||
* @see WebServerConfig
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@ToString
|
||||
@Builder
|
||||
public class ClientInfoDTO {
|
||||
|
||||
private final String channel;
|
||||
private final String clientAddress;
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package kr.xit.core.spring.config;
|
||||
|
||||
import java.util.List;
|
||||
import kr.xit.core.model.ClientInfoDTO;
|
||||
import kr.xit.core.spring.resolver.ClientInfoArgumentResolver;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* description : Web server 설정
|
||||
* packageName : kr.xit.core.spring.config
|
||||
* fileName : WebServerConfig
|
||||
* author : limju
|
||||
* date : 2023-04-26
|
||||
* ======================================================================
|
||||
* 변경일 변경자 변경 내용
|
||||
* ----------------------------------------------------------------------
|
||||
* 2023-04-26 limju 최초 생성
|
||||
*
|
||||
* </pre>
|
||||
* @see ClientInfoDTO
|
||||
* @see WebServerConfig
|
||||
*/
|
||||
@Configuration
|
||||
public class WebServerConfig implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
|
||||
resolvers.add(new ClientInfoArgumentResolver());
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package kr.xit.core.spring.resolver;
|
||||
|
||||
import kr.xit.core.model.ClientInfoDTO;
|
||||
import kr.xit.core.spring.config.WebServerConfig;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.bind.support.WebDataBinderFactory;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* description : Client 헤더값에서 ClientInfoDTO 객체 생성
|
||||
* HandlerMethodArgumentResolver 인터페이스를 구현하여 ClientInfoDTO 객체 생성
|
||||
* -> WebMvcConfigurer 인터페이스를 구현하여 Resolver 를 등록
|
||||
* packageName : kr.xit.core.spring.resolver
|
||||
* fileName : ClientInfoArgumentResolver
|
||||
* author : limju
|
||||
* date : 2023-04-26
|
||||
* ======================================================================
|
||||
* 변경일 변경자 변경 내용
|
||||
* ----------------------------------------------------------------------
|
||||
* 2023-04-26 limju 최초 생성
|
||||
*
|
||||
* </pre>
|
||||
* @see ClientInfoDTO
|
||||
* @see WebServerConfig
|
||||
*/
|
||||
public class ClientInfoArgumentResolver implements HandlerMethodArgumentResolver {
|
||||
|
||||
private static final String HEADER_CHANNEL = "X-APP-CHANNEL";
|
||||
private static final String HEADER_CLIENT_IP = "X-FORWORD-FOR";
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
return ClientInfoDTO.class.equals(parameter.getParameterType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(@Nullable MethodParameter parameter,
|
||||
ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest,
|
||||
WebDataBinderFactory binderFactory) throws Exception {
|
||||
|
||||
String channel = webRequest.getHeader(HEADER_CHANNEL);
|
||||
String clientAddress = webRequest.getHeader(HEADER_CLIENT_IP);
|
||||
return new ClientInfoDTO(channel, clientAddress);
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<link rel="stylesheet" type="text/css" href="/resources/static/semantic/dist/semantic.min.css">
|
||||
<script
|
||||
src="https://code.jquery.com/jquery-3.1.1.min.js"
|
||||
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
|
||||
crossorigin="anonymous"></script>
|
||||
<script src="/resources/static/semantic/dist/semantic.min.js"></script>
|
||||
<title>login</title>
|
||||
</head>
|
||||
<body>
|
||||
<form class="ui form">
|
||||
<div class="field">
|
||||
<label>id</label>
|
||||
<input type="text" name="id" placeholder="사용자 ID" value="admin">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>password</label>
|
||||
<input type="text" name="password" placeholder="비밀번호" value="1">
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="ui checkbox">
|
||||
<input type="checkbox" tabindex="0" class="hidden">
|
||||
<label>id 저장</label>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="userSe" value="USR">
|
||||
<button class="ui button" type="submit">Submit</button>
|
||||
</form>
|
||||
</body>
|
||||
<script>
|
||||
|
||||
const postForm = (body) => {
|
||||
return fetch('/auth/loginJwt', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-APP-CHANNEL': 'WEB',
|
||||
'X-FORWORD-FOR': '211.119.124.73',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmit = async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const form = document.querySelector('form');
|
||||
const data = Object.fromEntries(new FormData(form).entries());
|
||||
|
||||
// const body = {
|
||||
// id: document.querySelector('input[name="id"]').value,
|
||||
// password: document.querySelector('input[name="password"]').value,
|
||||
// userSe: document.querySelector('input[name="userSe"]').value,
|
||||
// }
|
||||
|
||||
const res = await postForm(JSON.stringify(data))
|
||||
const json = await res.json();
|
||||
console.log(json)
|
||||
};
|
||||
|
||||
document.querySelector('form').addEventListener("click", handleSubmit);
|
||||
</script>
|
||||
</html>
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue