Skip to content

Commit

Permalink
Updated dependencies (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-v authored Oct 1, 2022
1 parent ae3a81c commit 88f14d8
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 109 deletions.
104 changes: 28 additions & 76 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

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

<artifactId>scalecube-security-parent</artifactId>
Expand Down Expand Up @@ -39,22 +39,22 @@
</modules>

<properties>
<scalecube-config.version>0.4.16</scalecube-config.version>
<scalecube-commons.version>1.0.18</scalecube-commons.version>
<scalecube-config.version>0.4.18</scalecube-config.version>
<scalecube-commons.version>1.0.21</scalecube-commons.version>

<jjwt.version>0.11.2</jjwt.version>
<reactor.version>2020.0.10</reactor.version>
<jackson.version>2.11.0</jackson.version>
<slf4j.version>1.7.30</slf4j.version>
<snakeyaml.version>1.26</snakeyaml.version>
<reactor.version>2020.0.23</reactor.version>
<jackson.version>2.13.3</jackson.version>
<slf4j.version>1.7.36</slf4j.version>

<mockito.version>3.1.0</mockito.version>
<mockito-junit-jupiter.version>4.6.1</mockito-junit-jupiter.version>
<junit-jupiter.version>5.8.2</junit-jupiter.version>
<hamcrest.version>1.3</hamcrest.version>
<junit-jupiter.version>5.4.2</junit-jupiter.version>
<vault-java-driver.version>5.0.0</vault-java-driver.version>
<testcontainers.version>1.15.1</testcontainers.version>
<!-- TODO: remove explicit version of `jna` once testcontainers fixes dependencies conflict -->
<jna.version>5.5.0</jna.version>
<vault-java-driver.version>5.1.0</vault-java-driver.version>
<testcontainers.version>1.17.4</testcontainers.version>

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

<dependencyManagement>
Expand Down Expand Up @@ -85,12 +85,6 @@
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- Yaml -->
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>${snakeyaml.version}</version>
</dependency>
<!-- Jsonwebtoken -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
Expand All @@ -115,18 +109,22 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- TestContainers -->
<!-- Test -->
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>vault</artifactId>
<version>${testcontainers.version}</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>${jna.version}</version>
<scope>test</scope>
<groupId>com.bettercloud</groupId>
<artifactId>vault-java-driver</artifactId>
<version>${vault-java-driver.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- Test scope -->
<!-- Test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand All @@ -140,68 +138,22 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>${hamcrest.version}</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito-junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<artifactId>hamcrest-all</artifactId>
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>deploy2Github</id>
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/scalecube/scalecube-security</url>
</repository>
</distributionManagement>
</profile>
<profile>
<id>deploy2Maven</id>
<distributionManagement>
<repository>
<id>ossrh</id>
<name>Central Repository OSSRH</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-gpg-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
2 changes: 0 additions & 2 deletions tokens/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>vault</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.bettercloud</groupId>
<artifactId>vault-java-driver</artifactId>
<version>${vault-java-driver.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public JwksKeyProvider readTimeout(Duration readTimeout) {
public Mono<Key> findKey(String kid) {
return computeKey(kid)
.switchIfEmpty(Mono.error(new KeyNotFoundException("Key was not found, kid: " + kid)))
.doOnSubscribe(s -> LOGGER.debug("[findKey] Looking up key in jwks, kid: {}", kid))
.subscribeOn(Schedulers.boundedElastic())
.publishOn(Schedulers.boundedElastic());
}
Expand Down
4 changes: 2 additions & 2 deletions vault/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public VaultClientTokenSupplier vaultRole(String vaultRole) {
public Mono<String> getToken() {
return Mono.fromRunnable(this::validate)
.then(Mono.fromCallable(this::getToken0))
.doOnSubscribe(s -> LOGGER.debug("[getToken] Getting vault client token"))
.doOnSuccess(s -> LOGGER.debug("[getToken][success] result: {}", mask(s)))
.doOnError(th -> LOGGER.error("[getToken][error] cause: {}", th.toString()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import com.bettercloud.vault.json.Json;
import com.bettercloud.vault.rest.Rest;
import com.bettercloud.vault.rest.RestException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.scalecube.security.vault.VaultServiceRolesInstaller.ServiceRoles.Role;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
Expand All @@ -17,8 +21,6 @@
import java.util.function.Supplier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
import reactor.core.Exceptions;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
Expand All @@ -32,6 +34,8 @@ public final class VaultServiceRolesInstaller {
private static final List<Supplier<ServiceRoles>> DEFAULT_SERVICE_ROLES_SOURCES =
Collections.singletonList(new ResourcesServiceRolesSupplier());

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(new YAMLFactory());

private String vaultAddress;
private Mono<String> vaultTokenSupplier;
private Supplier<String> keyNameSupplier;
Expand Down Expand Up @@ -189,23 +193,18 @@ public VaultServiceRolesInstaller roleTtl(String roleTtl) {
public Mono<Void> install() {
return Mono.defer(this::install0)
.subscribeOn(Schedulers.boundedElastic())
.doOnSubscribe(s -> LOGGER.debug("[install] Installing vault service roles"))
.doOnSuccess(s -> LOGGER.debug("[install][success] Installed vault service roles"))
.doOnError(
th ->
LOGGER.error(
"[install][error] Failed to install vault service roles, cause: {}",
th.toString()))
.then();
.doOnError(th -> LOGGER.error("Failed to install serviceRoles, cause: {}", th.toString()));
}

private Mono<Void> install0() {
if (isNullOrNoneOrEmpty(vaultAddress)) {
LOGGER.debug("Skipping serviceRoles installation, vaultAddress not set");
return Mono.empty();
}

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

Expand All @@ -214,7 +213,7 @@ private Mono<Void> install0() {
token -> {
final Rest rest = new Rest().header(VAULT_TOKEN_HEADER, token);

String keyName = keyNameSupplier.get();
final String keyName = keyNameSupplier.get();
createVaultIdentityKey(rest.url(buildVaultIdentityKeyUri(keyName)), keyName);

for (Role role : serviceRoles.roles) {
Expand All @@ -226,6 +225,7 @@ private Mono<Void> install0() {
role.permissions);
}
})
.doOnSuccess(s -> LOGGER.debug("Installed serviceRoles ({})", serviceRoles))
.then();
}

Expand All @@ -242,7 +242,7 @@ private ServiceRoles loadServiceRoles() {
}
} catch (Throwable th) {
LOGGER.warn(
"Fail to load ServiceRoles from {}, cause {}", serviceRolesSource, th.getMessage());
"Failed to load serviceRoles from {}, cause {}", serviceRolesSource, th.getMessage());
}
}

Expand Down Expand Up @@ -333,6 +333,13 @@ public void setRoles(List<Role> roles) {
this.roles = roles;
}

@Override
public String toString() {
return new StringJoiner(", ", ServiceRoles.class.getSimpleName() + "[", "]")
.add("roles=" + roles)
.toString();
}

public static class Role {

private String role;
Expand All @@ -353,6 +360,14 @@ public List<String> getPermissions() {
public void setPermissions(List<String> permissions) {
this.permissions = permissions;
}

@Override
public String toString() {
return new StringJoiner(", ", Role.class.getSimpleName() + "[", "]")
.add("role='" + role + "'")
.add("permissions=" + permissions)
.toString();
}
}
}

Expand All @@ -372,11 +387,15 @@ public ResourcesServiceRolesSupplier(String fileName) {

@Override
public ServiceRoles get() {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream inputStream = classLoader.getResourceAsStream(fileName);
return inputStream != null
? new Yaml(new Constructor(ServiceRoles.class)).load(inputStream)
: null;
try {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream inputStream = classLoader.getResourceAsStream(fileName);
return inputStream != null
? OBJECT_MAPPER.readValue(inputStream, ServiceRoles.class)
: null;
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Override
Expand All @@ -403,8 +422,14 @@ public EnvironmentServiceRolesSupplier(String envKey) {

@Override
public ServiceRoles get() {
final String value = System.getenv(envKey);
return value != null ? new Yaml(new Constructor(ServiceRoles.class)).load(value) : null;
try {
final String value = System.getenv(envKey);
return value != null
? OBJECT_MAPPER.readValue(new StringReader(value), ServiceRoles.class)
: null;
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Override
Expand Down Expand Up @@ -435,7 +460,7 @@ public ServiceRoles get() {
try {
final File file = new File(this.file);
return file.exists()
? new Yaml(new Constructor(ServiceRoles.class)).load(new FileInputStream(file))
? OBJECT_MAPPER.readValue(new FileInputStream(file), ServiceRoles.class)
: null;
} catch (Exception e) {
throw Exceptions.propagate(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,6 @@ public Mono<String> getToken(Map<String, String> tags) {
vaultToken -> {
final String uri = buildServiceTokenUri(tags);
return Mono.fromCallable(() -> rpcGetToken(uri, vaultToken))
.doOnSubscribe(
s ->
LOGGER.debug(
"[getToken] Getting vault service token, uri='{}', tags={}",
uri,
tags))
.doOnSuccess(
s ->
LOGGER.debug(
Expand All @@ -134,7 +128,7 @@ public Mono<String> getToken(Map<String, String> tags) {
});
}

private String rpcGetToken(String uri, String vaultToken) {
private static String rpcGetToken(String uri, String vaultToken) {
try {
final RestResponse response =
new Rest().header(VAULT_TOKEN_HEADER, vaultToken).url(uri).get();
Expand Down

0 comments on commit 88f14d8

Please sign in to comment.