You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by gp...@apache.org on 2012/02/27 22:11:42 UTC

[1/2] git commit: DELTASPIKE-74 tests for @Secured

Updated Branches:
  refs/heads/master f6ca9fed5 -> a820478fc


DELTASPIKE-74 tests for @Secured

first part which is compatible
with the current version of arquillian


Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/a820478f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/a820478f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/a820478f

Branch: refs/heads/master
Commit: a820478fcef95811e15d40c53a55eda646331f6b
Parents: 316a6ad
Author: gpetracek <gp...@apache.org>
Authored: Mon Feb 27 20:34:27 2012 +0100
Committer: gpetracek <gp...@apache.org>
Committed: Mon Feb 27 22:09:27 2012 +0100

----------------------------------------------------------------------
 .../impl/secured/SecuredAnnotationTest.java        |  132 +++++++
 .../test/security/impl/secured/SecuredBean1.java   |   38 ++
 .../test/security/impl/secured/SecuredBean2.java   |   36 ++
 .../test/security/impl/secured/SecuredBean3.java   |   39 ++
 .../impl/secured/SecuredBeanWithStereotype.java    |   39 ++
 .../impl/secured/TestAccessDecisionVoter.java      |   66 ++++
 .../test/util/ShrinkWrapArchiveUtil.java           |  296 +++++++++++++++
 .../impl/src/test/resources/META-INF/beans.xml     |    9 +-
 .../impl/src/test/resources/WEB-INF/beans.xml      |   33 --
 9 files changed, 647 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/a820478f/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/SecuredAnnotationTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/SecuredAnnotationTest.java b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/SecuredAnnotationTest.java
new file mode 100644
index 0000000..c0979d3
--- /dev/null
+++ b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/SecuredAnnotationTest.java
@@ -0,0 +1,132 @@
+/*
+ * 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.deltaspike.test.security.impl.secured;
+
+import org.apache.deltaspike.core.api.provider.BeanProvider;
+import org.apache.deltaspike.core.impl.exclude.ExcludeExtension;
+import org.apache.deltaspike.core.util.ClassUtils;
+import org.apache.deltaspike.security.api.AccessDeniedException;
+import org.apache.deltaspike.test.util.ShrinkWrapArchiveUtil;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.Asset;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.enterprise.inject.spi.Extension;
+
+
+/**
+ * Test for {@link org.apache.deltaspike.security.api.Secured}
+ */
+@RunWith(Arquillian.class)
+public class SecuredAnnotationTest
+{
+    @Deployment
+    public static WebArchive deploy()
+    {
+        boolean isOwbAvailable = ClassUtils.tryToLoadClassForName("org.apache.webbeans.spi.ContainerLifecycle") != null;
+
+        String[] excludedFiles;
+
+        Asset beansXml = new StringAsset(
+            "<beans>" +
+                "<interceptors><class>org.apache.deltaspike.security.impl.SecurityInterceptor</class></interceptors>" +
+            "</beans>"
+        );
+
+        if (isOwbAvailable)
+        {
+            excludedFiles = new String[]{"META-INF.apache-deltaspike.properties"};
+        }
+        else
+        {
+            excludedFiles = new String[]{"META-INF.apache-deltaspike.properties", "META-INF.beans.xml"};
+        }
+        
+        return ShrinkWrap.create(WebArchive.class)
+                .addAsLibraries(ShrinkWrapArchiveUtil.getArchives(null,
+                        "META-INF/beans.xml",
+                        new String[]{"org.apache.deltaspike.core",
+                                "org.apache.deltaspike.security",
+                                "org.apache.deltaspike.test.security.impl.secured"},
+                        excludedFiles))
+                .addAsServiceProvider(Extension.class, ExcludeExtension.class)
+                .addAsWebInfResource(beansXml, "beans.xml");
+    }
+
+    @Test
+    public void simpleInterceptorTest()
+    {
+        SecuredBean1 testBean = BeanProvider.getContextualReference(SecuredBean1.class, false);
+
+        Assert.assertEquals("result", testBean.getResult());
+
+        try
+        {
+            testBean.getBlockedResult();
+            Assert.fail();
+        }
+        catch (AccessDeniedException e)
+        {
+            //expected exception
+        }
+    }
+
+    //@Test
+    public void interceptorTestWithStereotype()
+    {
+        SecuredBean2 testBean = BeanProvider.getContextualReference(SecuredBean2.class, false);
+
+        Assert.assertEquals("result", testBean.getResult());
+
+        try
+        {
+            testBean.getBlockedResult();
+            Assert.fail();
+        }
+        catch (AccessDeniedException e)
+        {
+            //expected exception
+        }
+    }
+
+    //@Test
+    public void simpleInterceptorTestOnMethods()
+    {
+        SecuredBean3 testBean = BeanProvider.getContextualReference(SecuredBean3.class, false);
+
+        Assert.assertEquals("result", testBean.getResult());
+
+        try
+        {
+            testBean.getBlockedResult();
+            Assert.fail();
+        }
+        catch (AccessDeniedException e)
+        {
+            //expected exception
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/a820478f/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/SecuredBean1.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/SecuredBean1.java b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/SecuredBean1.java
new file mode 100644
index 0000000..d0c2502
--- /dev/null
+++ b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/SecuredBean1.java
@@ -0,0 +1,38 @@
+/*
+ * 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.deltaspike.test.security.impl.secured;
+
+import org.apache.deltaspike.security.api.Secured;
+
+import javax.enterprise.context.ApplicationScoped;
+
+@ApplicationScoped
+@Secured(TestAccessDecisionVoter.class)
+public class SecuredBean1
+{
+    public String getBlockedResult()
+    {
+        return "blocked result";
+    }
+
+    public String getResult()
+    {
+        return "result";
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/a820478f/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/SecuredBean2.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/SecuredBean2.java b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/SecuredBean2.java
new file mode 100644
index 0000000..340f612
--- /dev/null
+++ b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/SecuredBean2.java
@@ -0,0 +1,36 @@
+/*
+ * 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.deltaspike.test.security.impl.secured;
+
+import javax.enterprise.context.ApplicationScoped;
+
+@ApplicationScoped
+@SecuredBeanWithStereotype
+public class SecuredBean2
+{
+    public String getBlockedResult()
+    {
+        return "blocked result";
+    }
+
+    public String getResult()
+    {
+        return "result";
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/a820478f/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/SecuredBean3.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/SecuredBean3.java b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/SecuredBean3.java
new file mode 100644
index 0000000..7b5d5ec
--- /dev/null
+++ b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/SecuredBean3.java
@@ -0,0 +1,39 @@
+/*
+ * 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.deltaspike.test.security.impl.secured;
+
+import org.apache.deltaspike.security.api.Secured;
+
+import javax.enterprise.context.ApplicationScoped;
+
+@ApplicationScoped
+public class SecuredBean3
+{
+    @Secured(TestAccessDecisionVoter.class)
+    public String getBlockedResult()
+    {
+        return "blocked result";
+    }
+
+    @Secured(TestAccessDecisionVoter.class)
+    public String getResult()
+    {
+        return "result";
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/a820478f/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/SecuredBeanWithStereotype.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/SecuredBeanWithStereotype.java b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/SecuredBeanWithStereotype.java
new file mode 100644
index 0000000..74e00eb
--- /dev/null
+++ b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/SecuredBeanWithStereotype.java
@@ -0,0 +1,39 @@
+/*
+ * 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.deltaspike.test.security.impl.secured;
+
+import org.apache.deltaspike.security.api.Secured;
+
+import javax.enterprise.inject.Stereotype;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Stereotype
+
+@Retention(value = RUNTIME)
+@Target({TYPE, METHOD})
+
+@Secured(TestAccessDecisionVoter.class)
+public @interface SecuredBeanWithStereotype
+{
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/a820478f/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/TestAccessDecisionVoter.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/TestAccessDecisionVoter.java b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/TestAccessDecisionVoter.java
new file mode 100644
index 0000000..55f49ec
--- /dev/null
+++ b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/secured/TestAccessDecisionVoter.java
@@ -0,0 +1,66 @@
+/*
+ * 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.deltaspike.test.security.impl.secured;
+
+import org.apache.deltaspike.security.api.AccessDecisionVoter;
+import org.apache.deltaspike.security.api.AccessDecisionVoterContext;
+import org.apache.deltaspike.security.api.SecurityViolation;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.interceptor.InvocationContext;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ *
+ */
+@ApplicationScoped
+public class TestAccessDecisionVoter implements AccessDecisionVoter
+{
+    private static final long serialVersionUID = 1331427301357439804L;
+
+    @Override
+    public Set<SecurityViolation> checkPermission(AccessDecisionVoterContext accessDecisionVoterContext)
+    {
+        Method method = accessDecisionVoterContext.<InvocationContext>getSource().getMethod();
+
+        if (!method.getName().contains("Blocked"))
+        {
+            return Collections.emptySet();
+        }
+        return new HashSet<SecurityViolation>() {
+            private static final long serialVersionUID = 9033579102593906350L;
+
+            {
+                add(new SecurityViolation()
+                {
+                    private static final long serialVersionUID = -7990980050100180829L;
+
+                    @Override
+                    public String getReason()
+                    {
+                        return "blocked";
+                    }
+                });
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/a820478f/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/util/ShrinkWrapArchiveUtil.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/util/ShrinkWrapArchiveUtil.java b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/util/ShrinkWrapArchiveUtil.java
new file mode 100644
index 0000000..6bc2cec
--- /dev/null
+++ b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/util/ShrinkWrapArchiveUtil.java
@@ -0,0 +1,296 @@
+/*
+ * 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.deltaspike.test.util;
+
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.jar.JarInputStream;
+import java.util.logging.Logger;
+import java.util.zip.ZipEntry;
+
+/**
+ * Lots of neat little helpers to more easily create JavaArchives from marker files on the classpath.
+ * This should finally get moved to ShrinkWrap core!
+ *
+ * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ * @deprecated This class should get moved to ShrinkWrap itself!
+ */
+public class ShrinkWrapArchiveUtil
+{
+    private static final Logger LOG = Logger.getLogger(ShrinkWrapArchiveUtil.class.getName());
+    /**
+     * Resolve all markerFiles from the current ClassPath and package the root nodes
+     * into a JavaArchive.
+     * @param classLoader to use
+     * @param markerFile
+     * @param includeIfPackageExists if not null, we will only create JavaArchives if the given package exists
+     * @param excludeIfPackageExists if not null, we will <b>not</b> create JavaArchives if the given package exists.
+     *                               This has a higher precedence than includeIfPackageExists.
+     * @return
+     */
+    public static JavaArchive[] getArchives(ClassLoader classLoader,
+                                            String markerFile,
+                                            String[] includeIfPackageExists,
+                                            String[] excludeIfPackageExists)
+    {
+        if (classLoader == null) {
+            classLoader = ShrinkWrapArchiveUtil.class.getClassLoader();
+        }
+
+        try {
+            Enumeration<URL> foundFiles = classLoader.getResources(markerFile);
+
+            List<JavaArchive> archives = new ArrayList<JavaArchive>();
+
+            while (foundFiles.hasMoreElements()) {
+                URL foundFile = foundFiles.nextElement();
+                LOG.fine("Evaluating Java ClassPath URL " + foundFile.toExternalForm());
+
+                JavaArchive archive = createArchive(foundFile, markerFile, includeIfPackageExists, excludeIfPackageExists);
+                if (archive != null) {
+                    LOG.info("Adding Java ClassPath URL as JavaArchive " + foundFile.toExternalForm());
+                    archives.add(archive);
+                }
+            }
+
+            return archives.toArray(new JavaArchive[archives.size()]);
+        }
+        catch (IOException ioe) {
+            throw new RuntimeException(ioe);
+        }
+
+    }
+
+    private static JavaArchive createArchive(URL foundFile, String markerFile,
+                                             String[] includeIfPackageExists, String[] excludeIfPackageExists)
+            throws IOException {
+        String urlString = foundFile.toString();
+        int idx = urlString.lastIndexOf(markerFile);
+        urlString = urlString.substring(0, idx);
+
+        String jarUrlPath = isJarUrl(urlString);
+        if (jarUrlPath != null)
+        {
+            return addJarArchive((new URL(ensureCorrectUrlFormat(jarUrlPath))).openStream(),
+                    includeIfPackageExists, excludeIfPackageExists);
+        }
+        else
+        {
+            File f = new File( (new URL(ensureCorrectUrlFormat(urlString))).getFile() );
+            if (!f.exists())
+            {
+                // try a fallback if the URL contains %20 -> spaces
+                if (urlString.contains("%20"))
+                {
+                    urlString = urlString.replaceAll("%20", " ");
+                    f = new File( (new URL(ensureCorrectUrlFormat(urlString))).getFile() );
+                }
+
+            }
+
+            return addFileArchive(f, includeIfPackageExists, excludeIfPackageExists);
+        }
+    }
+
+    private static JavaArchive addJarArchive(InputStream inputStream,
+                                             String[] includeIfPackageExists,
+                                             String[] excludeIfPackageExists)
+            throws IOException {
+        JavaArchive ret = null;
+        JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class);
+
+        if (includeIfPackageExists == null) {
+            // no include rule, thus add it immediately
+            ret = javaArchive;
+        }
+
+        JarInputStream jar = new JarInputStream(inputStream);
+        try {
+            for (ZipEntry jarEntry = jar.getNextEntry(); jarEntry != null; jarEntry = jar.getNextEntry()) {
+                String entryName = jarEntry.getName();
+
+                if (jarEntry.isDirectory()) {
+                    // exclude rule
+                    if (excludeIfPackageExists(entryName, excludeIfPackageExists)) {
+                        return null;
+                    }
+
+                    if (ret == null && includeIfPackageExists(entryName, includeIfPackageExists)) {
+                        ret = javaArchive;
+                    }
+
+                    continue;
+                }
+
+                if (entryName.endsWith(".class")) {
+                    String className = pathToClassName(entryName.substring(0, entryName.length()-(".class".length())));
+                    javaArchive.addClass(className);
+                }
+                else {
+                    javaArchive.addAsResource(entryName);
+                }
+            }
+        }
+        finally {
+            try {
+                jar.close();
+            }
+            catch (IOException ignored) {
+                // all fine
+            }
+        }
+
+        return ret;
+    }
+
+    private static JavaArchive addFileArchive(File archiveBasePath,
+                                              String[] includeIfPackageExists,
+                                              String[] excludeIfPackageExists)
+            throws IOException {
+        if (!archiveBasePath.exists()) {
+            return null;
+        }
+
+        JavaArchive ret = null;
+        JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class);
+
+        if (includeIfPackageExists == null) {
+            // no include rule, thus add it immediately
+            ret = javaArchive;
+        }
+
+        int basePathLength = archiveBasePath.getAbsolutePath().length() + 1;
+
+        for (File archiveEntry : collectArchiveEntries(archiveBasePath) ) {
+            String entryName = archiveEntry.getAbsolutePath().substring(basePathLength);
+
+            // exclude rule
+            if (excludeIfPackageExists(entryName, excludeIfPackageExists)) {
+                continue;
+            }
+
+            // include rule
+            if (ret == null && includeIfPackageExists(entryName, includeIfPackageExists)) {
+                ret = javaArchive;
+            }
+
+            if (entryName.endsWith(".class")) {
+                String className = pathToClassName(entryName.substring(0, entryName.length()-(".class".length())));
+
+                javaArchive.addClass(className);
+            }
+            else {
+                javaArchive.addAsResource(entryName.replace('\\', '/'));
+            }
+        }
+
+        return ret;
+    }
+
+    private static List<File> collectArchiveEntries(File archiveBasePath)
+    {
+        if (archiveBasePath.isDirectory()) {
+            List<File> archiveEntries = new ArrayList<File>();
+            File[] files = archiveBasePath.listFiles();
+
+            for (File file : files) {
+                if (file.isDirectory()) {
+                    archiveEntries.addAll(collectArchiveEntries(file));
+                }
+                else {
+                    archiveEntries.add(file);
+                }
+            }
+
+            return archiveEntries;
+        }
+
+        return Collections.EMPTY_LIST;
+    }
+
+
+    private static boolean excludeIfPackageExists(String jarEntryName, String[] excludeOnPackages) {
+        if (excludeOnPackages != null) {
+            String packageName = pathToClassName(jarEntryName);
+
+            for (String excludeOnPackage : excludeOnPackages) {
+                if (packageName.startsWith(excludeOnPackage)) {
+                    return true;
+                }
+            }
+        }
+
+        return false;
+    }
+
+    private static boolean includeIfPackageExists(String jarEntryName, String[] includeOnPackages) {
+        if (includeOnPackages == null ) {
+            return true;
+        }
+
+        String packageName = pathToClassName(jarEntryName);
+
+        for (String includeOnPackage : includeOnPackages) {
+            if (packageName.startsWith(includeOnPackage)) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * check if the given url path is a Jar
+     * @param urlPath
+     * @return
+     */
+    private static String isJarUrl(String urlPath) {
+        // common prefixes of the url are: jar: (tomcat), zip: (weblogic) and wsjar: (websphere)
+        final int jarColon = urlPath.indexOf(':');
+        if (urlPath.endsWith("!/") && jarColon > 0) {
+            urlPath = urlPath.substring(jarColon + 1, urlPath.length() - 2);
+            return urlPath;
+        }
+
+        return null;
+    }
+
+    private static String ensureCorrectUrlFormat(String url) {
+        //fix for wls
+        if(!url.startsWith("file:/")) {
+            url = "file:/" + url;
+        }
+        return url;
+    }
+
+    private static String pathToClassName(String pathName) {
+        return pathName.replace('/', '.').replace('\\', '.');   // replace unix and windows separators
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/a820478f/deltaspike/modules/security/impl/src/test/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/resources/META-INF/beans.xml b/deltaspike/modules/security/impl/src/test/resources/META-INF/beans.xml
index e17526f..0eaf52c 100644
--- a/deltaspike/modules/security/impl/src/test/resources/META-INF/beans.xml
+++ b/deltaspike/modules/security/impl/src/test/resources/META-INF/beans.xml
@@ -20,12 +20,5 @@
 <beans xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
-    <!-- TODO change it to the global alternative approach as soon as it is committed -->
-    <alternatives>
-        <class>org.apache.deltaspike.test.security.impl.customsecured.AlternativeSecurityStrategy</class>
-    </alternatives>
-
-    <interceptors>
-        <class>org.apache.deltaspike.security.impl.SecurityInterceptor</class>
-    </interceptors>
+    <!-- DON'T add content to this file - it's >only< needed as marker file for the test-scan -->
 </beans>

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/a820478f/deltaspike/modules/security/impl/src/test/resources/WEB-INF/beans.xml
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/resources/WEB-INF/beans.xml b/deltaspike/modules/security/impl/src/test/resources/WEB-INF/beans.xml
deleted file mode 100644
index 739e67e..0000000
--- a/deltaspike/modules/security/impl/src/test/resources/WEB-INF/beans.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-    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.
--->
-<beans xmlns="http://java.sun.com/xml/ns/javaee"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
-
-    <!-- TODO change it to the global alternative approach as soon as it is committed -->
-    <alternatives>
-        <class>org.apache.deltaspike.test.security.impl.customsecured.AlternativeSecurityStrategy</class>
-    </alternatives>
-
-    <!-- workaround which works with arquillian+owb but not with arquillian+weld - TODO get rid of it at all -->
-    <interceptors>
-        <class>org.apache.deltaspike.security.impl.SecurityInterceptor</class>
-    </interceptors>
-</beans>