//user credentials
Credentials creds = null;
//User Session and Session ID vars definition
UserSession userSession = null;
String sessionID = null;
String encodedSessionID = null;
//Create the credentials store
try {
this.valveConf =
ValveConfigurationInstance.getValveConfig(gsaValveConfigPath);
} catch (ValveConfigurationException e) {
logger.error("Valve Config instantiation error: " + e);
}
logger.debug("Creating the credentials store");
creds = new Credentials();
String username = null;
//Setting Valve parameters
logger.debug("Setting Valve params");
setValveParams(request);
//Protection
if ((!isKerberos) || (!isNegotiate)) {
logger.error("Configuration error: if you want to use Kerberos silent AuthN, isKerberos and isNegotiate config vars have to be set to true");
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Configuration error - Kerberos is not set properly");
return;
}
Cookie cookies[] = null;
// Retrieve cookies
cookies = request.getCookies();
// Protection: look for auth and referer cookies
if (cookies != null) {
// Look for the referer cookie
for (int i = 0; i < cookies.length; i++) {
// Look for the referer cookie
if ((cookies[i].getName()).equals(refererCookieName)) {
// Cache cookie
gsaRefererCookie = cookies[i];
logger.debug("Referer cookie already exists: " +
gsaRefererCookie.getValue());
} else {
// Look for the auth cookie
if ((cookies[i].getName()).equals(authCookieName)) {
// Cache cookie
gsaAuthCookie = cookies[i];
logger.debug("Auth cookie already exists: " +
gsaAuthCookie.getValue());
}
}
if ((gsaRefererCookie != null) && (gsaAuthCookie != null)) {
// Exit
break;
}
}
}
// Protection
if (!isSAML) {
if (gsaRefererCookie == null) {
// Raise error
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"The GSA authentication servlet couldn't read the referer cookie");
// Log error
logger.error("The GSA authentication servlet couldn't read the referer cookie, pls. check the cookie domain value");
// Return
return;
}
} else {
//SAML
//Get SAML Params
relayState = request.getParameter("RelayState");
samlRequest = request.getParameter("SAMLRequest");
//String relayStateCookie = valveConf.getSAMLConfig().getRelayStateCookie();
boolean noParams = false;
boolean cookieExist = true;
//Protection
if ((relayState == null) || (relayState.equals(""))) {
noParams = true;
} else {
if ((samlRequest == null) || (samlRequest.equals(""))) {
noParams = true;
}
}
createRefererCookie(gsaRefererCookie);
//if ((noParams)&&(!cookieExist)) {
if (noParams) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
"Invalid request");
return;
}
}
logger.debug("Let's validate if gsaAuthCookie is present");
if (gsaAuthCookie != null) {
if (!isSAML) {
//redirect
String redirect = gsaRefererCookie.getValue();
logger.debug("redirect is " + redirect);
//redirect only if the URL is different than the login one
if (!redirect.equals(loginUrl)) {
//user properly authenticated
logger.debug("The user was properly authenticated. Lets redirect to..." +
redirect);
// Redirect
response.sendRedirect(redirect);
} else {
logger.debug("It's the login URL. No redirect");
}
} else {
logger.debug("As this is SAML. Let's obviate the previous authentication cookie");
gsaAuthCookie = null;
}
}
userSession = new UserSession();
Sessions sessions = Sessions.getInstance();
sessions.setMaxSessionAgeMinutes(maxSessionAge);
sessions.setSessionTimeoutMinutes(sessionTimeout);