knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smol...@apache.org
Subject [knox] branch master updated: KNOX-2657 - Token generation page improvements: (#492)
Date Thu, 09 Sep 2021 07:33:56 GMT
This is an automated email from the ASF dual-hosted git repository.

smolnar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git


The following commit(s) were added to refs/heads/master by this push:
     new 4307f89  KNOX-2657 - Token generation page improvements: (#492)
4307f89 is described below

commit 4307f89f857a36d157430c31ff68f20ca8636264
Author: Sandor Molnar <smolnar@apache.org>
AuthorDate: Thu Sep 9 09:33:50 2021 +0200

    KNOX-2657 - Token generation page improvements: (#492)
    
    - error box is decorated and hidden when not required
    - result box is displayed upon successful token generation
    - date/time information on token management and token generation page uses the same format
and time zone
---
 .../main/resources/applications/tokengen/app/index.html    |  2 +-
 .../resources/applications/tokengen/app/js/tokengen.js     | 11 ++++++++---
 .../knox/gateway/services/security/token/KnoxToken.java    | 14 +++++++++++++-
 .../token-management/app/token.management.component.html   |  4 ++--
 .../token-management/app/token.management.component.ts     |  4 ++++
 5 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/gateway-applications/src/main/resources/applications/tokengen/app/index.html
b/gateway-applications/src/main/resources/applications/tokengen/app/index.html
index 26c8c8a..dbde759 100644
--- a/gateway-applications/src/main/resources/applications/tokengen/app/index.html
+++ b/gateway-applications/src/main/resources/applications/tokengen/app/index.html
@@ -80,7 +80,7 @@
                             <label style="display: none; color: red;" id="invalidLifetimeText"><i
class="icon-warning"></i>Invalid lifetime!</label>
                         </div>
                     </div>
-                    <span id="errorBox" class="help-inline" style="color:white;display:none;"><span
class="errorMsg"></span>
+                    <span id="errorBox" class="help-inline" style="color:red;display:none;"><span
class="errorMsg"></span>
                         <i class="icon-warning-sign" style="color:#ae2817;"></i>
                     </span>
                     <div style="align-content: center; width: 25%;">
diff --git a/gateway-applications/src/main/resources/applications/tokengen/app/js/tokengen.js
b/gateway-applications/src/main/resources/applications/tokengen/app/js/tokengen.js
index ad552bf..09b2521 100644
--- a/gateway-applications/src/main/resources/applications/tokengen/app/js/tokengen.js
+++ b/gateway-applications/src/main/resources/applications/tokengen/app/js/tokengen.js
@@ -185,6 +185,8 @@ var gen = function() {
     var lt_mins = form.lt_mins.value;
     var lifespanInputEnabled = form.lifespanInputEnabled.value;
     var _gen = function() {
+        $('#errorBox').hide();
+        $('#resultBox').hide();
         var apiUrl = tokenURL;
         var params = "";
         if (lifespanInputEnabled === "true") {
@@ -209,8 +211,7 @@ var gen = function() {
                     var decodedToken = b64DecodeUnicode(accessToken.split(".")[1]);
                     var jwtjson = JSON.parse(decodedToken);
                     $('#accessPasscode').text(resp.passcode);
-                    var date = new Date(resp.expires_in);
-                    $('#expiry').text(date.toLocaleString());
+                    $('#expiry').text(new Date(resp.expires_in).toLocaleString());
                     $('#user').text(jwtjson.sub);
                     var homepageURL = resp.homepage_url;
                     $('#homepage_url').html("<a href=\"" + baseURL + homepageURL + "\">Homepage
URL</a>");
@@ -223,7 +224,11 @@ var gen = function() {
                 	window.location.reload();
                   }
                   else {
-                    $('#errorBox .errorMsg').text("Response from " + request.responseURL
+ " - " + request.status + ": " + request.statusText);
+                    var errorMsg = "Response from " + request.responseURL + " - " + request.status
+ ": " + request.statusText;
+                    if (request.responseText) {
+                        errorMsg += " (" + request.responseText + ")";
+                    }
+                    $('#errorBox .errorMsg').text(errorMsg);
                   }
                 }
             }
diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/token/KnoxToken.java
b/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/token/KnoxToken.java
index 41bf819..7bf071e 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/token/KnoxToken.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/token/KnoxToken.java
@@ -22,7 +22,7 @@ import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.Locale;
 
-public class KnoxToken implements Comparable<KnoxToken>{
+public class KnoxToken implements Comparable<KnoxToken> {
   // SimpleDateFormat is not thread safe must use as a ThreadLocal
   private static final ThreadLocal<DateFormat> KNOX_TOKEN_TS_FORMAT = ThreadLocal
       .withInitial(() -> new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.getDefault()));
@@ -53,14 +53,26 @@ public class KnoxToken implements Comparable<KnoxToken>{
     return KNOX_TOKEN_TS_FORMAT.get().format(new Date(issueTime));
   }
 
+  public long getIssueTimeLong() {
+    return issueTime;
+  }
+
   public String getExpiration() {
     return KNOX_TOKEN_TS_FORMAT.get().format(new Date(expiration));
   }
 
+  public long getExpirationLong() {
+    return expiration;
+  }
+
   public String getMaxLifetime() {
     return KNOX_TOKEN_TS_FORMAT.get().format(new Date(maxLifetime));
   }
 
+  public long getMaxLifetimeLong() {
+    return maxLifetime;
+  }
+
   public TokenMetadata getMetadata() {
     return metadata;
   }
diff --git a/knox-token-management-ui/token-management/app/token.management.component.html
b/knox-token-management-ui/token-management/app/token.management.component.html
index 14f86de..8143109 100644
--- a/knox-token-management-ui/token-management/app/token.management.component.html
+++ b/knox-token-management-ui/token-management/app/token.management.component.html
@@ -34,8 +34,8 @@
             <tbody>
             <tr *ngFor="let knoxToken of mf.data">
                 <td>{{knoxToken.tokenId}}</td>
-                <td>{{knoxToken.issueTime}}</td>
-                <td>{{knoxToken.expiration}}</td>
+                <td>{{formatDateTime(knoxToken.issueTimeLong)}}</td>
+                <td>{{formatDateTime(knoxToken.expirationLong)}}</td>
                 <td>{{knoxToken.metadata.comment}}</td>
                 <td>
                     <button *ngIf="knoxToken.metadata.enabled" (click)="disableToken(knoxToken.tokenId);">Disable</button>
diff --git a/knox-token-management-ui/token-management/app/token.management.component.ts b/knox-token-management-ui/token-management/app/token.management.component.ts
index 1c35732..8cbe761 100644
--- a/knox-token-management-ui/token-management/app/token.management.component.ts
+++ b/knox-token-management-ui/token-management/app/token.management.component.ts
@@ -71,4 +71,8 @@ export class TokenManagementComponent implements OnInit {
     gotoTokenGenerationPage() {
         window.open(this.tokenGenerationPageURL, '_blank');
     }
+
+    formatDateTime(dateTime: number) {
+        return new Date(dateTime).toLocaleString();
+    }
 }

Mime
View raw message