• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geosolutions-it / MapStore2 / 19933858499

04 Dec 2025 01:54PM UTC coverage: 76.636% (-0.03%) from 76.661%
19933858499

Pull #11648

github

web-flow
Update User Guide - Itinerary plugin (#11768)

* add_11664

* Update docs/user-guide/itinerary.md

Co-authored-by: Suren <dsuren1@gmail.com>

* Update docs/user-guide/itinerary.md

Co-authored-by: Suren <dsuren1@gmail.com>

* Update docs/user-guide/itinerary.md

Co-authored-by: Suren <dsuren1@gmail.com>

* Update docs/user-guide/itinerary.md

Co-authored-by: Suren <dsuren1@gmail.com>

---------

Co-authored-by: Suren <dsuren1@gmail.com>
Pull Request #11648: #11644: Implement dynamic request configurations

32316 of 50296 branches covered (64.25%)

132 of 155 new or added lines in 40 files covered. (85.16%)

283 existing lines in 32 files now uncovered.

40207 of 52465 relevant lines covered (76.64%)

37.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.44
/web/client/utils/SecurityUtils.js
1
/**
2
import { keys } from 'lodash';
3
 * Copyright 2016, GeoSolutions Sas.
4
 * All rights reserved.
5
 *
6
 * This source code is licensed under the BSD-style license found in the
7
 * LICENSE file in the root directory of this source tree.
8
 */
9

10
import ConfigUtils from "./ConfigUtils";
11
import URL from "url";
12
import head from "lodash/head";
13
import isNil from "lodash/isNil";
14
import isArray from "lodash/isArray";
15
import isEmpty from "lodash/isEmpty";
16

17
import {setStore as stateSetStore, getState} from "./StateUtils";
18

19
export const USER_GROUP_ALL = 'everyone';
1✔
20

21
export function getCredentials(id) {
22
    const securityStorage = JSON.parse(sessionStorage.getItem('credentialStorage') ?? "{}");
367✔
23
    return securityStorage[id] || {};
367✔
24
}
25
export function setCredentials(id, credentials) {
26
    const securityStorage = JSON.parse(sessionStorage.getItem('credentialStorage') ?? "{}");
26✔
27
    sessionStorage.setItem('credentialStorage', JSON.stringify(Object.assign({}, securityStorage, {[id]: credentials})));
26✔
28
}
29
/**
30
 * Stores the logged user security information.
31
 */
32
export function setStore(store) {
33
    stateSetStore(store);
10✔
34
}
35

36
/**
37
 * Gets security state form the store.
38
 */
39
export function getSecurityInfo() {
40
    return getState().security || {};
386✔
41
}
42

43
/**
44
 * Returns the current user or undefined if not available.
45
 */
46
export function getUser() {
47
    return getSecurityInfo()?.user;
12✔
48
}
49

50
/**
51
 * Returns the current user basic authentication header value.
52
 */
53
export function getBasicAuthHeader() {
54
    return getSecurityInfo()?.authHeader;
3✔
55
}
56

57
/**
58
 * Returns the current user access token value.
59
 */
60
export function getToken() {
61
    return getSecurityInfo()?.token;
353✔
62
}
63

64
/**
65
 * Returns the current user refresh token value.
66
 * The refresh token is used to get a new access token.
67
 */
68
export function getRefreshToken() {
69
    return getSecurityInfo()?.refresh_token;
18✔
70
}
71

72
/**
73
 * Return the user attributes as an array. If the user is undefined or
74
 * doesn't have any attributes an empty array is returned.
75
 */
76
export function getUserAttributes(providedUser) {
77
    const user = providedUser || getUser();
40✔
78
    if (!user || !user.attribute) {
40✔
79
        // not user defined or the user doesn't have any attributes
80
        return [];
28✔
81
    }
82
    const attributes = user.attribute;
12✔
83
    // if the user has only one attribute we need to put it in an array
84
    return isArray(attributes) ? attributes : [attributes];
12✔
85
}
86

87
/**
88
 * Search in the user attributes an attribute that matches the provided
89
 * attribute name. The search will not be case sensitive. Undefined is
90
 * returned if the attribute could not be found.
91
 */
92
export function findUserAttribute(attributeName) {
93
    // getting the user attributes
94
    const userAttributes = getUserAttributes();
8✔
95
    if (!userAttributes || !attributeName ) {
8!
96
        // the user as no attributes or the provided attribute name is undefined
UNCOV
97
        return null;
×
98
    }
99
    return head(userAttributes.filter(attribute => attribute.name
8✔
100
        && attribute.name.toLowerCase() === attributeName.toLowerCase()));
101
}
102

103
/**
104
 * Search in the user attributes an attribute that matches the provided
105
 * attribute name. The search will not be case sensitive. Undefined is
106
 * returned if the attribute could not be found otherwise the attribute
107
 * value is returned.
108
 */
109
export function findUserAttributeValue(attributeName) {
110
    const userAttribute = findUserAttribute(attributeName);
4✔
111
    return userAttribute?.value;
4✔
112
}
113

114
/**
115
 * Returns an array with the configured authentication rules. If no rules
116
 * were configured an empty array is returned.
117
 */
118
export function getAuthenticationRules() {
119
    return ConfigUtils.getConfigProp('authenticationRules') || [];
1,353✔
120
}
121

122
/**
123
 * Checks if authentication is activated or not.
124
 */
125
export function isAuthenticationActivated() {
126
    return ConfigUtils.getConfigProp('useAuthenticationRules') || false;
1,434✔
127
}
128

129
/**
130
 * Returns the authentication method that should be used for the provided URL.
131
 * We go through the authentication rules and find the first one that matches
132
 * the provided URL, if no rule matches the provided URL undefined is returned.
133
 */
134
export function getAuthenticationMethod(url) {
135
    const foundRule = head(getAuthenticationRules().filter(
324✔
136
        rule => rule && rule.urlPattern && url.match(new RegExp(rule.urlPattern, "i"))));
569✔
137
    return foundRule?.method;
324✔
138
}
139

140
/**
141
 * Returns the authentication rule that should be used for the provided URL.
142
 * We go through the authentication rules and find the first one that matches
143
 * the provided URL, if no rule matches the provided URL undefined is returned.
144
 */
145
export function getAuthenticationRule(url) {
146
    return head(getAuthenticationRules().filter(
1,027✔
147
        rule => rule && rule.urlPattern && url.match(new RegExp(rule.urlPattern, "i"))));
1,476✔
148
}
149

150
export function getAuthKeyParameter(url) {
151
    const foundRule = getAuthenticationRule(url);
501✔
152
    return foundRule?.authkeyParamName ?? 'authkey';
501✔
153
}
154

155
export function getAuthenticationHeaders(url, securityToken, security) {
156
    if (!url || !isAuthenticationActivated()) {
124✔
157
        return null;
35✔
158
    }
159
    const storedProtectedService = getCredentials(security?.sourceId);
89✔
160
    if (security && storedProtectedService) {
89✔
161
        return {
4✔
162
            "Authorization": `Basic ${btoa(storedProtectedService.username + ":" + storedProtectedService.password)}`
163
        };
164
    }
165
    switch (getAuthenticationMethod(url)) {
85✔
166
    case 'bearer': {
167
        const token = !isNil(securityToken) ? securityToken : getToken();
3!
168
        if (!token) {
3!
NEW
169
            return null;
×
170
        }
171
        return {
3✔
172
            "Authorization": `Bearer ${token}`
173
        };
174
    }
175
    case 'header': {
176
        const rule = getAuthenticationRule(url);
1✔
177
        return rule.headers;
1✔
178
    }
179
    default:
180
        // we cannot handle the required authentication method
181
        return null;
81✔
182
    }
183
}
184

185
/**
186
 * This method will add query parameter based authentications to an object
187
 * containing query parameters.
188
 */
189
export function addAuthenticationParameter(url, parameters, securityToken) {
190
    if (!url || !isAuthenticationActivated()) {
285✔
191
        return parameters;
86✔
192
    }
193
    switch (getAuthenticationMethod(url)) {
199✔
194
    case 'authkey': {
195
        const token = !isNil(securityToken) ? securityToken : getToken();
165✔
196
        if (!token) {
165✔
197
            return parameters;
12✔
198
        }
199
        const authParam = getAuthKeyParameter(url);
153✔
200
        return Object.assign(parameters || {}, {[authParam]: token});
153✔
201
    }
202
    case 'test': {
203
        const rule = getAuthenticationRule(url);
1✔
204
        const token = rule ? rule.token : "";
1!
205
        const authParam = getAuthKeyParameter(url);
1✔
206
        return Object.assign(parameters || {}, { [authParam]: token });
1!
207
    }
208
    default:
209
        // we cannot handle the required authentication method
210
        return parameters;
33✔
211
    }
212
}
213

214
/**
215
 * This method will add query parameter based authentications to an url.
216
 */
217
export function addAuthenticationToUrl(url) {
218
    if (!url || !isAuthenticationActivated()) {
5✔
219
        return url;
1✔
220
    }
221
    const parsedUrl = URL.parse(url, true);
4✔
222
    parsedUrl.query = addAuthenticationParameter(url, parsedUrl.query);
4✔
223
    // we need to remove this to force the use of query
224
    delete parsedUrl.search;
4✔
225
    return URL.format(parsedUrl);
4✔
226
}
227

228
export function clearNilValuesForParams(params = {}) {
68✔
229
    return Object.keys(params).reduce((pre, cur) => {
71✔
230
        return !isNil(params[cur]) ? {...pre, [cur]: params[cur]} : pre;
5✔
231
    }, {});
232
}
233

234
export function addAuthenticationToSLD(layerParams, options) {
235
    if (layerParams.SLD) {
234✔
236
        const parsed = URL.parse(layerParams.SLD, true);
2✔
237
        const params = addAuthenticationParameter(layerParams.SLD, parsed.query, options.securityToken);
2✔
238
        return Object.assign({}, layerParams, {
2✔
239
            SLD: URL.format(Object.assign({}, parsed, {
240
                query: params,
241
                search: undefined
242
            }))
243
        });
244
    }
245
    return layerParams;
232✔
246
}
247

248
export function cleanAuthParamsFromURL(url) {
249
    return ConfigUtils.filterUrlParams(url, [getAuthKeyParameter(url)].filter(p => p));
344✔
250
}
251

252
/**
253
 * it creates the headers function for axios config, if it finds a reference in sessionStorage
254
 * @param {string} protectedId the id of the protected service to look for in sessionStorage
255
 * @returns {object} the headers Basic
256
 */
257
export const getAuthorizationBasic = (protectedId) => {
1✔
258
    let headers = {};
215✔
259
    const storedProtectedService = getCredentials(protectedId);
215✔
260
    if (!isEmpty(storedProtectedService)) {
215✔
261
        headers = {
1✔
262
            Authorization: `Basic ${btoa(storedProtectedService.username + ":" + storedProtectedService.password)}`
263
        };
264
    }
265
    return headers;
215✔
266
};
267

268
/**
269
 * This utility class will get information about the current logged user directly from the store.
270
 */
271
const SecurityUtils = {
1✔
272
    getAuthorizationBasic,
273
    getCredentials,
274
    setCredentials,
275
    setStore,
276
    getSecurityInfo,
277
    getUser,
278
    getBasicAuthHeader,
279
    getToken,
280
    getRefreshToken,
281
    getUserAttributes,
282
    findUserAttribute,
283
    findUserAttributeValue,
284
    getAuthenticationRules,
285
    isAuthenticationActivated,
286
    getAuthenticationMethod,
287
    getAuthenticationRule,
288
    addAuthenticationToUrl,
289
    addAuthenticationParameter,
290
    clearNilValuesForParams,
291
    addAuthenticationToSLD,
292
    getAuthKeyParameter,
293
    cleanAuthParamsFromURL,
294
    getAuthenticationHeaders,
295
    USER_GROUP_ALL
296
};
297

298
export default SecurityUtils;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc