-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathacs.jag
73 lines (57 loc) · 2.69 KB
/
acs.jag
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
<%
(function () {
var log = new Log(),
configs = require('/config.json'),
samlResponse = request.getParameter('SAMLResponse'),
sessionId = session.getId(),
process = require('process'),
samlRequest = request.getParameter('SAMLRequest'),
relayState = request.getParameter('RelayState'),
sso = require('sso'),
samlRespObj,
keyStoreProps = {
KEY_STORE_NAME: process.getProperty('carbon.home') + configs.ssoConfiguration.keyStoreName,
KEY_STORE_PASSWORD: configs.ssoConfiguration.keyStorePassword,
IDP_ALIAS: configs.ssoConfiguration.identityAlias
},
sso_sessions = application.get('sso_sessions');
if (!sso_sessions) {
application.put('sso_sessions', {});
sso_sessions = application.get('sso_sessions');
}
if (samlResponse != null) {
samlRespObj = sso.client.getSamlObject(samlResponse);
if (!sso.client.isLogoutResponse(samlRespObj)) {
// validating the signature
if (configs.ssoConfiguration.responseSigningEnabled) {
if (sso.client.validateSignature(samlRespObj, keyStoreProps)) {
var sessionObj = sso.client.decodeSAMLLoginResponse(samlRespObj, samlResponse, sessionId);
log.info(stringify(sessionObj));
if (sessionObj.sessionIndex != null || sessionObj.sessionIndex != 'undefined') {
session.put("LOGGED_IN_USER", sessionObj.loggedInUser);
session.put("Loged", "true");
sso_sessions[sso_sessions[sessionObj.sessionIndex] = sessionObj.sessionId] = sessionObj.sessionIndex;
var user = require('/modules/user.js');
if (user.loginWithSAML(sessionObj.loggedInUser)) {
log.info('user is set :::' + sessionObj.loggedInUser);
response.sendRedirect('/mdm-dashboard');
}
}
}
}
} else {
session.invalidate();
response.sendRedirect('/mdm-dashboard');
}
}
// if saml request is a log out request, then invalidate session.
if (samlRequest != null) {
var index = sso.client.decodeSAMLLogoutRequest(sso.client.getSamlObject(samlRequest));
log.info('BACKEND LOGOUT RECIEVED FROM STORE THE INDEX IS ######' + index);
var jSessionId = application.get('sso_sessions')[index];
delete application.get('sso_sessions')[index];
log.info('store Session Id :::' + jSessionId);
session.invalidate();
}
}());
%>