Applied checkstyle rules

This commit is contained in:
Marcin Grzejszczak
2019-02-07 11:25:07 +01:00
parent c70c70e32d
commit c8a772e5ba
45 changed files with 1101 additions and 613 deletions

View File

@@ -14,3 +14,11 @@ continuation_indent_size = 8
indent_style = tab
indent_size = 4
continuation_indent_size = 8
[*.yml]
indent_style = space
indent_size = 2
[*.yaml]
indent_style = space
indent_size = 2

View File

@@ -10,7 +10,9 @@
<profiles>
<profile>
<id>spring</id>
<activation><activeByDefault>true</activeByDefault></activation>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>spring-snapshots</id>

View File

@@ -9,10 +9,10 @@ services:
addons:
apt:
sources:
- mongodb-3.0-precise
- mongodb-3.0-precise
packages:
- mongodb-org-server
- mongodb-org-shell
- mongodb-org-server
- mongodb-org-shell
jdk:
- oraclejdk8

View File

@@ -1,5 +1,7 @@
<?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/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,6 @@
<?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"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -47,8 +48,10 @@
<netty.version>4.1.30.Final</netty.version>
<okhttp3.version>3.10.0</okhttp3.version>
<google-api-services-iam.version>v1-rev259-1.25.0</google-api-services-iam.version>
<google-auth-library-oauth2-http.version>0.10.0</google-auth-library-oauth2-http.version>
<google-api-services-iam.version>v1-rev259-1.25.0
</google-api-services-iam.version>
<google-auth-library-oauth2-http.version>0.10.0
</google-auth-library-oauth2-http.version>
</properties>
<dependencyManagement>

View File

@@ -1,5 +1,7 @@
<?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/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>

View File

@@ -1,5 +1,7 @@
<?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/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>

View File

@@ -52,17 +52,6 @@ public class VaultConfigAwsBootstrapConfiguration {
public static class AwsSecretBackendMetadataFactory
implements SecretBackendMetadataFactory<VaultAwsProperties> {
@Override
public SecretBackendMetadata createMetadata(
VaultAwsProperties backendDescriptor) {
return forAws(backendDescriptor);
}
@Override
public boolean supports(VaultSecretBackendDescriptor backendDescriptor) {
return backendDescriptor instanceof VaultAwsProperties;
}
/**
* Creates {@link SecretBackendMetadata} for a secret backend using
* {@link VaultAwsProperties}. This accessor transforms Vault's username/password
@@ -114,6 +103,17 @@ public class VaultConfigAwsBootstrapConfiguration {
};
}
@Override
public SecretBackendMetadata createMetadata(
VaultAwsProperties backendDescriptor) {
return forAws(backendDescriptor);
}
@Override
public boolean supports(VaultSecretBackendDescriptor backendDescriptor) {
return backendDescriptor instanceof VaultAwsProperties;
}
}
}

View File

@@ -63,6 +63,12 @@ public class VaultConfigAwsTests {
private static final String ARN = "arn:aws:iam::aws:policy/ReadOnlyAccess";
@Value("${cloud.aws.credentials.accessKey}")
String accessKey;
@Value("${cloud.aws.credentials.secretKey}")
String secretKey;
/**
* Initialize the aws secret backend.
*/
@@ -91,12 +97,6 @@ public class VaultConfigAwsTests {
vaultOperations.write("aws/roles/readonly", Collections.singletonMap("arn", ARN));
}
@Value("${cloud.aws.credentials.accessKey}")
String accessKey;
@Value("${cloud.aws.credentials.secretKey}")
String secretKey;
@Test
public void shouldInitializeAwsProperties() {

View File

@@ -1,5 +1,7 @@
<?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/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>

View File

@@ -52,17 +52,6 @@ public class VaultConfigConsulBootstrapConfiguration {
public static class ConsulSecretBackendMetadataFactory
implements SecretBackendMetadataFactory<VaultConsulProperties> {
@Override
public SecretBackendMetadata createMetadata(
VaultConsulProperties backendDescriptor) {
return forConsul(backendDescriptor);
}
@Override
public boolean supports(VaultSecretBackendDescriptor backendDescriptor) {
return backendDescriptor instanceof VaultConsulProperties;
}
/**
* Creates a {@link SecretBackendMetadata} for a secret backend using
* {@link VaultConsulProperties}. This accessor transforms Vault's token property
@@ -109,6 +98,17 @@ public class VaultConfigConsulBootstrapConfiguration {
};
}
@Override
public SecretBackendMetadata createMetadata(
VaultConsulProperties backendDescriptor) {
return forConsul(backendDescriptor);
}
@Override
public boolean supports(VaultSecretBackendDescriptor backendDescriptor) {
return backendDescriptor instanceof VaultConsulProperties;
}
}
}

View File

@@ -74,6 +74,9 @@ public class VaultConfigConsulTests {
private static final ParameterizedTypeReference<Map<String, String>> STRING_MAP = new ParameterizedTypeReference<Map<String, String>>() {
};
@Value("${spring.cloud.consul.token}")
String token;
/**
* Initialize the consul secret backend.
*/
@@ -120,9 +123,6 @@ public class VaultConfigConsulTests {
}
}
@Value("${spring.cloud.consul.token}")
String token;
@Test
public void shouldHaveToken() {
assertThat(this.token).isNotEmpty();

View File

@@ -1,5 +1,7 @@
<?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/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>

View File

@@ -56,17 +56,6 @@ public class VaultConfigDatabaseBootstrapConfiguration {
public static class DatabaseSecretBackendMetadataFactory
implements SecretBackendMetadataFactory<DatabaseSecretProperties> {
@Override
public SecretBackendMetadata createMetadata(
DatabaseSecretProperties backendDescriptor) {
return forDatabase(backendDescriptor);
}
@Override
public boolean supports(VaultSecretBackendDescriptor backendDescriptor) {
return backendDescriptor instanceof DatabaseSecretProperties;
}
/**
* Creates a {@link SecretBackendMetadata} for a secret backend using
* {@link DatabaseSecretProperties}. This accessor transforms Vault's
@@ -117,6 +106,17 @@ public class VaultConfigDatabaseBootstrapConfiguration {
};
}
@Override
public SecretBackendMetadata createMetadata(
DatabaseSecretProperties backendDescriptor) {
return forDatabase(backendDescriptor);
}
@Override
public boolean supports(VaultSecretBackendDescriptor backendDescriptor) {
return backendDescriptor instanceof DatabaseSecretProperties;
}
}
}

View File

@@ -66,6 +66,15 @@ public class VaultConfigCassandraTests {
private static final String CREATE_USER_AND_GRANT_CQL = "CREATE USER '{{username}}' WITH PASSWORD '{{password}}' NOSUPERUSER;"
+ "GRANT SELECT ON ALL KEYSPACES TO {{username}};";
@Value("${spring.data.cassandra.username}")
String username;
@Value("${spring.data.cassandra.password}")
String password;
@Autowired
Cluster cluster;
/**
* Initialize the cassandra secret backend.
*/
@@ -99,15 +108,6 @@ public class VaultConfigCassandraTests {
vaultOperations.write("cassandra/roles/readonly", role);
}
@Value("${spring.data.cassandra.username}")
String username;
@Value("${spring.data.cassandra.password}")
String password;
@Autowired
Cluster cluster;
@Test
public void shouldConnectUsingCluster() {
this.cluster.connect().close();

View File

@@ -69,6 +69,15 @@ public class VaultConfigMongoTests {
private static final String ROLES = "[ \"readWrite\", { \"role\": \"read\", \"db\": \"admin\" } ]";
@Value("${spring.data.mongodb.username}")
String username;
@Value("${spring.data.mongodb.password}")
String password;
@Autowired
MongoClient mongoClient;
/**
* Initialize the mongo secret backend.
*/
@@ -99,15 +108,6 @@ public class VaultConfigMongoTests {
vaultOperations.write("mongodb/roles/readonly", role);
}
@Value("${spring.data.mongodb.username}")
String username;
@Value("${spring.data.mongodb.password}")
String password;
@Autowired
MongoClient mongoClient;
@Test
public void shouldConnectUsingDataSource() {

View File

@@ -67,6 +67,15 @@ public class VaultConfigMySqlDatabaseTests {
private static final String CREATE_USER_AND_GRANT_SQL = "CREATE USER '{{name}}'@'%' IDENTIFIED BY '{{password}}';"
+ "GRANT SELECT ON *.* TO '{{name}}'@'%';";
@Value("${spring.datasource.username}")
String username;
@Value("${spring.datasource.password}")
String password;
@Autowired
DataSource dataSource;
/**
* Initialize the mysql secret backend.
*/
@@ -100,15 +109,6 @@ public class VaultConfigMySqlDatabaseTests {
vaultOperations.write("database/roles/readonly", body);
}
@Value("${spring.datasource.username}")
String username;
@Value("${spring.datasource.password}")
String password;
@Autowired
DataSource dataSource;
@Test
public void shouldConnectUsingDataSource() throws SQLException {

View File

@@ -64,6 +64,15 @@ public class VaultConfigMySqlTests {
private static final String CREATE_USER_AND_GRANT_SQL = "CREATE USER '{{name}}'@'%' IDENTIFIED BY '{{password}}';"
+ "GRANT SELECT ON *.* TO '{{name}}'@'%';";
@Value("${spring.datasource.username}")
String username;
@Value("${spring.datasource.password}")
String password;
@Autowired
DataSource dataSource;
/**
* Initialize the mysql secret backend.
*/
@@ -88,15 +97,6 @@ public class VaultConfigMySqlTests {
Collections.singletonMap("sql", CREATE_USER_AND_GRANT_SQL));
}
@Value("${spring.datasource.username}")
String username;
@Value("${spring.datasource.password}")
String password;
@Autowired
DataSource dataSource;
@Test
public void shouldConnectUsingDataSource() throws SQLException {

View File

@@ -69,6 +69,15 @@ public class VaultConfigPostgreSqlTests {
+ "LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}';\n"
+ "GRANT SELECT ON ALL TABLES IN SCHEMA public TO \"{{name}}\";";
@Value("${spring.datasource.username}")
String username;
@Value("${spring.datasource.password}")
String password;
@Autowired
DataSource dataSource;
/**
* Initialize the postgresql secret backend.
*/
@@ -93,15 +102,6 @@ public class VaultConfigPostgreSqlTests {
Collections.singletonMap("sql", CREATE_USER_AND_GRANT_SQL));
}
@Value("${spring.datasource.username}")
String username;
@Value("${spring.datasource.password}")
String password;
@Autowired
DataSource dataSource;
@Test
public void shouldConnectUsingDataSource() throws SQLException {

View File

@@ -293,15 +293,15 @@ commitlog_segment_size_in_mb: 32
# any class that implements the SeedProvider interface and has a
# constructor that takes a Map<String, String> of parameters will do.
seed_provider:
# Addresses of hosts that are deemed contact points.
# Cassandra nodes use this list of hosts to find each other and learn
# the topology of the ring. You must change this if you are running
# multiple nodes!
- class_name: org.apache.cassandra.locator.SimpleSeedProvider
parameters:
# seeds is actually a comma-delimited list of addresses.
# Ex: "<ip1>,<ip2>,<ip3>"
- seeds: "127.0.0.1"
# Addresses of hosts that are deemed contact points.
# Cassandra nodes use this list of hosts to find each other and learn
# the topology of the ring. You must change this if you are running
# multiple nodes!
- class_name: org.apache.cassandra.locator.SimpleSeedProvider
parameters:
# seeds is actually a comma-delimited list of addresses.
# Ex: "<ip1>,<ip2>,<ip3>"
- seeds: "127.0.0.1"
# For workloads with more data than can fit in memory, Cassandra's
# bottleneck will be reads that need to fetch data from
@@ -741,7 +741,7 @@ endpoint_snitch: SimpleSnitch
# controls how often to perform the more expensive part of host score
# calculation
dynamic_snitch_update_interval_in_ms: 100
dynamic_snitch_update_interval_in_ms: 100
# controls how often to reset all host scores, allowing a bad host to
# possibly recover
dynamic_snitch_reset_interval_in_ms: 600000
@@ -810,34 +810,34 @@ request_scheduler: org.apache.cassandra.scheduler.NoScheduler
# http://download.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#CreateKeystore
#
server_encryption_options:
internode_encryption: none
keystore: conf/.keystore
keystore_password: cassandra
truststore: conf/.truststore
truststore_password: cassandra
# More advanced defaults below:
# protocol: TLS
# algorithm: SunX509
# store_type: JKS
# cipher_suites: [TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA,TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]
# require_client_auth: false
internode_encryption: none
keystore: conf/.keystore
keystore_password: cassandra
truststore: conf/.truststore
truststore_password: cassandra
# More advanced defaults below:
# protocol: TLS
# algorithm: SunX509
# store_type: JKS
# cipher_suites: [TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA,TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]
# require_client_auth: false
# enable or disable client/server encryption.
client_encryption_options:
enabled: false
# If enabled and optional is set to true encrypted and unencrypted connections are handled.
optional: false
keystore: conf/.keystore
keystore_password: cassandra
# require_client_auth: false
# Set trustore and truststore_password if require_client_auth is true
# truststore: conf/.truststore
# truststore_password: cassandra
# More advanced defaults below:
# protocol: TLS
# algorithm: SunX509
# store_type: JKS
# cipher_suites: [TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA,TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]
enabled: false
# If enabled and optional is set to true encrypted and unencrypted connections are handled.
optional: false
keystore: conf/.keystore
keystore_password: cassandra
# require_client_auth: false
# Set trustore and truststore_password if require_client_auth is true
# truststore: conf/.truststore
# truststore_password: cassandra
# More advanced defaults below:
# protocol: TLS
# algorithm: SunX509
# store_type: JKS
# cipher_suites: [TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA,TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]
# internode_compression controls whether traffic between nodes is
# compressed.

View File

@@ -1,5 +1,7 @@
<?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/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>

View File

@@ -57,17 +57,6 @@ public class VaultConfigRabbitMqBootstrapConfiguration {
public static class RabbitMqSecretBackendMetadataFactory
implements SecretBackendMetadataFactory<VaultRabbitMqProperties> {
@Override
public SecretBackendMetadata createMetadata(
VaultRabbitMqProperties backendDescriptor) {
return forRabbitMq(backendDescriptor);
}
@Override
public boolean supports(VaultSecretBackendDescriptor backendDescriptor) {
return backendDescriptor instanceof VaultRabbitMqProperties;
}
/**
* Creates a {@link SecretBackendMetadata} for a secret backend using
* {@link VaultRabbitMqProperties}. This accessor transforms Vault's
@@ -120,6 +109,17 @@ public class VaultConfigRabbitMqBootstrapConfiguration {
};
}
@Override
public SecretBackendMetadata createMetadata(
VaultRabbitMqProperties backendDescriptor) {
return forRabbitMq(backendDescriptor);
}
@Override
public boolean supports(VaultSecretBackendDescriptor backendDescriptor) {
return backendDescriptor instanceof VaultRabbitMqProperties;
}
}
}

View File

@@ -70,6 +70,15 @@ public class VaultConfigRabbitMqTests {
private static final String VHOSTS_ROLE = "{\"/\":{\"write\": \".*\", \"read\": \".*\"}}";
@Value("${spring.rabbitmq.username}")
String username;
@Value("${spring.rabbitmq.password}")
String password;
@Autowired
org.springframework.amqp.rabbit.connection.ConnectionFactory connectionFactory;
/**
* Initialize the rabbitmq secret backend.
*/
@@ -102,15 +111,6 @@ public class VaultConfigRabbitMqTests {
Collections.singletonMap("vhosts", VHOSTS_ROLE));
}
@Value("${spring.rabbitmq.username}")
String username;
@Value("${spring.rabbitmq.password}")
String password;
@Autowired
org.springframework.amqp.rabbit.connection.ConnectionFactory connectionFactory;
@Test
public void shouldConnectSpringConnectionFactory() {
this.connectionFactory.createConnection().close();

View File

@@ -1,5 +1,7 @@
<?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/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>

View File

@@ -94,6 +94,65 @@ class ClientAuthenticationFactory {
private final RestOperations externalRestOperations;
static AppRoleAuthenticationOptions getAppRoleAuthenticationOptions(
VaultProperties vaultProperties) {
AppRoleProperties appRole = vaultProperties.getAppRole();
AppRoleAuthenticationOptionsBuilder builder = AppRoleAuthenticationOptions
.builder().path(appRole.getAppRolePath());
if (StringUtils.hasText(appRole.getRole())) {
builder.appRole(appRole.getRole());
}
RoleId roleId = getRoleId(vaultProperties, appRole);
SecretId secretId = getSecretId(vaultProperties, appRole);
builder.roleId(roleId).secretId(secretId);
return builder.build();
}
private static RoleId getRoleId(VaultProperties vaultProperties,
AppRoleProperties appRole) {
if (StringUtils.hasText(appRole.getRoleId())) {
return RoleId.provided(appRole.getRoleId());
}
if (StringUtils.hasText(vaultProperties.getToken())
&& StringUtils.hasText(appRole.getRole())) {
return RoleId.pull(VaultToken.of(vaultProperties.getToken()));
}
if (StringUtils.hasText(vaultProperties.getToken())) {
return RoleId.wrapped(VaultToken.of(vaultProperties.getToken()));
}
throw new IllegalArgumentException(
"Cannot configure RoleId. Any of role-id, initial token, or initial toke and role name must be configured.");
}
private static SecretId getSecretId(VaultProperties vaultProperties,
AppRoleProperties appRole) {
if (StringUtils.hasText(appRole.getSecretId())) {
return SecretId.provided(appRole.getSecretId());
}
if (StringUtils.hasText(vaultProperties.getToken())
&& StringUtils.hasText(appRole.getRole())) {
return SecretId.pull(VaultToken.of(vaultProperties.getToken()));
}
if (StringUtils.hasText(vaultProperties.getToken())) {
return SecretId.wrapped(VaultToken.of(vaultProperties.getToken()));
}
return SecretId.absent();
}
/**
* @return a new {@link ClientAuthentication}.
*/
@@ -197,65 +256,6 @@ class ClientAuthenticationFactory {
return new AppRoleAuthentication(options, this.restOperations);
}
static AppRoleAuthenticationOptions getAppRoleAuthenticationOptions(
VaultProperties vaultProperties) {
AppRoleProperties appRole = vaultProperties.getAppRole();
AppRoleAuthenticationOptionsBuilder builder = AppRoleAuthenticationOptions
.builder().path(appRole.getAppRolePath());
if (StringUtils.hasText(appRole.getRole())) {
builder.appRole(appRole.getRole());
}
RoleId roleId = getRoleId(vaultProperties, appRole);
SecretId secretId = getSecretId(vaultProperties, appRole);
builder.roleId(roleId).secretId(secretId);
return builder.build();
}
private static RoleId getRoleId(VaultProperties vaultProperties,
AppRoleProperties appRole) {
if (StringUtils.hasText(appRole.getRoleId())) {
return RoleId.provided(appRole.getRoleId());
}
if (StringUtils.hasText(vaultProperties.getToken())
&& StringUtils.hasText(appRole.getRole())) {
return RoleId.pull(VaultToken.of(vaultProperties.getToken()));
}
if (StringUtils.hasText(vaultProperties.getToken())) {
return RoleId.wrapped(VaultToken.of(vaultProperties.getToken()));
}
throw new IllegalArgumentException(
"Cannot configure RoleId. Any of role-id, initial token, or initial toke and role name must be configured.");
}
private static SecretId getSecretId(VaultProperties vaultProperties,
AppRoleProperties appRole) {
if (StringUtils.hasText(appRole.getSecretId())) {
return SecretId.provided(appRole.getSecretId());
}
if (StringUtils.hasText(vaultProperties.getToken())
&& StringUtils.hasText(appRole.getRole())) {
return SecretId.pull(VaultToken.of(vaultProperties.getToken()));
}
if (StringUtils.hasText(vaultProperties.getToken())) {
return SecretId.wrapped(VaultToken.of(vaultProperties.getToken()));
}
return SecretId.absent();
}
private ClientAuthentication awsEc2Authentication(VaultProperties vaultProperties) {
VaultProperties.AwsEc2Properties awsEc2 = vaultProperties.getAwsEc2();

View File

@@ -102,16 +102,6 @@ public class KeyValueSecretBackendMetadata extends SecretBackendMetadataSupport
return new KeyValueSecretBackendMetadata(path, propertyTransformer);
}
@Override
public String getPath() {
return this.path;
}
@Override
public PropertyTransformer getPropertyTransformer() {
return this.propertyTransformer;
}
/**
* Build a list of context paths from application name and the active profile names.
* Application name and profiles support multiple (comma-separated) values.
@@ -180,6 +170,16 @@ public class KeyValueSecretBackendMetadata extends SecretBackendMetadataSupport
return contexts;
}
@Override
public String getPath() {
return this.path;
}
@Override
public PropertyTransformer getPropertyTransformer() {
return this.propertyTransformer;
}
/**
* {@link PropertyTransformer} that strips a prefix from property names.
*/

View File

@@ -31,6 +31,10 @@ import lombok.extern.apachecommons.CommonsLog;
@CommonsLog
final class SecretBackendFactories {
private SecretBackendFactories() {
}
static Collection<SecretBackendMetadata> createSecretBackendMetadata(
Collection<VaultSecretBackendDescriptor> vaultSecretBackendDescriptors,
Collection<SecretBackendMetadataFactory<? super VaultSecretBackendDescriptor>> factories) {
@@ -73,8 +77,4 @@ final class SecretBackendFactories {
return accessor;
}
private SecretBackendFactories() {
}
}

View File

@@ -32,6 +32,10 @@ import org.springframework.vault.support.SslConfiguration.KeyStoreConfiguration;
*/
final class VaultConfigurationUtil {
private VaultConfigurationUtil() {
}
/**
* Create a {@link SslConfiguration} given {@link Ssl SSL properties}.
* @param ssl the SSL properties.
@@ -89,8 +93,4 @@ final class VaultConfigurationUtil {
return vaultEndpoint;
}
private VaultConfigurationUtil() {
}
}

View File

@@ -130,6 +130,15 @@ public class VaultProperties implements EnvironmentAware {
}
}
/**
* Enumeration of authentication methods.
*/
public enum AuthenticationMethod {
TOKEN, APPID, APPROLE, AWS_EC2, AWS_IAM, AZURE_MSI, CERT, CUBBYHOLE, GCP_GCE, GCP_IAM, KUBERNETES
}
/**
* Discovery properties.
*/
@@ -329,6 +338,11 @@ public class VaultProperties implements EnvironmentAware {
@Data
public static class GcpIamProperties {
/**
* Credentials configuration.
*/
private final GcpCredentials credentials = new GcpCredentials();
/**
* Mount path of the Kubernetes authentication backend.
*/
@@ -355,11 +369,6 @@ public class VaultProperties implements EnvironmentAware {
*/
private Duration jwtValidity = Duration.ofMinutes(15);
/**
* Credentials configuration.
*/
private final GcpCredentials credentials = new GcpCredentials();
}
/**
@@ -476,13 +485,4 @@ public class VaultProperties implements EnvironmentAware {
}
/**
* Enumeration of authentication methods.
*/
public enum AuthenticationMethod {
TOKEN, APPID, APPROLE, AWS_EC2, AWS_IAM, AZURE_MSI, CERT, CUBBYHOLE, GCP_GCE, GCP_IAM, KUBERNETES
}
}

View File

@@ -47,17 +47,6 @@ public class VaultReactiveHealthIndicator extends AbstractReactiveHealthIndicato
this.vaultOperations = vaultOperations;
}
@Override
protected Mono<Health> doHealthCheck(Builder builder) {
return this.vaultOperations
.doWithSession((it) -> it.get().uri("sys/health").exchange())
.flatMap((it) -> it.bodyToMono(VaultHealthImpl.class))
.onErrorResume(WebClientResponseException.class,
VaultReactiveHealthIndicator::deserializeError)
.map((vaultHealthResponse) -> getHealth(builder, vaultHealthResponse));
}
private static Mono<? extends VaultHealthImpl> deserializeError(
WebClientResponseException e) {
@@ -99,6 +88,17 @@ public class VaultReactiveHealthIndicator extends AbstractReactiveHealthIndicato
return builder.build();
}
@Override
protected Mono<Health> doHealthCheck(Builder builder) {
return this.vaultOperations
.doWithSession((it) -> it.get().uri("sys/health").exchange())
.flatMap((it) -> it.bodyToMono(VaultHealthImpl.class))
.onErrorResume(WebClientResponseException.class,
VaultReactiveHealthIndicator::deserializeError)
.map((vaultHealthResponse) -> getHealth(builder, vaultHealthResponse));
}
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
private static final class VaultHealthImpl implements VaultHealth {

View File

@@ -50,6 +50,9 @@ import static org.assertj.core.api.Assertions.assertThat;
"spring.cloud.vault.host=foo", "spring.cloud.vault.uri=https://localhost:8200", })
public class ReactiveVaultOperationsTests {
@Autowired
ReactiveVaultOperations reactiveOperations;
@BeforeClass
public static void beforeClass() {
@@ -63,9 +66,6 @@ public class ReactiveVaultOperationsTests {
vaultRule.prepare().getVaultOperations().write("secret/testVaultApp", object);
}
@Autowired
ReactiveVaultOperations reactiveOperations;
@Test
public void shouldAccessVault() {

View File

@@ -56,6 +56,9 @@ import static org.assertj.core.api.Assertions.assertThat;
"spring.main.allow-bean-definition-overriding=true" })
public class VaultConfigAppIdCustomMechanismTests {
@Value("${vault.value}")
String configValue;
@BeforeClass
public static void beforeClass() {
@@ -102,9 +105,6 @@ public class VaultConfigAppIdCustomMechanismTests {
userIdData);
}
@Value("${vault.value}")
String configValue;
@Test
public void contextLoads() {
assertThat(this.configValue).isEqualTo(getClass().getSimpleName());

View File

@@ -55,6 +55,9 @@ import static org.assertj.core.api.Assertions.assertThat;
// https://github.com/spring-cloud/spring-cloud-commons/issues/214
public class VaultConfigAppIdTests {
@Value("${vault.value}")
String configValue;
@BeforeClass
public static void beforeClass() {
@@ -102,9 +105,6 @@ public class VaultConfigAppIdTests {
userIdData);
}
@Value("${vault.value}")
String configValue;
@Test
public void contextLoads() {
assertThat(this.configValue).isEqualTo("foo");

View File

@@ -55,6 +55,9 @@ import static org.junit.Assume.assumeTrue;
// https://github.com/spring-cloud/spring-cloud-commons/issues/214
public class VaultConfigAppRoleTests {
@Value("${vault.value}")
String configValue;
@BeforeClass
public static void beforeClass() {
@@ -106,9 +109,6 @@ public class VaultConfigAppRoleTests {
}
@Value("${vault.value}")
String configValue;
@Test
public void contextLoads() {
assertThat(this.configValue).isEqualTo("foo");

View File

@@ -54,6 +54,9 @@ import static org.junit.Assume.assumeTrue;
"spring.cloud.vault.generic.applicationName=VaultConfigCubbyholeAuthenticationTests" })
public class VaultConfigCubbyholeAuthenticationTests {
@Value("${vault.value}")
String configValue;
@BeforeClass
public static void beforeClass() {
@@ -88,9 +91,6 @@ public class VaultConfigCubbyholeAuthenticationTests {
System.clearProperty("spring.cloud.vault.token");
}
@Value("${vault.value}")
String configValue;
@Test
public void contextLoads() {
assertThat(this.configValue).isEqualTo(getClass().getSimpleName());

View File

@@ -48,6 +48,12 @@ import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(classes = VaultConfigDisabledTests.TestApplication.class, properties = "spring.cloud.vault.enabled=false")
public class VaultConfigDisabledTests {
@Autowired
Environment environment;
@Autowired
ApplicationContext applicationContext;
@BeforeClass
public static void beforeClass() {
@@ -58,12 +64,6 @@ public class VaultConfigDisabledTests {
Collections.singletonMap("vault.value", "foo"));
}
@Autowired
Environment environment;
@Autowired
ApplicationContext applicationContext;
@Test
public void shouldNotContainVaultProperties() {
assertThat(this.environment.containsProperty("vault.value")).isFalse();

View File

@@ -46,6 +46,9 @@ import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(classes = VaultConfigGenericBackendDisabledTests.TestApplication.class, properties = "spring.cloud.vault.generic.enabled=false")
public class VaultConfigGenericBackendDisabledTests {
@Autowired
Environment environment;
@BeforeClass
public static void beforeClass() {
@@ -56,9 +59,6 @@ public class VaultConfigGenericBackendDisabledTests {
Collections.singletonMap("vault.value", "foo"));
}
@Autowired
Environment environment;
@Test
public void shouldNotContainVaultProperties() {
assertThat(this.environment.containsProperty("vault.value")).isFalse();

View File

@@ -58,6 +58,15 @@ import static org.assertj.core.api.Assertions.assertThat;
// https://github.com/spring-cloud/spring-cloud-commons/issues/214
public class VaultConfigTests {
@Value("${vault.value}")
String configValue;
@Autowired
Environment environment;
@Autowired
ApplicationContext applicationContext;
@BeforeClass
public static void beforeClass() {
@@ -71,15 +80,6 @@ public class VaultConfigTests {
vaultRule.prepare().getVaultOperations().write("secret/testVaultApp", object);
}
@Value("${vault.value}")
String configValue;
@Autowired
Environment environment;
@Autowired
ApplicationContext applicationContext;
@Test
public void contextLoads() {
assertThat(this.configValue).isEqualTo("foo");

View File

@@ -56,6 +56,9 @@ import static org.springframework.cloud.vault.util.Settings.findWorkDir;
"spring.cloud.vault.reactive.enabled=false" })
public class VaultConfigTlsCertAuthenticationTests {
@Value("${vault.value}")
String configValue;
@BeforeClass
public static void beforeClass() {
@@ -95,9 +98,6 @@ public class VaultConfigTlsCertAuthenticationTests {
vaultOperations.write("auth/cert/certs/my-role", role);
}
@Value("${vault.value}")
String configValue;
@Test
public void contextLoads() {
assertThat(this.configValue).isEqualTo("foo");

View File

@@ -50,6 +50,9 @@ import static org.assertj.core.api.Assertions.assertThat;
@ActiveProfiles("my-profile")
public class VaultConfigWithContextTests {
@Value("${vault.value}")
String configValue;
@BeforeClass
public static void beforeClass() {
@@ -65,9 +68,6 @@ public class VaultConfigWithContextTests {
Collections.singletonMap("vault.value", "world"));
}
@Value("${vault.value}")
String configValue;
@Test
public void contextLoads() {
assertThat(this.configValue).isEqualTo("hello");

View File

@@ -48,6 +48,9 @@ import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(classes = VaultConfigWithVaultConfigurerTests.TestApplication.class, properties = "VaultConfigWithVaultConfigurerTests.custom.config=true")
public class VaultConfigWithVaultConfigurerTests {
@Value("${vault.value}")
String configValue;
@BeforeClass
public static void beforeClass() {
@@ -63,9 +66,6 @@ public class VaultConfigWithVaultConfigurerTests {
Collections.singletonMap("vault.value", "world"));
}
@Value("${vault.value}")
String configValue;
@Test
public void contextLoads() {
assertThat(this.configValue).isEqualTo("hello");

View File

@@ -47,10 +47,11 @@ import static org.assertj.core.api.Assertions.assertThat;
@ActiveProfiles({ "integrationtest" })
public class VaultPropertySourceLocatorIntegrationTests extends IntegrationTestSupport {
@SpringBootApplication
public static class TestApplication {
@Value("${vault.value}")
String configValue;
}
@Value("${icebreaker.value}")
String additionalValue;
@BeforeClass
public static void beforeClass() {
@@ -76,12 +77,6 @@ public class VaultPropertySourceLocatorIntegrationTests extends IntegrationTestS
"icebreaker.value", "additional context:integrationtest value"));
}
@Value("${vault.value}")
String configValue;
@Value("${icebreaker.value}")
String additionalValue;
@Test
public void getsSecretFromVaultUsingVaultApplicationName() {
assertThat(this.configValue)
@@ -94,4 +89,9 @@ public class VaultPropertySourceLocatorIntegrationTests extends IntegrationTestS
.isEqualTo("additional context:integrationtest value");
}
@SpringBootApplication
public static class TestApplication {
}
}

View File

@@ -60,6 +60,15 @@ import static org.junit.Assume.assumeTrue;
"spring.cloud.vault.application-name=testVaultApp" })
public class VaultVersionedKvBackendConfigTests {
@Value("${vault.value}")
String configValue;
@Autowired
Environment environment;
@Autowired
ApplicationContext applicationContext;
@BeforeClass
public static void beforeClass() {
@@ -77,15 +86,6 @@ public class VaultVersionedKvBackendConfigTests {
Collections.singletonMap("data", object));
}
@Value("${vault.value}")
String configValue;
@Autowired
Environment environment;
@Autowired
ApplicationContext applicationContext;
@Test
public void contextLoads() {
assertThat(this.configValue).isEqualTo("foo");

View File

@@ -1,12 +1,14 @@
<?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/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies-parent</artifactId>
<version>2.1.2.BUILD-SNAPSHOT</version>
<relativePath />
<relativePath/>
<!-- lookup parent from repository -->
</parent>