2023-05-12 15:32 API 인증
This commit is contained in:
parent
100a9e3011
commit
a525a5d8b6
@ -30,7 +30,9 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(certificationInterceptor())
|
||||
.addPathPatterns("/api/**");
|
||||
.addPathPatterns("/api/accessKey/**")
|
||||
.addPathPatterns("/api/accessKey/**")
|
||||
;
|
||||
//.excludePathPatterns("/css/**", "/images/**", "/js/**");
|
||||
}
|
||||
|
||||
|
||||
@ -28,5 +28,8 @@ public class AccessKeyVO implements Serializable {
|
||||
private String accessToken; //access_token 고유번호
|
||||
private String tokenObj; //access_token 고유번호
|
||||
private String expirePnttm; //access_token 파기일시
|
||||
|
||||
//for call_info
|
||||
private String callInfo; //access_token 고유번호
|
||||
|
||||
}
|
||||
@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
@ -42,19 +43,10 @@ public class CertificationInterceptor implements HandlerInterceptor{
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||
throws Exception {
|
||||
//HttpSession session = request.getSession();
|
||||
|
||||
System.out.println("=====preHandle=4=apikey==");
|
||||
System.out.println("=====preHandle=4=apikey=="+request.getRequestURI());
|
||||
|
||||
System.out.println("=====preHandle=4=apikey=="+request.getRemoteAddr());
|
||||
System.out.println("=====preHandle=4=apikey=="+request.getRemoteHost());
|
||||
System.out.println("=====preHandle=4=apikey=="+request.getRemotePort());
|
||||
System.out.println("=====preHandle=4=apikey=="+request.getRemoteUser());
|
||||
System.out.println("=====preHandle=4=apikey=="+request.getRequestedSessionId());
|
||||
System.out.println("=====preHandle=4=apikey==");
|
||||
|
||||
|
||||
|
||||
// URL 접속정보
|
||||
String referer = request.getHeader("Referer");
|
||||
//System.out.println("=====preHandle=5=apikey=refer="+referer);
|
||||
|
||||
//step0-1.log 남기기
|
||||
//step0-2.IP 체크
|
||||
@ -77,7 +69,7 @@ public class CertificationInterceptor implements HandlerInterceptor{
|
||||
lettnLoginLogVO.setConectId(request.getParameter("mberId"));
|
||||
|
||||
//device type
|
||||
if(isMobile(request)){
|
||||
if(_isMobile(request)){
|
||||
lettnLoginLogVO.setDeviceType("M");
|
||||
}else{
|
||||
lettnLoginLogVO.setDeviceType("P");
|
||||
@ -98,22 +90,23 @@ public class CertificationInterceptor implements HandlerInterceptor{
|
||||
lettnLoginLogService.insert(lettnLoginLogVO);
|
||||
|
||||
|
||||
//step0-2.IP 체크
|
||||
//step0-2.IP 체크(호출IP체크)
|
||||
lettnLoginLogVO = lettnLoginLogService.selectIgnoreIpCnt(lettnLoginLogVO);
|
||||
int i_ignoreCnt = lettnLoginLogVO.getCnt();
|
||||
|
||||
//IP 접근 제어
|
||||
if (i_ignoreCnt>0) {
|
||||
//제한 아이피인 경우는 화면 안나옴 처리
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.getWriter().write("{\"resultCode\":\"403\",\"message\":\"Forbidden\"}");
|
||||
|
||||
this._jsonResult(response, HttpStatus.FORBIDDEN);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}catch(Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
//내부 오류
|
||||
this._jsonResult(response, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@ -124,27 +117,26 @@ public class CertificationInterceptor implements HandlerInterceptor{
|
||||
AccessKeyVO accessKeyVO = new AccessKeyVO();
|
||||
accessKeyVO.setAccessKey(request.getParameter("accessKey"));
|
||||
accessKeyVO.setMberId(request.getParameter("mberId"));
|
||||
accessKeyVO.setCallInfo(referer);
|
||||
|
||||
accessKeyVO = accessKeyService.selectRKey(accessKeyVO);
|
||||
|
||||
//인증 실패
|
||||
if (accessKeyVO ==null) {
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.getWriter().write("{\"resultCode\":\"401\",\"message\":\"Unauthorized\"}");
|
||||
|
||||
this._jsonResult(response, HttpStatus.UNAUTHORIZED);
|
||||
return false;
|
||||
}
|
||||
|
||||
}catch(Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.getWriter().write("{\"resultCode\":\"401\",\"message\":\"Unauthorized\"}");
|
||||
|
||||
|
||||
//내부 오류
|
||||
this._jsonResult(response, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -165,8 +157,11 @@ public class CertificationInterceptor implements HandlerInterceptor{
|
||||
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/*모바일접속 유무*/
|
||||
private boolean isMobile(HttpServletRequest request) {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
private boolean _isMobile(HttpServletRequest request) throws Exception{
|
||||
String userAgent = request.getHeader("user-agent");
|
||||
boolean mobile1 = userAgent.matches(".*(iPhone|iPod|Android|Windows CE|BlackBerry|Symbian|Windows Phone|webOS|Opera Mini|Opera Mobi|POLARIS|IEMobile|lgtelecom|nokia|SonyEricsson).*");
|
||||
boolean mobile2 = userAgent.matches(".*(LG|SAMSUNG|Samsung).*");
|
||||
@ -175,5 +170,16 @@ public class CertificationInterceptor implements HandlerInterceptor{
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void _jsonResult(
|
||||
HttpServletResponse p_response
|
||||
, HttpStatus p_HttpStatus
|
||||
) throws Exception{
|
||||
p_response.setContentType("application/json");
|
||||
p_response.setCharacterEncoding("UTF-8");
|
||||
p_response.getWriter().write("{\"resultCode\":\""+p_HttpStatus.value()+"\",\"message\":\""+p_HttpStatus.getReasonPhrase()+"\"}");
|
||||
|
||||
//return "{\"resultCode\":\""+p_HttpStatus.value()+"\",\"message\":\""+p_HttpStatus.getReasonPhrase()+"\"}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.itn.mjonApi.cmn.idgen.mapper.domain.SendMsgVO;
|
||||
@ -46,7 +47,8 @@ public class AccessKeyRestController {
|
||||
* 2.plain text
|
||||
*
|
||||
*/
|
||||
@GetMapping("/api/accessKey/SendMsg")
|
||||
@PostMapping("/api/accessKey/SendMsg")
|
||||
//@GetMapping("/api/accessKey/SendMsg")
|
||||
public ResponseEntity<RestResponse> apiaccessKeysendMsg(
|
||||
@ModelAttribute SendMsgVO sendMsgVO
|
||||
){
|
||||
|
||||
@ -89,10 +89,14 @@
|
||||
<include refid="select_column_name"/>
|
||||
FROM
|
||||
<include refid="table_name"/> a
|
||||
, lettngnrlmber_access_call_info b
|
||||
WHERE
|
||||
1=1
|
||||
AND a.ACCESS_KEY = #{accessKey}
|
||||
AND a.MBER_ID = #{mberId}
|
||||
AND a.ACCESS_KEY = #{accessKey}
|
||||
AND a.MBER_ID = #{mberId}
|
||||
AND a.ACCESS_no = b.ACCESS_NO
|
||||
AND b.CALL_INFO LIKE CONCAT(#{callInfo}, '%')
|
||||
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user