forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCredential.js
More file actions
95 lines (83 loc) · 3.81 KB
/
Credential.js
File metadata and controls
95 lines (83 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
* This program are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
import {SuperMap} from '../SuperMap';
/**
* @class SuperMap.Credential
* @category Security
* @classdesc SuperMap 的安全证书类,其中包括 token 等安全验证信息。</br>
* 需要使用用户名和密码在:"http://localhost:8090/iserver/services/security/tokens" 下申请 value。</br>
* 获得形如:"2OMwGmcNlrP2ixqv1Mk4BuQMybOGfLOrljruX6VcYMDQKc58Sl9nMHsqQaqeBx44jRvKSjkmpZKK1L596y7skQ.." 的 value。</br>
* 目前支持的功能包括:地图服务、专题图、量算、查询、公交换乘、空间分析、网络分析,不支持轮询功能。</br>
* @param {string} value - 访问受安全限制的服务时用于通过安全认证的验证信息。
* @param {string} [name='token'] - 验证信息前缀,name=value 部分的 name 部分。
* @example
* var pixcel = new SuperMap.Credential("valueString","token");
* pixcel.destroy();
*/
export class Credential {
constructor(value, name) {
/**
* @member {string} SuperMap.Bounds.prototype.value
* @description 访问受安全限制的服务时用于通过安全认证的验证信息。
*/
this.value = value ? value : "";
/**
* @member {string} [SuperMap.Bounds.prototype.name='token']
* @description 验证信息前缀,name=value 部分的 name 部分。
*/
this.name = name ? name : "token";
this.CLASS_NAME = "SuperMap.Credential";
}
/**
* @function SuperMap.Credential.prototype.getUrlParameters
* @example
* var credential = new SuperMap.Credential("valueString","token");
* //这里 str = "token=valueString";
* var str = credential.getUrlParameters();
* @returns {string} 返回安全信息组成的 url 片段。
*/
getUrlParameters() {
//当需要其他安全信息的时候,则需要return this.name + "=" + this.value + "&" + "...";的形式添加。
return this.name + "=" + this.value;
}
/**
* @function SuperMap.Bounds.prototype.getValue
* @description 获取 value。
* @example
* var credential = new SuperMap.Credential("2OMwGmcNlrP2ixqv1Mk4BuQMybOGfLOrljruX6VcYMDQKc58Sl9nMHsqQaqeBx44jRvKSjkmpZKK1L596y7skQ..","token");
* //这里 str = "2OMwGmcNlrP2ixqv1Mk4BuQMybOGfLOrljruX6VcYMDQKc58Sl9nMHsqQaqeBx44jRvKSjkmpZKK1L596y7skQ..";
* var str = credential.getValue();
* @returns {string} 返回 value 字符串,在 iServer 服务下该 value 值即为 token 值。
*/
getValue() {
return this.value;
}
/**
*
* @function SuperMap.Credential.prototype.destroy
* @description 销毁此对象。销毁后此对象的所有属性为 null,而不是初始值。
* @example
* var credential = new SuperMap.Credential("valueString","token");
* credential.destroy();
*/
destroy() {
this.value = null;
this.name = null;
}
}
/**
* @member {SuperMap.Credential} SuperMap.Credential.CREDENTIAL
* @description 这个对象保存一个安全类的实例,在服务端需要安全验证的时候必须进行设置。
* @constant
* @example
* 代码实例:
* // 当iServer启用服务安全的时候,下边的代码是必须的。安全证书类能够接收一个value和一个name参数。
* var value = "(以iServer为例,这里是申请的token值)";
* var name = "token";
* // 默认name参数为token,所以当使用iServer服务的时候可以不进行设置。
* SuperMap.Credential.CREDENTIAL = new SuperMap.Credential(value, name);
*
*/
Credential.CREDENTIAL = null;
SuperMap.Credential = Credential;