Skip to content

Commit a85cdcb

Browse files
authored
KNOX-3096 - Remote Authentication Provider for Levaraging other Knox Instances (#994)
* KNOX-3096 - Remote Auth Provider initial commit
1 parent 098140d commit a85cdcb

File tree

9 files changed

+755
-0
lines changed

9 files changed

+755
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
<parent>
22+
<groupId>org.apache.knox</groupId>
23+
<artifactId>gateway</artifactId>
24+
<version>2.1.0-SNAPSHOT</version>
25+
</parent>
26+
27+
<artifactId>gateway-provider-security-authc-remote</artifactId>
28+
<name>gateway-provider-security-authc-remote</name>
29+
<description>An extension of the gateway that provides a remote authentication capability.</description>
30+
31+
<dependencies>
32+
<dependency>
33+
<groupId>org.apache.knox</groupId>
34+
<artifactId>gateway-spi</artifactId>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.apache.knox</groupId>
38+
<artifactId>gateway-util-common</artifactId>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>javax.servlet</groupId>
43+
<artifactId>javax.servlet-api</artifactId>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>com.google.guava</groupId>
48+
<artifactId>guava</artifactId>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>org.apache.knox</groupId>
53+
<artifactId>gateway-i18n</artifactId>
54+
</dependency>
55+
56+
<dependency>
57+
<groupId>org.apache.knox</groupId>
58+
<artifactId>gateway-test-utils</artifactId>
59+
<scope>test</scope>
60+
</dependency>
61+
</dependencies>
62+
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with this
4+
* work for additional information regarding copyright ownership. The ASF
5+
* licenses this file to you under the Apache License, Version 2.0 (the
6+
* "License"); you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations under
15+
* the License.
16+
*/
17+
package org.apache.knox.gateway;
18+
19+
import org.apache.knox.gateway.i18n.messages.Message;
20+
import org.apache.knox.gateway.i18n.messages.MessageLevel;
21+
import org.apache.knox.gateway.i18n.messages.Messages;
22+
import org.apache.knox.gateway.i18n.messages.StackTrace;
23+
24+
25+
@Messages(logger="org.apache.knox.gateway.provider.federation.remote")
26+
public interface RemoteAuthMessages {
27+
@Message( level = MessageLevel.WARN, text = "Missing required parameter named: {0}. Please check topology configuration.)" )
28+
void missingRequiredParameter(String paramName);
29+
30+
@Message( level = MessageLevel.WARN, text = "Authentication of the user failed.)" )
31+
void failedToAuthenticateToRemoteAuthServer();
32+
33+
@Message( level = MessageLevel.WARN, text = "Error received during authentication process: {0}.)" )
34+
void errorReceivedWhileAuthenticatingRequest(@StackTrace( level = MessageLevel.ERROR) Exception e);
35+
36+
@Message( level = MessageLevel.WARN, text = "Error received during authentication process: {0} {1}.)" )
37+
void failedToLoadTruststore(String message, @StackTrace( level = MessageLevel.ERROR) Exception e);
38+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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.deploy;
19+
20+
import org.apache.knox.gateway.descriptor.FilterParamDescriptor;
21+
import org.apache.knox.gateway.descriptor.ResourceDescriptor;
22+
import org.apache.knox.gateway.topology.Provider;
23+
import org.apache.knox.gateway.topology.Service;
24+
25+
import java.util.ArrayList;
26+
import java.util.List;
27+
import java.util.Locale;
28+
import java.util.Map;
29+
import java.util.Map.Entry;
30+
31+
public class RemoteAuthDeploymentContributor extends ProviderDeploymentContributorBase {
32+
33+
private static final String ROLE = "authentication";
34+
private static final String NAME = "RemoteAuthProvider";
35+
36+
private static final String FILTER_CLASSNAME = "org.apache.knox.gateway.filter.RemoteAuthFilter";
37+
38+
@Override
39+
public String getRole() {
40+
return ROLE;
41+
}
42+
43+
@Override
44+
public String getName() {
45+
return NAME;
46+
}
47+
48+
@Override
49+
public void initializeContribution(DeploymentContext context) {
50+
super.initializeContribution(context);
51+
}
52+
53+
@Override
54+
public void contributeFilter(DeploymentContext context, Provider provider, Service service,
55+
ResourceDescriptor resource, List<FilterParamDescriptor> params) {
56+
// blindly add all the provider params as filter init params
57+
if (params == null) {
58+
params = new ArrayList<>();
59+
}
60+
Map<String, String> providerParams = provider.getParams();
61+
for(Entry<String, String> entry : providerParams.entrySet()) {
62+
params.add( resource.createFilterParam().name( entry.getKey().toLowerCase(Locale.ROOT) ).value( entry.getValue() ) );
63+
}
64+
resource.addFilter().name( getName() ).role( getRole() ).impl(FILTER_CLASSNAME).params( params );
65+
}
66+
}

0 commit comments

Comments
 (0)