<%

include("util/constants.jag");
var commonUtil = require("/util/utility.jag");

commonUtil.setServerURL();

var samlConfig = application.get(SAML_PROPERTIES);
var sso = require("sso");
var sessionId = session.getId();
var encodedSAMLRequest;
var postUrl = samlConfig['SAML.IdPUrl'];
var issuer = samlConfig['SAML.IssuerID'];


if(request.getParameter("login") === 'true'){
	encodedSAMLRequest = sso.client.getEncodedSAMLAuthRequest(issuer);
	
}else if(request.getParameter("logout") === 'true'){
	var user = session.get(LOGGED_IN_USER);
    sso_sessions = application.get('sso_sessions'),
    encodedSAMLRequest = sso.client.getEncodedSAMLLogoutRequest(user, sso_sessions[sessionId], issuer);
}

%>


<!DOCTYPE html>
<!--[if lt IE 7]>
<html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>
<html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>
<html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js"> <!--<![endif]-->
<head>

</head>
<body>

<div>

<p>You are now being redirected to Identity Server. If the
redirection fails, please click on the button below.</p>
<form method="POST" action="<%=postUrl%>">
<p>
   <input type="hidden" name="SAMLRequest" value="<%= encodedSAMLRequest %>"/>
   <input type="hidden" name="SSOAuthSessionID" value="<%= sessionId %>"/>
   <button type="submit">Redirect manually</button>
</p>
</form>
</div>
<script type = "text/javascript" >
	document.forms[0].submit();
</script>

</body>
</html>
