This is an automated email from the ASF dual-hosted git repository.

harikrishna pushed a commit to branch 2FA
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/2FA by this push:
     new 5f1112b483e Added 2fa info to login response
5f1112b483e is described below

commit 5f1112b483ea7f018f19826830872632a643202c
Author: Harikrishna Patnala <[email protected]>
AuthorDate: Sat Oct 29 05:34:45 2022 +0530

    Added 2fa info to login response
---
 .../main/java/org/apache/cloudstack/api/ApiConstants.java    |  1 +
 .../org/apache/cloudstack/api/response/LoginCmdResponse.java | 12 ++++++++++++
 server/src/main/java/com/cloud/api/ApiServer.java            |  7 +++++--
 server/src/main/java/com/cloud/api/ApiServlet.java           |  4 ++--
 4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java 
b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
index 2485ea4abe7..786b0ddbbad 100644
--- a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
@@ -228,6 +228,7 @@ public class ApiConstants {
     public static final String IP6_ADDRESS = "ip6address";
     public static final String IP_ADDRESS_ID = "ipaddressid";
     public static final String IS_2FA_ENABLED = "is2faenabled";
+    public static final String IS_2FA_VERIFIED = "is2faverified";
 
     public static final String IS_ASYNC = "isasync";
     public static final String IP_AVAILABLE = "ipavailable";
diff --git 
a/api/src/main/java/org/apache/cloudstack/api/response/LoginCmdResponse.java 
b/api/src/main/java/org/apache/cloudstack/api/response/LoginCmdResponse.java
index baba7ba805f..94cf380cb05 100644
--- a/api/src/main/java/org/apache/cloudstack/api/response/LoginCmdResponse.java
+++ b/api/src/main/java/org/apache/cloudstack/api/response/LoginCmdResponse.java
@@ -74,6 +74,10 @@ public class LoginCmdResponse extends 
AuthenticationCmdResponse {
     @Param(description = "Is two factor authentication enabled")
     private String is2FAenabled;
 
+    @SerializedName(value = ApiConstants.IS_2FA_VERIFIED)
+    @Param(description = "Is two factor authentication verified")
+    private String is2FAverified;
+
     public String getUsername() {
         return username;
     }
@@ -175,4 +179,12 @@ public class LoginCmdResponse extends 
AuthenticationCmdResponse {
     public void set2FAenabled(String is2FAenabled) {
         this.is2FAenabled = is2FAenabled;
     }
+
+    public String Is2FAverfied() {
+        return is2FAverified;
+    }
+
+    public void set2FAverfied(String is2FAverified) {
+        this.is2FAverified = is2FAverified;
+    }
 }
diff --git a/server/src/main/java/com/cloud/api/ApiServer.java 
b/server/src/main/java/com/cloud/api/ApiServer.java
index 4f0fbb969e8..2979639aabe 100644
--- a/server/src/main/java/com/cloud/api/ApiServer.java
+++ b/server/src/main/java/com/cloud/api/ApiServer.java
@@ -1072,6 +1072,9 @@ public class ApiServer extends ManagerBase implements 
HttpRequestHandler, ApiSer
                 if (ApiConstants.IS_2FA_ENABLED.equalsIgnoreCase(attrName)) {
                     response.set2FAenabled(attrObj.toString());
                 }
+                if (ApiConstants.IS_2FA_VERIFIED.equalsIgnoreCase(attrName)) {
+                    response.set2FAverfied(attrObj.toString());
+                }
             }
         }
         response.setResponseName("loginresponse");
@@ -1135,8 +1138,8 @@ public class ApiServer extends ManagerBase implements 
HttpRequestHandler, ApiSer
                 session.setAttribute("timezoneoffset", 
Float.valueOf(offsetInHrs).toString());
             }
 
-            session.setAttribute("2FAenabled", 
Boolean.toString(userAcct.isTwoFactorAuthenticationEnabled()));
-            session.setAttribute("2FAverified", false);
+            session.setAttribute(ApiConstants.IS_2FA_ENABLED, 
Boolean.toString(userAcct.isTwoFactorAuthenticationEnabled()));
+            session.setAttribute(ApiConstants.IS_2FA_VERIFIED, false);
 
             // (bug 5483) generate a session key that the user must submit on 
every request to prevent CSRF, add that
             // to the login response so that session-based authenticators know 
to send the key back
diff --git a/server/src/main/java/com/cloud/api/ApiServlet.java 
b/server/src/main/java/com/cloud/api/ApiServlet.java
index afecfd25565..ef7407062a4 100644
--- a/server/src/main/java/com/cloud/api/ApiServlet.java
+++ b/server/src/main/java/com/cloud/api/ApiServlet.java
@@ -305,7 +305,7 @@ public class ApiServlet extends HttpServlet {
                 userId = (Long)session.getAttribute("userid");
                 UserAccount userAccount = 
accountMgr.getUserAccountById(userId);
                 boolean is2FAenabled = 
userAccount.isTwoFactorAuthenticationEnabled();
-                boolean is2FAverified = (boolean) 
session.getAttribute("2FAverified");
+                boolean is2FAverified = (boolean) 
session.getAttribute(ApiConstants.IS_2FA_VERIFIED);
                 if (is2FAenabled && !is2FAverified) {
                     APIAuthenticator apiAuthenticator = 
authManager.getAPIAuthenticator(command);
                     if ((command != null && 
!command.equals(ValidateUserTwoFactorAuthenticationCodeCmd.APINAME)) || 
apiAuthenticator == null ) {
@@ -320,7 +320,7 @@ public class ApiServlet extends HttpServlet {
                         HttpUtils.writeHttpResponse(resp, serializedResponse, 
HttpServletResponse.SC_UNAUTHORIZED, responseType, 
ApiServer.JSONcontentType.value());
                     } else {
                         String responseString = 
apiAuthenticator.authenticate(command, params, session, remoteAddress, 
responseType, auditTrailSb, req, resp);
-                        session.setAttribute("2FAverified", true);
+                        session.setAttribute(ApiConstants.IS_2FA_VERIFIED, 
true);
                         HttpUtils.writeHttpResponse(resp, responseString, 
HttpServletResponse.SC_OK, responseType, ApiServer.JSONcontentType.value());
                         return;
                     }

Reply via email to