사용자 API 신청 처리 (화면 작업만)
parent
67679f4e71
commit
f4898c508d
|
|
@ -0,0 +1,58 @@
|
|||
package geoinfo.main.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import geoinfo.util.KeyGenerator;
|
||||
import ictway.comm.util.parseData;
|
||||
import ictway.comm.util.strUtil;
|
||||
|
||||
@Controller
|
||||
public class ApiController {
|
||||
Logger log = Logger.getLogger(this.getClass());
|
||||
|
||||
/*
|
||||
* 사용자 > API 신청 화면
|
||||
*/
|
||||
@RequestMapping(value = "apiKey.do")
|
||||
public ModelAndView goApiKeyPage(ModelAndView model, @RequestParam HashMap<String, Object> params) throws Exception {
|
||||
|
||||
|
||||
|
||||
model.setViewName("body/api/apiKey");
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "createApiKey.do")
|
||||
@ResponseBody
|
||||
public Map<String, Object> UserApiInfo(HttpServletRequest request, HttpServletResponse response, @RequestParam HashMap<String, Object> params) {
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
|
||||
|
||||
strUtil sUtil = new strUtil();
|
||||
String userType = sUtil.checkNull(parseData.parseData((String)params.get("userType")));
|
||||
|
||||
String apiKey = KeyGenerator.generateUniqueKey();
|
||||
System.out.println("Generated apiKey ==>" + apiKey);
|
||||
log.info("apiKey ==> " + apiKey);
|
||||
log.info("userType ==> " + userType);
|
||||
|
||||
resultMap.put("code", "SUCCESS");
|
||||
resultMap.put("msg", "API 신청이 완료됐습니다.");
|
||||
resultMap.put("data",apiKey);
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -372,6 +372,11 @@ public class MainController
|
|||
eGovUrl = "faq.do";
|
||||
mv.setViewName("home/main.jsp?url=/body/board/main");
|
||||
}
|
||||
else if (url.equals("apiKey"))
|
||||
{
|
||||
eGovUrl = "apiKey.do";
|
||||
mv.setViewName("home/main.jsp?url=/body/board/main");
|
||||
}
|
||||
else if (url.equals("join"))
|
||||
{
|
||||
eGovUrl = "join.do";
|
||||
|
|
|
|||
|
|
@ -0,0 +1,77 @@
|
|||
/*********************************************************************************
|
||||
* 파 일 명 : RsBox.java
|
||||
* 작 성 일 : 2005.02
|
||||
* 작 성 자 : 최군길
|
||||
*---------------------------------------------------------------------------------
|
||||
* 프로그램명 : RsBox
|
||||
* 기능 및 설명 : JDBC Result Set Box Util
|
||||
*---------------------------------------------------------------------------------
|
||||
* 기 타 :
|
||||
*********************************************************************************/
|
||||
package geoinfo.util;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.*;
|
||||
|
||||
public class KeyGenerator {
|
||||
/**
|
||||
* 키 생성에 사용될 문자셋 (영문 대문자 + 영문 소문자 + 숫자)
|
||||
*/
|
||||
private static final String ALPHANUMERIC_CHARACTERS =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
/**
|
||||
* 생성할 키의 길이
|
||||
*/
|
||||
private static final int KEY_LENGTH = 43;
|
||||
|
||||
/**
|
||||
* 암호학적으로 안전한 난수 생성기 인스턴스.
|
||||
* 이 인스턴스는 한 번만 생성하여 재사용하는 것이 좋습니다.
|
||||
*/
|
||||
private static final SecureRandom secureRandom = new SecureRandom();
|
||||
|
||||
/**
|
||||
* 43글자의 고유한 랜덤 키를 생성합니다.
|
||||
*
|
||||
* @return 43글자의 영문/숫자 랜덤 키
|
||||
*/
|
||||
public static String generateUniqueKey() {
|
||||
// Java 1.7에서는 StringBuilder가 더 효율적입니다.
|
||||
// (StringBuffer는 스레드 안전성이 필요할 때 사용)
|
||||
StringBuilder sb = new StringBuilder(KEY_LENGTH);
|
||||
|
||||
for (int i = 0; i < KEY_LENGTH; i++) {
|
||||
// 0부터 (문자셋 길이 - 1) 사이의 랜덤 인덱스를 가져옵니다.
|
||||
int randomIndex = secureRandom.nextInt(ALPHANUMERIC_CHARACTERS.length());
|
||||
|
||||
// 문자셋에서 해당 인덱스의 문자를 선택하여 추가합니다.
|
||||
char randomChar = ALPHANUMERIC_CHARACTERS.charAt(randomIndex);
|
||||
sb.append(randomChar);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 메인 메소드 (테스트용)
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// 키 생성
|
||||
String key1 = KeyGenerator.generateUniqueKey();
|
||||
String key2 = KeyGenerator.generateUniqueKey();
|
||||
|
||||
// 생성된 키와 길이 출력
|
||||
System.out.println("생성된 키 1: " + key1);
|
||||
System.out.println("키 1의 길이 : " + key1.length());
|
||||
|
||||
System.out.println("-------------------------------------------------");
|
||||
|
||||
System.out.println("생성된 키 2: " + key2);
|
||||
System.out.println("키 2의 길이 : " + key2.length());
|
||||
|
||||
// 두 키가 다른지 확인 (거의 100% 다름)
|
||||
boolean areKeysDifferent = !key1.equals(key2);
|
||||
System.out.println("두 키가 다른가? " + areKeysDifferent);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
<%@ page language="java" contentType="text/html; charset=utf-8"%>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
</script>
|
||||
|
||||
<form name="frm" method="post">
|
||||
|
||||
<%-- 사용자 타입(국토교통부/행정안전부/해안수산부/기타공공기관/일반) --%>
|
||||
<ul class="row marB30">
|
||||
<li class="col col-xs-4 text-center"><label><input type="radio" name="userType" value="국토교통부">국토교통부</label></li>
|
||||
<li class="col col-xs-4 text-center"><label><input type="radio" name="userType" value="행정안전부">행정안전부</label></li>
|
||||
<li class="col col-xs-4 text-center"><label><input type="radio" name="userType" value="해양수산부">해양수산부</label></li>
|
||||
</ul>
|
||||
|
||||
<div class="row text-center">
|
||||
<a href="javascript:void(0);" class="apiKeyReq btn btn-large btn-green" onclick="javascript:generateApiKey();"> 신청하기 </a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!--function 정의 -->
|
||||
<script type="text/javascript">
|
||||
|
||||
// 사용자 > API 신청 버튼 클릭
|
||||
function generateApiKey() {
|
||||
var userType = $('input[name="userType"]:checked').val()
|
||||
$.ajax({
|
||||
url : "/createApiKey.do",
|
||||
type : "post",
|
||||
data : {userType: userType},
|
||||
dataType :"json",
|
||||
success : function(res){
|
||||
alert("apiKey ==> " + res.data)
|
||||
},
|
||||
error : function(){
|
||||
alert("오류입니다.");
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
@ -181,6 +181,11 @@
|
|||
</c:otherwise>
|
||||
</c:choose>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a href="#" onClick="gourl('apiKey')" onFocus="this.blur()" class="nav-link nav-toggle">
|
||||
<span class="title">API 신청</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<c:if test="${isLogin == true}">
|
||||
<c:if test="${cls == 0}">
|
||||
|
|
|
|||
|
|
@ -171,6 +171,9 @@
|
|||
<li class="dropdown">
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#" onClick="gourl('faq')" onFocus="this.blur()">시추정보 FAQ</a>
|
||||
</li>
|
||||
<li class="dropdown">
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#" onClick="gourl('apiKey')" onFocus="this.blur()">API 신청</a>
|
||||
</li>
|
||||
<c:if test="${isLogin == true}">
|
||||
<c:if test="${cls == 0}">
|
||||
<li class="dropdown">
|
||||
|
|
|
|||
|
|
@ -366,6 +366,27 @@
|
|||
<!-- 커뮤니티 > 시추정보 Q&A 끝 -->
|
||||
</c:if>
|
||||
|
||||
<c:if test="${eGovUrl == 'apiKey.do'}">
|
||||
<!-- 커뮤니티 > API 신청 시작 -->
|
||||
<h1 class="page-title">
|
||||
<span class="page-title-text">API 신청</span>
|
||||
<ul class="page-category">
|
||||
<li class="category-item">게시판</li>
|
||||
<li class="category-item">API 신청</li>
|
||||
</ul>
|
||||
</h1>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
// 상단메뉴 활성화
|
||||
$(".nav > li.dropdown:eq(6)").addClass("on");
|
||||
// 왼쪽메뉴 활성화
|
||||
$("#community_sub_menu").css("display", "block");
|
||||
$("#community_sub_menu > li.nav-item:eq(4)").addClass("active");
|
||||
});
|
||||
</script>
|
||||
<!-- 커뮤니티 > 시추정보 Q&A 끝 -->
|
||||
</c:if>
|
||||
|
||||
<c:if test="${eGovUrl == 'homeEducationApplicationInquiry.do' || eGovUrl == 'homeEducationApplicationInput.do' }">
|
||||
<!-- 집합교육 신청 시작 -->
|
||||
<h1 class="page-title">
|
||||
|
|
|
|||
Loading…
Reference in New Issue