Skip to content

Commit

Permalink
Merge branch 'release-1.0.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
electronicpeter committed Nov 30, 2019
2 parents b7c58d0 + ef42247 commit 117441a
Show file tree
Hide file tree
Showing 71 changed files with 353 additions and 241 deletions.
56 changes: 28 additions & 28 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion datasafe-business/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>datasafe</artifactId>
<groupId>de.adorsys</groupId>
<version>1.0.0</version>
<version>1.0.0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion datasafe-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.adorsys</groupId>
<artifactId>datasafe</artifactId>
<version>1.0.0</version>
<version>1.0.0.1</version>
</parent>

<artifactId>datasafe-cli</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion datasafe-directory/datasafe-directory-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>de.adorsys</groupId>
<artifactId>datasafe-directory</artifactId>
<version>1.0.0</version>
<version>1.0.0.1</version>
</parent>
<artifactId>datasafe-directory-api</artifactId>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion datasafe-directory/datasafe-directory-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>de.adorsys</groupId>
<artifactId>datasafe-directory</artifactId>
<version>1.0.0</version>
<version>1.0.0.1</version>
</parent>
<artifactId>datasafe-directory-impl</artifactId>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import de.adorsys.datasafe.types.api.types.ReadStorePassword;

import java.net.URI;
import java.util.function.Supplier;

public class DFSConfigWithStorageCreds extends DefaultDFSConfig {

Expand All @@ -26,6 +27,14 @@ public DFSConfigWithStorageCreds(Uri systemRoot, ReadStorePassword systemPasswor
super(systemRoot, systemPassword);
}

public DFSConfigWithStorageCreds(URI systemRoot, Supplier<char[]> systemPassword) {
super(systemRoot, systemPassword);
}

public DFSConfigWithStorageCreds(String systemRoot, Supplier<char[]> systemPassword) {
super(systemRoot, systemPassword);
}

@Override
public CreateUserPrivateProfile defaultPrivateTemplate(UserIDAuth id) {
CreateUserPrivateProfile base = super.defaultPrivateTemplate(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.net.URI;
import java.util.Collections;
import java.util.function.Supplier;

/**
* Default DFS folders layout provider, suitable both for s3 and filesystem.
Expand Down Expand Up @@ -45,6 +46,16 @@ public DefaultDFSConfig(String systemRoot, ReadStorePassword systemPassword) {
this(new Uri(systemRoot), systemPassword);
}

/**
* @param systemRoot Root location for all files - private files, user profiles, etc. For example you want
* to place everything in datasafe/system directory within storage
* @param systemPassword System password to open keystore
*/
public DefaultDFSConfig(String systemRoot, Supplier<char[]> systemPassword) {
this(new Uri(systemRoot), new ReadStorePassword(systemPassword));
}


/**
* @param systemRoot Root location for all files - private files, user profiles, etc. For example you want
* to place everything in datasafe/system directory within storage
Expand All @@ -54,6 +65,15 @@ public DefaultDFSConfig(URI systemRoot, ReadStorePassword systemPassword) {
this(new Uri(systemRoot), systemPassword);
}

/**
* @param systemRoot Root location for all files - private files, user profiles, etc. For example you want
* to place everything in datasafe/system directory within storage
* @param systemPassword System password to open keystore
*/
public DefaultDFSConfig(URI systemRoot, Supplier<char[]> systemPassword) {
this(new Uri(systemRoot), new ReadStorePassword(systemPassword));
}

/**
* @param systemRoot Root location for all files - private files, user profiles, etc. For example you want
* to place everything in datasafe/system directory within storage
Expand Down
2 changes: 1 addition & 1 deletion datasafe-directory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>datasafe</artifactId>
<groupId>de.adorsys</groupId>
<version>1.0.0</version>
<version>1.0.0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion datasafe-encryption/datasafe-encryption-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.adorsys</groupId>
<artifactId>datasafe-encryption</artifactId>
<version>1.0.0</version>
<version>1.0.0.1</version>
</parent>
<artifactId>datasafe-encryption-api</artifactId>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.function.Supplier;

/**
* Wrapper that represents username and password.
*/
Expand All @@ -21,6 +23,11 @@ public UserIDAuth(String userID, ReadKeyPassword readKeyPassword) {
this.readKeyPassword = readKeyPassword;
}

public UserIDAuth(String userID, Supplier<char[]> readKeyPassword) {
this.userID = new UserID(userID);
this.readKeyPassword = new ReadKeyPassword(readKeyPassword);
}

@Override
public String toString() {
return "UserIDAuth{" +
Expand Down
2 changes: 1 addition & 1 deletion datasafe-encryption/datasafe-encryption-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.adorsys</groupId>
<artifactId>datasafe-encryption</artifactId>
<version>1.0.0</version>
<version>1.0.0.1</version>
</parent>
<artifactId>datasafe-encryption-impl</artifactId>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javax.inject.Inject;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/**
Expand Down Expand Up @@ -55,30 +56,36 @@ public InputStream read(ReadRequest<UserIDAuth, AbsoluteLocation<PrivateResource
*/
@RequiredArgsConstructor
private static final class CloseCoordinatingStream extends InputStream {

private final InputStream streamToRead;
private final List<InputStream> streamsToClose;

@Override
public int read(byte[] b, int off, int len) throws IOException {
return streamToRead.read(b, off, len);
}

@Override
public int read() throws IOException {
return streamToRead.read();
}

@Override
@SneakyThrows
public void close() {
super.close();
streamsToClose.forEach(CloseCoordinatingStream::doClose);
List<Exception> exceptions = new ArrayList<>();
try {
super.close();
} catch (Exception ex) {
exceptions.add(ex);
}
streamsToClose.forEach(it -> doClose(it, exceptions));
if (!exceptions.isEmpty()) {
throw exceptions.get(0);
}
}

@SneakyThrows
private static void doClose(InputStream stream) {
stream.close();
private static void doClose(InputStream stream, List<Exception> exceptions) {
try {
stream.close();
} catch (Exception ex) {
exceptions.add(ex);
}
}
}
}
}}
2 changes: 1 addition & 1 deletion datasafe-encryption/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>datasafe</artifactId>
<groupId>de.adorsys</groupId>
<version>1.0.0</version>
<version>1.0.0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion datasafe-examples/datasafe-examples-business/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.adorsys</groupId>
<artifactId>datasafe-examples</artifactId>
<version>1.0.0</version>
<version>1.0.0.1</version>
</parent>
<artifactId>datasafe-examples-business</artifactId>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import de.adorsys.datasafe.types.api.actions.WriteRequest;
import de.adorsys.datasafe.types.api.resource.AbsoluteLocation;
import de.adorsys.datasafe.types.api.resource.ResolvedResource;
import de.adorsys.datasafe.types.api.types.ReadStorePassword;
import de.adorsys.datasafe.types.api.utils.ReadKeyPasswordTestFactory;
import lombok.SneakyThrows;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -46,7 +45,7 @@ void createServices(@TempDir Path root) {
// BEGIN_SNIPPET:Create Datasafe services
// this will create all Datasafe files and user documents under <temp dir path>
defaultDatasafeServices = DaggerDefaultDatasafeServices.builder()
.config(new DefaultDFSConfig(root.toAbsolutePath().toUri(), new ReadStorePassword("secret")))
.config(new DefaultDFSConfig(root.toAbsolutePath().toUri(), "secret"::toCharArray))
.storage(new FileSystemStorageService(root))
.build();
// END_SNIPPET
Expand All @@ -63,7 +62,7 @@ void registerUser() {
IMPORTANT: For cases when user profile is stored on S3 without object locks, this requires some global
synchronization due to eventual consistency or you need to supply globally unique username on registration
*/
defaultDatasafeServices.userProfile().registerUsingDefaults(new UserIDAuth("user", ReadKeyPasswordTestFactory.getForString("passwrd")));
defaultDatasafeServices.userProfile().registerUsingDefaults(new UserIDAuth("user", "passwrd"::toCharArray));
// END_SNIPPET

assertThat(defaultDatasafeServices.userProfile().userExists(new UserID("user")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import de.adorsys.datasafe.types.api.resource.PrivateResource;
import de.adorsys.datasafe.types.api.resource.ResolvedResource;
import de.adorsys.datasafe.types.api.resource.Versioned;
import de.adorsys.datasafe.types.api.types.ReadStorePassword;
import de.adorsys.datasafe.types.api.utils.ReadKeyPasswordTestFactory;
import lombok.SneakyThrows;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -47,7 +46,7 @@ void createServices(@TempDir Path root) {
// BEGIN_SNIPPET:Create versioned Datasafe services
// this will create all Datasafe files and user documents under <temp dir path>
versionedServices = DaggerVersionedDatasafeServices.builder()
.config(new DefaultDFSConfig(root.toAbsolutePath().toUri(), new ReadStorePassword("secret")))
.config(new DefaultDFSConfig(root.toAbsolutePath().toUri(), "secret"::toCharArray))
.storage(new FileSystemStorageService(root))
.build();
// END_SNIPPET
Expand All @@ -64,7 +63,7 @@ void registerUser() {
IMPORTANT: For cases when user profile is stored on S3 without object locks, this requires some global
synchronization due to eventual consistency or you need to supply globally unique username on registration
*/
versionedServices.userProfile().registerUsingDefaults(new UserIDAuth("user", ReadKeyPasswordTestFactory.getForString("passwrd")));
versionedServices.userProfile().registerUsingDefaults(new UserIDAuth("user", "passwrd"::toCharArray));
// END_SNIPPET

assertThat(versionedServices.userProfile().userExists(new UserID("user")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import de.adorsys.datasafe.types.api.context.BaseOverridesRegistry;
import de.adorsys.datasafe.types.api.context.overrides.OverridesRegistry;
import de.adorsys.datasafe.types.api.resource.Uri;
import de.adorsys.datasafe.types.api.types.ReadStorePassword;
import de.adorsys.datasafe.types.api.utils.ReadKeyPasswordTestFactory;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand All @@ -38,13 +36,13 @@ void testPathEncryptionOverridden(@TempDir Path root) {

// Customized service, without creating complete module and building it:
DefaultDatasafeServices datasafeServices = DaggerDefaultDatasafeServices.builder()
.config(new DefaultDFSConfig(root.toAbsolutePath().toUri(), new ReadStorePassword("secret")))
.config(new DefaultDFSConfig(root.toAbsolutePath().toUri(), "secret"::toCharArray))
.storage(new FileSystemStorageService(root))
.overridesRegistry(registry)
.build();

// registering user
UserIDAuth user = new UserIDAuth("user", ReadKeyPasswordTestFactory.getForString("passwrd"));
UserIDAuth user = new UserIDAuth("user", "passwrd"::toCharArray);
datasafeServices.userProfile().registerUsingDefaults(user);
// writing into user privatespace, note that with default implementation `file.txt` would be encrypted
datasafeServices.privateService().write(WriteRequest.forDefaultPrivate(user, "file.txt"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.adorsys</groupId>
<artifactId>datasafe-examples</artifactId>
<version>1.0.0</version>
<version>1.0.0.1</version>
</parent>
<artifactId>datasafe-examples-customize-dagger</artifactId>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import de.adorsys.datasafe.encrypiton.api.types.UserIDAuth;
import de.adorsys.datasafe.storage.impl.fs.FileSystemStorageService;
import de.adorsys.datasafe.types.api.actions.WriteRequest;
import de.adorsys.datasafe.types.api.types.ReadStorePassword;
import de.adorsys.datasafe.types.api.utils.ReadKeyPasswordTestFactory;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

Expand All @@ -25,12 +23,12 @@ void testPathEncryptionOverridden(@TempDir Path root) {
// BEGIN_SNIPPET:Create custom-built Datasafe service
// Customized service, we create required module using compile time DI provided by Dagger:
CustomlyBuiltDatasafeServices datasafeServices = DaggerCustomlyBuiltDatasafeServices.builder()
.config(new DefaultDFSConfig(root.toAbsolutePath().toUri(), new ReadStorePassword("secret")))
.config(new DefaultDFSConfig(root.toAbsolutePath().toUri(), "secret"::toCharArray))
.storage(new FileSystemStorageService(root))
.build();

// registering user
UserIDAuth user = new UserIDAuth("user", ReadKeyPasswordTestFactory.getForString("passwrd"));
UserIDAuth user = new UserIDAuth("user", "password"::toCharArray);
datasafeServices.userProfile().registerUsingDefaults(user);
// writing into user privatespace, note that with default implementation `file.txt` would be encrypted
datasafeServices.privateService().write(WriteRequest.forDefaultPrivate(user, "file.txt"));
Expand Down
2 changes: 1 addition & 1 deletion datasafe-examples/datasafe-examples-multidfs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.adorsys</groupId>
<artifactId>datasafe-examples</artifactId>
<version>1.0.0</version>
<version>1.0.0.1</version>
</parent>
<artifactId>datasafe-examples-multidfs</artifactId>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
import de.adorsys.datasafe.types.api.resource.AbsoluteLocation;
import de.adorsys.datasafe.types.api.resource.BasePrivateResource;
import de.adorsys.datasafe.types.api.resource.StorageIdentifier;
import de.adorsys.datasafe.types.api.types.ReadStorePassword;
import de.adorsys.datasafe.types.api.utils.ExecutorServiceUtil;
import de.adorsys.datasafe.types.api.utils.ReadKeyPasswordTestFactory;
import lombok.SneakyThrows;
import lombok.experimental.Delegate;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -115,7 +113,7 @@ void testMultiUserStorageUserSetup() {
OverridesRegistry registry = new BaseOverridesRegistry();
DefaultDatasafeServices multiDfsDatasafe = DaggerDefaultDatasafeServices
.builder()
.config(new DFSConfigWithStorageCreds(directoryBucketS3Uri, new ReadStorePassword("PAZZWORT")))
.config(new DFSConfigWithStorageCreds(directoryBucketS3Uri, "PAZZWORT"::toCharArray))
// This storage service will route requests to proper bucket based on URI content:
// URI with directoryBucket to `directoryStorage`
// URI with filesBucketOne will get dynamically generated S3Storage
Expand Down Expand Up @@ -156,8 +154,7 @@ void testMultiUserStorageUserSetup() {
// Depending on path of file - filesBucketOne or filesBucketTwo - requests will be routed to proper bucket.
// I.e. path filesBucketOne/path/to/file will end up in `filesBucketOne` with key path/to/file
// his profile and access credentials for `filesBucketOne` will be in `configBucket`
UserIDAuth john = new UserIDAuth("john",
ReadKeyPasswordTestFactory.getForString("secret"));
UserIDAuth john = new UserIDAuth("john", "secret"::toCharArray);
// Here, nothing expects John has own storage credentials:
multiDfsDatasafe.userProfile().registerUsingDefaults(john);

Expand Down
2 changes: 1 addition & 1 deletion datasafe-examples/datasafe-examples-versioned-s3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>de.adorsys</groupId>
<artifactId>datasafe-examples</artifactId>
<version>1.0.0</version>
<version>1.0.0.1</version>
</parent>
<artifactId>datasafe-examples-versioned-s3</artifactId>
<dependencies>
Expand Down
Loading

0 comments on commit 117441a

Please sign in to comment.