Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan D. Brooks2021-01-20 23:37:04 +0000
committerRyan D. Brooks2021-01-22 06:03:10 +0000
commit77f9c0dae3d69dcd91d35b1a63990a21fe19347f (patch)
treebedb916dc2053d41f3e14c7f09f53fd1706af1e0
parentc50805d3d4b9efcefa7a2f1ac00af641603a4aee (diff)
downloadorg.eclipse.osee-77f9c0dae3d69dcd91d35b1a63990a21fe19347f.tar.gz
org.eclipse.osee-77f9c0dae3d69dcd91d35b1a63990a21fe19347f.tar.xz
org.eclipse.osee-77f9c0dae3d69dcd91d35b1a63990a21fe19347f.zip
refactor[TW18625]: Remove JaxRsClient usage from jaxrs.server
-rw-r--r--plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/JaxRsApi.java4
-rw-r--r--plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsApiImpl.java8
-rw-r--r--plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsClient.java2
-rw-r--r--plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/ext/CxfJaxRsClientFactory.java1
-rw-r--r--plugins/org.eclipse.osee.jaxrs.server/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.osee.jaxrs.server/OSGI-INF/jaxrs.security.oauth2.resource.server.xml1
-rw-r--r--plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/rs/OAuth2ResourceServer.java12
-rw-r--r--plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/security/JaxRsOAuthResourceServerFilter.java42
8 files changed, 42 insertions, 29 deletions
diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/JaxRsApi.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/JaxRsApi.java
index f063e5fb4d7..2717ba15050 100644
--- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/JaxRsApi.java
+++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/JaxRsApi.java
@@ -42,7 +42,9 @@ public interface JaxRsApi {
<T> T readValue(String json, Class<? extends Collection> collectionClass, Class<?> elementClass);
- WebTarget newTarget(String uri);
+ WebTarget newTarget(String path);
+
+ WebTarget newTarget(String path, String serverUsername, String serverPassword);
<T> T newProxy(WebTarget target, Class<T> clazz);
diff --git a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsApiImpl.java b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsApiImpl.java
index 3589e574775..4c8574fd42f 100644
--- a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsApiImpl.java
+++ b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsApiImpl.java
@@ -98,6 +98,14 @@ public final class JaxRsApiImpl implements JaxRsApi {
return factory.newWebTarget(url(path));
}
+ @Override
+ public WebTarget newTarget(String path, String serverUsername, String serverPassword) {
+ JaxRsClientConfig config = factory.copyDefaultConfig();
+ config.setServerPassword(serverPassword);
+ config.setServerUsername(serverUsername);
+ return factory.newWebTarget(config, url(path));
+ }
+
private String url(String path) {
return baseUrl + "/" + path;
}
diff --git a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsClient.java b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsClient.java
index b775be5a154..94b0acdcd6d 100644
--- a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsClient.java
+++ b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/JaxRsClient.java
@@ -37,6 +37,8 @@ public final class JaxRsClient {
WebTarget newWebTarget(String url);
<T> T newProxy(String url, Class<T> clazz);
+
+ JaxRsClientConfig copyDefaultConfig();
}
public static JaxRsClientBuilder newBuilder() {
diff --git a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/ext/CxfJaxRsClientFactory.java b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/ext/CxfJaxRsClientFactory.java
index 5b1f9f8f6fa..2c7261c4dbd 100644
--- a/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/ext/CxfJaxRsClientFactory.java
+++ b/plugins/org.eclipse.osee.jaxrs.client/src/org/eclipse/osee/jaxrs/client/internal/ext/CxfJaxRsClientFactory.java
@@ -46,6 +46,7 @@ public class CxfJaxRsClientFactory implements JaxRsClientFactory {
client = builder.build();
}
+ @Override
public JaxRsClientConfig copyDefaultConfig() {
return config.copy();
}
diff --git a/plugins/org.eclipse.osee.jaxrs.server/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.jaxrs.server/META-INF/MANIFEST.MF
index 0a18c8a9175..e9699e78eae 100644
--- a/plugins/org.eclipse.osee.jaxrs.server/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.jaxrs.server/META-INF/MANIFEST.MF
@@ -75,7 +75,6 @@ Import-Package: com.fasterxml.jackson.core,
org.eclipse.osee.framework.jdk.core.type,
org.eclipse.osee.framework.jdk.core.util,
org.eclipse.osee.jaxrs,
- org.eclipse.osee.jaxrs.client,
org.eclipse.osee.jaxrs.mvc,
org.eclipse.osee.jdbc,
org.eclipse.osee.logger,
diff --git a/plugins/org.eclipse.osee.jaxrs.server/OSGI-INF/jaxrs.security.oauth2.resource.server.xml b/plugins/org.eclipse.osee.jaxrs.server/OSGI-INF/jaxrs.security.oauth2.resource.server.xml
index 87dc34a872f..57968029014 100644
--- a/plugins/org.eclipse.osee.jaxrs.server/OSGI-INF/jaxrs.security.oauth2.resource.server.xml
+++ b/plugins/org.eclipse.osee.jaxrs.server/OSGI-INF/jaxrs.security.oauth2.resource.server.xml
@@ -2,4 +2,5 @@
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" configuration-policy="require" deactivate="stop" modified="update">
<implementation class="org.eclipse.osee.jaxrs.server.internal.security.oauth2.rs.OAuth2ResourceServer" />
<reference bind="setJaxRsApplicationRegistry" cardinality="1..1" interface="org.eclipse.osee.jaxrs.server.internal.applications.JaxRsApplicationRegistry" name="JaxRsApplicationRegistry" policy="static"/>
+ <reference bind="bindJaxRsApi" cardinality="1..1" interface="org.eclipse.osee.framework.core.JaxRsApi" name="jaxRsApi" policy="static"/>
</scr:component>
diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/rs/OAuth2ResourceServer.java b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/rs/OAuth2ResourceServer.java
index b3a508f5fa7..badac72d13e 100644
--- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/rs/OAuth2ResourceServer.java
+++ b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/internal/security/oauth2/rs/OAuth2ResourceServer.java
@@ -19,6 +19,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
+import org.eclipse.osee.framework.core.JaxRsApi;
import org.eclipse.osee.jaxrs.server.internal.JaxRsConstants;
import org.eclipse.osee.jaxrs.server.internal.applications.JaxRsApplicationRegistry;
import org.eclipse.osee.jaxrs.server.security.JaxRsOAuth;
@@ -32,18 +33,23 @@ import org.osgi.framework.BundleContext;
*/
public class OAuth2ResourceServer {
- private JaxRsApplicationRegistry registry;
-
private final Set<String> registeredProviders = new HashSet<>();
private final AtomicBoolean wasRegistered = new AtomicBoolean();
private volatile JaxRsOAuthResourceServerFilter filter;
private volatile List<String> audiences;
private volatile Bundle bundle;
+ private JaxRsApplicationRegistry registry;
+ private JaxRsApi jaxRsApi;
+
public void setJaxRsApplicationRegistry(JaxRsApplicationRegistry registry) {
this.registry = registry;
}
+ public void bindJaxRsApi(JaxRsApi jaxRsApi) {
+ this.jaxRsApi = jaxRsApi;
+ }
+
public void start(BundleContext bundleContext, Map<String, Object> props) {
bundle = bundleContext.getBundle();
update(props);
@@ -72,7 +78,7 @@ public class OAuth2ResourceServer {
private void initialize(OAuth2ResourceServerConfig config) {
audiences = Collections.emptyList();
- Builder builder = JaxRsOAuthResourceServerFilter.newBuilder() //
+ Builder builder = JaxRsOAuthResourceServerFilter.newBuilder(jaxRsApi) //
.serverKey(config.getResourceServerKey()) //
.serverSecret(config.getResourceServerSecret())//
.serverUri(config.getValidationServerUri());
diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/security/JaxRsOAuthResourceServerFilter.java b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/security/JaxRsOAuthResourceServerFilter.java
index 2e4b1ca0ca0..3c565d5dcf5 100644
--- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/security/JaxRsOAuthResourceServerFilter.java
+++ b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/security/JaxRsOAuthResourceServerFilter.java
@@ -21,6 +21,7 @@ import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.core.Form;
@@ -32,17 +33,16 @@ import org.apache.cxf.rs.security.oauth2.provider.AccessTokenValidator;
import org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException;
import org.apache.cxf.rs.security.oauth2.utils.OAuthConstants;
import org.apache.cxf.security.SecurityContext;
+import org.eclipse.osee.framework.core.JaxRsApi;
import org.eclipse.osee.framework.jdk.core.util.Conditions;
import org.eclipse.osee.framework.jdk.core.util.Lib;
-import org.eclipse.osee.jaxrs.client.JaxRsClient;
-import org.eclipse.osee.jaxrs.client.JaxRsWebTarget;
import org.eclipse.osee.jaxrs.server.internal.security.oauth2.OAuthUtil;
/**
* Filter used to protect resource server end-points. This filter is used when the resource server is not located in the
* same JVM as the authorization server. When a request is processed, the resource server will contact the authorization
* server and validate the access token provided by the request through the HTTP authorization header.
- *
+ *
* @author Roberto E. Escobar
*/
@Provider
@@ -79,17 +79,23 @@ public class JaxRsOAuthResourceServerFilter implements ContainerRequestFilter {
delegate.filter(context);
};
- public static Builder newBuilder() {
- return new Builder();
+ public static Builder newBuilder(JaxRsApi jaxRsApi) {
+ return new Builder(jaxRsApi);
}
public static class Builder {
public static final long MAX_TOKEN_CACHE_EVICT_TIMEOUT_MILLIS = 24L * 60L * 60L * 1000L; // one day
+ private final JaxRsApi jaxRsApi;
+
private String resourceServerKey;
private String resourceServerSecret;
private String validationServerUri;
+ public Builder(JaxRsApi jaxRsApi) {
+ this.jaxRsApi = jaxRsApi;
+ }
+
public JaxRsOAuthResourceServerFilter build() {
ClientAccessTokenValidator validator = newTokenValidator();
return build(validator);
@@ -101,13 +107,7 @@ public class JaxRsOAuthResourceServerFilter implements ContainerRequestFilter {
}
private JaxRsOAuthResourceServerFilter build(ClientAccessTokenValidator validator) {
- JaxRsClient client = JaxRsClient.newBuilder()//
- .username(resourceServerKey)//
- .password(resourceServerSecret)//
- .build();
-
- validator.setClient(client);
- validator.setValidationServerUri(validationServerUri);
+ validator.setTarget(jaxRsApi.newTarget(validationServerUri, resourceServerKey, resourceServerSecret));
OAuth2RequestFilter filter = new OAuth2RequestFilter();
filter.setTokenValidator(validator);
@@ -186,29 +186,23 @@ public class JaxRsOAuthResourceServerFilter implements ContainerRequestFilter {
private static abstract class ClientAccessTokenValidator implements AccessTokenValidator {
- private JaxRsClient client;
- private String validationServerUri;
-
- public void setClient(JaxRsClient client) {
- this.client = client;
- }
-
- public void setValidationServerUri(String validationServerUri) {
- this.validationServerUri = validationServerUri;
- }
+ private WebTarget target;
@Override
public List<String> getSupportedAuthorizationSchemes() {
return Collections.singletonList(OAuthConstants.ALL_AUTH_SCHEMES);
}
+ public void setTarget(WebTarget target) {
+ this.target = target;
+ }
+
protected AccessTokenValidation getRemoteTokenValidation(String authScheme, String accessToken) {
Form form = new Form();
form.param(OAuthConstants.AUTHORIZATION_SCHEME_TYPE, authScheme);
form.param(OAuthConstants.AUTHORIZATION_SCHEME_DATA, accessToken);
- JaxRsWebTarget target = client.target(validationServerUri);
return target.request().post(Entity.form(form), AccessTokenValidation.class);
}
}
}
-}
+} \ No newline at end of file

Back to the top