Skip to content

Commit

Permalink
Merge pull request #66 from Gaia3D/feature/63-policy-security
Browse files Browse the repository at this point in the history
사용자 메인페이지 policy 요청 방식 ajax로 변경 #63
  • Loading branch information
ssshpark authored Feb 28, 2020
2 parents d638d5f + c81a898 commit 1f9c647
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 36 deletions.
29 changes: 0 additions & 29 deletions ndtp-user/src/main/java/ndtp/controller/DataController.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,34 +125,7 @@ public String map( HttpServletRequest request,
String roleCheckResult = roleValidator(request, userSession.getUserGroupId(), RoleKey.USER_DATA_READ.name());
if(roleCheckResult != null) return roleCheckResult;

GeoPolicy geoPolicy = CacheManager.getGeoPolicy();
UserPolicy userPolicy = userPolicyService.getUserPolicy(userSession.getUserId());
if(userPolicy.getUserId() != null) {
geoPolicy.setInitLatitude(userPolicy.getInitLatitude());
geoPolicy.setInitLongitude(userPolicy.getInitLongitude());
geoPolicy.setInitAltitude(userPolicy.getInitAltitude());
geoPolicy.setInitDuration(userPolicy.getInitDuration());
geoPolicy.setInitDefaultFov(userPolicy.getInitDefaultFov());
geoPolicy.setLod0(userPolicy.getLod0());
geoPolicy.setLod1(userPolicy.getLod1());
geoPolicy.setLod2(userPolicy.getLod2());
geoPolicy.setLod3(userPolicy.getLod3());
geoPolicy.setLod4(userPolicy.getLod4());
geoPolicy.setLod5(userPolicy.getLod5());
geoPolicy.setSsaoRadius(userPolicy.getSsaoRadius());
}

String geoPolicyJson = "";
String baseLayerJson = "";
try {
geoPolicyJson = objectMapper.writeValueAsString(geoPolicy);
List<LayerGroup> layerGroupList = LayerDisplaySupport.getListDisplayLayer(layerGroupService.getListLayerGroupAndLayer(), userPolicy.getBaseLayers());
baseLayerJson = objectMapper.writeValueAsString(layerGroupList);
} catch(Exception e) {
log.info("@@ objectMapper exception");
e.printStackTrace();
}

Long commonDataCount = 0l;
Long publicDataCount = 0l;
Long privateDataCount = 0l;
Expand Down Expand Up @@ -214,8 +187,6 @@ public String map( HttpServletRequest request,
model.addAttribute("dataList", dataList);
model.addAttribute("dataGroupList", dataGroupList);
model.addAttribute("userPolicy", userPolicy);
model.addAttribute("geoPolicyJson", geoPolicyJson);
model.addAttribute("baseLayerJson", baseLayerJson);
model.addAttribute("owner", userSession.getUserId());

return "/data/map";
Expand Down
85 changes: 85 additions & 0 deletions ndtp-user/src/main/java/ndtp/controller/PolicyRestController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package ndtp.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import lombok.extern.slf4j.Slf4j;
import ndtp.domain.CacheManager;
import ndtp.domain.GeoPolicy;
import ndtp.domain.Key;
import ndtp.domain.LayerGroup;
import ndtp.domain.UserPolicy;
import ndtp.domain.UserSession;
import ndtp.service.LayerGroupService;
import ndtp.service.UserPolicyService;
import ndtp.support.LayerDisplaySupport;

/**
* 초기 로딩 policy init
* @author PSH
*
*/
@Slf4j
@RestController
@RequestMapping("/policy/")
public class PolicyRestController {

private final UserPolicyService userPolicyService;
private final LayerGroupService layerGroupService;

public PolicyRestController(UserPolicyService userPolicyService, LayerGroupService layerGroupService) {
this.userPolicyService = userPolicyService;
this.layerGroupService = layerGroupService;
}

@GetMapping
public Map<String, Object> init(HttpServletRequest request) {
log.info("@@ Policy init");

Map<String, Object> result = new HashMap<>();
int statusCode = 0;
String errorCode = null;
String message = null;
try {
UserSession userSession = (UserSession)request.getSession().getAttribute(Key.USER_SESSION.name());
GeoPolicy geoPolicy = CacheManager.getGeoPolicy();
UserPolicy userPolicy = userPolicyService.getUserPolicy(userSession.getUserId());
if(userPolicy.getUserId() != null) {
geoPolicy.setInitLatitude(userPolicy.getInitLatitude());
geoPolicy.setInitLongitude(userPolicy.getInitLongitude());
geoPolicy.setInitAltitude(userPolicy.getInitAltitude());
geoPolicy.setInitDuration(userPolicy.getInitDuration());
geoPolicy.setInitDefaultFov(userPolicy.getInitDefaultFov());
geoPolicy.setLod0(userPolicy.getLod0());
geoPolicy.setLod1(userPolicy.getLod1());
geoPolicy.setLod2(userPolicy.getLod2());
geoPolicy.setLod3(userPolicy.getLod3());
geoPolicy.setLod4(userPolicy.getLod4());
geoPolicy.setLod5(userPolicy.getLod5());
geoPolicy.setSsaoRadius(userPolicy.getSsaoRadius());
}
List<LayerGroup> baseLayers = LayerDisplaySupport.getListDisplayLayer(layerGroupService.getListLayerGroupAndLayer(), userPolicy.getBaseLayers());
result.put("geoPolicy", geoPolicy);
result.put("baseLayers", baseLayers);
} catch(Exception e) {
e.printStackTrace();
statusCode = HttpStatus.INTERNAL_SERVER_ERROR.value();
errorCode = "db.exception";
message = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
}

result.put("statusCode", statusCode);
result.put("errorCode", errorCode);
result.put("message", message);

return result;
}
}
38 changes: 31 additions & 7 deletions ndtp-user/src/main/webapp/WEB-INF/views/data/map.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,18 @@
//Cesium.Ion.defaultAccessToken = '';
//var viewer = new Cesium.Viewer('magoContainer');
var MAGO3D_INSTANCE;
// ndtp 전역 네임스페이스
var NDTP = NDTP || {
policy : ${geoPolicyJson},
policy : {},
dataGroup : {},
baseLayers : ${baseLayerJson}
baseLayers : {}
};
magoInit();
initPolicy(function(){
magoInit();
});
function magoInit() {
var geoPolicyJson = ${geoPolicyJson};
var geoPolicyJson = NDTP.policy;
var cesiumViewerOption = {};
cesiumViewerOption.infoBox = false;
Expand All @@ -218,7 +220,7 @@
function magoLoadEnd(e) {
var magoInstance = e;
var geoPolicyJson = ${geoPolicyJson};
var geoPolicyJson = NDTP.policy;
var viewer = magoInstance.getViewer();
var magoManager = magoInstance.getMagoManager();
var f4dController = magoInstance.getF4dController();
Expand Down Expand Up @@ -250,7 +252,7 @@
CivilVoice(magoInstance);
// 기본 레이어 랜더링
setTimeout(function(){
NDTP.map = new mapInit(magoInstance, ${baseLayerJson}, ${geoPolicyJson});
NDTP.map = new mapInit(magoInstance, NDTP.baseLayers, geoPolicyJson);
NDTP.map.initLayer();
}, geoPolicyJson.initDuration * 1000);
Expand Down Expand Up @@ -846,6 +848,28 @@
}
}
// init policy
function initPolicy(callback) {
$.ajax({
url: "/policy/",
type: "GET",
headers: {"X-Requested-With": "XMLHttpRequest"},
dataType: "json",
success: function(msg){
if(msg.statusCode <= 200) {
NDTP.policy = msg.geoPolicy;
NDTP.baseLayers = msg.baseLayers;
callback();
} else {
alert(JS_MESSAGE[msg.errorCode]);
}
},
error:function(request,status,error){
alert(JS_MESSAGE["ajax.error.message"]);
}
});
}
function validate() {
if ($("#issueTitle").val() === "") {
alert("제목을 입력하여 주십시오.");
Expand Down

0 comments on commit 1f9c647

Please sign in to comment.