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 01361812f KNOX-2950 - Handling application path aliases (#787)
01361812f is described below

commit 01361812f852988681bda05565b9607ceb427b38
Author: Sandor Molnar <[email protected]>
AuthorDate: Mon Oct 9 22:44:51 2023 +0200

    KNOX-2950 - Handling application path aliases (#787)
---
 gateway-release/home/conf/gateway-site.xml               |  7 +++++++
 .../main/java/org/apache/knox/gateway/GatewayServer.java | 15 +++++++++++++++
 .../knox/gateway/config/impl/GatewayConfigImpl.java      | 16 ++++++++++++++++
 .../java/org/apache/knox/gateway/GatewayTestConfig.java  |  5 +++++
 .../org/apache/knox/gateway/config/GatewayConfig.java    |  4 ++++
 knox-homepage-ui/home/app/homepage.service.ts            |  6 ++++--
 .../token-generation/app/token-generation.service.ts     |  4 ++--
 .../token-management/app/token.management.component.ts   |  4 +++-
 .../token-management/app/token.management.service.ts     |  8 +++++---
 9 files changed, 61 insertions(+), 8 deletions(-)

diff --git a/gateway-release/home/conf/gateway-site.xml 
b/gateway-release/home/conf/gateway-site.xml
index 7a02fa58e..a33e908dd 100644
--- a/gateway-release/home/conf/gateway-site.xml
+++ b/gateway-release/home/conf/gateway-site.xml
@@ -141,6 +141,13 @@ limitations under the License.
         <description>A duration (in seconds) beyond a token’s expiration to 
wait before evicting its state. This configuration only applies when 
server-managed token state is enabled either in gateway-site or at the topology 
level.</description>
     </property>
 
+    <!-- @since 2.1.0 application path aliases -->
+    <property>
+        <name>gateway.application.path.alias.token-generation</name>
+        <value>tokengen</value>
+    </property>
+
+
     <!-- Knox Admin related config -->
     <property>
         <name>gateway.knox.admin.groups</name>
diff --git 
a/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServer.java 
b/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServer.java
index bb7b44ae8..16fe8970d 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServer.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/GatewayServer.java
@@ -926,6 +926,9 @@ public class GatewayServer {
         contexts.removeHandler( oldContext );
       }
       contexts.addHandler( newContext );
+
+      processApplicationPathAliases(warDir, topology);
+
       if( contexts.isRunning() && !newContext.isRunning() ) {
         newContext.start();
         if(!newContext.isAvailable()) {
@@ -939,6 +942,18 @@ public class GatewayServer {
     }
   }
 
+  private void processApplicationPathAliases(File warDir, Topology topology) {
+    final Map<String, Collection<String>> applicationPathAliases = 
config.getApplicationPathAliases();
+    applicationPathAliases.forEach((appName, aliases) -> {
+      if (warDir.getName().contains(appName) && !aliases.isEmpty()) {
+        aliases.forEach(alias -> {
+          WebAppContext aliasContext = createWebAppContext(topology, warDir, 
alias);
+          contexts.addHandler(aliasContext);
+        });
+      }
+    });
+  }
+
   private synchronized void internalDeactivateTopology( Topology topology ) {
 
     log.deactivatingTopology( topology.getName() );
diff --git 
a/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
 
b/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
index e065d548e..3d3848921 100644
--- 
a/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
+++ 
b/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
@@ -1496,4 +1496,20 @@ public class GatewayConfigImpl extends Configuration 
implements GatewayConfig {
     return usersCanSeeAllTokens == null ? false : 
usersCanSeeAllTokens.contains(userName);
   }
 
+  @Override
+  public Map<String, Collection<String>> getApplicationPathAliases() {
+    return getPathAliases(".application");
+  }
+
+  private Map<String, Collection<String>> getPathAliases(String qualifier) {
+    final String prefix = GATEWAY_CONFIG_FILE_PREFIX + qualifier + 
DEPLOYMENT_PATH_ALIAS;
+    final Map<String, Collection<String>> pathAliases = new HashMap<>();
+    this.forEach(config -> {
+      if (config.getKey().startsWith(prefix)) {
+        
pathAliases.put(config.getKey().substring(prefix.length()).toLowerCase(Locale.getDefault()),
 getTrimmedStringCollection(config.getKey()));
+      }
+    });
+    return pathAliases;
+  }
+
 }
diff --git 
a/gateway-spi-common/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
 
b/gateway-spi-common/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
index 3a3a61d29..3162f7140 100644
--- 
a/gateway-spi-common/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
+++ 
b/gateway-spi-common/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
@@ -1062,4 +1062,9 @@ public class GatewayTestConfig extends Configuration 
implements GatewayConfig {
     return false;
   }
 
+  @Override
+  public Map<String, Collection<String>> getApplicationPathAliases() {
+    return Collections.emptyMap();
+  }
+
 }
diff --git 
a/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java 
b/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java
index b46958973..83d1bb926 100644
--- 
a/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java
+++ 
b/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java
@@ -115,6 +115,8 @@ public interface GatewayConfig {
 
   String DEFAULT_API_SERVICES_VIEW_VERSION = "v1";
 
+  String DEPLOYMENT_PATH_ALIAS = ".path.alias.";
+
   /**
    * The location of the gateway configuration.
    * Subdirectories will be: topologies
@@ -894,4 +896,6 @@ public interface GatewayConfig {
    */
   boolean canSeeAllTokens(String userName);
 
+  Map<String, Collection<String>> getApplicationPathAliases();
+
 }
diff --git a/knox-homepage-ui/home/app/homepage.service.ts 
b/knox-homepage-ui/home/app/homepage.service.ts
index 6db36d7f3..123e762d3 100644
--- a/knox-homepage-ui/home/app/homepage.service.ts
+++ b/knox-homepage-ui/home/app/homepage.service.ts
@@ -27,8 +27,10 @@ import {SessionInformation} from 
'./sessionInformation/session.information';
 
 @Injectable()
 export class HomepageService {
-    apiUrl = window.location.pathname.replace(new RegExp('home/.*'), 
'api/v1/metadata/');
-    sessionUrl = window.location.pathname.replace(new RegExp('home/.*'), 
'session/api/v1/sessioninfo');
+    pathParts = window.location.pathname.split('/');
+    topologyContext = '/' + this.pathParts[1] + '/' + this.pathParts[2] + '/';
+    apiUrl = this.topologyContext + 'api/v1/metadata/';
+    sessionUrl = this.topologyContext + 'session/api/v1/sessioninfo';
     generalProxyInformationUrl = this.apiUrl + 'info';
     publicCertUrl = this.apiUrl + 'publicCert?type=';
     topologiesUrl = this.apiUrl + 'topologies';
diff --git 
a/knox-token-generation-ui/token-generation/app/token-generation.service.ts 
b/knox-token-generation-ui/token-generation/app/token-generation.service.ts
index e9a38637a..4b32ac42b 100644
--- a/knox-token-generation-ui/token-generation/app/token-generation.service.ts
+++ b/knox-token-generation-ui/token-generation/app/token-generation.service.ts
@@ -26,11 +26,11 @@ export class TokenGenService {
     readonly tssStatusRequestURL: string;
 
     constructor(private http: HttpClient) {
-        const loginPageSuffix = 'token-generation/index.html';
         const knoxtokenURL = 'knoxtoken/api/v1/token';
         const tssStatusURL = 'knoxtoken/api/v1/token/getTssStatus';
 
-        let topologyContext = 
window.location.pathname.replace(loginPageSuffix, '');
+        let pathParts = window.location.pathname.split('/');
+        let topologyContext = '/' + pathParts[1] + '/' + pathParts[2] + '/';
         let temporaryURL = topologyContext.substring(0, 
topologyContext.lastIndexOf('/'));
         this.baseURL = temporaryURL.substring(0, temporaryURL.lastIndexOf('/') 
+ 1);
         this.tokenURL = topologyContext + knoxtokenURL;
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 6c73db0bc..edc5f3493 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
@@ -32,7 +32,9 @@ import {SelectionModel} from '@angular/cdk/collections';
 
 export class TokenManagementComponent implements OnInit {
 
-    tokenGenerationPageURL = window.location.pathname.replace(new 
RegExp('token-management/.*'), 'token-generation/index.html');
+    pathParts = window.location.pathname.split('/');
+    topologyContext = '/' + this.pathParts[1] + '/' + this.pathParts[2] + '/';
+    tokenGenerationPageURL = this.topologyContext + 
'token-generation/index.html';
 
     userName: string;
     canSeeAllTokens: boolean;
diff --git 
a/knox-token-management-ui/token-management/app/token.management.service.ts 
b/knox-token-management-ui/token-management/app/token.management.service.ts
index 3abef06a3..bf240e84f 100644
--- a/knox-token-management-ui/token-management/app/token.management.service.ts
+++ b/knox-token-management-ui/token-management/app/token.management.service.ts
@@ -25,10 +25,12 @@ import {SessionInformation} from './session.information';
 
 @Injectable()
 export class TokenManagementService {
-    sessionUrl = window.location.pathname.replace(new 
RegExp('token-management/.*'), 'session/api/v1/sessioninfo');
-    apiUrl = window.location.pathname.replace(new 
RegExp('token-management/.*'), 'knoxtoken/api/v1/token/');
-    getAllKnoxTokensUrl = this.apiUrl + 'getUserTokens?allTokens=true';
+    pathParts = window.location.pathname.split('/');
+    topologyContext = '/' + this.pathParts[1] + '/' + this.pathParts[2] + '/';
+    sessionUrl = this.topologyContext + 'session/api/v1/sessioninfo';
+    apiUrl = this.topologyContext + 'knoxtoken/api/v1/token/';
     getKnoxTokensUrl = this.apiUrl + 'getUserTokens?userNameOrCreatedBy=';
+    getAllKnoxTokensUrl = this.apiUrl + 'getUserTokens?allTokens=true';
     enableKnoxTokenUrl = this.apiUrl + 'enable';
     enableKnoxTokensBatchUrl = this.apiUrl + 'enableTokens';
     disableKnoxTokenUrl = this.apiUrl + 'disable';

Reply via email to