Skip to content

Commit

Permalink
Upgrade JAX-RS implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
gl-johnson committed Jun 8, 2023
1 parent eb74676 commit 7458db0
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 48 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [3.0.5] - 2023-06-07
## [3.0.5] - 2023-06-08

### Fixed
- Fix dependency information stripped from non-shaded jar
Expand All @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
[cyberark/conjur-api-java#118](https://github.com/cyberark/conjur-api-java/issues/118)

### Changed
- Migrate JAX-RS to latest Jakarta version
[cyberark/conjur-api-java#119](https://github.com/cyberark/conjur-api-java/issues/119)
- Avoid calling `login` for host
[cyberark/conjur-api-java#117](https://github.com/cyberark/conjur-api-java/pull/117)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ to work around this:
If you don't properly install the Conjur certificate into the Java keystore, you may encounter
the folowing errors:
- `org.apache.cxf.interceptor.Fault: Could not send Message.`
- `javax.ws.rs.ProcessingException: javax.net.ssl.SSLHandshakeException: SSLHandshakeException`
- `jakarta.ws.rs.ProcessingException: javax.net.ssl.SSLHandshakeException: SSLHandshakeException`
- `javax.net.ssl.SSLHandshakeException: SSLHandshakeException`
- `javax.net.ssl.SSLHandshakeException: PKIX path building failed`
- `sun.security.validator.ValidatorException: PKIX path building failed`
Expand Down
2 changes: 1 addition & 1 deletion bin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ set -eo pipefail

docker run --rm \
-v "$PWD:/cyberark/conjur-java-api" \
-w /cyberark/conjur-java-api maven:3-jdk-8 \
-w /cyberark/conjur-java-api maven:3-jdk-11 \
/bin/bash -ec "mvn -X -e clean package -Dmaven.test.skip=true"
2 changes: 1 addition & 1 deletion bin/deploy-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ docker run --rm \
-v "$PWD:/cyberark/conjur-java-api" \
-v "$GPG_PASSWORD:/gpg_password" \
-v "$GPG_PRIVATE_KEY:/gpg_key" \
-w /cyberark/conjur-java-api maven:3-jdk-8 \
-w /cyberark/conjur-java-api maven:3-jdk-11 \
/bin/bash -ec "gpg --batch --passphrase-file /gpg_password --trust-model always --import /gpg_key
mvn versions:set -DnewVersion=${TAG}
mvn --settings settings.xml clean deploy -Dmaven.test.skip=true -P ossrh,sign
Expand Down
2 changes: 1 addition & 1 deletion bin/deploy-snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ docker run --rm \
-v "$PWD:/cyberark/conjur-java-api" \
-v "$GPG_PASSWORD:/gpg_password" \
-v "$GPG_PRIVATE_KEY:/gpg_key" \
-w /cyberark/conjur-java-api maven:3-jdk-8 \
-w /cyberark/conjur-java-api maven:3-jdk-11 \
/bin/bash -ec "gpg --batch --passphrase-file /gpg_password --trust-model always --import /gpg_key
mvn --settings settings.xml clean deploy -Dmaven.test.skip=true -P ossrh,sign"
35 changes: 23 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,34 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jaxrs.version>2.0</jaxrs.version>
</properties>
<dependencies>
<!--
JAXRS Implementation
You can change any of this, for example if you use Jersey 2.0 or a different implementation
(codehaus has one, I think).
-->

<!-- JAXRS Implementation -->
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${jaxrs.version}</version>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<version>3.5.5</version>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-binding</artifactId>
<version>3.1.2</version>
</dependency>

<!-- JSON support -->
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/com/cyberark/conjur/api/clients/AuthnClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import static com.cyberark.conjur.util.EncodeUriComponent.encodeUriComponent;

import javax.net.ssl.SSLContext;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.Response;

import com.cyberark.conjur.api.AuthnProvider;
import com.cyberark.conjur.api.Credentials;
Expand Down Expand Up @@ -80,8 +80,11 @@ public String login(){

private void init(final String username, final String password, final SSLContext sslContext) {
final ClientBuilder builder = ClientBuilder.newBuilder()
.register(new HttpBasicAuthFilter(username, password))
.sslContext(sslContext);
.register(new HttpBasicAuthFilter(username, password));

if(sslContext != null) {
builder.sslContext(sslContext);
}

Client client = builder.build();
WebTarget root = client.target(endpoints.getAuthnUri());
Expand Down
27 changes: 17 additions & 10 deletions src/main/java/com/cyberark/conjur/api/clients/ResourceClient.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.cyberark.conjur.api.clients;

import javax.net.ssl.SSLContext;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.Response;

import com.cyberark.conjur.api.Credentials;
import com.cyberark.conjur.api.Endpoints;
Expand Down Expand Up @@ -79,8 +79,12 @@ private Endpoints getEndpoints() {

private void init(Credentials credentials, SSLContext sslContext){
ClientBuilder builder = ClientBuilder.newBuilder()
.register(new TokenAuthFilter(new AuthnClient(credentials, endpoints, sslContext)))
.sslContext(sslContext);
.register(new TokenAuthFilter(new AuthnClient(credentials, endpoints, sslContext)));


if(sslContext != null) {
builder.sslContext(sslContext);
}

Client client = builder.build();

Expand All @@ -89,8 +93,11 @@ private void init(Credentials credentials, SSLContext sslContext){

private void init(Token token, SSLContext sslContext){
ClientBuilder builder = ClientBuilder.newBuilder()
.register(new TokenAuthFilter(new AuthnTokenClient(token)))
.sslContext(sslContext);
.register(new TokenAuthFilter(new AuthnTokenClient(token)));

if(sslContext != null) {
builder.sslContext(sslContext);
}

Client client = builder.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import org.apache.commons.codec.binary.Base64;

import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientRequestFilter;
import javax.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.client.ClientRequestContext;
import jakarta.ws.rs.client.ClientRequestFilter;
import jakarta.ws.rs.core.MultivaluedMap;
import java.io.IOException;
import java.nio.charset.Charset;

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/cyberark/conjur/util/rs/JsonBodyReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
package com.cyberark.conjur.util.rs;

import com.google.gson.Gson;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyReader;
import javax.ws.rs.ext.Provider;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.ext.MessageBodyReader;
import jakarta.ws.rs.ext.Provider;
import java.io.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.cyberark.conjur.api.Token;
import com.cyberark.conjur.util.Args;

import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientRequestFilter;
import jakarta.ws.rs.client.ClientRequestContext;
import jakarta.ws.rs.client.ClientRequestFilter;
import java.io.IOException;

/**
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/com/cyberark/conjur/api/ConjurTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;

import javax.ws.rs.ProcessingException;
import javax.ws.rs.WebApplicationException;
import jakarta.ws.rs.WebApplicationException;
import java.util.UUID;

/**
Expand Down Expand Up @@ -76,7 +75,7 @@ public void testSetVariableWithoutVariableInPolicy() {

@Test
public void testLogonWithAlterativeAuthenticator() {
expectedException.expect(ProcessingException.class);
expectedException.expect(WebApplicationException.class);
expectedException.expectMessage(UNAUTHORIZED_STATUS_CODE);

String authnUrl = System.getProperty(APPLIANCE_URL_PROPERTY) + ALTERNATIVE_AUTHN_ENDPOINT;
Expand Down

0 comments on commit 7458db0

Please sign in to comment.