<%@page import="oneit.utils.*,oneit.logging.*"%>
<%@page import="oneit.security.*, oneit.servlets.security.SessionSecUserDecorator"%>
<%@page import="java.util.Date"%>
<%@page import="oneit.objstore.services.TransactionServicesFactory"%>
<%@page import="performa.sso.*, oneit.objstore.*, oneit.appservices.config.*" %>

<%
    SecUser pageUser    = (SecUser)(session.getAttribute(SecUser.SEC_USER_ID));
    String  userName    = request.getParameter("userName");

    if (userName != null)
    {
        TransactionServicesFactory  tsf     = (TransactionServicesFactory)ConfigMgr.getConfigObject(ConfigMgr.GLOBAL_CONFIG_SYSTEM, "TransactionServices");
        ObjectTransaction           objTran = new ObjectTransaction (tsf);

        try
        {
            ClientAuthToken   authToken = new ClientAuthToken(userName, objTran);
            
            if(authToken.isAuthorised(null))
            {
                request.getSession().invalidate();
                request.getSession().setAttribute (AuthorisationToken.AUTH_TOKEN_ID, authToken);

                request.getSession ().setAttribute (SecUser.SEC_USER_ID, authToken.getLoggedInClient());

                // This is only to help with the tomcat manager, so you can see which user belongs to which session
                request.getSession ().setAttribute (SecUser.SEC_USER_ID+".desc", authToken.getDescription());
                request.getSession ().setAttribute (SecUser.SEC_USER_ID+".loggedin", ""+new Date());
                request.getSession ().setAttribute (SessionSecUserDecorator.REFRESH_SECURITY, Boolean.TRUE);

                objTran.commit();
                objTran.commitResources();

                response.sendRedirect("AdminPortal-Home.htm");
            }
        }
        finally
        {
            objTran.releaseResources();
        }        
    }
    
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
    </head>
    <body>
        <form method="POST">
            <input name="userName" value="">
            <input type="submit" name="Go" value="Submit">
        </form>
    </body>
</html>
