class LoginProcess {

    public void cleanup() {

        if (isFailed()) {
            // Always destroy the (new) failed session
            DEBUG.message("Authentication failed - destroying new session");
            authContext.destroySession();

            if (authContext.isSessionUpgrade()) {
                DEBUG.message("Session upgrade failed - restoring original session");
                authContext.restoreOldSession();
            } else {
                // Destroy any existing session too
                authContext.destroyOldSession();
            }

        } else if (isSuccessful()) {

            if (authContext.isForceAuth()) {
                DEBUG.message("Force Auth succeeded - restoring updated session.");
                authContext.destroySession();
                authContext.restoreOldSession();

            } else if (authContext.hasOldSession()
                    && SystemProperties.getAsBoolean(Constants.DESTROY_SESSION_AFTER_UPGRADE)) {
                DEBUG.message("Session upgrade succeeded - destroying old session");
                authContext.destroyOldSession();
            }

        }
    }

    public  LoginProcess(LoginAuthenticator loginAuthenticator, LoginConfiguration loginConfiguration,
            AuthenticationContext authContext, CoreServicesWrapper coreServicesWrapper);

}