浏览代码

Merge pull request #10343 from wangkx/login_to_home

HPCC-18184 Redirect login page to home page for existing session

Reviewed-By: Russ Whitehead <william.whitehead@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 7 年之前
父节点
当前提交
e0216f7b45
共有 1 个文件被更改,包括 13 次插入4 次删除
  1. 13 4
      esp/bindings/http/platform/httpservice.cpp

+ 13 - 4
esp/bindings/http/platform/httpservice.cpp

@@ -911,7 +911,6 @@ EspAuthState CEspHttpServer::checkUserAuth()
     //The preCheckAuth() does not return authUnknown when:
     //No authentication is required for the ESP binding;
     //Or no authentication is required for certain situations of not rootAuthRequired();
-    //Or a user is trying to access some resources for displaying login/logout pages;
     //Or this is a user request for updating password.
     EspAuthState authState = preCheckAuth(authReq);
     if (authState != authUnknown)
@@ -1041,9 +1040,6 @@ EspAuthState CEspHttpServer::preCheckAuth(EspAuthRequest& authReq)
     }
 #endif
 
-    if ((authReq.authBinding->getDomainAuthType() != AuthPerRequestOnly) && authReq.authBinding->isDomainAuthResources(authReq.httpPath.str()))
-        return authSucceeded;//Give the permission to send out some pages used for login or logout.
-
     return authUnknown;
 }
 
@@ -1105,6 +1101,9 @@ EspAuthState CEspHttpServer::checkUserAuthPerSession(EspAuthRequest& authReq)
     if (sessionID > 0)
         return authExistingSession(authReq, sessionID);//Check session based authentication using this session ID.
 
+    if ((authReq.authBinding->getDomainAuthType() != AuthPerRequestOnly) && authReq.authBinding->isDomainAuthResources(authReq.httpPath.str()))
+        return authSucceeded;//Give the permission to send out some pages used for login or logout.
+
     StringBuffer urlCookie;
     readCookie(SESSION_START_URL_COOKIE, urlCookie);
     if (strieq(authReq.httpPath.str(), authReq.authBinding->queryLoginURL()))
@@ -1292,6 +1291,14 @@ EspAuthState CEspHttpServer::authExistingSession(EspAuthRequest& authReq, unsign
 {
     ESPLOG(LogMax, "authExistingSession: %s<%u>", PropSessionID, sessionID);
 
+    bool getLoginPage = false;
+    if (authReq.authBinding->isDomainAuthResources(authReq.httpPath.str()))
+    {
+        if (!strieq(authReq.httpPath.str(), authReq.authBinding->queryLoginURL()))
+            return authSucceeded;//Give the permission to send out some unrestricted resource pages.
+        getLoginPage = true;
+    }
+
     Owned<IRemoteConnection> conn = getSDSConnection(authReq.authBinding->queryESPSessionSDSPath(), RTM_LOCK_WRITE, SESSION_SDS_LOCK_TIMEOUT);
     IPropertyTree* espSessions = conn->queryRoot();
     if (authReq.authBinding->getSessionTimeoutSeconds() >= 0)
@@ -1365,6 +1372,8 @@ EspAuthState CEspHttpServer::authExistingSession(EspAuthRequest& authReq, unsign
         ///authReq.ctx->setAuthorized(true);
         VStringBuffer sessionIDStr("%u", sessionID);
         addCookie(authReq.authBinding->querySessionIDCookieName(), sessionIDStr.str(), authReq.authBinding->getSessionTimeoutSeconds());
+        if (getLoginPage)
+            m_response->redirect(*m_request, "/");
     }
 
     return authSucceeded;