Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add ServerSetup extension to allow for setup before the deployment

  • Loading branch information...
commit 5bbdbb1f7428300982aeafc8e73864e817246ac7 1 parent 059b8f8
Stuart Douglas authored February 24, 2012

Showing 15 changed files with 412 additions and 287 deletions. Show diff stats Hide diff stats

  1. 22  arquillian/common/src/main/java/org/jboss/as/arquillian/api/ServerSetup.java
  2. 16  arquillian/common/src/main/java/org/jboss/as/arquillian/api/ServerSetupTask.java
  3. 1  arquillian/common/src/main/java/org/jboss/as/arquillian/container/CommonContainerExtension.java
  4. 105  arquillian/common/src/main/java/org/jboss/as/arquillian/container/ServerSetupObserver.java
  5. 69  ...ite/integration/basic/src/test/java/org/jboss/as/test/integration/security/AbstractSecurityDomainSetup.java
  6. 198  testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/web/security/SecurityTest.java
  7. 2  ...ntegration/basic/src/test/java/org/jboss/as/test/integration/web/security/WebSecurityPasswordBasedBase.java
  8. 84  ...basic/src/test/java/org/jboss/as/test/integration/web/security/WebSimpleRoleMappingSecurityDomainSetup.java
  9. 65  ...integration/basic/src/test/java/org/jboss/as/test/integration/web/security/WebTestsSecurityDomainSetup.java
  10. 7  ...egration/basic/src/test/java/org/jboss/as/test/integration/web/security/basic/WebSecurityBASICTestCase.java
  11. 6  ...ntegration/basic/src/test/java/org/jboss/as/test/integration/web/security/form/WebSecurityFORMTestCase.java
  12. 5  ...rc/test/java/org/jboss/as/test/integration/web/security/form/WebSecurityJBossSimpleRoleMappingTestCase.java
  13. 6  .../test/java/org/jboss/as/test/integration/web/security/form/WebSecurityJBossWebXmlSecurityRolesTestCase.java
  14. 105  ...src/test/java/org/jboss/as/test/integration/web/security/servlet3/WebSecurityProgrammaticLoginTestCase.java
  15. 8  ...tegration/basic/src/test/java/org/jboss/as/test/integration/web/security/tg/TransportGuaranteeTestCase.java
22  arquillian/common/src/main/java/org/jboss/as/arquillian/api/ServerSetup.java
... ...
@@ -0,0 +1,22 @@
  1
+package org.jboss.as.arquillian.api;
  2
+
  3
+import java.lang.annotation.ElementType;
  4
+import java.lang.annotation.Retention;
  5
+import java.lang.annotation.RetentionPolicy;
  6
+import java.lang.annotation.Target;
  7
+
  8
+/**
  9
+ * Annotation that can be applied to an arquillian test to allow for server setup to be performed
  10
+ * before the deployment is performed.
  11
+ *
  12
+ * This will be run before the first deployment is performed for each server.
  13
+ *
  14
+ * @author Stuart Douglas
  15
+ */
  16
+@Retention(RetentionPolicy.RUNTIME)
  17
+@Target(ElementType.TYPE)
  18
+public @interface ServerSetup {
  19
+
  20
+    Class<? extends ServerSetupTask> value();
  21
+
  22
+}
16  arquillian/common/src/main/java/org/jboss/as/arquillian/api/ServerSetupTask.java
... ...
@@ -0,0 +1,16 @@
  1
+package org.jboss.as.arquillian.api;
  2
+
  3
+import org.jboss.as.arquillian.container.ManagementClient;
  4
+
  5
+/**
  6
+ *
  7
+ * A task which is run before deployment that allows the client to customize the server config.
  8
+ *
  9
+ * @author Stuart Douglas
  10
+ */
  11
+public interface ServerSetupTask {
  12
+
  13
+    void setup(final ManagementClient managementClient);
  14
+
  15
+    void tearDown(final ManagementClient managementClient);
  16
+}
1  arquillian/common/src/main/java/org/jboss/as/arquillian/container/CommonContainerExtension.java
@@ -34,5 +34,6 @@ public void register(final ExtensionBuilder builder) {
34 34
         builder.service(ApplicationArchiveProcessor.class, OSGiApplicationArchiveProcessor.class);
35 35
         builder.service(DeploymentExceptionTransformer.class, ExceptionTransformer.class);
36 36
         builder.service(ResourceProvider.class, ManagementClientProvider.class);
  37
+        builder.observer(ServerSetupObserver.class);
37 38
     }
38 39
 }
105  arquillian/common/src/main/java/org/jboss/as/arquillian/container/ServerSetupObserver.java
... ...
@@ -0,0 +1,105 @@
  1
+package org.jboss.as.arquillian.container;
  2
+
  3
+import java.util.ArrayList;
  4
+import java.util.HashSet;
  5
+import java.util.List;
  6
+import java.util.Set;
  7
+
  8
+import org.jboss.arquillian.container.spi.Container;
  9
+import org.jboss.arquillian.container.spi.event.container.BeforeDeploy;
  10
+import org.jboss.arquillian.core.api.Instance;
  11
+import org.jboss.arquillian.core.api.annotation.Inject;
  12
+import org.jboss.arquillian.core.api.annotation.Observes;
  13
+import org.jboss.arquillian.test.spi.context.ClassContext;
  14
+import org.jboss.arquillian.test.spi.event.suite.AfterClass;
  15
+import org.jboss.as.arquillian.api.ServerSetup;
  16
+import org.jboss.as.arquillian.api.ServerSetupTask;
  17
+
  18
+/**
  19
+ * @author Stuart Douglas
  20
+ */
  21
+public class ServerSetupObserver {
  22
+
  23
+
  24
+    @Inject
  25
+    private Instance<ManagementClient> managementClient;
  26
+
  27
+    @Inject
  28
+    private Instance<ClassContext> classContextInstance;
  29
+
  30
+    private Set<ContainerClassHolder> alreadyRun = new HashSet<ContainerClassHolder>();
  31
+
  32
+    private final List<ManagementClient> active = new ArrayList<ManagementClient>();
  33
+    private ServerSetupTask current;
  34
+
  35
+    public synchronized void handleBeforeDeployment(@Observes BeforeDeploy event, Container container) throws IllegalAccessException, InstantiationException {
  36
+
  37
+        final ClassContext classContext = classContextInstance.get();
  38
+        if (classContext == null) {
  39
+            return;
  40
+        }
  41
+
  42
+        final Class<?> currentClass = classContext.getActiveId();
  43
+        final ContainerClassHolder holder = new ContainerClassHolder(container.getName(), currentClass);
  44
+        if (alreadyRun.contains(holder)) {
  45
+            return;
  46
+        }
  47
+        alreadyRun.add(holder);
  48
+        ServerSetup setup = currentClass.getAnnotation(ServerSetup.class);
  49
+        if (setup == null) {
  50
+            return;
  51
+        }
  52
+        if (current == null) {
  53
+            current = setup.value().newInstance();
  54
+        } else if (current.getClass() != setup.value()) {
  55
+            throw new RuntimeException("Mismatched ServerSetupTask current is " + current + " but " + currentClass + " is expecting " + setup.value());
  56
+        }
  57
+
  58
+        final ManagementClient client = managementClient.get();
  59
+        current.setup(client);
  60
+        active.add(client);
  61
+    }
  62
+
  63
+    public synchronized void handleAfterClass(@Observes AfterClass event) {
  64
+        if (current != null) {
  65
+            for(final ManagementClient client : active) {
  66
+                current.tearDown(client);
  67
+            }
  68
+            active.clear();
  69
+            current = null;
  70
+        }
  71
+    }
  72
+
  73
+
  74
+    private static final class ContainerClassHolder {
  75
+        private final Class<?> testClass;
  76
+        private final String name;
  77
+
  78
+        private ContainerClassHolder(final String name, final Class<?> testClass) {
  79
+            this.name = name;
  80
+            this.testClass = testClass;
  81
+        }
  82
+
  83
+        @Override
  84
+        public boolean equals(final Object o) {
  85
+            if (this == o) return true;
  86
+            if (o == null || getClass() != o.getClass()) return false;
  87
+
  88
+            final ContainerClassHolder that = (ContainerClassHolder) o;
  89
+
  90
+            if (name != null ? !name.equals(that.name) : that.name != null) return false;
  91
+            if (testClass != null ? !testClass.equals(that.testClass) : that.testClass != null) return false;
  92
+
  93
+            return true;
  94
+        }
  95
+
  96
+        @Override
  97
+        public int hashCode() {
  98
+            int result = testClass != null ? testClass.hashCode() : 0;
  99
+            result = 31 * result + (name != null ? name.hashCode() : 0);
  100
+            return result;
  101
+        }
  102
+    }
  103
+
  104
+
  105
+}
69  .../integration/basic/src/test/java/org/jboss/as/test/integration/security/AbstractSecurityDomainSetup.java
... ...
@@ -0,0 +1,69 @@
  1
+package org.jboss.as.test.integration.security;
  2
+
  3
+import java.util.List;
  4
+
  5
+import org.jboss.as.arquillian.api.ServerSetupTask;
  6
+import org.jboss.as.arquillian.container.ManagementClient;
  7
+import org.jboss.as.controller.client.ModelControllerClient;
  8
+import org.jboss.as.controller.client.OperationBuilder;
  9
+import org.jboss.as.security.Constants;
  10
+import org.jboss.dmr.ModelNode;
  11
+
  12
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
  13
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS;
  14
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
  15
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE;
  16
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ROLLBACK_ON_RUNTIME_FAILURE;
  17
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
  18
+
  19
+/**
  20
+ * @author Stuart Douglas
  21
+ */
  22
+public abstract class AbstractSecurityDomainSetup implements ServerSetupTask {
  23
+
  24
+    protected static void applyUpdates(final ModelControllerClient client, final List<ModelNode> updates) {
  25
+        for (ModelNode update : updates) {
  26
+            try {
  27
+                applyUpdate(client, update, false);
  28
+            } catch (Exception e) {
  29
+                throw new RuntimeException(e);
  30
+            }
  31
+        }
  32
+    }
  33
+
  34
+    protected static void applyUpdate(final ModelControllerClient client, ModelNode update, boolean allowFailure) throws Exception {
  35
+        try {
  36
+            ModelNode result = client.execute(new OperationBuilder(update).build());
  37
+            if (result.hasDefined("outcome") && (allowFailure || "success".equals(result.get("outcome").asString()))) {
  38
+                if (result.hasDefined("result")) {
  39
+                    System.out.println(result.get("result"));
  40
+                }
  41
+            } else if (result.hasDefined("failure-description")) {
  42
+                throw new RuntimeException(result.get("failure-description").toString());
  43
+            } else {
  44
+                throw new RuntimeException("Operation not successful; outcome = " + result.get("outcome"));
  45
+            }
  46
+        } finally {
  47
+            client.close();
  48
+        }
  49
+    }
  50
+
  51
+    @Override
  52
+    public void tearDown(final ManagementClient managementClient) {
  53
+
  54
+        ModelNode op = new ModelNode();
  55
+        op.get(OP).set(REMOVE);
  56
+        op.get(OP_ADDR).add(SUBSYSTEM, "security");
  57
+        op.get(OP_ADDR).add(Constants.SECURITY_DOMAIN, getSecurityDomainName());
  58
+        // Don't rollback when the AS detects the war needs the module
  59
+        op.get(OPERATION_HEADERS, ROLLBACK_ON_RUNTIME_FAILURE).set(false);
  60
+
  61
+        try {
  62
+            applyUpdate(managementClient.getControllerClient(), op, true);
  63
+        } catch (Exception e) {
  64
+            throw new RuntimeException(e);
  65
+        }
  66
+    }
  67
+
  68
+    protected abstract String getSecurityDomainName();
  69
+}
198  testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/web/security/SecurityTest.java
... ...
@@ -1,198 +0,0 @@
1  
-/*
2  
- * JBoss, Home of Professional Open Source.
3  
- * Copyright 2011, Red Hat, Inc., and individual contributors
4  
- * as indicated by the @author tags. See the copyright.txt file in the
5  
- * distribution for a full listing of individual contributors.
6  
- *
7  
- * This is free software; you can redistribute it and/or modify it
8  
- * under the terms of the GNU Lesser General Public License as
9  
- * published by the Free Software Foundation; either version 2.1 of
10  
- * the License, or (at your option) any later version.
11  
- *
12  
- * This software is distributed in the hope that it will be useful,
13  
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  
- * Lesser General Public License for more details.
16  
- *
17  
- * You should have received a copy of the GNU Lesser General Public
18  
- * License along with this software; if not, write to the Free
19  
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  
- */
22  
-
23  
-package org.jboss.as.test.integration.web.security;
24  
-
25  
-
26  
-import java.net.InetAddress;
27  
-import java.util.ArrayList;
28  
-import java.util.List;
29  
-
30  
-import org.jboss.as.controller.client.ModelControllerClient;
31  
-import org.jboss.as.controller.client.OperationBuilder;
32  
-import org.jboss.as.security.Constants;
33  
-import org.jboss.dmr.ModelNode;
34  
-import org.jboss.logging.Logger;
35  
-import org.junit.AfterClass;
36  
-
37  
-import static org.jboss.as.arquillian.container.Authentication.getCallbackHandler;
38  
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
39  
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART;
40  
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
41  
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS;
42  
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
43  
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE;
44  
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ROLLBACK_ON_RUNTIME_FAILURE;
45  
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
46  
-import static org.jboss.as.security.Constants.AUTHENTICATION;
47  
-import static org.jboss.as.security.Constants.CLASSIC;
48  
-import static org.jboss.as.security.Constants.CODE;
49  
-import static org.jboss.as.security.Constants.FLAG;
50  
-import static org.jboss.as.security.Constants.MAPPING;
51  
-import static org.jboss.as.security.Constants.MAPPING_MODULES;
52  
-import static org.jboss.as.security.Constants.MODULE_OPTIONS;
53  
-import static org.jboss.as.security.Constants.SECURITY_DOMAIN;
54  
-import static org.jboss.as.security.Constants.TYPE;
55  
-
56  
-/**
57  
- * Utility methods to create/remove simple security domains.
58  
- * <p/>
59  
- * Tests should inherit from this class, to make sure the security domain is removed.
60  
- *
61  
- * @author <a href="mailto:mmoyses@redhat.com">Marcus Moyses</a>
62  
- */
63  
-public class SecurityTest {
64  
-
65  
-    protected static String securityDomain = "web-tests";
66  
-
67  
-    private static final Logger log = Logger.getLogger(SecurityTest.class);
68  
-
69  
-    // this is removing the security domain after each test so I have to disable it
70  
-    @AfterClass
71  
-    public static void after() throws Exception {
72  
-        // remove test security domains
73  
-        try {
74  
-            removeSecurityDomain();
75  
-            log.info("Domain Removed - Allegedly");
76  
-        } catch (Exception e) {
77  
-            log.error(e);
78  
-            throw e;
79  
-        }
80  
-    }
81  
-
82  
-    protected static void createSecurityDomain() throws Exception {
83  
-
84  
-        log.debug("start of the domain creation");
85  
-
86  
-        final List<ModelNode> updates = new ArrayList<ModelNode>();
87  
-        ModelNode op = new ModelNode();
88  
-
89  
-        op.get(OP).set(ADD);
90  
-        op.get(OP_ADDR).add(SUBSYSTEM, "security");
91  
-        op.get(OP_ADDR).add(SECURITY_DOMAIN, securityDomain);
92  
-        updates.add(op);
93  
-
94  
-        op = new ModelNode();
95  
-        op.get(OP).set(ADD);
96  
-        op.get(OP_ADDR).add(SUBSYSTEM, "security");
97  
-        op.get(OP_ADDR).add(SECURITY_DOMAIN, securityDomain);
98  
-        op.get(OP_ADDR).add(AUTHENTICATION, Constants.CLASSIC);
99  
-
100  
-        ModelNode loginModule = op.get(Constants.LOGIN_MODULES).add();
101  
-        loginModule.get(CODE).set("UsersRoles");
102  
-        loginModule.get(FLAG).set("required");
103  
-        op.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true);
104  
-        updates.add(op);
105  
-
106  
-        try {
107  
-            applyUpdates(updates);
108  
-        } catch (Exception e) {
109  
-            log.error(e);
110  
-            throw e;
111  
-        }
112  
-        log.debug("end of the domain creation");
113  
-    }
114  
-
115  
-    protected static void createSimpleRoleMappingSecurityDomain() throws Exception {
116  
-
117  
-        log.debug("start of the domain creation");
118  
-
119  
-
120  
-        final List<ModelNode> updates = new ArrayList<ModelNode>();
121  
-
122  
-        ModelNode op = new ModelNode();
123  
-        op.get(OP).set(ADD);
124  
-        op.get(OP_ADDR).add(SUBSYSTEM, "security");
125  
-        op.get(OP_ADDR).add(SECURITY_DOMAIN, securityDomain);
126  
-        updates.add(op);
127  
-
128  
-        op = new ModelNode();
129  
-        op.get(OP).set(ADD);
130  
-        op.get(OP_ADDR).add(SUBSYSTEM, "security");
131  
-        op.get(OP_ADDR).add(SECURITY_DOMAIN, securityDomain);
132  
-        op.get(OP_ADDR).add(AUTHENTICATION, Constants.CLASSIC);
133  
-
134  
-        ModelNode loginModule = op.get(Constants.LOGIN_MODULES).add();
135  
-        loginModule.get(CODE).set("UsersRoles");
136  
-        loginModule.get(FLAG).set("required");
137  
-        updates.add(op);
138  
-
139  
-        op = new ModelNode();
140  
-        op.get(OP).set(ADD);
141  
-        op.get(OP_ADDR).add(SUBSYSTEM, "security");
142  
-        op.get(OP_ADDR).add(SECURITY_DOMAIN, securityDomain);
143  
-        op.get(OP_ADDR).add(MAPPING, CLASSIC);
144  
-
145  
-        ModelNode mappingModule = op.get(MAPPING_MODULES).add();
146  
-        mappingModule.get(CODE).set("SimpleRoles"); // see:  https://docs.jboss.org/author/display/AS71/Security+subsystem+configuration
147  
-        mappingModule.get(TYPE).set("role");
148  
-        ModelNode mappingOptions = mappingModule.get(MODULE_OPTIONS);
149  
-        mappingOptions.get("peter").set("superuser,gooduser");
150  
-        op.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true);
151  
-        updates.add(op);
152  
-
153  
-        try {
154  
-            applyUpdates(updates);
155  
-        } catch (Exception e) {
156  
-            log.error(e);
157  
-            throw e;
158  
-        }
159  
-        log.debug("end of the domain creation");
160  
-    }
161  
-
162  
-    protected static void removeSecurityDomain() throws Exception {
163  
-
164  
-        ModelNode op = new ModelNode();
165  
-        op.get(OP).set(REMOVE);
166  
-        op.get(OP_ADDR).add(SUBSYSTEM, "security");
167  
-        op.get(OP_ADDR).add(SECURITY_DOMAIN, securityDomain);
168  
-        // Don't rollback when the AS detects the war needs the module
169  
-        op.get(OPERATION_HEADERS, ROLLBACK_ON_RUNTIME_FAILURE).set(false);
170  
-
171  
-        applyUpdate(op, true);
172  
-    }
173  
-
174  
-    protected static void applyUpdates(final List<ModelNode> updates) throws Exception {
175  
-        for (ModelNode update : updates) {
176  
-            applyUpdate(update, false);
177  
-        }
178  
-    }
179  
-
180  
-    protected static void applyUpdate(ModelNode update, boolean allowFailure) throws Exception {
181  
-        final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getByName("localhost"), 9999, getCallbackHandler());
182  
-        try {
183  
-            ModelNode result = client.execute(new OperationBuilder(update).build());
184  
-            if (result.hasDefined("outcome") && (allowFailure || "success".equals(result.get("outcome").asString()))) {
185  
-                if (result.hasDefined("result")) {
186  
-                    System.out.println(result.get("result"));
187  
-                }
188  
-            } else if (result.hasDefined("failure-description")) {
189  
-                throw new RuntimeException(result.get("failure-description").toString());
190  
-            } else {
191  
-                throw new RuntimeException("Operation not successful; outcome = " + result.get("outcome"));
192  
-            }
193  
-        } finally {
194  
-            client.close();
195  
-        }
196  
-    }
197  
-
198  
-}
2  ...gration/basic/src/test/java/org/jboss/as/test/integration/web/security/WebSecurityPasswordBasedBase.java
@@ -29,7 +29,7 @@
29 29
  *
30 30
  * @author Anil Saldhana
31 31
  */
32  
-public abstract class WebSecurityPasswordBasedBase extends SecurityTest {
  32
+public abstract class WebSecurityPasswordBasedBase {
33 33
 
34 34
     private String hostname = "localhost";
35 35
     private int port = 8080;
84  ...ic/src/test/java/org/jboss/as/test/integration/web/security/WebSimpleRoleMappingSecurityDomainSetup.java
... ...
@@ -0,0 +1,84 @@
  1
+package org.jboss.as.test.integration.web.security;
  2
+
  3
+import java.util.ArrayList;
  4
+import java.util.List;
  5
+
  6
+import org.jboss.as.arquillian.container.ManagementClient;
  7
+import org.jboss.as.security.Constants;
  8
+import org.jboss.as.test.integration.security.AbstractSecurityDomainSetup;
  9
+import org.jboss.dmr.ModelNode;
  10
+import org.jboss.logging.Logger;
  11
+
  12
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
  13
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART;
  14
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
  15
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS;
  16
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
  17
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
  18
+import static org.jboss.as.security.Constants.AUTHENTICATION;
  19
+import static org.jboss.as.security.Constants.CLASSIC;
  20
+import static org.jboss.as.security.Constants.CODE;
  21
+import static org.jboss.as.security.Constants.FLAG;
  22
+import static org.jboss.as.security.Constants.MAPPING;
  23
+import static org.jboss.as.security.Constants.MAPPING_MODULES;
  24
+import static org.jboss.as.security.Constants.MODULE_OPTIONS;
  25
+import static org.jboss.as.security.Constants.TYPE;
  26
+
  27
+/**
  28
+ * @author Stuart Douglas
  29
+ */
  30
+public class WebSimpleRoleMappingSecurityDomainSetup extends AbstractSecurityDomainSetup {
  31
+
  32
+    private static final Logger log = Logger.getLogger(WebSimpleRoleMappingSecurityDomainSetup.class);
  33
+
  34
+    protected static final String WEB_SECURITY_DOMAIN = "web-tests";
  35
+
  36
+    @Override
  37
+    public void setup(final ManagementClient managementClient) {
  38
+        log.debug("start of the domain creation");
  39
+
  40
+
  41
+        final List<ModelNode> updates = new ArrayList<ModelNode>();
  42
+
  43
+        ModelNode op = new ModelNode();
  44
+        op.get(OP).set(ADD);
  45
+        op.get(OP_ADDR).add(SUBSYSTEM, "security");
  46
+        op.get(OP_ADDR).add(Constants.SECURITY_DOMAIN, getSecurityDomainName());
  47
+        updates.add(op);
  48
+
  49
+        op = new ModelNode();
  50
+        op.get(OP).set(ADD);
  51
+        op.get(OP_ADDR).add(SUBSYSTEM, "security");
  52
+        op.get(OP_ADDR).add(Constants.SECURITY_DOMAIN, getSecurityDomainName());
  53
+        op.get(OP_ADDR).add(AUTHENTICATION, Constants.CLASSIC);
  54
+
  55
+        ModelNode loginModule = op.get(Constants.LOGIN_MODULES).add();
  56
+        loginModule.get(CODE).set("UsersRoles");
  57
+        loginModule.get(FLAG).set("required");
  58
+        updates.add(op);
  59
+
  60
+        op = new ModelNode();
  61
+        op.get(OP).set(ADD);
  62
+        op.get(OP_ADDR).add(SUBSYSTEM, "security");
  63
+        op.get(OP_ADDR).add(Constants.SECURITY_DOMAIN, getSecurityDomainName());
  64
+        op.get(OP_ADDR).add(MAPPING, CLASSIC);
  65
+
  66
+        ModelNode mappingModule = op.get(MAPPING_MODULES).add();
  67
+        mappingModule.get(CODE).set("SimpleRoles"); // see:  https://docs.jboss.org/author/display/AS71/Security+subsystem+configuration
  68
+        mappingModule.get(TYPE).set("role");
  69
+        ModelNode mappingOptions = mappingModule.get(MODULE_OPTIONS);
  70
+        mappingOptions.get("peter").set("superuser,gooduser");
  71
+        op.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true);
  72
+        updates.add(op);
  73
+
  74
+        applyUpdates(managementClient.getControllerClient(), updates);
  75
+        log.debug("end of the domain creation");
  76
+    }
  77
+
  78
+
  79
+    @Override
  80
+    protected String getSecurityDomainName() {
  81
+        return WEB_SECURITY_DOMAIN;
  82
+    }
  83
+
  84
+}
65  ...egration/basic/src/test/java/org/jboss/as/test/integration/web/security/WebTestsSecurityDomainSetup.java
... ...
@@ -0,0 +1,65 @@
  1
+package org.jboss.as.test.integration.web.security;
  2
+
  3
+import java.util.ArrayList;
  4
+import java.util.List;
  5
+
  6
+import org.jboss.as.arquillian.container.ManagementClient;
  7
+import org.jboss.as.security.Constants;
  8
+import org.jboss.as.test.integration.security.AbstractSecurityDomainSetup;
  9
+import org.jboss.dmr.ModelNode;
  10
+import org.jboss.logging.Logger;
  11
+
  12
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
  13
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART;
  14
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
  15
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS;
  16
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
  17
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
  18
+import static org.jboss.as.security.Constants.AUTHENTICATION;
  19
+import static org.jboss.as.security.Constants.CODE;
  20
+import static org.jboss.as.security.Constants.FLAG;
  21
+import static org.jboss.as.security.Constants.SECURITY_DOMAIN;
  22
+
  23
+/**
  24
+ * @author Stuart Douglas
  25
+ */
  26
+public class WebTestsSecurityDomainSetup extends AbstractSecurityDomainSetup {
  27
+
  28
+    private static final Logger log = Logger.getLogger(WebTestsSecurityDomainSetup.class);
  29
+
  30
+    protected static final String WEB_SECURITY_DOMAIN = "web-tests";
  31
+
  32
+    @Override
  33
+    public void setup(final ManagementClient managementClient) {
  34
+        log.debug("start of the domain creation");
  35
+
  36
+        final List<ModelNode> updates = new ArrayList<ModelNode>();
  37
+        ModelNode op = new ModelNode();
  38
+
  39
+        op.get(OP).set(ADD);
  40
+        op.get(OP_ADDR).add(SUBSYSTEM, "security");
  41
+        op.get(OP_ADDR).add(SECURITY_DOMAIN, getSecurityDomainName());
  42
+        updates.add(op);
  43
+
  44
+        op = new ModelNode();
  45
+        op.get(OP).set(ADD);
  46
+        op.get(OP_ADDR).add(SUBSYSTEM, "security");
  47
+        op.get(OP_ADDR).add(SECURITY_DOMAIN, getSecurityDomainName());
  48
+        op.get(OP_ADDR).add(AUTHENTICATION, Constants.CLASSIC);
  49
+
  50
+        ModelNode loginModule = op.get(Constants.LOGIN_MODULES).add();
  51
+        loginModule.get(CODE).set("UsersRoles");
  52
+        loginModule.get(FLAG).set("required");
  53
+        op.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true);
  54
+        updates.add(op);
  55
+        applyUpdates(managementClient.getControllerClient(), updates);
  56
+        log.debug("end of the domain creation");
  57
+    }
  58
+
  59
+    @Override
  60
+    protected String getSecurityDomainName() {
  61
+        return WEB_SECURITY_DOMAIN;
  62
+    }
  63
+
  64
+
  65
+}
7  ...ation/basic/src/test/java/org/jboss/as/test/integration/web/security/basic/WebSecurityBASICTestCase.java
@@ -32,8 +32,10 @@
32 32
 import org.jboss.arquillian.container.test.api.Deployment;
33 33
 import org.jboss.arquillian.container.test.api.RunAsClient;
34 34
 import org.jboss.arquillian.junit.Arquillian;
  35
+import org.jboss.as.arquillian.api.ServerSetup;
35 36
 import org.jboss.as.test.integration.web.security.SecuredServlet;
36 37
 import org.jboss.as.test.integration.web.security.WebSecurityPasswordBasedBase;
  38
+import org.jboss.as.test.integration.web.security.WebTestsSecurityDomainSetup;
37 39
 import org.jboss.shrinkwrap.api.ShrinkWrap;
38 40
 import org.jboss.shrinkwrap.api.spec.WebArchive;
39 41
 import org.junit.runner.RunWith;
@@ -47,14 +49,11 @@
47 49
  */
48 50
 @RunWith(Arquillian.class)
49 51
 @RunAsClient
  52
+@ServerSetup(WebTestsSecurityDomainSetup.class)
50 53
 public class WebSecurityBASICTestCase extends WebSecurityPasswordBasedBase {
51 54
 
52 55
     @Deployment
53 56
     public static WebArchive deployment() throws Exception {
54  
-
55  
-        // create required security domains
56  
-        createSecurityDomain();
57  
-
58 57
         WebArchive war = ShrinkWrap.create(WebArchive.class, "web-secure-basic.war");
59 58
         war.addClass(SecuredServlet.class);
60 59
 
6  ...gration/basic/src/test/java/org/jboss/as/test/integration/web/security/form/WebSecurityFORMTestCase.java
@@ -41,8 +41,10 @@
41 41
 import org.jboss.arquillian.container.test.api.Deployment;
42 42
 import org.jboss.arquillian.container.test.api.RunAsClient;
43 43
 import org.jboss.arquillian.junit.Arquillian;
  44
+import org.jboss.as.arquillian.api.ServerSetup;
44 45
 import org.jboss.as.test.integration.web.security.SecuredServlet;
45 46
 import org.jboss.as.test.integration.web.security.WebSecurityPasswordBasedBase;
  47
+import org.jboss.as.test.integration.web.security.WebTestsSecurityDomainSetup;
46 48
 import org.jboss.shrinkwrap.api.ShrinkWrap;
47 49
 import org.jboss.shrinkwrap.api.spec.WebArchive;
48 50
 import org.junit.runner.RunWith;
@@ -56,13 +58,11 @@
56 58
  */
57 59
 @RunWith(Arquillian.class)
58 60
 @RunAsClient
  61
+@ServerSetup(WebTestsSecurityDomainSetup.class)
59 62
 public class WebSecurityFORMTestCase extends WebSecurityPasswordBasedBase {
60 63
 
61 64
     @Deployment
62 65
     public static WebArchive deployment() throws Exception {
63  
-        // FIXME hack to get things prepared before the deployment happens
64  
-        // create required security domains
65  
-        createSecurityDomain();
66 66
 
67 67
         WebArchive war = ShrinkWrap.create(WebArchive.class, "web-secure.war");
68 68
         war.addClasses(SecuredServlet.class);
5  ...test/java/org/jboss/as/test/integration/web/security/form/WebSecurityJBossSimpleRoleMappingTestCase.java
@@ -28,9 +28,10 @@
28 28
 import org.jboss.arquillian.container.test.api.RunAsClient;
29 29
 import org.jboss.arquillian.junit.Arquillian;
30 30
 import org.jboss.arquillian.test.api.ArquillianResource;
  31
+import org.jboss.as.arquillian.api.ServerSetup;
31 32
 import org.jboss.as.test.integration.web.security.SecuredServlet;
32  
-import org.jboss.as.test.integration.web.security.SecurityTest;
33 33
 import org.jboss.as.test.integration.web.security.WebSecurityPasswordBasedBase;
  34
+import org.jboss.as.test.integration.web.security.WebSimpleRoleMappingSecurityDomainSetup;
34 35
 import org.jboss.shrinkwrap.api.ShrinkWrap;
35 36
 import org.jboss.shrinkwrap.api.spec.WebArchive;
36 37
 import org.junit.Before;
@@ -44,6 +45,7 @@
44 45
  */
45 46
 @RunWith(Arquillian.class)
46 47
 @RunAsClient
  48
+@ServerSetup(WebSimpleRoleMappingSecurityDomainSetup.class)
47 49
 public class WebSecurityJBossSimpleRoleMappingTestCase extends WebSecurityFORMTestCase {
48 50
 
49 51
     public static final String deploymentName = "web-secure.war";
@@ -62,7 +64,6 @@ public void init() {
62 64
 
63 65
     @Deployment(name = deploymentName, order = 1, testable = false)
64 66
     public static WebArchive deployment() throws Exception {
65  
-        SecurityTest.createSimpleRoleMappingSecurityDomain();
66 67
 
67 68
         WebArchive war = ShrinkWrap.create(WebArchive.class, "web-secure.war");
68 69
         war.addClasses(SecuredServlet.class);
6  ...st/java/org/jboss/as/test/integration/web/security/form/WebSecurityJBossWebXmlSecurityRolesTestCase.java
@@ -28,8 +28,10 @@
28 28
 import org.jboss.arquillian.container.test.api.RunAsClient;
29 29
 import org.jboss.arquillian.junit.Arquillian;
30 30
 import org.jboss.arquillian.test.api.ArquillianResource;
  31
+import org.jboss.as.arquillian.api.ServerSetup;
31 32
 import org.jboss.as.test.integration.web.security.SecuredServlet;
32 33
 import org.jboss.as.test.integration.web.security.WebSecurityPasswordBasedBase;
  34
+import org.jboss.as.test.integration.web.security.WebTestsSecurityDomainSetup;
33 35
 import org.jboss.shrinkwrap.api.ShrinkWrap;
34 36
 import org.jboss.shrinkwrap.api.spec.WebArchive;
35 37
 import org.junit.Before;
@@ -43,6 +45,7 @@
43 45
  */
44 46
 @RunWith(Arquillian.class)
45 47
 @RunAsClient
  48
+@ServerSetup(WebTestsSecurityDomainSetup.class)
46 49
 public class WebSecurityJBossWebXmlSecurityRolesTestCase extends WebSecurityFORMTestCase {
47 50
 
48 51
     public static final String deploymentName = "web-secure.war";
@@ -61,9 +64,6 @@ public void init() {
61 64
 
62 65
     @Deployment(name = deploymentName, order = 1, testable = false)
63 66
     public static WebArchive deployment() throws Exception {
64  
-        // FIXME hack to get things prepared before the deployment happens
65  
-        // create required security domains
66  
-        createSecurityDomain();
67 67
 
68 68
         WebArchive war = ShrinkWrap.create(WebArchive.class, "web-secure.war");
69 69
         war.addClasses(SecuredServlet.class);
105  .../test/java/org/jboss/as/test/integration/web/security/servlet3/WebSecurityProgrammaticLoginTestCase.java
@@ -21,7 +21,6 @@
21 21
  */
22 22
 package org.jboss.as.test.integration.web.security.servlet3;
23 23
 
24  
-import java.net.InetAddress;
25 24
 import java.util.ArrayList;
26 25
 import java.util.List;
27 26
 
@@ -33,22 +32,21 @@
33 32
 import org.apache.http.util.EntityUtils;
34 33
 import org.jboss.arquillian.container.test.api.Deployment;
35 34
 import org.jboss.arquillian.junit.Arquillian;
36  
-import org.jboss.as.controller.client.ModelControllerClient;
37  
-import org.jboss.as.controller.client.OperationBuilder;
  35
+import org.jboss.as.arquillian.api.ServerSetup;
  36
+import org.jboss.as.arquillian.container.ManagementClient;
38 37
 import org.jboss.as.security.Constants;
  38
+import org.jboss.as.test.integration.security.AbstractSecurityDomainSetup;
39 39
 import org.jboss.dmr.ModelNode;
40 40
 import org.jboss.shrinkwrap.api.ShrinkWrap;
41 41
 import org.jboss.shrinkwrap.api.spec.WebArchive;
42 42
 import org.junit.Test;
43 43
 import org.junit.runner.RunWith;
44 44
 
45  
-import static org.jboss.as.arquillian.container.Authentication.getCallbackHandler;
46 45
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
47 46
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART;
48 47
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
49 48
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS;
50 49
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
51  
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE;
52 50
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
53 51
 import static org.jboss.as.security.Constants.AUTHENTICATION;
54 52
 import static org.jboss.as.security.Constants.CODE;
@@ -62,21 +60,13 @@
62 60
  * @author <a href="mailto:mmoyses@redhat.com">Marcus Moyses</a>
63 61
  */
64 62
 @RunWith(Arquillian.class)
  63
+@ServerSetup(WebSecurityProgrammaticLoginTestCase.SecurityDomainSetup.class)
65 64
 public class WebSecurityProgrammaticLoginTestCase {
66 65
 
67 66
     protected final String URL = "http://localhost:8080/" + getContextPath() + "/login/";
68 67
 
69 68
     @Deployment(testable = true)
70 69
     public static WebArchive deployment() {
71  
-        // FIXME hack to get things prepared before the deployment happens
72  
-        try {
73  
-            final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getByName("localhost"), 9999, getCallbackHandler());
74  
-            // create required security domains
75  
-            createSecurityDomains(client);
76  
-        } catch (Exception e) {
77  
-            // ignore
78  
-        }
79  
-
80 70
         WebArchive war = ShrinkWrap.create(WebArchive.class, "web-secure-programmatic-login.war");
81 71
         war.addAsResource(WebSecurityProgrammaticLoginTestCase.class.getPackage(), "users.properties", "users.properties");
82 72
         war.addAsResource(WebSecurityProgrammaticLoginTestCase.class.getPackage(), "roles.properties", "roles.properties");
@@ -89,14 +79,6 @@ public static WebArchive deployment() {
89 79
         return war;
90 80
     }
91 81
 
92  
-    // this is removing the security domain after each test so I have to disable it
93  
-//    @AfterClass
94  
-//    public static void after() throws Exception {
95  
-//        final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getByName("localhost"), 9999);
96  
-//        // remove test security domains
97  
-//        removeSecurityDomains(client);
98  
-//    }
99  
-
100 82
     /**
101 83
      * Test with user "anil" who has the right password and the right role to access the servlet
102 84
      *
@@ -152,59 +134,38 @@ public String getContextPath() {
152 134
         return "web-secure-programmatic-login";
153 135
     }
154 136
 
  137
+    static class SecurityDomainSetup extends AbstractSecurityDomainSetup {
155 138
 
156  
-    public static void createSecurityDomains(final ModelControllerClient client) throws Exception {
157  
-        final List<ModelNode> updates = new ArrayList<ModelNode>();
158  
-        ModelNode op = new ModelNode();
159  
-        String securityDomain = "web-programmatic-login";
160  
-
161  
-        op.get(OP).set(ADD);
162  
-        op.get(OP_ADDR).add(SUBSYSTEM, "security");
163  
-        op.get(OP_ADDR).add(SECURITY_DOMAIN, securityDomain);
164  
-        updates.add(op);
165  
-
166  
-        op = new ModelNode();
167  
-        op.get(OP).set(ADD);
168  
-        op.get(OP_ADDR).add(SUBSYSTEM, "security");
169  
-        op.get(OP_ADDR).add(SECURITY_DOMAIN, securityDomain);
170  
-        op.get(OP_ADDR).add(AUTHENTICATION, Constants.CLASSIC);
171  
-
172  
-        ModelNode loginModule = op.get(Constants.LOGIN_MODULES).add();
173  
-        loginModule.get(CODE).set("UsersRoles");
174  
-        loginModule.get(FLAG).set("required");
175  
-        op.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true);
176  
-        updates.add(op);
177  
-
178  
-        applyUpdates(updates, client);
179  
-    }
180  
-
181  
-    public static void removeSecurityDomains(final ModelControllerClient client) throws Exception {
182  
-        final List<ModelNode> updates = new ArrayList<ModelNode>();
183  
-        ModelNode op = new ModelNode();
184  
-        op.get(OP).set(REMOVE);
185  
-        op.get(OP_ADDR).add(SUBSYSTEM, "security");
186  
-        op.get(OP_ADDR).add(SECURITY_DOMAIN, "web-programmatic-login");
187  
-        updates.add(op);
188  
-
189  
-        applyUpdates(updates, client);
190  
-    }
191  
-
192  
-    public static void applyUpdates(final List<ModelNode> updates, final ModelControllerClient client) throws Exception {
193  
-        for (ModelNode update : updates) {
194  
-            applyUpdate(update, client);
  139
+        @Override
  140
+        protected String getSecurityDomainName() {
  141
+            return "web-programmatic-login";
195 142
         }
196  
-    }
197 143
 
198  
-    public static void applyUpdate(ModelNode update, final ModelControllerClient client) throws Exception {
199  
-        ModelNode result = client.execute(new OperationBuilder(update).build());
200  
-        if (result.hasDefined("outcome") && "success".equals(result.get("outcome").asString())) {
201  
-            if (result.hasDefined("result")) {
202  
-                System.out.println(result.get("result"));
203  
-            }
204  
-        } else if (result.hasDefined("failure-description")) {
205  
-            throw new RuntimeException(result.get("failure-description").toString());
206  
-        } else {
207  
-            throw new RuntimeException("Operation not successful; outcome = " + result.get("outcome"));
  144
+        @Override
  145
+        public void setup(final ManagementClient managementClient) {
  146
+            final List<ModelNode> updates = new ArrayList<ModelNode>();
  147
+            ModelNode op = new ModelNode();
  148
+            String securityDomain = "web-programmatic-login";
  149
+
  150
+            op.get(OP).set(ADD);
  151
+            op.get(OP_ADDR).add(SUBSYSTEM, "security");
  152
+            op.get(OP_ADDR).add(SECURITY_DOMAIN, securityDomain);
  153
+            updates.add(op);
  154
+
  155
+            op = new ModelNode();
  156
+            op.get(OP).set(ADD);
  157
+            op.get(OP_ADDR).add(SUBSYSTEM, "security");
  158
+            op.get(OP_ADDR).add(SECURITY_DOMAIN, securityDomain);
  159
+            op.get(OP_ADDR).add(AUTHENTICATION, Constants.CLASSIC);
  160
+
  161
+            ModelNode loginModule = op.get(Constants.LOGIN_MODULES).add();
  162
+            loginModule.get(CODE).set("UsersRoles");
  163
+            loginModule.get(FLAG).set("required");
  164
+            op.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true);
  165
+            updates.add(op);
  166
+
  167
+            applyUpdates(managementClient.getControllerClient(), updates);
208 168
         }
209 169
     }
  170
+
210 171
 }
8  ...ration/basic/src/test/java/org/jboss/as/test/integration/web/security/tg/TransportGuaranteeTestCase.java
@@ -39,10 +39,11 @@
39 39
 import org.jboss.arquillian.container.test.api.RunAsClient;
40 40
 import org.jboss.arquillian.junit.Arquillian;
41 41
 import org.jboss.arquillian.test.api.ArquillianResource;
  42
+import org.jboss.as.arquillian.api.ServerSetup;
42 43
 import org.jboss.as.test.http.util.HttpClientUtils;
43 44
 import org.jboss.as.test.integration.management.Connector;
44 45
 import org.jboss.as.test.integration.management.ServerManager;
45  
-import org.jboss.as.test.integration.web.security.SecurityTest;
  46
+import org.jboss.as.test.integration.web.security.WebTestsSecurityDomainSetup;
46 47
 import org.jboss.logging.Logger;
47 48
 import org.jboss.shrinkwrap.api.ShrinkWrap;
48 49
 import org.jboss.shrinkwrap.api.spec.WebArchive;
@@ -61,7 +62,8 @@
61 62
 
62 63
 @RunWith(Arquillian.class)
63 64
 @RunAsClient
64