Skip to content

Commit be2b9a4

Browse files
authored
KNOX-3279 - REST Catalog dispatch implementation for including configurable metadata as outbound request headers (#1182)
1 parent f81a5b8 commit be2b9a4

12 files changed

Lines changed: 900 additions & 7 deletions

File tree

gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/JWTFederationFilter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.knox.gateway.i18n.messages.MessagesFactory;
2323
import org.apache.knox.gateway.provider.federation.jwt.JWTMessages;
2424
import org.apache.knox.gateway.security.PrimaryPrincipal;
25+
import org.apache.knox.gateway.security.CommonTokenConstants;
2526
import org.apache.knox.gateway.services.security.token.UnknownTokenException;
2627
import org.apache.knox.gateway.services.security.token.impl.JWT;
2728
import org.apache.knox.gateway.services.security.token.impl.JWTToken;
@@ -54,10 +55,10 @@ public class JWTFederationFilter extends AbstractJWTFilter {
5455
private static final JWTMessages LOGGER = MessagesFactory.get( JWTMessages.class );
5556
/* A semicolon separated list of paths that need to bypass authentication */
5657
public static final String JWT_UNAUTHENTICATED_PATHS_PARAM = "jwt.unauthenticated.path.list";
57-
public static final String GRANT_TYPE = "grant_type";
58-
public static final String CLIENT_CREDENTIALS = "client_credentials";
59-
public static final String CLIENT_SECRET = "client_secret";
60-
public static final String CLIENT_ID = "client_id";
58+
public static final String GRANT_TYPE = CommonTokenConstants.GRANT_TYPE;
59+
public static final String CLIENT_CREDENTIALS = CommonTokenConstants.CLIENT_CREDENTIALS;
60+
public static final String CLIENT_SECRET = CommonTokenConstants.CLIENT_CREDENTIALS;
61+
public static final String CLIENT_ID = CommonTokenConstants.CLIENT_ID;
6162
public static final String INVALID_CLIENT_SECRET = "Error while parsing the received client secret";
6263
public static final String MISMATCHING_CLIENT_ID_AND_CLIENT_SECRET = "Client credentials flow with mismatching client_id and client_secret";
6364
public static final String REFRESH_TOKEN = "refresh_token";

gateway-service-definitions/src/main/resources/services/iceberg-rest/0.0.1/service.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@
2222
<shortDesc>ICEBERG-REST</shortDesc>
2323
<description>Apache Iceberg REST Catalog API</description>
2424
</metadata>
25-
2625
<routes>
2726
<route path="/iceberg-rest/**"/>
2827
</routes>
29-
<dispatch classname="org.apache.knox.gateway.dispatch.ConfigurableDispatch"
30-
ha-classname="org.apache.knox.gateway.ha.dispatch.ConfigurableHADispatch">
28+
<dispatch classname="org.apache.knox.gateway.service.restcatalog.RestCatalogDispatch"
29+
ha-classname="org.apache.knox.gateway.service.restcatalog.RestCatalogHaDispatch">
3130
<param>
3231
<name>shouldIncludePrincipalAndGroups</name>
3332
<value>true</value>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
<parent>
23+
<groupId>org.apache.knox</groupId>
24+
<artifactId>gateway</artifactId>
25+
<version>3.0.0-SNAPSHOT</version>
26+
</parent>
27+
28+
<artifactId>gateway-service-restcatalog</artifactId>
29+
30+
<dependencies>
31+
<dependency>
32+
<groupId>org.apache.knox</groupId>
33+
<artifactId>gateway-spi</artifactId>
34+
<scope>compile</scope>
35+
</dependency>
36+
<dependency>
37+
<groupId>javax.servlet</groupId>
38+
<artifactId>javax.servlet-api</artifactId>
39+
<scope>compile</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.apache.httpcomponents</groupId>
43+
<artifactId>httpclient</artifactId>
44+
<scope>compile</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.apache.httpcomponents</groupId>
48+
<artifactId>httpcore</artifactId>
49+
<scope>compile</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.apache.knox</groupId>
53+
<artifactId>gateway-provider-ha</artifactId>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.apache.knox</groupId>
57+
<artifactId>gateway-i18n</artifactId>
58+
</dependency>
59+
<dependency>
60+
<groupId>com.github.ben-manes.caffeine</groupId>
61+
<artifactId>caffeine</artifactId>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.eclipse.jetty</groupId>
65+
<artifactId>jetty-http</artifactId>
66+
<scope>test</scope>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.apache.knox</groupId>
70+
<artifactId>gateway-test-utils</artifactId>
71+
<scope>test</scope>
72+
</dependency>
73+
</dependencies>
74+
75+
</project>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.knox.gateway.service.restcatalog;
19+
20+
import org.apache.http.client.methods.HttpUriRequest;
21+
import org.apache.knox.gateway.dispatch.ConfigurableDispatch;
22+
23+
import javax.servlet.FilterConfig;
24+
import javax.servlet.http.HttpServletRequest;
25+
import javax.servlet.http.HttpServletResponse;
26+
import java.io.IOException;
27+
28+
/**
29+
* A Dispatch implementation that supports adding token metadata to the outbound request headers.
30+
*/
31+
public class RestCatalogDispatch extends ConfigurableDispatch {
32+
33+
private final TokenMetadataHeaderHandler headerHandler;
34+
35+
public RestCatalogDispatch(FilterConfig filterConfig) {
36+
headerHandler = new TokenMetadataHeaderHandler(filterConfig);
37+
}
38+
39+
@Override
40+
public void init() {
41+
super.init();
42+
}
43+
44+
@Override
45+
protected void executeRequest(HttpUriRequest outboundRequest,
46+
HttpServletRequest inboundRequest,
47+
HttpServletResponse outboundResponse) throws IOException {
48+
headerHandler.applyHeadersToRequest(inboundRequest, outboundRequest);
49+
super.executeRequest(outboundRequest, inboundRequest, outboundResponse);
50+
}
51+
52+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.knox.gateway.service.restcatalog;
19+
20+
import org.apache.http.client.methods.HttpUriRequest;
21+
import org.apache.knox.gateway.ha.dispatch.ConfigurableHADispatch;
22+
23+
import javax.servlet.FilterConfig;
24+
import javax.servlet.http.HttpServletRequest;
25+
import javax.servlet.http.HttpServletResponse;
26+
import java.io.IOException;
27+
28+
public class RestCatalogHaDispatch extends ConfigurableHADispatch {
29+
30+
static final String SERVICE_ROLE = "ICEBERG-REST";
31+
32+
private final TokenMetadataHeaderHandler headerHandler;
33+
34+
public RestCatalogHaDispatch(final FilterConfig filterConfig) {
35+
setServiceRole(SERVICE_ROLE);
36+
headerHandler = new TokenMetadataHeaderHandler(filterConfig);
37+
}
38+
39+
@Override
40+
public void init() {
41+
super.init();
42+
}
43+
44+
@Override
45+
protected void executeRequest(HttpUriRequest outboundRequest, HttpServletRequest inboundRequest, HttpServletResponse outboundResponse) throws IOException {
46+
headerHandler.applyHeadersToRequest(inboundRequest, outboundRequest);
47+
super.executeRequest(outboundRequest, inboundRequest, outboundResponse);
48+
}
49+
}

0 commit comments

Comments
 (0)