Browse Source

중간커밋

leeheejo 6 years ago
parent
commit
65995f4f21

+ 26 - 19
java/com/icontrols/oauth/controller/OAuthController.java

@@ -61,7 +61,7 @@ public class OAuthController {
 
 //	http://127.0.0.1:8080/api/oauth2/authorize?client_id=clientid&redirect_uri=http://127.0.0.1:8080/api/oauth2/redirect&scope=scope&response_type=code&state=state
 	@RequestMapping(value = "/authorize", method = RequestMethod.GET)
-	public @ResponseBody ModelAndView Authorize(@RequestHeader HttpHeaders headers,
+	public ModelAndView Authorize(@RequestHeader HttpHeaders headers,
 			@RequestParam(value = "response_type", required = true) String responseType,
 			@RequestParam(value = "client_id", required = true) String clientId,
 			@RequestParam(value = "state", required = true) String state, @RequestParam(value = "scope") String scope,
@@ -109,7 +109,7 @@ public class OAuthController {
 		return mav;
 	}
 
-	@RequestMapping(value = "/user/info/submit", method = RequestMethod.POST)
+	@RequestMapping(value = "/user/info/submit", method = RequestMethod.GET)
 	public ModelAndView sendCode(HttpSession httpSession, HttpServletResponse httpResponse,
 			@RequestParam(value = "complex", required = true) String complex,
 			@RequestParam(value = "dong", required = true) String dong,
@@ -137,12 +137,22 @@ public class OAuthController {
 		logger.info("*[wallpadCode]");
 		logger.info("*code: " + wallpadCode);
 
-//		http://61.33.215.54:8002/iotservice/code/request
-//		{
-//			 "dong":"802", 
-//			 "ho": "704",
-//			 "code" :"931206",
-//			}
+		// 세대정보 인코딩
+		String homeInfo = complex + "/" + dong + "/" + ho;
+		// db에 저장
+
+		ValueOperations<String, Object> vop = redisTemplate.opsForValue();
+		Duration d = Duration.ofSeconds(180);
+
+		while (!vop.setIfAbsent(wallpadCode, homeInfo, d)) {
+			wallpadCode = "";
+			for (int i = 0; i < 6; i++) {
+				wallpadCode += Integer.toString(generator.nextInt(10));
+			}
+		}
+
+		logger.info("*[redis]");
+		logger.info("*(key,value): (" + wallpadCode + "," + homeInfo + ")");
 
 		// 단지서버로 월패드인증번호 전송
 		WallpadCode body = new WallpadCode(dong, ho, wallpadCode);
@@ -163,15 +173,6 @@ public class OAuthController {
 			new ResponseStatusException(HttpStatus.BAD_REQUEST, ERROR.INVALID_HOMEINFO);
 		}
 
-		// 세대정보 인코딩
-		String homeInfo = complex + "/" + dong + "/" + ho;
-		// db에 저장
-		ValueOperations<String, Object> vop = redisTemplate.opsForValue();
-		Duration d = Duration.ofSeconds(180);
-		vop.set(wallpadCode, homeInfo, d);
-		logger.info("*[redis]");
-		logger.info("*(key,value): (" + wallpadCode + "," + homeInfo + ")");
-
 		ModelAndView mav = new ModelAndView();
 		mav.setViewName("InsertCode");
 		return mav;
@@ -227,7 +228,13 @@ public class OAuthController {
 		logger.info("*1. code: " + code);
 
 		Duration d = Duration.ofSeconds(180);
-		vop.set(code, homeInfo, d);
+
+		while (!vop.setIfAbsent(code, homeInfo, d)) {
+			code = "";
+			for (int i = 0; i < 10; i++) {
+				code += String.valueOf((char) ((int) (rnd.nextInt(26)) + 65));
+			}
+		}
 
 		String redirectUri = (String) httpSession.getAttribute("redirectUri");
 		redirectUri += "?state=" + httpSession.getAttribute("state");
@@ -240,7 +247,7 @@ public class OAuthController {
 	}
 
 	// 토큰 발급하는 부분
-	@RequestMapping(value = "/token", method = RequestMethod.GET, produces = "application/json")
+	@RequestMapping(value = "/token", method = RequestMethod.POST, produces = "application/json")
 	public @ResponseBody Token Token(@RequestParam(value = "grant_type", required = true) String grantType,
 			@RequestParam(value = "code", required = false) String code,
 			@RequestParam(value = "refresh_token", required = false) String refreshToken, HttpSession httpSession)

+ 5 - 2
src/main/resources/application.properties

@@ -15,6 +15,9 @@ spring.jpa.generate-ddl=true
 spring.datasource.username=admin
 spring.datasource.password = hdci12#$
 
-#spring.datasource.username=root
-#spring.datasource.password = 2072712l^^
+
+server.ssl.key-store=classpath:tomcat.jks
+server.ssl.key-store-password=hdci12#$
+
+logging.config=classpath:logback-spring.xml
 

+ 28 - 0
src/main/resources/logback-spring.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+    <include resource="org/springframework/boot/logging/logback/base.xml"/>
+
+    <appender name="dailyRollingFileAppender"
+              class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <append>true</append>
+        <prudent>true</prudent>
+
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <fileNamePattern>log/LogFile_%d{yyyy-MM-dd}.log</fileNamePattern>
+            <maxHistory>30</maxHistory>
+        </rollingPolicy>
+        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
+            <level>DEBUG</level>
+        </filter>
+
+        <encoder>
+            <pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{35} - %msg%n</pattern>
+        </encoder>
+    </appender>
+
+    <logger name="com.icontrols.uplus.interfaces" level="DEBUG"></logger>
+
+    <root level="INFO">
+        <appender-ref ref="dailyRollingFileAppender" />
+    </root>
+</configuration>

+ 30 - 42
src/main/webapp/WEB-INF/jsp/InsertCode.jsp

@@ -9,10 +9,10 @@
 	href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
 	integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
 	crossorigin="anonymous">
-<title>Insert title here</title>
+<title>사용자 인증</title>
 <style type="text/css">
 body {
-	padding-top: 30px;
+	padding: 30px;
 }
 
 @media screen and (min-width : 640px) { /* Styles */
@@ -23,51 +23,39 @@ body {
 }
 </style>
 </head>
-<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
+<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
 <script type="text/javascript" language="javascript">
-	$(document)
-			.ready(
-					function() {
-						$("#btn")
-								.click(
-										function btnClickHandler() {
-											var code = $("#code").val();
-											if (code == "")
-												alert("월패드에 표시된 코드를 입력하세요.");
-											else {
-												console.log(code);
-												$
-														.ajax({
-															url : "/api/oauth2/validate",
-															data : {
-																code : code
-															},
-															success : function(
-																	data,
-																	dataType) {
-																if (data) {
-																	console
-																	console.log("*true");
-																	window.location.href = 'http://61.33.215.56:8003/api/oauth2/code/generate';
-																} else {
-																	alert("월패드 코드 인증 실패");
-																}
-
-															}
-														});
+	function btnClickHandler() {
+		var code = $("#code").val();
+		if (code == "")
+			alert("월패드에 표시된 코드를 입력하세요.");
+		else {
+			console.log(code);
+			$.ajax({
+					type: "GET",
+					url : "/api/oauth2/validate",
+					data : {
+							code : code
+							},
+					success : function(data) {
+											console.log(data);
+											if (data == true) {
+												window.location.href = 'https://teldev.hdc-smart.com:443/api/oauth2/code/generate';
+												} else {
+												alert("월패드 코드 인증 실패");
+												}
 											}
-										});
 					});
+																						
+		}
+	}
 </script>
 <body>
 	<!-- <form method="post" action="validate"> -->
-	<form class = "myclass">
-		<label for="code">인증번호</label> 
-		<input type="text" class="form-control" id="code" name="code" value="704" required>
-		<br>
-		<br>
-		<button class="btn btn-primary btn-block" id="btn" name="btn">Submit</button>
-		<!-- </form> -->
-	</form>
+	<div class="myclass">
+		<label for="code">인증번호</label> <input type="text" class="form-control"
+			id="code" name="code" required> <br> <br>
+		<input type="button" class="btn btn-primary btn-block" onClick="javascript:btnClickHandler();"value ="인증하기"/>
+	</div>
 </body>
 </html>

+ 6 - 6
src/main/webapp/WEB-INF/jsp/InsertUserInfo.jsp

@@ -14,11 +14,11 @@
 	href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
 	integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
 	crossorigin="anonymous">
-<title>Insert title here</title>
+<title>»ç¿ëÀÚ ÀÎÁõ</title>
 <style type="text/css">
 
 body {
-	padding-top: 30px;
+	padding: 30px;
 	
 }
 
@@ -32,7 +32,7 @@ body {
 </head>
 
 <body>
-	<form method="post" action="user/info/submit" class = "myclass">
+	<form method="get" action="user/info/submit" class = "myclass">
 	
 		<label for="complex">´ÜÁö</label> 
 		<select class="form-control" id="complex" name="complex" required>
@@ -43,13 +43,13 @@ body {
 		</select> 
 		<br>
 		<label for="dong">µ¿</label> 
-		<input type="text" class="form-control" id="dong" name="dong" value="802" required>
+		<input type="text" class="form-control" id="dong" name="dong" required>
 		<br> 
 		<label for="ho">È£</label> 
-		<input type="text" class="form-control" id="ho" name="ho" value="1103" required>
+		<input type="text" class="form-control" id="ho" name="ho" required>
 		<br> 
 		<br>
-		<button type="submit" class="btn btn-primary btn-block">Submit</button>
+		<button id="submit" name ="submit" type="submit" class="btn btn-primary btn-block">Submit</button>
 	</form>
 
 </body>