tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject git commit: TOMEE-1434 TOMEE-1430 support for roles/users in tomee embedded
Date Wed, 29 Oct 2014 14:02:42 GMT
Repository: tomee
Updated Branches:
  refs/heads/tomee-1.7.x fe9d200af -> 9189aaea5


TOMEE-1434 TOMEE-1430 support for roles/users in tomee embedded


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/9189aaea
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/9189aaea
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/9189aaea

Branch: refs/heads/tomee-1.7.x
Commit: 9189aaea5dd24bd52f64cf2abfbd867e7a7c54da
Parents: fe9d200
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Wed Oct 29 15:02:28 2014 +0100
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Wed Oct 29 15:02:36 2014 +0100

----------------------------------------------------------------------
 .../embedded/EmbeddedTomEEConfiguration.java    | 39 +++++++++++++++++++-
 .../embedded/EmbeddedTomEEContainer.java        |  8 ++++
 .../apache/tomee/embedded/Configuration.java    | 20 ++++++++++
 .../org/apache/tomee/embedded/Container.java    | 13 +++++++
 4 files changed, 79 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/9189aaea/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEConfiguration.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEConfiguration.java
b/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEConfiguration.java
index af2177c..1e3deb4 100644
--- a/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEConfiguration.java
+++ b/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEConfiguration.java
@@ -20,6 +20,7 @@ import org.apache.openejb.OpenEJBRuntimeException;
 import org.apache.openejb.arquillian.common.IO;
 import org.apache.openejb.arquillian.common.Prefixes;
 import org.apache.openejb.arquillian.common.TomEEConfiguration;
+import org.jboss.arquillian.config.descriptor.api.Multiline;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -40,6 +41,8 @@ public class EmbeddedTomEEConfiguration extends TomEEConfiguration {
     private String clientAuth;
     private String keyAlias;
     private String sslProtocol;
+    private String users;
+    private String roles;
 
     public int getHttpsPort() {
         return httpsPort;
@@ -105,6 +108,32 @@ public class EmbeddedTomEEConfiguration extends TomEEConfiguration {
         this.sslProtocol = sslProtocol;
     }
 
+    public String getUsers() {
+        return users;
+    }
+
+    public Properties getUsersAsProperties() {
+        return toProperties(users);
+    }
+
+    @Multiline
+    public void setUsers(final String users) {
+        this.users = users;
+    }
+
+    public String getRoles() {
+        return roles;
+    }
+
+    public Properties getRolesAsProperties() {
+        return toProperties(roles);
+    }
+
+    @Multiline
+    public void setRoles(final String roles) {
+        this.roles = roles;
+    }
+
     @Override
     public int[] portsAlreadySet() {
         final List<Integer> value = new ArrayList<Integer>();
@@ -125,8 +154,16 @@ public class EmbeddedTomEEConfiguration extends TomEEConfiguration {
             return new Properties();
         }
 
+        return toProperties(properties);
+    }
+
+    private static Properties toProperties(final String value) {
+        if (value == null || value.isEmpty()) {
+            return null;
+        }
+
         final Properties properties = new Properties();
-        final ByteArrayInputStream bais = new ByteArrayInputStream(getProperties().getBytes());
+        final ByteArrayInputStream bais = new ByteArrayInputStream(value.getBytes());
         try {
             properties.load(bais);
         } catch (final IOException e) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/9189aaea/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
b/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
index 613d2d9..e6f4d6a 100644
--- a/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
+++ b/arquillian/arquillian-tomee-embedded/src/main/java/org/apache/openejb/arquillian/embedded/EmbeddedTomEEContainer.java
@@ -44,6 +44,7 @@ import javax.enterprise.context.RequestScoped;
 import javax.enterprise.context.SessionScoped;
 import javax.servlet.http.HttpSession;
 import java.io.File;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -96,6 +97,13 @@ public class EmbeddedTomEEContainer extends TomEEContainer<EmbeddedTomEEConfigur
         configuration.setKeyAlias(tomeeConfiguration.getKeyAlias());
         configuration.setSslProtocol(tomeeConfiguration.getSslProtocol());
 
+        if (tomeeConfiguration.getRoles() != null) {
+            configuration.setRoles(new HashMap<String, String>(Map.class.cast(tomeeConfiguration.getRolesAsProperties())));
+        }
+        if (tomeeConfiguration.getUsers() != null) {
+            configuration.setUsers(new HashMap<String, String>(Map.class.cast(tomeeConfiguration.getUsersAsProperties())));
+        }
+
         return configuration;
     }
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/9189aaea/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Configuration.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Configuration.java
b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Configuration.java
index e705a38..702ef8a 100644
--- a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Configuration.java
+++ b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Configuration.java
@@ -19,6 +19,7 @@ package org.apache.tomee.embedded;
 import org.apache.openejb.util.NetworkUtil;
 
 import java.io.File;
+import java.util.Map;
 import java.util.Properties;
 
 /**
@@ -44,6 +45,9 @@ public class Configuration {
     private String keyAlias;
     private String sslProtocol;
 
+    private Map<String, String> users;
+    private Map<String, String> roles;
+
     public int getHttpPort() {
         return httpPort;
     }
@@ -195,4 +199,20 @@ public class Configuration {
         properties.setProperty(key, value);
         return this;
     }
+
+    public Map<String, String> getUsers() {
+        return users;
+    }
+
+    public void setUsers(final Map<String, String> users) { // useful for tools like
maven plugin
+        this.users = users;
+    }
+
+    public Map<String, String> getRoles() {
+        return roles;
+    }
+
+    public void setRoles(final Map<String, String> roles) {
+        this.roles = roles;
+    }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/9189aaea/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java
index 4b00885..147d002 100644
--- a/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java
+++ b/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java
@@ -241,6 +241,19 @@ public class Container implements Closeable {
         // Bootstrap Tomcat
         Logger.getInstance(LogCategory.OPENEJB_STARTUP, Container.class).info("Starting TomEE
from: " + base.getAbsolutePath()); // create it after Logger is configured
 
+        if (configuration.getUsers() != null) {
+            for (final Map.Entry<String, String> user : configuration.getUsers().entrySet())
{
+                tomcat.addUser(user.getKey(), user.getValue());
+            }
+        }
+        if (configuration.getRoles() != null) {
+            for (final Map.Entry<String, String> user : configuration.getRoles().entrySet())
{
+                for (final String role : user.getValue().split(" *, *")) {
+                    tomcat.addRole(user.getKey(), role);
+                }
+            }
+        }
+
         final String catalinaBase = base.getAbsolutePath();
         System.setProperty("openejb.deployments.classpath", "false");
         System.setProperty("catalina.home", catalinaBase);


Mime
View raw message