james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [02/10] james-project git commit: JAMES-2525 implements swift auth protocol config readers
Date Thu, 11 Oct 2018 02:28:40 GMT
JAMES-2525 implements swift auth protocol config readers


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/a4872d69
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/a4872d69
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/a4872d69

Branch: refs/heads/master
Commit: a4872d69a9d62aad11fb3331e7daa192536ebd04
Parents: 7bb6e80
Author: Jean Helou <jhe@codamens.fr>
Authored: Wed Sep 5 12:00:01 2018 +0200
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Oct 11 09:26:14 2018 +0700

----------------------------------------------------------------------
 .../swift/SwiftKeystone2ObjectStorage.java      |   4 +-
 .../swift/SwiftKeystone3ObjectStorage.java      |  14 +-
 .../swift/SwiftTempAuthObjectStorage.java       |  15 ++
 .../objectstorage/SwiftConfigurationReader.java |  26 ++
 .../SwiftKeystone2ConfigurationReader.java      |  74 ++++++
 .../SwiftKeystone3ConfigurationReader.java      | 134 ++++++++++
 .../SwiftTmpAuthConfigurationReader.java        |  90 +++++++
 .../SwiftKeystone2ConfigurationReaderTest.java  | 150 +++++++++++
 .../SwiftKeystone3ConfigurationReaderTest.java  | 254 +++++++++++++++++++
 .../SwiftTmpAuthConfigurationReaderTest.java    | 183 +++++++++++++
 10 files changed, 940 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/a4872d69/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftKeystone2ObjectStorage.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftKeystone2ObjectStorage.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftKeystone2ObjectStorage.java
index 5ace285..bf75bcd 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftKeystone2ObjectStorage.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftKeystone2ObjectStorage.java
@@ -114,8 +114,8 @@ public class SwiftKeystone2ObjectStorage {
                 return this;
             }
 
-            public Builder region(Region region) {
-                this.region = Optional.of(region);
+            public Builder region(Optional<Region> region) {
+                this.region = region;
                 return this;
             }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4872d69/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftKeystone3ObjectStorage.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftKeystone3ObjectStorage.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftKeystone3ObjectStorage.java
index f5e7272..c0dcee3 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftKeystone3ObjectStorage.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftKeystone3ObjectStorage.java
@@ -110,8 +110,13 @@ public class SwiftKeystone3ObjectStorage {
                 return this;
             }
 
-            public Builder region(Region region) {
-                this.region = Optional.of(region);
+            public Builder region(Optional<Region> region) {
+                this.region = region;
+                return this;
+            }
+
+            public Builder domainId(Optional<DomainId> domainId) {
+                this.domainId = domainId;
                 return this;
             }
 
@@ -120,6 +125,11 @@ public class SwiftKeystone3ObjectStorage {
                 return this;
             }
 
+            public Builder project(Optional<Project> project) {
+                this.project = project;
+                return this;
+            }
+
             public Builder project(Project project) {
                 this.project = Optional.of(project);
                 return this;

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4872d69/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftTempAuthObjectStorage.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftTempAuthObjectStorage.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftTempAuthObjectStorage.java
index e8f1129..b5b1c22 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftTempAuthObjectStorage.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftTempAuthObjectStorage.java
@@ -123,6 +123,11 @@ public class SwiftTempAuthObjectStorage {
                 return this;
             }
 
+            public Builder region(Optional<Region> region) {
+                this.region = region;
+                return this;
+            }
+
             public Builder tempAuthHeaderUserName(UserHeaderName tmpAuthHeaderUser) {
                 userHeaderName = Optional.of(tmpAuthHeaderUser);
                 return this;
@@ -133,6 +138,16 @@ public class SwiftTempAuthObjectStorage {
                 return this;
             }
 
+            public Builder tempAuthHeaderUserName(Optional<UserHeaderName> tmpAuthHeaderUser) {
+                userHeaderName = tmpAuthHeaderUser;
+                return this;
+            }
+
+            public Builder tempAuthHeaderPassName(Optional<PassHeaderName> tmpAuthHeaderPass) {
+                passHeaderName = tmpAuthHeaderPass;
+                return this;
+            }
+
             public Configuration build() {
                 Preconditions.checkState(endpoint != null);
                 Preconditions.checkState(tenantName != null);

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4872d69/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/SwiftConfigurationReader.java
----------------------------------------------------------------------
diff --git a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/SwiftConfigurationReader.java b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/SwiftConfigurationReader.java
new file mode 100644
index 0000000..662a894
--- /dev/null
+++ b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/SwiftConfigurationReader.java
@@ -0,0 +1,26 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.modules.objectstorage;
+
+public interface SwiftConfigurationReader {
+    String OBJECTSTORAGE_SWIFT_ENDPOINT = "objectstorage.swift.endpoint";
+    String OBJECTSTORAGE_SWIFT_CREDENTIALS = "objectstorage.swift.credentials";
+    String OBJECTSTORAGE_SWIFT_REGION = "objectstorage.swift.region";
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4872d69/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/SwiftKeystone2ConfigurationReader.java
----------------------------------------------------------------------
diff --git a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/SwiftKeystone2ConfigurationReader.java b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/SwiftKeystone2ConfigurationReader.java
new file mode 100644
index 0000000..d2f1d03
--- /dev/null
+++ b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/SwiftKeystone2ConfigurationReader.java
@@ -0,0 +1,74 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.modules.objectstorage;
+
+import java.net.URI;
+import java.util.Optional;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.james.blob.objectstorage.swift.Credentials;
+import org.apache.james.blob.objectstorage.swift.Identity;
+import org.apache.james.blob.objectstorage.swift.Region;
+import org.apache.james.blob.objectstorage.swift.SwiftKeystone2ObjectStorage;
+import org.apache.james.blob.objectstorage.swift.TenantName;
+import org.apache.james.blob.objectstorage.swift.UserName;
+
+import com.google.common.base.Preconditions;
+
+public class SwiftKeystone2ConfigurationReader implements SwiftConfigurationReader {
+
+    private static final String OBJECTSTORAGE_SWIFT_KEYSTONE_2_USERNAME =
+        "objectstorage.swift.keystone2.username";
+    private static final String OBJECTSTORAGE_SWIFT_KEYSTONE_2_TENANTNAME =
+        "objectstorage.swift.keystone2.tenantname";
+
+    public static SwiftKeystone2ObjectStorage.Configuration readSwiftConfiguration(Configuration configuration) {
+        String endpointStr = configuration.getString(OBJECTSTORAGE_SWIFT_ENDPOINT, null);
+        String crendentialsStr = configuration.getString(OBJECTSTORAGE_SWIFT_CREDENTIALS, null);
+        String userNameStr = configuration.getString(OBJECTSTORAGE_SWIFT_KEYSTONE_2_USERNAME, null);
+        String tenantNameStr = configuration.getString(OBJECTSTORAGE_SWIFT_KEYSTONE_2_TENANTNAME, null);
+
+        Preconditions.checkArgument(endpointStr != null,
+            OBJECTSTORAGE_SWIFT_ENDPOINT + " is a mandatory configuration value");
+        Preconditions.checkArgument(crendentialsStr != null,
+            OBJECTSTORAGE_SWIFT_CREDENTIALS + " is a mandatory configuration value");
+        Preconditions.checkArgument(userNameStr != null,
+            OBJECTSTORAGE_SWIFT_KEYSTONE_2_USERNAME + " is a mandatory configuration value");
+        Preconditions.checkArgument(tenantNameStr != null,
+            OBJECTSTORAGE_SWIFT_KEYSTONE_2_TENANTNAME + " is a mandatory configuration value");
+
+        URI endpoint = URI.create(endpointStr);
+        Credentials credentials = Credentials.of(crendentialsStr);
+        UserName userName = UserName.of(userNameStr);
+        TenantName tenantName = TenantName.of(tenantNameStr);
+        Identity identity = Identity.of(tenantName, userName);
+
+        Optional<Region> region = Optional.ofNullable(
+            configuration.getString(OBJECTSTORAGE_SWIFT_REGION, null))
+            .map(Region::of);
+
+        return SwiftKeystone2ObjectStorage.configBuilder()
+            .endpoint(endpoint)
+            .credentials(credentials)
+            .region(region)
+            .identity(identity)
+            .build();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4872d69/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/SwiftKeystone3ConfigurationReader.java
----------------------------------------------------------------------
diff --git a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/SwiftKeystone3ConfigurationReader.java b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/SwiftKeystone3ConfigurationReader.java
new file mode 100644
index 0000000..bc51a89
--- /dev/null
+++ b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/SwiftKeystone3ConfigurationReader.java
@@ -0,0 +1,134 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.modules.objectstorage;
+
+import java.net.URI;
+import java.util.Optional;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.james.blob.objectstorage.swift.Credentials;
+import org.apache.james.blob.objectstorage.swift.DomainId;
+import org.apache.james.blob.objectstorage.swift.DomainName;
+import org.apache.james.blob.objectstorage.swift.IdentityV3;
+import org.apache.james.blob.objectstorage.swift.Project;
+import org.apache.james.blob.objectstorage.swift.ProjectName;
+import org.apache.james.blob.objectstorage.swift.Region;
+import org.apache.james.blob.objectstorage.swift.SwiftKeystone3ObjectStorage;
+import org.apache.james.blob.objectstorage.swift.UserName;
+import org.apache.james.util.OptionalUtils;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * See openstack identity V3 documentation
+ *
+ * @link https://developer.openstack.org/api-ref/identity/v3/#authentication-and-token-management
+ */
+public class SwiftKeystone3ConfigurationReader implements SwiftConfigurationReader {
+
+    private static final String OBJECTSTORAGE_SWIFT_KEYSTONE_3_USER_NAME =
+        "objectstorage.swift.keystone3.user.name";
+
+    private static final String OBJECTSTORAGE_SWIFT_KEYSTONE_3_USER_DOMAIN =
+        "objectstorage.swift.keystone3.user.domain";
+
+    private static final String OBJECTSTORAGE_SWIFT_KEYSTONE_3_DOMAIN_ID =
+        "objectstorage.swift.keystone3.scope.domainid";
+
+    private static final String OBJECTSTORAGE_SWIFT_KEYSTONE_3_PROJECT_NAME =
+        "objectstorage.swift.keystone3.scope.project.name";
+
+    private static final String OBJECTSTORAGE_SWIFT_KEYSTONE_3_PROJECT_DOMAIN_NAME =
+        "objectstorage.swift.keystone3.scope.project.domainname";
+
+    private static final String OBJECTSTORAGE_SWIFT_KEYSTONE_3_PROJECT_DOMAIN_ID =
+        "objectstorage.swift.keystone3.scope.project.domainid";
+
+    public static SwiftKeystone3ObjectStorage.Configuration readSwiftConfiguration(Configuration configuration) {
+        String endpointStr = configuration.getString(OBJECTSTORAGE_SWIFT_ENDPOINT, null);
+        String crendentialsStr = configuration.getString(OBJECTSTORAGE_SWIFT_CREDENTIALS, null);
+
+        Preconditions.checkArgument(endpointStr != null,
+            OBJECTSTORAGE_SWIFT_ENDPOINT + " is a mandatory configuration value");
+        Preconditions.checkArgument(crendentialsStr != null,
+            OBJECTSTORAGE_SWIFT_CREDENTIALS + " is a mandatory configuration value");
+
+        URI endpoint = URI.create(endpointStr);
+        Credentials credentials = Credentials.of(crendentialsStr);
+
+        IdentityV3 identity = readIdentity(configuration);
+
+        Optional<DomainId> domainScope = Optional.ofNullable(
+            configuration.getString(OBJECTSTORAGE_SWIFT_KEYSTONE_3_DOMAIN_ID, null))
+            .map(DomainId::of);
+
+        Optional<Project> projectScope = readProjectScope(configuration);
+
+        Optional<Region> region = Optional.ofNullable(
+            configuration.getString(OBJECTSTORAGE_SWIFT_REGION, null))
+            .map(Region::of);
+
+        return SwiftKeystone3ObjectStorage.configBuilder()
+            .endpoint(endpoint)
+            .credentials(credentials)
+            .region(region)
+            .identity(identity)
+            .domainId(domainScope)
+            .project(projectScope)
+            .build();
+    }
+
+    private static IdentityV3 readIdentity(Configuration configuration) {
+        String userNameStr = configuration.getString(OBJECTSTORAGE_SWIFT_KEYSTONE_3_USER_NAME, null);
+        String domainNameStr = configuration.getString(OBJECTSTORAGE_SWIFT_KEYSTONE_3_USER_DOMAIN, null);
+
+        Preconditions.checkArgument(userNameStr != null,
+            OBJECTSTORAGE_SWIFT_KEYSTONE_3_USER_NAME + " is a mandatory configuration value");
+        Preconditions.checkArgument(domainNameStr != null,
+            OBJECTSTORAGE_SWIFT_KEYSTONE_3_USER_DOMAIN + " is a mandatory configuration value");
+
+        UserName userName =
+            UserName.of(userNameStr);
+
+        DomainName userDomain =
+            DomainName.of(domainNameStr);
+        return IdentityV3.of(userDomain, userName);
+    }
+
+    private static Optional<Project> readProjectScope(Configuration configuration) {
+        Optional<ProjectName> projectName = Optional.ofNullable(
+            configuration.getString(OBJECTSTORAGE_SWIFT_KEYSTONE_3_PROJECT_NAME, null))
+            .map(ProjectName::of);
+
+        Optional<DomainName> projectDomainName = Optional.ofNullable(
+            configuration.getString(OBJECTSTORAGE_SWIFT_KEYSTONE_3_PROJECT_DOMAIN_NAME, null))
+            .map(DomainName::of);
+
+        Optional<DomainId> projectDomainId = Optional.ofNullable(
+            configuration.getString(OBJECTSTORAGE_SWIFT_KEYSTONE_3_PROJECT_DOMAIN_ID, null))
+            .map(DomainId::of);
+
+        return OptionalUtils.or(
+            projectName.flatMap(project -> projectDomainName.map(domain -> Project.of(project, domain))),
+            projectName.flatMap(project -> projectDomainId.map(domain -> Project.of(project, domain))),
+            projectName.map(Project::of)
+        );
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4872d69/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/SwiftTmpAuthConfigurationReader.java
----------------------------------------------------------------------
diff --git a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/SwiftTmpAuthConfigurationReader.java b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/SwiftTmpAuthConfigurationReader.java
new file mode 100644
index 0000000..467fa42
--- /dev/null
+++ b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/SwiftTmpAuthConfigurationReader.java
@@ -0,0 +1,90 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.modules.objectstorage;
+
+import java.net.URI;
+import java.util.Optional;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.james.blob.objectstorage.swift.Credentials;
+import org.apache.james.blob.objectstorage.swift.Identity;
+import org.apache.james.blob.objectstorage.swift.PassHeaderName;
+import org.apache.james.blob.objectstorage.swift.Region;
+import org.apache.james.blob.objectstorage.swift.SwiftTempAuthObjectStorage;
+import org.apache.james.blob.objectstorage.swift.TenantName;
+import org.apache.james.blob.objectstorage.swift.UserHeaderName;
+import org.apache.james.blob.objectstorage.swift.UserName;
+
+import com.google.common.base.Preconditions;
+
+public class SwiftTmpAuthConfigurationReader implements SwiftConfigurationReader {
+
+    private static final String OBJECTSTORAGE_SWIFT_TEMPAUTH_USERNAME =
+        "objectstorage.swift.tempauth.username";
+    private static final String OBJECTSTORAGE_SWIFT_TEMPAUTH_TENANTNAME =
+        "objectstorage.swift.tempauth.tenantname";
+    private static final String OBJECTSTORAGE_SWIFT_TEMPAUTH_PASS_HEADER_NAME =
+        "objectstorage.swift.tempauth.passheadername";
+    private static final String OBJECTSTORAGE_SWIFT_TEMPAUTH_USER_HEADER_NAME =
+        "objectstorage.swift.tempauth.userheadername";
+
+    public static SwiftTempAuthObjectStorage.Configuration readSwiftConfiguration(Configuration configuration) {
+        String endpointStr = configuration.getString(OBJECTSTORAGE_SWIFT_ENDPOINT, null);
+        String crendentialsStr = configuration.getString(OBJECTSTORAGE_SWIFT_CREDENTIALS, null);
+        String userNameStr = configuration.getString(OBJECTSTORAGE_SWIFT_TEMPAUTH_USERNAME, null);
+        String tenantNameStr = configuration.getString(OBJECTSTORAGE_SWIFT_TEMPAUTH_TENANTNAME, null);
+
+        Preconditions.checkArgument(endpointStr != null,
+            OBJECTSTORAGE_SWIFT_ENDPOINT + " is a mandatory configuration value");
+        Preconditions.checkArgument(crendentialsStr != null,
+            OBJECTSTORAGE_SWIFT_CREDENTIALS + " is a mandatory configuration value");
+        Preconditions.checkArgument(userNameStr != null,
+            OBJECTSTORAGE_SWIFT_TEMPAUTH_USERNAME + " is a mandatory configuration value");
+        Preconditions.checkArgument(tenantNameStr != null,
+            OBJECTSTORAGE_SWIFT_TEMPAUTH_TENANTNAME + " is a mandatory configuration value");
+
+        URI endpoint = URI.create(endpointStr);
+        Credentials credentials = Credentials.of(crendentialsStr);
+        UserName userName = UserName.of(userNameStr);
+        TenantName tenantName = TenantName.of(tenantNameStr);
+        Identity identity = Identity.of(tenantName, userName);
+
+        Optional<Region> region = Optional.ofNullable(
+            configuration.getString(SwiftConfigurationReader.OBJECTSTORAGE_SWIFT_REGION, null))
+            .map(Region::of);
+
+        Optional<PassHeaderName> passHeaderName = Optional.ofNullable(
+            configuration.getString(OBJECTSTORAGE_SWIFT_TEMPAUTH_PASS_HEADER_NAME, null))
+            .map(PassHeaderName::of);
+
+        Optional<UserHeaderName> userHeaderName = Optional.ofNullable(
+            configuration.getString(OBJECTSTORAGE_SWIFT_TEMPAUTH_USER_HEADER_NAME, null))
+            .map(UserHeaderName::of);
+
+        return SwiftTempAuthObjectStorage.configBuilder()
+            .endpoint(endpoint)
+            .credentials(credentials)
+            .region(region)
+            .identity(identity)
+            .tempAuthHeaderPassName(passHeaderName)
+            .tempAuthHeaderUserName(userHeaderName)
+            .build();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4872d69/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/SwiftKeystone2ConfigurationReaderTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/SwiftKeystone2ConfigurationReaderTest.java b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/SwiftKeystone2ConfigurationReaderTest.java
new file mode 100644
index 0000000..2b6f81b
--- /dev/null
+++ b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/SwiftKeystone2ConfigurationReaderTest.java
@@ -0,0 +1,150 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.modules.objectstorage;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.io.StringReader;
+import java.net.URI;
+import java.util.Optional;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.james.blob.objectstorage.swift.Credentials;
+import org.apache.james.blob.objectstorage.swift.Region;
+import org.apache.james.blob.objectstorage.swift.SwiftKeystone2ObjectStorage;
+import org.apache.james.blob.objectstorage.swift.TenantName;
+import org.apache.james.blob.objectstorage.swift.UserName;
+import org.junit.jupiter.api.Test;
+
+class SwiftKeystone2ConfigurationReaderTest {
+    private static final String ENDPOINT = "http://auth.example.com/v2.0";
+    private static final String CONFIG_ENDPOINT =
+        "objectstorage.swift.endpoint=" + ENDPOINT;
+
+    private static final String CREDENTIALS = "this_is_a_secret";
+    private static final String CONFIG_CREDENTIALS =
+        "objectstorage.swift.credentials=" + CREDENTIALS;
+
+    private static final String REGION = "EMEA";
+    private static final String CONFIG_REGION =
+        "objectstorage.swift.region=" + REGION;
+
+    private static final String USER_NAME = "user";
+    private static final String CONFIG_USER_NAME =
+        "objectstorage.swift.keystone2.username=" + USER_NAME;
+
+    private static final String TENANT_NAME = "tenant";
+    private static final String CONFIG_TENANT_NAME =
+        "objectstorage.swift.keystone2.tenantname=" + TENANT_NAME;
+
+    @Test
+    void readBasicKeystone2Configuration() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_ENDPOINT,
+            CONFIG_CREDENTIALS,
+            CONFIG_USER_NAME,
+            CONFIG_TENANT_NAME)));
+        assertThat(SwiftKeystone2ConfigurationReader.readSwiftConfiguration(configuration))
+            .isEqualTo(
+                SwiftKeystone2ObjectStorage.configBuilder()
+                    .endpoint(URI.create(ENDPOINT))
+                    .credentials(Credentials.of(CREDENTIALS))
+                    .tenantName(TenantName.of(TENANT_NAME))
+                    .userName(UserName.of(USER_NAME))
+                    .build()
+            );
+    }
+
+    @Test
+    void readKeystone2ConfigurationWithRegion() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_ENDPOINT,
+            CONFIG_CREDENTIALS,
+            CONFIG_USER_NAME,
+            CONFIG_TENANT_NAME,
+            CONFIG_REGION)));
+        assertThat(SwiftKeystone2ConfigurationReader.readSwiftConfiguration(configuration))
+            .isEqualTo(
+                SwiftKeystone2ObjectStorage.configBuilder()
+                    .endpoint(URI.create(ENDPOINT))
+                    .credentials(Credentials.of(CREDENTIALS))
+                    .tenantName(TenantName.of(TENANT_NAME))
+                    .userName(UserName.of(USER_NAME))
+                    .region(Optional.of(Region.of(REGION)))
+                    .build()
+            );
+    }
+
+    @Test
+    void failToReadSwiftKeyston2ConfigurationWhenMissingEndpoint() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_CREDENTIALS,
+            CONFIG_USER_NAME,
+            CONFIG_TENANT_NAME,
+            CONFIG_REGION)));
+        assertThatThrownBy(() ->
+            SwiftKeystone2ConfigurationReader.readSwiftConfiguration(configuration))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void failToReadSwiftKeyston2ConfigurationWhenMissingCrendentials() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_ENDPOINT,
+            CONFIG_USER_NAME,
+            CONFIG_TENANT_NAME,
+            CONFIG_REGION)));
+        assertThatThrownBy(() ->
+            SwiftKeystone2ConfigurationReader.readSwiftConfiguration(configuration))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void failToReadSwiftKeyston2ConfigurationWhenMissingUserName() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_ENDPOINT,
+            CONFIG_CREDENTIALS,
+            CONFIG_TENANT_NAME,
+            CONFIG_REGION)));
+        assertThatThrownBy(() ->
+            SwiftKeystone2ConfigurationReader.readSwiftConfiguration(configuration))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void failToReadSwiftKeyston2ConfigurationWhenMissingTenantName() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_ENDPOINT,
+            CONFIG_CREDENTIALS,
+            CONFIG_USER_NAME,
+            CONFIG_REGION)));
+        assertThatThrownBy(() ->
+            SwiftKeystone2ConfigurationReader.readSwiftConfiguration(configuration))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4872d69/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/SwiftKeystone3ConfigurationReaderTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/SwiftKeystone3ConfigurationReaderTest.java b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/SwiftKeystone3ConfigurationReaderTest.java
new file mode 100644
index 0000000..0d1dbf0
--- /dev/null
+++ b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/SwiftKeystone3ConfigurationReaderTest.java
@@ -0,0 +1,254 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.modules.objectstorage;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.io.StringReader;
+import java.net.URI;
+import java.util.Optional;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.james.blob.objectstorage.swift.Credentials;
+import org.apache.james.blob.objectstorage.swift.DomainId;
+import org.apache.james.blob.objectstorage.swift.DomainName;
+import org.apache.james.blob.objectstorage.swift.IdentityV3;
+import org.apache.james.blob.objectstorage.swift.Project;
+import org.apache.james.blob.objectstorage.swift.ProjectName;
+import org.apache.james.blob.objectstorage.swift.Region;
+import org.apache.james.blob.objectstorage.swift.SwiftKeystone3ObjectStorage;
+import org.apache.james.blob.objectstorage.swift.UserName;
+import org.junit.jupiter.api.Test;
+
+class SwiftKeystone3ConfigurationReaderTest {
+    private static final String ENDPOINT = "http://auth.example.com/v2.0";
+    private static final String CONFIG_ENDPOINT =
+        "objectstorage.swift.endpoint=" + ENDPOINT;
+
+    private static final String CREDENTIALS = "this_is_a_secret";
+    private static final String CONFIG_CREDENTIALS =
+        "objectstorage.swift.credentials=" + CREDENTIALS;
+
+    private static final String REGION = "EMEA";
+    private static final String CONFIG_REGION =
+        "objectstorage.swift.region=" + REGION;
+
+    private static final String USER_NAME = "user";
+    private static final String CONFIG_USER_NAME =
+        "objectstorage.swift.keystone3.user.name=" + USER_NAME;
+
+    private static final String USER_DOMAIN_NAME = "user_domain";
+    private static final String CONFIG_USER_DOMAIN_NAME =
+        "objectstorage.swift.keystone3.user.domain=" + USER_DOMAIN_NAME;
+
+    private static final String SCOPE_DOMAIN_ID = "scope_domain";
+    private static final String CONFIG_SCOPE_DOMAIN_ID =
+        "objectstorage.swift.keystone3.scope.domainid=" + SCOPE_DOMAIN_ID;
+
+    private static final String SCOPE_PROJECT_NAME = "scope_project_name";
+    private static final String CONFIG_SCOPE_PROJECT_NAME =
+        "objectstorage.swift.keystone3.scope.project.name=" + SCOPE_PROJECT_NAME;
+    private static final String SCOPE_PROJECT_DOMAIN_NAME = "scope_project_domain_name";
+    private static final String CONFIG_SCOPE_PROJECT_DOMAIN_NAME =
+        "objectstorage.swift.keystone3.scope.project.domainname=" + SCOPE_PROJECT_DOMAIN_NAME;
+    private static final String SCOPE_PROJECT_DOMAIN_ID = "scope_project_domain_id";
+    private static final String CONFIG_SCOPE_PROJECT_DOMAIN_ID =
+        "objectstorage.swift.keystone3.scope.project.domainid=" + SCOPE_PROJECT_DOMAIN_ID;
+
+    @Test
+    void readUnscopedKeystone3Configuration() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_ENDPOINT,
+            CONFIG_CREDENTIALS,
+            CONFIG_USER_NAME,
+            CONFIG_USER_DOMAIN_NAME)));
+        assertThat(SwiftKeystone3ConfigurationReader.readSwiftConfiguration(configuration))
+            .isEqualTo(
+                SwiftKeystone3ObjectStorage.configBuilder()
+                    .endpoint(URI.create(ENDPOINT))
+                    .credentials(Credentials.of(CREDENTIALS))
+                    .identity(IdentityV3.of(DomainName.of(USER_DOMAIN_NAME), UserName.of(USER_NAME)))
+                    .build()
+            );
+    }
+
+    @Test
+    void readUnscopedKeystone3ConfigurationWithRegion() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_ENDPOINT,
+            CONFIG_CREDENTIALS,
+            CONFIG_USER_NAME,
+            CONFIG_USER_DOMAIN_NAME,
+            CONFIG_REGION)));
+        assertThat(SwiftKeystone3ConfigurationReader.readSwiftConfiguration(configuration))
+            .isEqualTo(
+                SwiftKeystone3ObjectStorage.configBuilder()
+                    .endpoint(URI.create(ENDPOINT))
+                    .credentials(Credentials.of(CREDENTIALS))
+                    .identity(IdentityV3.of(DomainName.of(USER_DOMAIN_NAME), UserName.of(USER_NAME)))
+                    .region(Optional.of(Region.of(REGION)))
+                    .build()
+            );
+    }
+
+    @Test
+    void failsToReadKeystone3ConfigurationWithoutEndpoint() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_CREDENTIALS,
+            CONFIG_USER_NAME,
+            CONFIG_USER_DOMAIN_NAME)));
+        assertThatThrownBy(() -> SwiftKeystone3ConfigurationReader.readSwiftConfiguration(configuration))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void failsToReadKeystone3ConfigurationWithoutCredentials() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_ENDPOINT,
+            CONFIG_USER_NAME,
+            CONFIG_USER_DOMAIN_NAME)));
+        assertThatThrownBy(() -> SwiftKeystone3ConfigurationReader.readSwiftConfiguration(configuration))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void failsToReadKeystone3ConfigurationWithoutUserName() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_ENDPOINT,
+            CONFIG_CREDENTIALS,
+            CONFIG_USER_DOMAIN_NAME)));
+        assertThatThrownBy(() -> SwiftKeystone3ConfigurationReader.readSwiftConfiguration(configuration))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void failsToReadKeystone3ConfigurationWithoutUserDomainName() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_ENDPOINT,
+            CONFIG_CREDENTIALS,
+            CONFIG_USER_NAME)));
+        assertThatThrownBy(() -> SwiftKeystone3ConfigurationReader.readSwiftConfiguration(configuration))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void readDomainScopedKeystone3Configuration() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_ENDPOINT,
+            CONFIG_CREDENTIALS,
+            CONFIG_USER_NAME,
+            CONFIG_USER_DOMAIN_NAME,
+            CONFIG_SCOPE_DOMAIN_ID)));
+        assertThat(SwiftKeystone3ConfigurationReader.readSwiftConfiguration(configuration))
+            .isEqualTo(
+                SwiftKeystone3ObjectStorage.configBuilder()
+                    .endpoint(URI.create(ENDPOINT))
+                    .credentials(Credentials.of(CREDENTIALS))
+                    .identity(IdentityV3.of(DomainName.of(USER_DOMAIN_NAME), UserName.of(USER_NAME)))
+                    .domainId(DomainId.of(SCOPE_DOMAIN_ID))
+                    .build()
+            );
+    }
+
+    @Test
+    void readProjectScopedKeystone3Configuration() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_ENDPOINT,
+            CONFIG_CREDENTIALS,
+            CONFIG_USER_NAME,
+            CONFIG_USER_DOMAIN_NAME,
+            CONFIG_SCOPE_PROJECT_NAME,
+            CONFIG_REGION)));
+        assertThat(SwiftKeystone3ConfigurationReader.readSwiftConfiguration(configuration))
+            .isEqualTo(
+                SwiftKeystone3ObjectStorage.configBuilder()
+                    .endpoint(URI.create(ENDPOINT))
+                    .credentials(Credentials.of(CREDENTIALS))
+                    .identity(IdentityV3.of(DomainName.of(USER_DOMAIN_NAME), UserName.of(USER_NAME)))
+                    .region(Optional.of(Region.of(REGION)))
+                    .project(Project.of(ProjectName.of(SCOPE_PROJECT_NAME)))
+                    .build()
+            );
+    }
+
+    @Test
+    void readProjectOfDomainNameScopedKeystone3Configuration() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_ENDPOINT,
+            CONFIG_CREDENTIALS,
+            CONFIG_USER_NAME,
+            CONFIG_USER_DOMAIN_NAME,
+            CONFIG_SCOPE_PROJECT_NAME,
+            CONFIG_SCOPE_PROJECT_DOMAIN_NAME,
+            CONFIG_REGION)));
+        assertThat(SwiftKeystone3ConfigurationReader.readSwiftConfiguration(configuration))
+            .isEqualTo(
+                SwiftKeystone3ObjectStorage.configBuilder()
+                    .endpoint(URI.create(ENDPOINT))
+                    .credentials(Credentials.of(CREDENTIALS))
+                    .identity(IdentityV3.of(
+                        DomainName.of(USER_DOMAIN_NAME),
+                        UserName.of(USER_NAME)))
+                    .region(Optional.of(Region.of(REGION)))
+                    .project(Project.of(
+                        ProjectName.of(SCOPE_PROJECT_NAME),
+                        DomainName.of(SCOPE_PROJECT_DOMAIN_NAME)))
+                    .build()
+            );
+    }
+
+    @Test
+    void readProjectOfDomainIdScopedKeystone3Configuration() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_ENDPOINT,
+            CONFIG_CREDENTIALS,
+            CONFIG_USER_NAME,
+            CONFIG_USER_DOMAIN_NAME,
+            CONFIG_SCOPE_PROJECT_NAME,
+            CONFIG_SCOPE_PROJECT_DOMAIN_ID,
+            CONFIG_REGION)));
+        assertThat(SwiftKeystone3ConfigurationReader.readSwiftConfiguration(configuration))
+            .isEqualTo(
+                SwiftKeystone3ObjectStorage.configBuilder()
+                    .endpoint(URI.create(ENDPOINT))
+                    .credentials(Credentials.of(CREDENTIALS))
+                    .identity(IdentityV3.of(
+                        DomainName.of(USER_DOMAIN_NAME),
+                        UserName.of(USER_NAME)))
+                    .region(Optional.of(Region.of(REGION)))
+                    .project(Project.of(
+                        ProjectName.of(SCOPE_PROJECT_NAME),
+                        DomainId.of(SCOPE_PROJECT_DOMAIN_ID)))
+                    .build()
+            );
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4872d69/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/SwiftTmpAuthConfigurationReaderTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/SwiftTmpAuthConfigurationReaderTest.java b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/SwiftTmpAuthConfigurationReaderTest.java
new file mode 100644
index 0000000..f5c2b7e
--- /dev/null
+++ b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/SwiftTmpAuthConfigurationReaderTest.java
@@ -0,0 +1,183 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.modules.objectstorage;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.io.StringReader;
+import java.net.URI;
+import java.util.Optional;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.james.blob.objectstorage.swift.Credentials;
+import org.apache.james.blob.objectstorage.swift.PassHeaderName;
+import org.apache.james.blob.objectstorage.swift.Region;
+import org.apache.james.blob.objectstorage.swift.SwiftTempAuthObjectStorage;
+import org.apache.james.blob.objectstorage.swift.TenantName;
+import org.apache.james.blob.objectstorage.swift.UserHeaderName;
+import org.apache.james.blob.objectstorage.swift.UserName;
+import org.junit.jupiter.api.Test;
+
+class SwiftTmpAuthConfigurationReaderTest {
+    private static final String ENDPOINT = "http://auth.example.com/v2.0";
+    private static final String CONFIG_ENDPOINT =
+        "objectstorage.swift.endpoint=" + ENDPOINT;
+
+    private static final String CREDENTIALS = "this_is_a_secret";
+    private static final String CONFIG_CREDENTIALS =
+        "objectstorage.swift.credentials=" + CREDENTIALS;
+
+    private static final String REGION = "EMEA";
+    private static final String CONFIG_REGION =
+        "objectstorage.swift.region=" + REGION;
+
+    private static final String USER_NAME = "user";
+    private static final String CONFIG_USER_NAME =
+        "objectstorage.swift.tempauth.username=" + USER_NAME;
+
+    private static final String TENANT_NAME = "tenant";
+    private static final String CONFIG_TENANT_NAME =
+        "objectstorage.swift.tempauth.tenantname=" + TENANT_NAME;
+
+    private static final String PASS_HEADER_NAME = "X-Pass-Header";
+    private static final String CONFIG_PASS_HEADER_NAME =
+        "objectstorage.swift.tempauth.passheadername=" + PASS_HEADER_NAME;
+
+    private static final String USER_HEADER_NAME = "X-User-Header";
+    private static final String CONFIG_USER_HEADER_NAME =
+        "objectstorage.swift.tempauth.userheadername=" + USER_HEADER_NAME;
+
+    @Test
+    void readBasicTempAuthConfiguration() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_ENDPOINT,
+            CONFIG_CREDENTIALS,
+            CONFIG_USER_NAME,
+            CONFIG_TENANT_NAME)));
+        assertThat(SwiftTmpAuthConfigurationReader.readSwiftConfiguration(configuration))
+            .isEqualTo(
+                SwiftTempAuthObjectStorage.configBuilder()
+                    .endpoint(URI.create(ENDPOINT))
+                    .credentials(Credentials.of(CREDENTIALS))
+                    .tenantName(TenantName.of(TENANT_NAME))
+                    .userName(UserName.of(USER_NAME))
+                    .build()
+            );
+    }
+
+    @Test
+    void readKeystone2ConfigurationWithRegion() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_ENDPOINT,
+            CONFIG_CREDENTIALS,
+            CONFIG_USER_NAME,
+            CONFIG_TENANT_NAME,
+            CONFIG_REGION)));
+        assertThat(SwiftTmpAuthConfigurationReader.readSwiftConfiguration(configuration))
+            .isEqualTo(
+                SwiftTempAuthObjectStorage.configBuilder()
+                    .endpoint(URI.create(ENDPOINT))
+                    .credentials(Credentials.of(CREDENTIALS))
+                    .tenantName(TenantName.of(TENANT_NAME))
+                    .userName(UserName.of(USER_NAME))
+                    .region(Optional.of(Region.of(REGION)))
+                    .build()
+            );
+    }
+
+    @Test
+    void readKeystone2ConfigurationWithCustomTempAuthHeaders() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_ENDPOINT,
+            CONFIG_CREDENTIALS,
+            CONFIG_USER_NAME,
+            CONFIG_TENANT_NAME,
+            CONFIG_USER_HEADER_NAME,
+            CONFIG_PASS_HEADER_NAME)));
+        assertThat(SwiftTmpAuthConfigurationReader.readSwiftConfiguration(configuration))
+            .isEqualTo(
+                SwiftTempAuthObjectStorage.configBuilder()
+                    .endpoint(URI.create(ENDPOINT))
+                    .credentials(Credentials.of(CREDENTIALS))
+                    .tenantName(TenantName.of(TENANT_NAME))
+                    .userName(UserName.of(USER_NAME))
+                    .tempAuthHeaderUserName(UserHeaderName.of(USER_HEADER_NAME))
+                    .tempAuthHeaderPassName(PassHeaderName.of(PASS_HEADER_NAME))
+                    .build()
+            );
+    }
+
+    @Test
+    void failToReadSwiftKeyston2ConfigurationWhenMissingEndpoint() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_CREDENTIALS,
+            CONFIG_USER_NAME,
+            CONFIG_TENANT_NAME,
+            CONFIG_REGION)));
+        assertThatThrownBy(() ->
+            SwiftTmpAuthConfigurationReader.readSwiftConfiguration(configuration))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void failToReadSwiftKeyston2ConfigurationWhenMissingCrendentials() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_ENDPOINT,
+            CONFIG_USER_NAME,
+            CONFIG_TENANT_NAME,
+            CONFIG_REGION)));
+        assertThatThrownBy(() ->
+            SwiftTmpAuthConfigurationReader.readSwiftConfiguration(configuration))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void failToReadSwiftKeyston2ConfigurationWhenMissingUserName() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_ENDPOINT,
+            CONFIG_CREDENTIALS,
+            CONFIG_TENANT_NAME,
+            CONFIG_REGION)));
+        assertThatThrownBy(() ->
+            SwiftTmpAuthConfigurationReader.readSwiftConfiguration(configuration))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void failToReadSwiftKeyston2ConfigurationWhenMissingTenantName() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.load(new StringReader(StringUtils.joinWith("\n",
+            CONFIG_ENDPOINT,
+            CONFIG_CREDENTIALS,
+            CONFIG_USER_NAME,
+            CONFIG_REGION)));
+        assertThatThrownBy(() ->
+            SwiftTmpAuthConfigurationReader.readSwiftConfiguration(configuration))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message