Skip to content

Commit

Permalink
Cleanup dependencies (#101)
Browse files Browse the repository at this point in the history
* Updated `scalecube-parent` to use jdk17.
* Get rid of dependency on `slf4j`.
* Bump `jackson` to `2.18.0`.
  • Loading branch information
artem-v authored Oct 7, 2024
1 parent eb9218a commit 4c68401
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 74 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/branch-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,23 @@ jobs:
name: Branch CI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
- uses: actions/checkout@v4
- uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK 1.8
uses: actions/setup-java@v1
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 1.8
java-version: 17
distribution: zulu
server-id: github
server-username: GITHUB_ACTOR
server-password: GITHUB_TOKEN
- name: Maven Build
run: mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true -Ddockerfile.skip=true -B -V
run: mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
env:
GITHUB_TOKEN: ${{ secrets.ORGANIZATION_TOKEN }}
- name: Maven Verify
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/pre-release-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ jobs:
name: Pre-release CI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v1
- uses: actions/checkout@v4
- uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up Java for publishing to GitHub Packages
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
java-version: 1.8
java-version: 17
distribution: zulu
server-id: github
server-username: GITHUB_ACTOR
server-password: GITHUB_TOKEN
Expand All @@ -33,9 +34,10 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.ORGANIZATION_TOKEN }}
- name: Set up Java for publishing to Maven Central Repository
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
java-version: 1.8
java-version: 17
distribution: zulu
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
Expand Down
20 changes: 11 additions & 9 deletions .github/workflows/release-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,26 @@ jobs:
name: Release CI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git checkout ${{ github.event.release.target_commitish }}
- uses: actions/cache@v1
- uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up Java for publishing to GitHub Packages
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
java-version: 1.8
java-version: 17
distribution: zulu
server-id: github
server-username: GITHUB_ACTOR
server-password: GITHUB_TOKEN
- name: Maven Build
run: mvn clean install -DskipTests=true -Ddockerfile.skip=true -B -V
run: mvn clean install -DskipTests=true -B -V
env:
GITHUB_TOKEN: ${{ secrets.ORGANIZATION_TOKEN }}
- name: Maven Verify
Expand All @@ -41,17 +42,18 @@ jobs:
run: |
mvn -B build-helper:parse-version release:prepare \
-DreleaseVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.incrementalVersion} \
-Darguments="-DskipTests=true -Ddockerfile.skip=true"
-Darguments="-DskipTests=true"
echo release_tag=$(git describe --tags --abbrev=0) >> $GITHUB_OUTPUT
- name: Perform release
run: mvn -B release:perform -Pdeploy2Github -Darguments="-DskipTests=true -Ddockerfile.skip=true -Pdeploy2Github"
run: mvn -B release:perform -Pdeploy2Github -Darguments="-DskipTests=true -Pdeploy2Github"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ secrets.GITHUB_REPOSITORY }}
- name: Set up Java for publishing to Maven Central Repository
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
java-version: 1.8
java-version: 17
distribution: zulu
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
Expand Down
14 changes: 14 additions & 0 deletions checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.0//EN"
"https://checkstyle.org/dtds/suppressions_1_0.dtd">


<suppressions>
<suppress checks="AbbreviationAsWordInName" files=".*"/>
<suppress checks="MissingJavadocTypeCheck" files=".*"/>
<suppress checks="MissingJavadocMethodCheck" files=".*"/>
<suppress checks="MissingSwitchDefault" files=".*"/>
<suppress checks="VariableDeclarationUsageDistance" files=".*"/>
</suppressions>
11 changes: 7 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.scalecube</groupId>
<artifactId>scalecube-parent</artifactId>
<version>0.2.20</version>
<version>0.3.1</version>
</parent>

<artifactId>scalecube-security-parent</artifactId>
Expand Down Expand Up @@ -41,17 +43,18 @@
<properties>
<reactor.version>2020.0.32</reactor.version>
<vault-java-driver.version>5.1.0</vault-java-driver.version>
<jackson.version>2.15.1</jackson.version>
<slf4j.version>2.0.7</slf4j.version>
<jackson.version>2.18.0</jackson.version>
<jjwt.version>0.11.2</jjwt.version>

<mockito-junit.version>4.6.1</mockito-junit.version>
<junit-jupiter.version>5.8.2</junit-jupiter.version>
<hamcrest.version>1.3</hamcrest.version>
<testcontainers.version>1.20.1</testcontainers.version>
<slf4j.version>2.0.7</slf4j.version>

<distributionManagement.url>https://maven.pkg.github.com/scalecube/scalecube-security
</distributionManagement.url>
<checkstyle.suppressions.location>checkstyle-suppressions.xml</checkstyle.suppressions.location>
</properties>

<dependencyManagement>
Expand Down
4 changes: 0 additions & 4 deletions tokens/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- Tests -->
<dependency>
<groupId>org.testcontainers</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,12 @@
import java.util.Base64;
import java.util.Base64.Decoder;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.Exceptions;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;

public final class JwksKeyProvider implements KeyProvider {

private static final Logger LOGGER = LoggerFactory.getLogger(JwksKeyProvider.class);

private static final ObjectMapper OBJECT_MAPPER = newObjectMapper();

private String jwksUri;
Expand Down Expand Up @@ -101,7 +97,6 @@ private JwkInfoList computeKeyList() throws IOException {

int responseCode = httpClient.getResponseCode();
if (responseCode != 200) {
LOGGER.error("[computeKey][{}] Not expected response code: {}", jwksUri, responseCode);
throw new KeyProviderException("Not expected response code: " + responseCode);
}

Expand All @@ -112,7 +107,6 @@ private static JwkInfoList toKeyList(InputStream stream) {
try (InputStream inputStream = new BufferedInputStream(stream)) {
return OBJECT_MAPPER.readValue(inputStream, JwkInfoList.class);
} catch (IOException e) {
LOGGER.error("[toKeyList] Exception occurred: {}", e.toString());
throw Exceptions.propagate(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package io.scalecube.security.tokens.jwt;

import io.scalecube.security.tokens.jwt.jsonwebtoken.JsonwebtokenParserFactory;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.security.Key;
import java.time.Duration;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;

public final class JwtTokenResolverImpl implements JwtTokenResolver {

private static final Logger LOGGER = LoggerFactory.getLogger(JwtTokenResolver.class);
private static final Logger LOGGER = System.getLogger(JwtTokenResolver.class.getName());

private KeyProvider keyProvider;
private JwtTokenParserFactory tokenParserFactory = new JsonwebtokenParserFactory();
Expand Down Expand Up @@ -100,7 +100,7 @@ public Mono<Map<String, Object>> resolve(String token) {
String kid = (String) header.get("kid");
Objects.requireNonNull(kid, "kid is missing");

LOGGER.debug("[resolveToken][kid:{}] Resolving token {}", kid, mask(token));
LOGGER.log(Level.DEBUG, "[resolveToken][kid:{0}] Resolving token {1}", kid, mask(token));

// workaround to remove safely on errors
AtomicReference<Mono<Key>> computedValueHolder = new AtomicReference<>();
Expand All @@ -110,13 +110,19 @@ public Mono<Map<String, Object>> resolve(String token) {
.doOnError(throwable -> cleanup(kid, computedValueHolder))
.doOnError(
throwable ->
LOGGER.error(
"[resolveToken][kid:{}][{}] Exception occurred: {}",
LOGGER.log(
Level.ERROR,
"[resolveToken][kid:{0}][{1}] Exception occurred: {2}",
kid,
mask(token),
throwable.toString()))
.doOnSuccess(
s -> LOGGER.debug("[resolveToken][kid:{}] Resolved token {}", kid, mask(token)));
s ->
LOGGER.log(
Level.DEBUG,
"[resolveToken][kid:{0}] Resolved token {1}",
kid,
mask(token)));
});
}

Expand Down
4 changes: 0 additions & 4 deletions vault/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
<groupId>com.bettercloud</groupId>
<artifactId>vault-java-driver</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
Expand All @@ -21,12 +23,10 @@
import java.util.StringJoiner;
import java.util.function.Function;
import java.util.function.Supplier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class VaultServiceRolesInstaller {

private static final Logger LOGGER = LoggerFactory.getLogger(VaultServiceRolesInstaller.class);
private static final Logger LOGGER = System.getLogger(VaultServiceRolesInstaller.class.getName());

private static final String VAULT_TOKEN_HEADER = "X-Vault-Token";

Expand Down Expand Up @@ -58,23 +58,19 @@ private VaultServiceRolesInstaller(Builder builder) {
this.roleTtl = builder.roleTtl;
}

public static Builder builder() {
return new Builder();
}

/**
* Builds vault oidc micro-infrastructure (identity roles and keys) to use it for
* machine-to-machine authentication.
*/
public void install() {
if (isNullOrNoneOrEmpty(vaultAddress)) {
LOGGER.debug("Skipping serviceRoles installation, vaultAddress not set");
LOGGER.log(Level.DEBUG, "Skipping serviceRoles installation, vaultAddress not set");
return;
}

final ServiceRoles serviceRoles = loadServiceRoles();
if (serviceRoles == null || serviceRoles.roles.isEmpty()) {
LOGGER.debug("Skipping serviceRoles installation, serviceRoles not set");
LOGGER.log(Level.DEBUG, "Skipping serviceRoles installation, serviceRoles not set");
return;
}

Expand All @@ -90,7 +86,7 @@ public void install() {
rest.url(buildVaultIdentityRoleUri(roleName)), keyName, roleName, role.permissions);
}

LOGGER.debug("Installed serviceRoles ({})", serviceRoles);
LOGGER.log(Level.DEBUG, "Installed serviceRoles ({0})", serviceRoles);
}

private ServiceRoles loadServiceRoles() {
Expand All @@ -108,15 +104,14 @@ private ServiceRoles loadServiceRoles() {
return null;
}

private static void verifyOk(int status, String operation) {
private static void verifyOk(int status) {
if (status != 200 && status != 204) {
LOGGER.error("Not expected status ({}) returned on [{}]", status, operation);
throw new IllegalStateException("Not expected status returned, status=" + status);
}
}

private void createVaultIdentityKey(Rest rest, String keyName) {
LOGGER.debug("[createVaultIdentityKey] {}", keyName);
LOGGER.log(Level.DEBUG, "[createVaultIdentityKey] {0}", keyName);

byte[] body =
Json.object()
Expand All @@ -128,15 +123,15 @@ private void createVaultIdentityKey(Rest rest, String keyName) {
.getBytes();

try {
verifyOk(rest.body(body).post().getStatus(), "createVaultIdentityKey");
verifyOk(rest.body(body).post().getStatus());
} catch (RestException e) {
throw new RuntimeException(e);
}
}

private void createVaultIdentityRole(
Rest rest, String keyName, String roleName, List<String> permissions) {
LOGGER.debug("[createVaultIdentityRole] {}", roleName);
LOGGER.log(Level.DEBUG, "[createVaultIdentityRole] {0}", roleName);

byte[] body =
Json.object()
Expand All @@ -147,7 +142,7 @@ private void createVaultIdentityRole(
.getBytes();

try {
verifyOk(rest.body(body).post().getStatus(), "createVaultIdentityRole");
verifyOk(rest.body(body).post().getStatus());
} catch (RestException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -352,7 +347,7 @@ public static class Builder {
private String keyVerificationTtl = "1h";
private String roleTtl = "1m";

private Builder() {}
public Builder() {}

public Builder vaultAddress(String vaultAddress) {
this.vaultAddress = vaultAddress;
Expand Down
Loading

0 comments on commit 4c68401

Please sign in to comment.