Author: sohil.shah(a)jboss.com
Date: 2010-06-13 13:45:21 -0400 (Sun, 13 Jun 2010)
New Revision: 1132
Added:
authz/gatein/authz-plugin/trunk/service/src/test/resources/conf/
authz/gatein/authz-plugin/trunk/service/src/test/resources/conf/portal/
authz/gatein/authz-plugin/trunk/service/src/test/resources/conf/portal/test-configuration.xml
authz/gatein/authz-plugin/trunk/service/src/test/resources/conf/test-configuration.xml
authz/gatein/authz-plugin/trunk/test-tools/
authz/gatein/authz-plugin/trunk/test-tools/pom.xml
authz/gatein/authz-plugin/trunk/test-tools/src/
authz/gatein/authz-plugin/trunk/test-tools/src/main/
authz/gatein/authz-plugin/trunk/test-tools/src/main/java/
authz/gatein/authz-plugin/trunk/test-tools/src/main/java/org/
authz/gatein/authz-plugin/trunk/test-tools/src/main/java/org/jboss/
authz/gatein/authz-plugin/trunk/test-tools/src/main/java/org/jboss/gatein/
authz/gatein/authz-plugin/trunk/test-tools/src/main/java/org/jboss/gatein/authz/
authz/gatein/authz-plugin/trunk/test-tools/src/main/java/org/jboss/gatein/authz/test/
authz/gatein/authz-plugin/trunk/test-tools/src/main/java/org/jboss/gatein/authz/test/tools/
authz/gatein/authz-plugin/trunk/test-tools/src/main/java/org/jboss/gatein/authz/test/tools/ContainerBuilder.java
authz/gatein/authz-plugin/trunk/testwebapp/
authz/gatein/authz-plugin/trunk/testwebapp/pom.xml
authz/gatein/authz-plugin/trunk/testwebapp/src/
authz/gatein/authz-plugin/trunk/testwebapp/src/main/
authz/gatein/authz-plugin/trunk/testwebapp/src/main/java/
authz/gatein/authz-plugin/trunk/testwebapp/src/main/java/org/
authz/gatein/authz-plugin/trunk/testwebapp/src/main/java/org/jboss/
authz/gatein/authz-plugin/trunk/testwebapp/src/main/java/org/jboss/gatein/
authz/gatein/authz-plugin/trunk/testwebapp/src/main/java/org/jboss/gatein/authz/
authz/gatein/authz-plugin/trunk/testwebapp/src/main/java/org/jboss/gatein/authz/test/
authz/gatein/authz-plugin/trunk/testwebapp/src/main/java/org/jboss/gatein/authz/test/web/
authz/gatein/authz-plugin/trunk/testwebapp/src/main/java/org/jboss/gatein/authz/test/web/TestKernel.java
authz/gatein/authz-plugin/trunk/testwebapp/src/main/resources/
authz/gatein/authz-plugin/trunk/testwebapp/src/main/webapp/
authz/gatein/authz-plugin/trunk/testwebapp/src/main/webapp/WEB-INF/
authz/gatein/authz-plugin/trunk/testwebapp/src/main/webapp/WEB-INF/jsp/
authz/gatein/authz-plugin/trunk/testwebapp/src/main/webapp/WEB-INF/jsp/kernel.jsp
authz/gatein/authz-plugin/trunk/testwebapp/src/main/webapp/WEB-INF/web.xml
Modified:
authz/gatein/authz-plugin/trunk/.classpath
authz/gatein/authz-plugin/trunk/pom.xml
authz/gatein/authz-plugin/trunk/service/pom.xml
authz/gatein/authz-plugin/trunk/service/src/main/java/org/jboss/gatein/authz/service/SecurityService.java
authz/gatein/authz-plugin/trunk/service/src/test/java/org/jboss/gatein/authz/service/TestKernelStartup.java
authz/gatein/authz-plugin/trunk/tools/pom.xml
Log:
refactoring
Modified: authz/gatein/authz-plugin/trunk/.classpath
===================================================================
--- authz/gatein/authz-plugin/trunk/.classpath 2010-06-12 22:05:26 UTC (rev 1131)
+++ authz/gatein/authz-plugin/trunk/.classpath 2010-06-13 17:45:21 UTC (rev 1132)
@@ -2,7 +2,8 @@
<classpath>
<classpathentry kind="src" path="service/src/main/java"/>
<classpathentry kind="src" path="service/src/test/java"/>
- <classpathentry kind="src" path="tools/src/main/java"/>
+ <classpathentry kind="src" path="test-tools/src/main/java"/>
+ <classpathentry kind="src" path="testwebapp/src/main/java"/>
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con"
path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con"
path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
Modified: authz/gatein/authz-plugin/trunk/pom.xml
===================================================================
--- authz/gatein/authz-plugin/trunk/pom.xml 2010-06-12 22:05:26 UTC (rev 1131)
+++ authz/gatein/authz-plugin/trunk/pom.xml 2010-06-13 17:45:21 UTC (rev 1132)
@@ -10,7 +10,8 @@
<modules>
<module>service</module>
- <module>tools</module>
+ <module>test-tools</module>
+ <module>testwebapp</module>
</modules>
<properties>
@@ -25,11 +26,11 @@
<version>3.8.2</version>
</dependency>
- <!--
- <dependency> <groupId>apache-log4j</groupId>
- <artifactId>log4j</artifactId> <version>1.2.14</version>
- </dependency>
- -->
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ </dependency>
<!-- GateIn Kernel dependencies -->
<dependency>
@@ -158,18 +159,6 @@
</dependencies>
</dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
-
- <!--
- <dependency> <groupId>apache-log4j</groupId>
- <artifactId>log4j</artifactId> </dependency>
- -->
- </dependencies>
-
<build>
<plugins>
<plugin>
Modified: authz/gatein/authz-plugin/trunk/service/pom.xml
===================================================================
--- authz/gatein/authz-plugin/trunk/service/pom.xml 2010-06-12 22:05:26 UTC (rev 1131)
+++ authz/gatein/authz-plugin/trunk/service/pom.xml 2010-06-13 17:45:21 UTC (rev 1132)
@@ -9,18 +9,12 @@
</parent>
<groupId>org.jboss.gatein.authz.service</groupId>
- <artifactId>service</artifactId>
- <name>service</name>
+ <artifactId>gatein.security.service</artifactId>
+ <name>gatein.security.service</name>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
- <dependencies>
- <dependency>
- <groupId>org.jboss.gatein.authz.tools</groupId>
- <artifactId>tools</artifactId>
- <version>${project.version}</version>
- </dependency>
-
+ <dependencies>
<!-- GateIn Kernel -->
<dependency>
<groupId>org.exoplatform.kernel</groupId>
@@ -50,12 +44,7 @@
<groupId>picocontainer</groupId>
<artifactId>picocontainer</artifactId>
</dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <version>1.5.6</version>
- <scope>test</scope>
- </dependency>
+
<!-- Authz -->
<dependency>
@@ -92,5 +81,23 @@
<groupId>org.antlr</groupId>
<artifactId>antlr-runtime</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.5.6</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.gatein.authz.test.tools</groupId>
+ <artifactId>gatein.security.test.tools</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Modified:
authz/gatein/authz-plugin/trunk/service/src/main/java/org/jboss/gatein/authz/service/SecurityService.java
===================================================================
---
authz/gatein/authz-plugin/trunk/service/src/main/java/org/jboss/gatein/authz/service/SecurityService.java 2010-06-12
22:05:26 UTC (rev 1131)
+++
authz/gatein/authz-plugin/trunk/service/src/main/java/org/jboss/gatein/authz/service/SecurityService.java 2010-06-13
17:45:21 UTC (rev 1132)
@@ -22,10 +22,7 @@
******************************************************************************/
package org.jboss.gatein.authz.service;
-import java.net.URL;
-
import org.exoplatform.container.PortalContainer;
-import org.jboss.gatein.authz.tools.ContainerBuilder;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -40,10 +37,6 @@
public void start()
{
- //TODO: log message using GateIn Logging Framework
- /*URL rootURL =
getClass().getResource("/conf/gatein-authz-configuration.xml");
- URL portalURL =
getClass().getResource("/conf/portal/gatein-authz-configuration.xml");
- new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).build();*/
}
public void stop()
Modified:
authz/gatein/authz-plugin/trunk/service/src/test/java/org/jboss/gatein/authz/service/TestKernelStartup.java
===================================================================
---
authz/gatein/authz-plugin/trunk/service/src/test/java/org/jboss/gatein/authz/service/TestKernelStartup.java 2010-06-12
22:05:26 UTC (rev 1131)
+++
authz/gatein/authz-plugin/trunk/service/src/test/java/org/jboss/gatein/authz/service/TestKernelStartup.java 2010-06-13
17:45:21 UTC (rev 1132)
@@ -22,6 +22,10 @@
******************************************************************************/
package org.jboss.gatein.authz.service;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
import org.exoplatform.container.PortalContainer;
import org.jboss.security.authz.policy.server.event.LocalEventBus;
@@ -39,7 +43,7 @@
import org.jboss.gatein.authz.service.provisioning.RelationalDBPolicyStoreComponent;
import org.jboss.gatein.authz.service.tools.HibernateServiceComponent;
-import junit.framework.TestCase;
+import org.jboss.gatein.authz.test.tools.ContainerBuilder;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -52,6 +56,10 @@
@Override
protected void setUp() throws Exception
{
+ URL rootURL = getClass().getResource("/conf/test-configuration.xml");
+ URL portalURL =
getClass().getResource("/conf/portal/test-configuration.xml");
+ new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).build();
+
this.securityService = new SecurityService();
this.securityService.start();
}
Added:
authz/gatein/authz-plugin/trunk/service/src/test/resources/conf/portal/test-configuration.xml
===================================================================
---
authz/gatein/authz-plugin/trunk/service/src/test/resources/conf/portal/test-configuration.xml
(rev 0)
+++
authz/gatein/authz-plugin/trunk/service/src/test/resources/conf/portal/test-configuration.xml 2010-06-13
17:45:21 UTC (rev 1132)
@@ -0,0 +1,138 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+ <!--
+
+ Copyright (C) 2009 eXo Platform SAS. This is free software; you can redistribute it
and/or modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version. This software is distributed in the
+ hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details. You should have received a copy of the
GNU Lesser General Public License along with this software; if not,
+ write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ -->
+<configuration
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd
http://www.exoplaform.org/xml/ns/kernel_1_1.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd">
+
+ <!-- Policy Server Stack -->
+ <component>
+ <type>org.jboss.gatein.authz.service.event.LocalEventBusComponent</type>
+ <init-params>
+ <value-param>
+ <name>name</name>
+ <value>/policy-server/EventBus</value>
+ </value-param>
+ </init-params>
+ </component>
+
+ <component>
+ <type>org.jboss.gatein.authz.service.tools.HibernateServiceComponent</type>
+ <init-params>
+ <value-param>
+ <name>name</name>
+ <value>/policy-server/HibernateService</value>
+ </value-param>
+ </init-params>
+ </component>
+
+ <component>
+ <type>org.jboss.gatein.authz.service.provisioning.RelationalDBPolicyStoreComponent</type>
+ <init-params>
+ <value-param>
+ <name>name</name>
+ <value>/policy-server/PolicyStore</value>
+ </value-param>
+ </init-params>
+ </component>
+
+ <component>
+ <type>org.jboss.gatein.authz.service.plugin.DroolsRuleManagerComponent</type>
+ <init-params>
+ <value-param>
+ <name>name</name>
+ <value>/policy-server/DroolsRuleManager</value>
+ </value-param>
+ </init-params>
+ </component>
+
+ <component>
+ <type>org.jboss.gatein.authz.service.decision.PolicyDecisionPointComponent</type>
+ <init-params>
+ <value-param>
+ <name>name</name>
+ <value>/policy-server/PolicyDecisionPoint</value>
+ </value-param>
+ <value-param>
+ <name>debug</name>
+ <value>true</value>
+ </value-param>
+ </init-params>
+ </component>
+
+ <component>
+ <type>org.jboss.gatein.authz.service.PolicyServerComponent</type>
+ <init-params>
+ <value-param>
+ <name>name</name>
+ <value>/policy-server/PolicyServer</value>
+ </value-param>
+ </init-params>
+ </component>
+
+ <!-- Agent Integration Stack -->
+ <component>
+ <type>org.jboss.gatein.authz.service.agent.services.PolicyComposerComponent</type>
+ <init-params>
+ <value-param>
+ <name>name</name>
+ <value>/agent/PolicyComposer</value>
+ </value-param>
+ </init-params>
+ </component>
+
+ <component>
+ <type>org.jboss.gatein.authz.service.agent.services.EnforcementStateGeneratorComponent</type>
+ <init-params>
+ <value-param>
+ <name>name</name>
+ <value>/agent/EnforcementStateGenerator</value>
+ </value-param>
+ </init-params>
+ </component>
+
+ <component>
+ <type>org.jboss.gatein.authz.service.agent.enforcement.EnforcementCacheComponent</type>
+ <init-params>
+ <value-param>
+ <name>name</name>
+ <value>/agent/EnforcementCache</value>
+ </value-param>
+ </init-params>
+ </component>
+
+ <component>
+ <type>org.jboss.gatein.authz.service.agent.services.LocalEventObserverComponent</type>
+ <init-params>
+ <value-param>
+ <name>name</name>
+ <value>/agent/ServerEventObserver</value>
+ </value-param>
+ </init-params>
+ </component>
+
+ <component>
+ <type>org.jboss.gatein.authz.service.agent.enforcement.LocalEnforcementPointComponent</type>
+ <init-params>
+ <value-param>
+ <name>name</name>
+ <value>/agent/LocalEnforcementPoint</value>
+ </value-param>
+ </init-params>
+ </component>
+
+ <component>
+ <type>org.jboss.gatein.authz.service.agent.provisioning.LocalPolicyProvisionerComponent</type>
+ <init-params>
+ <value-param>
+ <name>name</name>
+ <value>/agent/LocalPolicyProvisioner</value>
+ </value-param>
+ </init-params>
+ </component>
+</configuration>
\ No newline at end of file
Added:
authz/gatein/authz-plugin/trunk/service/src/test/resources/conf/test-configuration.xml
===================================================================
---
authz/gatein/authz-plugin/trunk/service/src/test/resources/conf/test-configuration.xml
(rev 0)
+++
authz/gatein/authz-plugin/trunk/service/src/test/resources/conf/test-configuration.xml 2010-06-13
17:45:21 UTC (rev 1132)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+ <!--
+
+ Copyright (C) 2009 eXo Platform SAS. This is free software; you can redistribute it
and/or modify it under the terms of the GNU Lesser General Public License
+ as published by the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version. This software is distributed in the
+ hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details. You should have received a copy of the
GNU Lesser General Public License along with this software; if not,
+ write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ -->
+<configuration
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd
http://www.exoplaform.org/xml/ns/kernel_1_1.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd">
+</configuration>
\ No newline at end of file
Added: authz/gatein/authz-plugin/trunk/test-tools/pom.xml
===================================================================
--- authz/gatein/authz-plugin/trunk/test-tools/pom.xml (rev 0)
+++ authz/gatein/authz-plugin/trunk/test-tools/pom.xml 2010-06-13 17:45:21 UTC (rev 1132)
@@ -0,0 +1,59 @@
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jboss.gatein.authz</groupId>
+ <artifactId>gatein-authz-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.jboss.gatein.authz.test.tools</groupId>
+ <artifactId>gatein.security.test.tools</artifactId>
+ <name>gatein.security.test.tools</name>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.commons</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.component.cache</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.component.command</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.component.common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.container</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.component.ext.cache.impl.jboss.v3</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>picocontainer</groupId>
+ <artifactId>picocontainer</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.5.6</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Added:
authz/gatein/authz-plugin/trunk/test-tools/src/main/java/org/jboss/gatein/authz/test/tools/ContainerBuilder.java
===================================================================
---
authz/gatein/authz-plugin/trunk/test-tools/src/main/java/org/jboss/gatein/authz/test/tools/ContainerBuilder.java
(rev 0)
+++
authz/gatein/authz-plugin/trunk/test-tools/src/main/java/org/jboss/gatein/authz/test/tools/ContainerBuilder.java 2010-06-13
17:45:21 UTC (rev 1132)
@@ -0,0 +1,258 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.gatein.authz.test.tools;
+
+import junit.framework.AssertionFailedError;
+import org.exoplatform.commons.utils.PropertyManager;
+import org.exoplatform.commons.utils.Tools;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.container.RootContainer;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * <p>An helper for building a root container and a portal container. I have done
several attempt to make easily
+ * and safe root/portal container boot for unit test. This one is my best attempt so
far.</p>
+ *
+ * <p>Note that the portal container are booted in the order they are declared
first.</p>
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class ContainerBuilder
+{
+
+ /** A hack used during the boot of a portal container. */
+ private final ThreadLocal<String> bootedPortalName = new
ThreadLocal<String>();
+
+ /** . */
+ private ClassLoader loader;
+
+ /** . */
+ private List<URL> configURLs;
+
+ /** . */
+ private LinkedHashMap<String, List<URL>> portalConfigURLs;
+
+ /** . */
+ private Set<String> profiles;
+
+ public ContainerBuilder()
+ {
+ this.loader = Thread.currentThread().getContextClassLoader();
+ this.configURLs = new ArrayList<URL>();
+ this.portalConfigURLs = new LinkedHashMap<String, List<URL>>();
+ }
+
+ public ContainerBuilder withRoot(String configPath)
+ {
+ configURLs.addAll(urls(configPath));
+ return this;
+ }
+
+ public ContainerBuilder withRoot(URL configURL)
+ {
+ configURLs.add(configURL);
+ return this;
+ }
+
+ public ContainerBuilder withPortal(String configPath)
+ {
+ return withPortal("portal", configPath);
+ }
+
+ public ContainerBuilder withPortal(String portalName, String configPath)
+ {
+ for (URL configURL : urls(configPath))
+ {
+ withPortal(portalName, configURL);
+ }
+ return this;
+ }
+
+ public ContainerBuilder withPortal(URL configURL)
+ {
+ return withPortal("portal", configURL);
+ }
+
+ public ContainerBuilder withPortal(String portalName, URL configURL)
+ {
+ List<URL> urls = portalConfigURLs.get(portalName);
+ if (urls == null)
+ {
+ urls = new ArrayList<URL>();
+ portalConfigURLs.put(portalName, urls);
+ }
+ urls.add(configURL);
+ return this;
+ }
+
+ public ContainerBuilder withLoader(ClassLoader loader)
+ {
+ this.loader = loader;
+ return this;
+ }
+
+
+ private List<URL> urls(String path)
+ {
+ try
+ {
+ return Collections.list(loader.getResources(path));
+ }
+ catch (IOException e)
+ {
+ AssertionFailedError err = new AssertionFailedError();
+ err.initCause(e);
+ throw err;
+ }
+ }
+
+ public RootContainer build()
+ {
+ try
+ {
+ return _build();
+ }
+ catch (Exception e)
+ {
+ AssertionFailedError err = new AssertionFailedError();
+ err.initCause(e);
+ throw err;
+ }
+ }
+
+ private RootContainer _build() throws Exception
+ {
+ //
+ if (configURLs.size() == 0)
+ {
+ throw new IllegalStateException("Must provide at least one URL for building
the root container");
+ }
+
+ // Must clear the top container first otherwise it's not going to work well
+ // it's a big ugly but I don't want to change anything in the
ExoContainerContext class for now
+ // and this is for unit testing
+ Field topContainerField =
ExoContainerContext.class.getDeclaredField("topContainer");
+ topContainerField.setAccessible(true);
+ topContainerField.set(null, null);
+
+ // Same remark than above
+ Field singletonField =
RootContainer.class.getDeclaredField("singleton_");
+ singletonField.setAccessible(true);
+ singletonField.set(null, null);
+
+ // Setup profiles
+ if (profiles == null)
+ {
+ PropertyManager.setProperty(PropertyManager.RUNTIME_PROFILES, "");
+ }
+ else
+ {
+ StringBuilder builder = new StringBuilder();
+ for (Iterator<String> i = profiles.iterator();i.hasNext();)
+ {
+ builder.append(i.next());
+ if (i.hasNext())
+ {
+ builder.append(',');
+ }
+ }
+ PropertyManager.setProperty(PropertyManager.RUNTIME_PROFILES,
builder.toString());
+ }
+
+ //
+ ClassLoader rootCL = new ClassLoader(loader)
+ {
+ @Override
+ public Enumeration<URL> getResources(String name) throws IOException
+ {
+ if ("conf/configuration.xml".equals(name))
+ {
+ return Collections.enumeration(configURLs);
+ }
+ else if ("conf/portal/configuration.xml".equals(name))
+ {
+ String portalName = bootedPortalName.get();
+ return Collections.enumeration(portalConfigURLs.get(portalName));
+ }
+ else if ("conf/portal/test-configuration.xml".equals(name))
+ {
+ return Collections.enumeration(Collections.<URL>emptyList());
+ }
+ else
+ {
+ return super.getResources(name);
+ }
+ }
+ };
+
+ //
+ ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
+
+ // Boot root container
+ RootContainer root;
+ try
+ {
+ Thread.currentThread().setContextClassLoader(rootCL);
+
+ //
+ root = RootContainer.getInstance();
+
+ //
+ for (String portalName : portalConfigURLs.keySet())
+ {
+ try
+ {
+ bootedPortalName.set(portalName);
+ root.getPortalContainer(portalName);
+ }
+ finally
+ {
+ bootedPortalName.set(null);
+ }
+ }
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(oldCL);
+ }
+
+ //
+ return root;
+ }
+
+ public static RootContainer bootstrap(URL configurationURL, String... profiles)
+ {
+ ContainerBuilder builder = new ContainerBuilder();
+ builder.withRoot(configurationURL);
+ return builder.build();
+ }
+}
Added: authz/gatein/authz-plugin/trunk/testwebapp/pom.xml
===================================================================
--- authz/gatein/authz-plugin/trunk/testwebapp/pom.xml (rev 0)
+++ authz/gatein/authz-plugin/trunk/testwebapp/pom.xml 2010-06-13 17:45:21 UTC (rev 1132)
@@ -0,0 +1,80 @@
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jboss.gatein.authz</groupId>
+ <artifactId>gatein-authz-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.jboss.gatein.authz.test.web</groupId>
+ <artifactId>testwebapp</artifactId>
+ <name>testwebapp</name>
+ <packaging>war</packaging>
+ <version>1.0-SNAPSHOT</version>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.gatein.authz.service</groupId>
+ <artifactId>gatein.security.service</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- GateIn Kernel -->
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.commons</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.component.cache</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.component.command</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.component.common</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.container</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.component.ext.cache.impl.jboss.v3</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>picocontainer</groupId>
+ <artifactId>picocontainer</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Authz -->
+ <dependency>
+ <groupId>org.jboss.security.authz</groupId>
+ <artifactId>policy-server</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.security.authz</groupId>
+ <artifactId>agent</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Added:
authz/gatein/authz-plugin/trunk/testwebapp/src/main/java/org/jboss/gatein/authz/test/web/TestKernel.java
===================================================================
---
authz/gatein/authz-plugin/trunk/testwebapp/src/main/java/org/jboss/gatein/authz/test/web/TestKernel.java
(rev 0)
+++
authz/gatein/authz-plugin/trunk/testwebapp/src/main/java/org/jboss/gatein/authz/test/web/TestKernel.java 2010-06-13
17:45:21 UTC (rev 1132)
@@ -0,0 +1,134 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2010, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.gatein.authz.test.web;
+
+import java.io.IOException;
+import java.net.URI;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.exoplatform.container.PortalContainer;
+import org.jboss.gatein.authz.service.SecurityService;
+import
org.jboss.gatein.authz.service.agent.provisioning.LocalPolicyProvisionerComponent;
+
+import org.jboss.security.authz.agent.provisioning.PolicyProvisioner;
+import org.jboss.security.authz.agent.services.CompositionContext;
+import org.jboss.security.authz.components.action.Read;
+import org.jboss.security.authz.components.resource.URIResource;
+import org.jboss.security.authz.components.subject.Roles;
+import org.jboss.security.authz.model.Effect;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public final class TestKernel extends HttpServlet
+{
+ private SecurityService securityService;
+ private PolicyProvisioner provisioner;
+
+ @Override
+ public void init() throws ServletException
+ {
+ try
+ {
+ super.init();
+
+ System.out.println("Initializing the GateIn Security Kernel....");
+ this.securityService = new SecurityService();
+ this.securityService.start();
+
+ PortalContainer portal = this.securityService.getContainer();
+
+ //Provisioner service
+ System.out.println("Loading up Security Components............");
+ LocalPolicyProvisionerComponent provisionerComponent =
(LocalPolicyProvisionerComponent)portal.
+ getComponentInstanceOfType(LocalPolicyProvisionerComponent.class);
+ this.provisioner = provisionerComponent.getPolicyProvisioner();
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException
+ {
+ this.process(request, response);
+ }
+
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException
+ {
+ this.process(request, response);
+ }
+
+ private void process(HttpServletRequest request,HttpServletResponse response)
+ {
+ try
+ {
+ this.executeProvisioningRequests();
+
+ this.getServletContext().getRequestDispatcher("/WEB-INF/jsp/kernel.jsp").forward(request,
response);
+ }
+ catch(Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private void executeProvisioningRequests() throws Exception
+ {
+ // SetUp Resource
+ URIResource resource = new URIResource();
+ resource.setUri(new URI("/root/level1/level2/index.html"));
+
+ Read action = new Read();
+
+ Roles allowedRoles = new Roles();
+ allowedRoles.addName("user");
+
+ // Setup the Context for the Composition with these components
+ CompositionContext context = new CompositionContext();
+ context.setPolicyTarget(resource);
+ context.addPolicyRule(Effect.PERMIT, action, allowedRoles,
+ "allowExpression");
+
+ this.provisioner.deploy(context);
+
+ System.out.println("---------------------------------------------");
+ System.out.println("Mock Policy successfully provisioned.........");
+ System.out.println("---------------------------------------------");
+ }
+
+ private void executeEnforcementRequests()
+ {
+
+ }
+}
Added: authz/gatein/authz-plugin/trunk/testwebapp/src/main/webapp/WEB-INF/jsp/kernel.jsp
===================================================================
--- authz/gatein/authz-plugin/trunk/testwebapp/src/main/webapp/WEB-INF/jsp/kernel.jsp
(rev 0)
+++
authz/gatein/authz-plugin/trunk/testwebapp/src/main/webapp/WEB-INF/jsp/kernel.jsp 2010-06-13
17:45:21 UTC (rev 1132)
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<HTML><HEAD><TITLE>Gatein Security Kernel</TITLE>
+<META http-equiv=Content-Type content="text/html">
+</HEAD>
+<BODY>
+<P>
+<H3>Gatein Security Kernel</H3>
+<P></P>
+</BODY>
+</HTML>
\ No newline at end of file
Added: authz/gatein/authz-plugin/trunk/testwebapp/src/main/webapp/WEB-INF/web.xml
===================================================================
--- authz/gatein/authz-plugin/trunk/testwebapp/src/main/webapp/WEB-INF/web.xml
(rev 0)
+++ authz/gatein/authz-plugin/trunk/testwebapp/src/main/webapp/WEB-INF/web.xml 2010-06-13
17:45:21 UTC (rev 1132)
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ 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.
+-->
+
+<web-app
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/web-app_2_5.xsd"
+ version="2.5">
+
+ <display-name>Welcome to Gatein Security</display-name>
+ <description>
+ Welcome to Gatein Security Framework
+ </description>
+
+ <servlet>
+ <servlet-name>TestKernel</servlet-name>
+ <servlet-class>org.jboss.gatein.authz.test.web.TestKernel</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>TestKernel</servlet-name>
+ <url-pattern>/kernel/*</url-pattern>
+ </servlet-mapping>
+
+</web-app>
Modified: authz/gatein/authz-plugin/trunk/tools/pom.xml
===================================================================
--- authz/gatein/authz-plugin/trunk/tools/pom.xml 2010-06-12 22:05:26 UTC (rev 1131)
+++ authz/gatein/authz-plugin/trunk/tools/pom.xml 2010-06-13 17:45:21 UTC (rev 1132)
@@ -40,14 +40,20 @@
<artifactId>exo.kernel.component.ext.cache.impl.jboss.v3</artifactId>
</dependency>
<dependency>
+ <groupId>picocontainer</groupId>
+ <artifactId>picocontainer</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.5.6</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>picocontainer</groupId>
- <artifactId>picocontainer</artifactId>
- </dependency>
</dependencies>
</project>
\ No newline at end of file