iServerSecurity.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="UTF-8">
  8. <title data-i18n="resources.title_iServerSecurity"></title>
  9. </head>
  10. <body style=" margin: 0;overflow: auto;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  11. <div class="container">
  12. <div class="page-header">
  13. <h4 data-i18n="resources.title_iServerSecurity"></h4>
  14. </div>
  15. <div class="row">
  16. <table class="table table-bordered col-md-6">
  17. <thead>
  18. <tr>
  19. <th class="text-center" data-i18n="resources.text_function"></th>
  20. <th class="text-center" data-i18n="resources.text_instance"></th>
  21. </tr>
  22. </thead>
  23. <tbody>
  24. <!--登录-->
  25. <tr>
  26. <td class="text-center text-success" data-i18n="resources.text_login"></td>
  27. <td>
  28. <div class="col-md-10 col-md-offset-1">
  29. <form class="form-horizontal">
  30. <fieldset>
  31. <div class="form-group">
  32. <label for="loginUrl_iserver" class="col-md-2 control-label"
  33. data-i18n="resources.text_serviceAddress" style="width:26.666667%;"></label>
  34. <div class="col-md-8">
  35. <input type="text" class="form-control" id="loginUrl_iserver"
  36. data-i18n="[placeholder]resources.text_iServerAddress">
  37. </div>
  38. </div>
  39. <div class="form-group">
  40. <label for="username_login" class="col-md-2 control-label"
  41. data-i18n="resources.text_userName" style="width:26.666667%;"></label>
  42. <div class="col-md-8">
  43. <input type="text" class="form-control" id="username_login">
  44. </div>
  45. </div>
  46. <div class="form-group">
  47. <label for="password_login" class="col-md-2 control-label"
  48. data-i18n="resources.text_password" style="width:26.666667%;"></label>
  49. <div class="col-md-8">
  50. <input type="password" class="form-control" id="password_login">
  51. </div>
  52. </div>
  53. <div class="form-group">
  54. <div class="col-md-12 text-center">
  55. <a class="btn btn-success" onclick="loginiServer()"
  56. data-i18n="resources.text_login"></a>
  57. <a class="btn btn-success" onclick="logoutiServer()"
  58. data-i18n="resources.text_logout"></a>
  59. </div>
  60. </div>
  61. </fieldset>
  62. </form>
  63. </div>
  64. </td>
  65. </tr>
  66. <!--token 申请-->
  67. <tr>
  68. <td class="text-center text-success" data-i18n="resources.text_applyForToken"></td>
  69. <td>
  70. <div class="col-md-10 col-md-offset-1">
  71. <form class="form-horizontal">
  72. <fieldset>
  73. <div class="form-group">
  74. <label for="serviceUrlToken_iserver" class="col-md-2 control-label"
  75. data-i18n="resources.text_serviceAddress" style="width:26.666667%;"></label>
  76. <div class="col-md-8">
  77. <input type="text" class="form-control" id="serviceUrlToken_iserver"
  78. data-i18n="[placeholder]resources.text_iServerAddress">
  79. </div>
  80. </div>
  81. <div class="form-group">
  82. <label for="username_iserver" class="col-md-2 control-label"
  83. data-i18n="resources.text_userName" style="width:26.666667%;"></label>
  84. <div class="col-md-8">
  85. <input type="text" class="form-control" id="username_iserver">
  86. </div>
  87. </div>
  88. <div class="form-group">
  89. <label for="password_iserver" class="col-md-2 control-label"
  90. data-i18n="resources.text_password" style="width:26.666667%;"></label>
  91. <div class="col-md-8">
  92. <input type="password" class="form-control" id="password_iserver">
  93. </div>
  94. </div>
  95. <div class="form-group">
  96. <label for="clientType_iserver" class="col-md-2 control-label"
  97. data-i18n="resources.text_clientID" style="width:26.666667%;"></label>
  98. <div class="col-md-8">
  99. <select class="form-control" id="clientType_iserver" name="clientType">
  100. <option value="Referer" selected="selected">HTTP Referer</option>
  101. <option value="IP" data-i18n="resources.text_clientIP"></option>
  102. <option value="RequestIP"
  103. data-i18n="resources.text_currentRequestIP"></option>
  104. <option value="NONE" data-i18n="resources.text_noClientLimit"></option>
  105. </select>
  106. </div>
  107. </div>
  108. <div class="form-group">
  109. <label for="referer_iserver" class="col-md-2 control-label"
  110. data-i18n="resources.text_refererIPEmpty" style="width:26.666667%;"></label>
  111. <div class="col-md-8">
  112. <input class="form-control" id="referer_iserver">
  113. </div>
  114. </div>
  115. <div class="form-group">
  116. <label for="expiration_iserver" class="col-md-2 control-label"
  117. data-i18n="resources.text_termValid" style="width:26.666667%;"></label>
  118. <div class="col-md-8">
  119. <select class="form-control" id="expiration_iserver" name="expiration">
  120. <option value="60" selected="selected"
  121. data-i18n="resources.text_oneHour"></option>
  122. <option value="1440" data-i18n="resources.text_oneDay"></option>
  123. <option value="10080" data-i18n="resources.text_oneWeek"></option>
  124. <option value="43200" data-i18n="resources.text_oneMonth"></option>
  125. <option value="525600" data-i18n="resources.text_oneYear"></option>
  126. </select>
  127. </div>
  128. </div>
  129. <div class="form-group">
  130. <div class="col-md-12 text-center">
  131. <a class="btn btn-success" onclick="generateiServerToken()"
  132. data-i18n="resources.text_applyToken"></a>
  133. </div>
  134. </div>
  135. </fieldset>
  136. </form>
  137. </div>
  138. </td>
  139. </tr>
  140. <!-- 注册token -->
  141. <tr>
  142. <td class="text-center text-success" data-i18n="resources.text_tokenAuthorized"></td>
  143. <td>
  144. <div class="col-md-10 col-md-offset-1">
  145. <form class="form-horizontal">
  146. <fieldset>
  147. <div class="form-group">
  148. <label for="tokenServiceUrl_iserver" class="col-md-2 control-label"
  149. data-i18n="resources.text_serviceAddress" style="width:26.666667%;"></label>
  150. <div class="col-md-8">
  151. <input type="text" class="form-control" id="tokenServiceUrl_iserver"
  152. placeholder="http://localhost:8090/web/services/32">
  153. </div>
  154. </div>
  155. <div class="form-group">
  156. <label for="token_iserver" class="col-md-2 control-label" style="width:26.666667%;">Token</label>
  157. <div class="col-md-8">
  158. <input type="text" class="form-control" id="token_iserver">
  159. </div>
  160. </div>
  161. <div class="col-md-12 text-center">
  162. <a class="btn btn-success" onclick="registeriServerTokenAndRequestService()"
  163. data-i18n="resources.text_accessing"></a>
  164. </div>
  165. </fieldset>
  166. </form>
  167. </div>
  168. </td>
  169. </tr>
  170. <!-- 出图 -->
  171. <tr>
  172. <td class="text-center text-success" data-i18n="resources.text_tokenAuthorizedGetMap"></td>
  173. <td>
  174. <div class="col-md-10 col-md-offset-1">
  175. <form class="form-horizontal">
  176. <fieldset>
  177. <div class="form-group">
  178. <label for="serviceUrlMap_iserver" class="col-md-2 control-label"
  179. data-i18n="resources.text_serviceAddress" style="width:26.666667%;"></label>
  180. <div class="col-md-8">
  181. <input type="text" class="form-control" id="serviceUrlMap_iserver">
  182. </div>
  183. </div>
  184. <div class="form-group">
  185. <label for="mapToken_iserver" class="col-md-2 control-label" style="width:26.666667%;">Token</label>
  186. <div class="col-md-8">
  187. <input type="text" class="form-control" id="mapToken_iserver">
  188. </div>
  189. </div>
  190. <div class="form-group">
  191. <div class="col-md-12 text-center">
  192. <a class="btn btn-success" onclick="showMapWithToken()"
  193. data-i18n="resources.text_getMap"></a>
  194. </div>
  195. </div>
  196. </fieldset>
  197. </form>
  198. </div>
  199. </td>
  200. </tr>
  201. <tr>
  202. <td colspan="3">
  203. <div class="row">
  204. <div class="col-md-12 text-center">
  205. <div class="col-md-12" id="iserver_map" style=" height: 300px;"></div>
  206. </div>
  207. </div>
  208. </td>
  209. </tr>
  210. </tbody>
  211. </table>
  212. </div>
  213. </div>
  214. <script type="text/javascript" include="jquery,bootstrap,widgets.alert" src="../js/include-web.js"></script>
  215. <script type="text/javascript" src="../../dist/leaflet/include-leaflet.js"></script>
  216. <script>
  217. $(document).ready(function () {
  218. $("#loginUrl_iserver").val("http://localhost:8090/iserver");
  219. $("#serviceUrlToken_iserver").val("http://localhost:8090/iserver");
  220. $("#tokenServiceUrl_iserver").val("http://localhost:8090/iserver/services/map-china400/rest/maps/China");
  221. $("#token_iserver").val("EKqSsPg1gVJgm26RaA-o_h0hfuwS6qtn9uw-EjTqS4c10x9a0hv0h-EcTm5gct9gxqhAexDnp9LDGNTtIkAKvQ..");
  222. $("#serviceUrlMap_iserver").val("http://localhost:8090/iserver/services/map-china400/rest/maps/China");
  223. $('#mapToken_iserver').val("EKqSsPg1gVJgm26RaA-o_h0hfuwS6qtn9uw-EjTqS4c10x9a0hv0h-EcTm5gct9gxqhAexDnp9LDGNTtIkAKvQ..");
  224. });
  225. /*登录*/
  226. function loginiServer() {
  227. var loginUrl = $("#loginUrl_iserver").val();
  228. var userName = $('#username_login').val();
  229. var password = $('#password_login').val();
  230. if (!checkUrl(loginUrl)) {
  231. return;
  232. }
  233. SuperMap.SecurityManager
  234. .loginiServer(loginUrl, userName, password)
  235. .then(function (result) {
  236. console.log(JSON.stringify(result));
  237. if (result.succeed) {
  238. widgets.alert.showAlert(resources.msg_loginSuccess, true);
  239. } else {
  240. widgets.alert.showAlert(resources.msg_loginFailed, false);
  241. }
  242. });
  243. }
  244. /*登录 end*/
  245. /*登出*/
  246. function logoutiServer() {
  247. var loginUrl = $("#loginUrl_iserver").val();
  248. SuperMap.SecurityManager
  249. .logoutiServer(loginUrl)
  250. .then(function (succeed) {
  251. if (succeed) {
  252. widgets.alert.showAlert(resources.msg_logoutSuccess, true);
  253. } else {
  254. widgets.alert.showAlert(resources.msg_logoutFailed, false);
  255. }
  256. });
  257. }
  258. /*登出 end*/
  259. /*申请token*/
  260. function generateiServerToken() {
  261. var serverTokenUrl = $("#serviceUrlToken_iserver").val();
  262. if (!checkUrl(serverTokenUrl)) {
  263. return;
  264. }
  265. var serverInfo = new SuperMap.ServerInfo(SuperMap.ServerType.ISERVER, {
  266. server: serverTokenUrl
  267. });
  268. SuperMap.SecurityManager.registerServers([serverInfo]);
  269. var userName = $('#username_iserver').val();
  270. var password = $('#password_iserver').val();
  271. var clientType = $('#clientType_iserver').val();
  272. var referer = $('#referer_iserver').val();
  273. var expiration = $('#expiration_iserver').val();
  274. SuperMap.SecurityManager.generateToken(serverTokenUrl, new SuperMap.TokenServiceParameter({
  275. userName: userName,
  276. password: password,
  277. clientType: clientType,
  278. referer: referer,
  279. ip: referer,
  280. expiration: expiration
  281. })).then(function (result) {
  282. widgets.alert.showAlert(result, true);
  283. });
  284. }
  285. /*申请token end*/
  286. /*token访问服务*/
  287. function registeriServerTokenAndRequestService() {
  288. var token = $('#token_iserver').val();
  289. var serviceUrl = getiServerTokenServiceUrl();
  290. if (!checkUrl(serviceUrl)) {
  291. return;
  292. }
  293. SuperMap.SecurityManager.destroyToken(serviceUrl);
  294. //使用前要先注册token,如果为该地址注册过则不用重复注册
  295. SuperMap.SecurityManager.registerToken(serviceUrl, token);
  296. L.supermap
  297. .mapService(serviceUrl)
  298. .getMapInfo(function (json) {
  299. if (json.error) {
  300. widgets.alert.showAlert(JSON.stringify(json.error), false);
  301. } else {
  302. widgets.alert.showAlert(JSON.stringify(json.result), true);
  303. }
  304. });
  305. }
  306. function getiServerTokenServiceUrl() {
  307. return $("#tokenServiceUrl_iserver").val();
  308. }
  309. /*token访问服务 end*/
  310. /*出图*/
  311. function showMapWithToken() {
  312. var token = $('#mapToken_iserver').val();
  313. var mapUrl = $('#serviceUrlMap_iserver').val();
  314. if (!checkUrl(mapUrl)) {
  315. return;
  316. }
  317. //使用前要先注册token,如果为该地址注册过则不用重复注册
  318. SuperMap.SecurityManager.registerToken(mapUrl, token);
  319. var onlineMap = L.map('iserver_map', {
  320. center: [30, 104],
  321. maxZoom: 18,
  322. zoom: 2
  323. });
  324. L.supermap.tiledMapLayer(mapUrl).addTo(onlineMap);
  325. }
  326. /*出图 end*/
  327. function checkUrl(url) {
  328. if (url === "") {
  329. widgets.alert.showAlert(resources.msg_fillInURL, false);
  330. return false;
  331. }
  332. return true;
  333. }
  334. </script>
  335. </body>
  336. </html>