Fixing the problem of common log out

revert-70aa11f8
Megala 8 years ago
parent b10c323582
commit e5870e1306

@ -486,67 +486,74 @@ var module = {};
*/ */
module.ssoAcs = function (request, response) { module.ssoAcs = function (request, response) {
var samlResponse = request.getParameter("SAMLResponse"); var samlResponse = request.getParameter("SAMLResponse");
if (!samlResponse) { var samlRequest = request.getParameter('SAMLRequest');
var msg = "SAML response is not found in request parameters.";
log.error(msg);
response.sendError(400, msg);
return;
}
var ssoClient = require("sso").client; var ssoClient = require("sso").client;
var samlResponseObj; var samlResponseObj;
try {
samlResponseObj = ssoClient.getSamlObject(samlResponse); if (samlResponse) {
} catch (e) { try {
log.error(e.message, e); samlResponseObj = ssoClient.getSamlObject(samlResponse);
response.sendError(500, e.message); } catch (e) {
return; log.error(e.message, e);
} response.sendError(500, e.message);
if (ssoClient.isLogoutResponse(samlResponseObj)) { return;
// This is a logout response. }
module.logout(response); if (ssoClient.isLogoutResponse(samlResponseObj)) {
} else { // This is a logout response.
// This is a login response. module.logout(response);
var ssoConfigs = getSsoConfigurations(); } else {
var rsEnabled = ssoConfigs[constants.APP_CONF_AUTH_MODULE_SSO_RESPONSE_SIGNING_ENABLED]; // This is a login response.
if (utils.parseBoolean(rsEnabled)) { var ssoConfigs = getSsoConfigurations();
var CarbonUtils = Packages.org.wso2.carbon.utils.CarbonUtils; var rsEnabled = ssoConfigs[constants.APP_CONF_AUTH_MODULE_SSO_RESPONSE_SIGNING_ENABLED];
var keyStorePassword = CarbonUtils.getServerConfiguration().getFirstProperty("Security.TrustStore.Password"); if (utils.parseBoolean(rsEnabled)) {
var keyStoreName = CarbonUtils.getServerConfiguration().getFirstProperty("Security.TrustStore.Location"); var CarbonUtils = Packages.org.wso2.carbon.utils.CarbonUtils;
var identityAlias = ssoConfigs[constants.APP_CONF_AUTH_MODULE_SSO_IDENTITY_ALIAS]; var keyStorePassword = CarbonUtils.getServerConfiguration().getFirstProperty("Security.TrustStore.Password");
var keyStoreParams = { var keyStoreName = CarbonUtils.getServerConfiguration().getFirstProperty("Security.TrustStore.Location");
KEY_STORE_NAME: keyStoreName, var identityAlias = ssoConfigs[constants.APP_CONF_AUTH_MODULE_SSO_IDENTITY_ALIAS];
KEY_STORE_PASSWORD: keyStorePassword, var keyStoreParams = {
IDP_ALIAS: identityAlias, KEY_STORE_NAME: keyStoreName,
USE_ST_KEY: !ssoConfigs[constants.APP_CONF_AUTH_MODULE_SSO_USE_ST_KEY] KEY_STORE_PASSWORD: keyStorePassword,
}; IDP_ALIAS: identityAlias,
if (!ssoClient.validateSignature(samlResponseObj, keyStoreParams)) { USE_ST_KEY: !ssoConfigs[constants.APP_CONF_AUTH_MODULE_SSO_USE_ST_KEY]
var msg = "Invalid signature found in the SAML response."; };
if (!ssoClient.validateSignature(samlResponseObj, keyStoreParams)) {
var msg = "Invalid signature found in the SAML response.";
log.error(msg);
response.sendError(500, msg);
return;
}
}
/**
* @type {{sessionId: string, loggedInUser: string, sessionIndex: string, samlToken:
* string}}
*/
var ssoSession = ssoClient.decodeSAMLLoginResponse(samlResponseObj, samlResponse,
session.getId());
if (ssoSession.sessionId) {
var ssoSessions = getSsoSessions();
ssoSessions[ssoSession.sessionId] = ssoSession;
if (ssoSessions.sessionIndex != null || ssoSessions.sessionIndex != 'undefined') {
module.loadTenant(ssoSessions.loggedInUser);
var carbonUser = (require("carbon")).server.tenantUser(ssoSession.loggedInUser);
utils.setCurrentUser(carbonUser.username, carbonUser.domain, carbonUser.tenantId);
var scriptArgument = {input: {samlToken: ssoSession.samlToken}, user: module.getCurrentUser()};
handleEvent(OPERATION_LOGIN, EVENT_SUCCESS, scriptArgument);
}
} else {
var msg = "Cannot decode SAML login response.";
log.error(msg); log.error(msg);
response.sendError(500, msg); response.sendError(500, msg);
return;
} }
} }
/** }
* @type {{sessionId: string, loggedInUser: string, sessionIndex: string, samlToken: if (samlRequest) {
* string}} var index = ssoClient.decodeSAMLLogoutRequest(ssoClient.getSamlObject(samlRequest));
*/ if (log.isDebugEnabled()) {
var ssoSession = ssoClient.decodeSAMLLoginResponse(samlResponseObj, samlResponse, log.debug("Back end log out request received for the session Id : " + index);
session.getId());
if (ssoSession.sessionId) {
var ssoSessions = getSsoSessions();
ssoSessions[ssoSession.sessionId] = ssoSession;
if (ssoSessions.sessionIndex != null || ssoSessions.sessionIndex != 'undefined') {
module.loadTenant(ssoSessions.loggedInUser);
var carbonUser = (require("carbon")).server.tenantUser(ssoSession.loggedInUser);
utils.setCurrentUser(carbonUser.username, carbonUser.domain, carbonUser.tenantId);
var scriptArgument = {input: {samlToken: ssoSession.samlToken}, user: module.getCurrentUser()};
handleEvent(OPERATION_LOGIN, EVENT_SUCCESS, scriptArgument);
}
} else {
var msg = "Cannot decode SAML login response.";
log.error(msg);
response.sendError(500, msg);
} }
var jSessionId = getSsoSessions()[index];
delete getSsoSessions()[index];
session.invalidate();
} }
}; };

Loading…
Cancel
Save