[jboss-cvs] JBossAS SVN: r65022 - in projects/microcontainer/trunk: reliance-identity and 52 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Sep 3 18:19:29 EDT 2007
Author: alesj
Date: 2007-09-03 18:19:29 -0400 (Mon, 03 Sep 2007)
New Revision: 65022
Added:
projects/microcontainer/trunk/reliance-identity/
projects/microcontainer/trunk/reliance-identity/pom.xml
projects/microcontainer/trunk/reliance-identity/src/
projects/microcontainer/trunk/reliance-identity/src/etc/
projects/microcontainer/trunk/reliance-identity/src/main/
projects/microcontainer/trunk/reliance-identity/src/main/org/
projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/
projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/
projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/
projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/Authenticator.java
projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/Configuration.java
projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/DefaultAuthenticator.java
projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/Identity.java
projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/MicrocontainerLoginModule.java
projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/SimpleGroup.java
projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/SimplePrincipal.java
projects/microcontainer/trunk/reliance-identity/src/resources/
projects/microcontainer/trunk/reliance-identity/src/resources/main/
projects/microcontainer/trunk/reliance-identity/src/resources/tests/
projects/microcontainer/trunk/reliance-identity/src/tests/
projects/microcontainer/trunk/reliance-jbpm/
projects/microcontainer/trunk/reliance-jbpm/pom.xml
projects/microcontainer/trunk/reliance-jbpm/src/
projects/microcontainer/trunk/reliance-jbpm/src/etc/
projects/microcontainer/trunk/reliance-jbpm/src/main/
projects/microcontainer/trunk/reliance-jbpm/src/main/org/
projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/
projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/
projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/
projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/container/
projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/container/JbpmContextContainer.java
projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/server/
projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/server/plugins/
projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/server/plugins/AbstractConsoleInvoker.java
projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/server/plugins/AbstractConsolerServer.java
projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/server/spi/
projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/server/spi/ConsoleInvoker.java
projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/server/spi/ConsoleServer.java
projects/microcontainer/trunk/reliance-jbpm/src/resources/
projects/microcontainer/trunk/reliance-jbpm/src/resources/main/
projects/microcontainer/trunk/reliance-jbpm/src/resources/tests/
projects/microcontainer/trunk/reliance-jbpm/src/tests/
projects/microcontainer/trunk/reliance-rules/
projects/microcontainer/trunk/reliance-rules/pom.xml
projects/microcontainer/trunk/reliance-rules/src/
projects/microcontainer/trunk/reliance-rules/src/etc/
projects/microcontainer/trunk/reliance-rules/src/etc/reliance-deployer-beans.xml
projects/microcontainer/trunk/reliance-rules/src/main/
projects/microcontainer/trunk/reliance-rules/src/main/org/
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/ConstantsKernelGlobalResolver.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/KernelGlobalResolver.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/ManagedWorkingMemory.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/NamingKernelGlobalResolver.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/PackageGenerator.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/PackageWrapper.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/RuleBaseBean.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/RuleDependencyCheck.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/CRUDAwareAspect.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/DisableFireAllRules.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/DisableFireAllRulesInterceptor.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/FireAllRulesAfter.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/FireAllRulesAfterInvocationInterceptor.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/FireAllRulesAspect.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/FireAllRulesFlag.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/FlagAwareAspect.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/StatefulSessionCreationInterceptor.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/rules/
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/rules/Flag.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/rules/Nameable.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/security/
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/security/PermissionCheck.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/security/Role.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/security/RoleTracker.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/security/RuleBasedIdentity.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/DependencyItemFactory.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/RuleBasedDependencyItem.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/RuleBasedDependencyItemFactory.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/RuleDependencyMapper.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/RulesAware.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/CSVRulesDeployer.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/DRLFileDeployer.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/ExcelRulesDeployer.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/InputTypeInfo.java
projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/SpreadsheetRulesDeployer.java
projects/microcontainer/trunk/reliance-rules/src/resources/
projects/microcontainer/trunk/reliance-rules/src/resources/main/
projects/microcontainer/trunk/reliance-rules/src/resources/main/schema/
projects/microcontainer/trunk/reliance-rules/src/resources/main/schema/reliance_1_0.xsd
projects/microcontainer/trunk/reliance-rules/src/resources/tests/
projects/microcontainer/trunk/reliance-rules/src/resources/tests/org/
projects/microcontainer/trunk/reliance-rules/src/resources/tests/org/jboss/
projects/microcontainer/trunk/reliance-rules/src/resources/tests/org/jboss/test/
projects/microcontainer/trunk/reliance-rules/src/resources/tests/org/jboss/test/reliance/
projects/microcontainer/trunk/reliance-rules/src/resources/tests/org/jboss/test/reliance/drools/
projects/microcontainer/trunk/reliance-rules/src/resources/tests/org/jboss/test/reliance/drools/test/
projects/microcontainer/trunk/reliance-rules/src/resources/tests/org/jboss/test/reliance/drools/test/ConceptTestCase.xml
projects/microcontainer/trunk/reliance-rules/src/resources/tests/org/jboss/test/reliance/jbpm/
projects/microcontainer/trunk/reliance-rules/src/resources/tests/org/jboss/test/reliance/jbpm/test/
projects/microcontainer/trunk/reliance-rules/src/tests/
projects/microcontainer/trunk/reliance-rules/src/tests/org/
projects/microcontainer/trunk/reliance-rules/src/tests/org/jboss/
projects/microcontainer/trunk/reliance-rules/src/tests/org/jboss/test/
projects/microcontainer/trunk/reliance-rules/src/tests/org/jboss/test/reliance/
projects/microcontainer/trunk/reliance-rules/src/tests/org/jboss/test/reliance/drools/
projects/microcontainer/trunk/reliance-rules/src/tests/org/jboss/test/reliance/drools/support/
projects/microcontainer/trunk/reliance-rules/src/tests/org/jboss/test/reliance/drools/support/RolesAdapter.java
projects/microcontainer/trunk/reliance-rules/src/tests/org/jboss/test/reliance/drools/support/Tester.java
projects/microcontainer/trunk/reliance-rules/src/tests/org/jboss/test/reliance/drools/test/
projects/microcontainer/trunk/reliance-rules/src/tests/org/jboss/test/reliance/drools/test/ConceptTestCase.java
projects/microcontainer/trunk/reliance-rules/src/tests/org/jboss/test/reliance/jbpm/
Log:
JBoss Reliance: Identity, Rules, jBPM
Added: projects/microcontainer/trunk/reliance-identity/pom.xml
===================================================================
--- projects/microcontainer/trunk/reliance-identity/pom.xml (rev 0)
+++ projects/microcontainer/trunk/reliance-identity/pom.xml 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,57 @@
+<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">
+ <parent>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-microcontainer</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>jboss-reliance-identity</artifactId>
+ <packaging>jar</packaging>
+ <name>JBoss Microcontainer Reliance Identity</name>
+ <url>http://www.jboss.com/products/jbossmc</url>
+ <description>JBoss Microcontainer Reliance Identity</description>
+ <build>
+ <resources>
+ <resource>
+ <directory>src/resources/main</directory>
+ </resource>
+ </resources>
+ <testResources>
+ <testResource>
+ <directory>src/resources/tests</directory>
+ </testResource>
+ </testResources>
+ </build>
+ <!-- Do not add version information here, use ../build/pom.xml instead -->
+ <dependencies>
+ <!-- Global dependencies -->
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jbossxb</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-kernel</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-aop-mc-int</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-deployers-vfs</artifactId>
+ </dependency>
+ <!-- Test dependencies -->
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-test</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-container</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Added: projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/Authenticator.java
===================================================================
--- projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/Authenticator.java (rev 0)
+++ projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/Authenticator.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.identity;
+
+/**
+ * Simple authenticator interface.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface Authenticator
+{
+ /**
+ * Check if username/password is ok.
+ *
+ * @param username the username
+ * @param password the password
+ * @return true if ok, false otherwise
+ */
+ boolean authenticate(String username, String password);
+}
Added: projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/Configuration.java
===================================================================
--- projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/Configuration.java (rev 0)
+++ projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/Configuration.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,102 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.identity;
+
+import java.util.HashMap;
+import javax.security.auth.login.AppConfigurationEntry;
+
+/**
+ * Factory for the JAAS Configuration used by Microcontainer Security.
+ *
+ * @author Shane Bryzak
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class Configuration
+{
+ static final String DEFAULT_JAAS_CONFIG_NAME = "default";
+
+ private String loginModuleClassName = MicrocontainerLoginModule.class.getName();
+ private javax.security.auth.login.Configuration configuration;
+
+ public void create()
+ {
+ configuration = createConfiguration();
+ }
+
+ /**
+ * Create configuration.
+ *
+ * @return the configuration
+ */
+ protected javax.security.auth.login.Configuration createConfiguration()
+ {
+ return new javax.security.auth.login.Configuration()
+ {
+ private AppConfigurationEntry[] aces = {createAppConfigurationEntry()};
+
+ @Override
+ public AppConfigurationEntry[] getAppConfigurationEntry(String name)
+ {
+ return DEFAULT_JAAS_CONFIG_NAME.equals(name) ? aces : null;
+ }
+
+ @Override
+ public void refresh()
+ {
+ }
+ };
+ }
+
+ /**
+ * Create AppConfigurationEntry.
+ *
+ * @return app. configuration entry
+ */
+ protected AppConfigurationEntry createAppConfigurationEntry()
+ {
+ return new AppConfigurationEntry(
+ loginModuleClassName,
+ AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
+ new HashMap<String, String>()
+ );
+ }
+
+ /**
+ * Get the configuration.
+ *
+ * @return the configuration
+ */
+ public javax.security.auth.login.Configuration getConfiguration()
+ {
+ return configuration;
+ }
+
+ /**
+ * Set the login module class name.
+ *
+ * @param loginModuleClassName class name
+ */
+ public void setLoginModuleClassName(String loginModuleClassName)
+ {
+ this.loginModuleClassName = loginModuleClassName;
+ }
+}
Added: projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/DefaultAuthenticator.java
===================================================================
--- projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/DefaultAuthenticator.java (rev 0)
+++ projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/DefaultAuthenticator.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,42 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.identity;
+
+/**
+ * Default / dummy authenticator.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class DefaultAuthenticator implements Authenticator
+{
+ static Authenticator INSTANCE = new DefaultAuthenticator();
+
+ public DefaultAuthenticator()
+ {
+ // todo - perhaps <server_configuration/conf/mc-users.properties>
+ }
+
+ public boolean authenticate(String username, String password)
+ {
+ return true;
+ }
+}
Added: projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/Identity.java
===================================================================
--- projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/Identity.java (rev 0)
+++ projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/Identity.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,462 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.identity;
+
+import java.io.IOException;
+import java.security.Principal;
+import java.security.acl.Group;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
+
+import org.jboss.logging.Logger;
+import org.jboss.beans.metadata.plugins.annotations.Inject;
+
+/**
+ * Simple identity.
+ *
+ * @author Shane Bryzak
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class Identity
+{
+ protected static Logger log = Logger.getLogger(Identity.class);
+ public static final String ROLES_GROUP = "Roles";
+
+ private String username;
+ private String password;
+ private Principal principal;
+ private Subject subject;
+ private String jaasConfigName = null;
+ private Configuration configuration;
+ /**
+ * Flag that indicates we are in the process of authenticating
+ */
+ private boolean authenticating = false;
+ private List<String> preAuthenticationRoles = new ArrayList<String>();
+
+ public void create()
+ {
+ subject = new Subject();
+ }
+
+ public boolean login()
+ {
+ try
+ {
+ authenticate();
+ if (log.isTraceEnabled())
+ {
+ log.trace("Login successful for: " + getUsername());
+ }
+ return true;
+ }
+ catch (LoginException ex)
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("Login failed for: " + getUsername(), ex);
+ }
+ return false;
+ }
+ }
+
+ /**
+ * Logout.
+ */
+ public void logout()
+ {
+ principal = null;
+ }
+
+ /**
+ * Are credential set.
+ *
+ * @return true if credentials set
+ */
+ public boolean isCredentialsSet()
+ {
+ return username != null && password != null;
+ }
+
+ /**
+ * Attempts a quiet login, suppressing any login exceptions and not creating
+ * any faces messages. This method is intended to be used primarily as an
+ * internal API call, however has been made public for convenience.
+ */
+ public void quietLogin()
+ {
+ try
+ {
+ if (isCredentialsSet()) authenticate();
+ }
+ catch (LoginException ignored)
+ {
+ }
+ }
+
+ /**
+ * Authenticate.
+ *
+ * @throws LoginException for any login exception
+ */
+ public void authenticate()
+ throws LoginException
+ {
+ // If we're already authenticated, then don't authenticate again
+ if (!isLoggedIn())
+ {
+ authenticate(getLoginContext());
+ }
+ }
+
+ /**
+ * Authenticate.
+ *
+ * @param loginContext the login exception
+ * @throws LoginException for any login exception
+ */
+ public void authenticate(LoginContext loginContext)
+ throws LoginException
+ {
+ try
+ {
+ authenticating = true;
+ preAuthenticate();
+ loginContext.login();
+ postAuthenticate();
+ }
+ finally
+ {
+ authenticating = false;
+ }
+ }
+
+ /**
+ * PreAuthentificate.
+ */
+ protected void preAuthenticate()
+ {
+ unAuthenticate();
+ preAuthenticationRoles.clear();
+ }
+
+ /**
+ * Post authentificate.
+ */
+ protected void postAuthenticate()
+ {
+ // Populate the working memory with the user's principals
+ for (Principal p : getSubject().getPrincipals())
+ {
+ if (!(p instanceof Group))
+ {
+ if (principal == null)
+ {
+ principal = p;
+ break;
+ }
+ }
+ }
+
+ if (!preAuthenticationRoles.isEmpty() && isLoggedIn())
+ {
+ for (String role : preAuthenticationRoles)
+ {
+ addRole(role);
+ }
+ preAuthenticationRoles.clear();
+ }
+ password = null;
+ }
+
+ /**
+ * Removes all Role objects from the security context, removes the "Roles"
+ * group from the user's subject.
+ */
+ protected void unAuthenticate()
+ {
+ principal = null;
+
+ for (Group sg : getSubject().getPrincipals(Group.class))
+ {
+ if (ROLES_GROUP.equals(sg.getName()))
+ {
+ getSubject().getPrincipals().remove(sg);
+ break;
+ }
+ }
+ }
+
+ /**
+ * Is logged in.
+ * @return true if logged in
+ */
+ public boolean isLoggedIn()
+ {
+ return isLoggedIn(false);
+ }
+
+ /**
+ * Is logged in.
+ *
+ * @param attemptLogin try to attempt login
+ * @return true if logged in
+ */
+ public boolean isLoggedIn(boolean attemptLogin)
+ {
+ if (!authenticating && attemptLogin && getPrincipal() == null && isCredentialsSet())
+ {
+ quietLogin();
+ }
+ // If there is a principal set, then the user is logged in.
+ return getPrincipal() != null;
+ }
+
+ /**
+ * Checks if the authenticated Identity is a member of the specified role.
+ *
+ * @param role String The name of the role to check
+ * @return boolean True if the user is a member of the specified role
+ */
+ public boolean hasRole(String role)
+ {
+ isLoggedIn(true);
+
+ for (Group sg : getSubject().getPrincipals(Group.class))
+ {
+ if (ROLES_GROUP.equals(sg.getName()))
+ {
+ return sg.isMember(new SimplePrincipal(role));
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Adds a role to the user's subject, and their security context
+ *
+ * @param role The name of the role to add
+ * @return true if logged in
+ */
+ public boolean addRole(String role)
+ {
+ if (!isLoggedIn())
+ {
+ preAuthenticationRoles.add(role);
+ return false;
+ }
+ else
+ {
+ for (Group sg : getSubject().getPrincipals(Group.class))
+ {
+ if (ROLES_GROUP.equals(sg.getName()))
+ {
+ return sg.addMember(new SimplePrincipal(role));
+ }
+ }
+
+ SimpleGroup roleGroup = new SimpleGroup(ROLES_GROUP);
+ roleGroup.addMember(new SimplePrincipal(role));
+ getSubject().getPrincipals().add(roleGroup);
+ return true;
+ }
+ }
+
+ /**
+ * Removes a role from the user's subject and their security context
+ *
+ * @param role The name of the role to remove
+ */
+ public void removeRole(String role)
+ {
+ for (Group sg : getSubject().getPrincipals(Group.class))
+ {
+ if (ROLES_GROUP.equals(sg.getName()))
+ {
+ Enumeration e = sg.members();
+ while (e.hasMoreElements())
+ {
+ Principal member = (Principal)e.nextElement();
+ if (member.getName().equals(role))
+ {
+ sg.removeMember(member);
+ break;
+ }
+ }
+
+ }
+ }
+ }
+
+ /**
+ * Get LoginContext.
+ *
+ * @return the login context
+ * @throws LoginException for any login exception
+ */
+ protected LoginContext getLoginContext() throws LoginException
+ {
+ if (getJaasConfigName() != null)
+ return new LoginContext(getJaasConfigName(), getSubject(), getDefaultCallbackHandler());
+
+ return new LoginContext(
+ Configuration.DEFAULT_JAAS_CONFIG_NAME,
+ getSubject(),
+ getDefaultCallbackHandler(),
+ configuration.getConfiguration()
+ );
+ }
+
+ /**
+ * Creates a callback handler that can handle a standard username/password
+ * callback, using the username and password properties.
+ *
+ * @return CallbackHandler instance
+ */
+ protected CallbackHandler getDefaultCallbackHandler()
+ {
+ return new CallbackHandler()
+ {
+ public void handle(Callback[] callbacks)
+ throws IOException, UnsupportedCallbackException
+ {
+ for (Callback callback : callbacks)
+ {
+ if (callback instanceof NameCallback)
+ {
+ ((NameCallback)callback).setName(getUsername());
+ }
+ else if (callback instanceof PasswordCallback)
+ {
+ ((PasswordCallback)callback).setPassword(getPassword() != null ? getPassword().toCharArray() : null);
+ }
+ else
+ {
+ throw new UnsupportedCallbackException(callback, "Unsupported callback");
+ }
+ }
+
+ }
+ };
+ }
+
+ /**
+ * Get the username.
+ *
+ * @return username
+ */
+ public String getUsername()
+ {
+ return username;
+ }
+
+ /**
+ * Set the username.
+ *
+ * @param username the username
+ */
+ public void setUsername(String username)
+ {
+ this.username = username;
+ }
+
+ /**
+ * Get the password.
+ *
+ * @return the password
+ */
+ public String getPassword()
+ {
+ return password;
+ }
+
+ /**
+ * Set the password.
+ *
+ * @param password the password
+ */
+ public void setPassword(String password)
+ {
+ this.password = password;
+ }
+
+ /**
+ * Get the principal.
+ *
+ * @return the principal
+ */
+ public Principal getPrincipal()
+ {
+ return principal;
+ }
+
+ /**
+ * Get the subject.
+ *
+ * @return the subject
+ */
+ public Subject getSubject()
+ {
+ return subject;
+ }
+
+ /**
+ * Get the jaas config name.
+ *
+ * @return the jaas config name
+ */
+ public String getJaasConfigName()
+ {
+ return jaasConfigName;
+ }
+
+ /**
+ * Set the jaas config name.
+ *
+ * @param jaasConfigName the jass config name
+ */
+ public void setJaasConfigName(String jaasConfigName)
+ {
+ this.jaasConfigName = jaasConfigName;
+ }
+
+ /**
+ * Set the configuration.
+ *
+ * @param configuration the configuration
+ */
+ @Inject
+ public void setConfiguration(Configuration configuration)
+ {
+ this.configuration = configuration;
+ }
+
+}
Added: projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/MicrocontainerLoginModule.java
===================================================================
--- projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/MicrocontainerLoginModule.java (rev 0)
+++ projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/MicrocontainerLoginModule.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,140 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.identity;
+
+import java.security.acl.Group;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
+
+import org.jboss.logging.Logger;
+import static org.jboss.reliance.identity.Identity.ROLES_GROUP;
+
+/**
+ * Performs authentication using a Microcontainer context.
+ *
+ * @author Shane Bryzak
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class MicrocontainerLoginModule implements LoginModule
+{
+ private static final Logger log = Logger.getLogger(MicrocontainerLoginModule.class);
+
+ protected Set<String> roles = new HashSet<String>();
+
+ protected Subject subject;
+ protected Map<String, ?> options;
+ protected CallbackHandler callbackHandler;
+
+ protected String username;
+ protected String password;
+
+ public boolean abort() throws LoginException
+ {
+ return true;
+ }
+
+ public boolean commit() throws LoginException
+ {
+ subject.getPrincipals().add(new SimplePrincipal(username));
+
+ Group roleGroup = null;
+ for (Group g : subject.getPrincipals(Group.class))
+ {
+ if (ROLES_GROUP.equalsIgnoreCase(g.getName()))
+ {
+ roleGroup = g;
+ break;
+ }
+ }
+
+ if (roleGroup == null) roleGroup = new SimpleGroup(ROLES_GROUP);
+ for (String role : roles)
+ {
+ roleGroup.addMember(new SimplePrincipal(role));
+ }
+
+ subject.getPrincipals().add(roleGroup);
+
+ return true;
+ }
+
+ public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options)
+ {
+ this.subject = subject;
+ this.options = options;
+ this.callbackHandler = callbackHandler;
+ }
+
+ public boolean login() throws LoginException
+ {
+ try
+ {
+ NameCallback cbName = new NameCallback("Enter username");
+ PasswordCallback cbPassword = new PasswordCallback("Enter password", false);
+
+ // Get the username and password from the callback handler
+ callbackHandler.handle(new Callback[]{cbName, cbPassword});
+ username = cbName.getName();
+ password = new String(cbPassword.getPassword());
+ }
+ catch (Exception ex)
+ {
+ log.error("Error logging in", ex);
+ throw new LoginException(ex.getMessage());
+ }
+
+ Authenticator authenticator = getAuthenticator();
+ try
+ {
+ return authenticator.authenticate(username, password);
+ }
+ catch (Exception ex)
+ {
+ log.error("Error invoking login method", ex);
+ throw new LoginException(ex.getMessage());
+ }
+ }
+
+ public boolean logout() throws LoginException
+ {
+ return true;
+ }
+
+ /**
+ * Get the authentificator.
+ *
+ * @return the authentificator
+ */
+ protected Authenticator getAuthenticator()
+ {
+ return DefaultAuthenticator.INSTANCE;
+ }
+}
+
Added: projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/SimpleGroup.java
===================================================================
--- projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/SimpleGroup.java (rev 0)
+++ projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/SimpleGroup.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,114 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.identity;
+
+import java.io.Serializable;
+import java.security.Principal;
+import java.security.acl.Group;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Implementation of the Group interface, used for holding roles etc.
+ *
+ * @author Shane Bryzak
+ */
+public class SimpleGroup implements Group, Serializable
+{
+ private static final long serialVersionUID = 5766373925836425908L;
+
+ /**
+ * The name of the group
+ */
+ private String name;
+
+ /**
+ * The members of this group
+ */
+ private Set<Principal> members = new HashSet<Principal>();
+
+ public SimpleGroup(String name)
+ {
+ this.name = name;
+ }
+
+ public boolean addMember(Principal user)
+ {
+ return members.add(user);
+ }
+
+ public boolean isMember(Principal member)
+ {
+ if (members.contains(member))
+ {
+ return true;
+ }
+ else
+ {
+ for (Principal m : members)
+ {
+ if (m instanceof Group && ((Group)m).isMember(member))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public Enumeration<? extends Principal> members()
+ {
+ return Collections.enumeration(members);
+ }
+
+ public boolean removeMember(Principal user)
+ {
+ return members.remove(user);
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof SimpleGroup)
+ {
+ SimpleGroup other = (SimpleGroup)obj;
+ return other.name.equals(name);
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return name.hashCode();
+ }
+}
Added: projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/SimplePrincipal.java
===================================================================
--- projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/SimplePrincipal.java (rev 0)
+++ projects/microcontainer/trunk/reliance-identity/src/main/org/jboss/reliance/identity/SimplePrincipal.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,75 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.identity;
+
+import java.io.Serializable;
+import java.security.Principal;
+
+/**
+ * Simple implementation of the Principal interface, supporting a named user.
+ *
+ * @author Shane Bryzak
+ */
+public class SimplePrincipal implements Principal, Serializable
+{
+ private static final long serialVersionUID = 5609375932836425908L;
+
+ private String name;
+
+ public SimplePrincipal(String name)
+ {
+ this.name = name;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof Principal)
+ {
+ Principal other = (Principal)obj;
+ return name == null ?
+ other.getName() == null :
+ name.equals(other.getName());
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return name == null ? 0 : name.hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return name;
+ }
+}
Added: projects/microcontainer/trunk/reliance-jbpm/pom.xml
===================================================================
--- projects/microcontainer/trunk/reliance-jbpm/pom.xml (rev 0)
+++ projects/microcontainer/trunk/reliance-jbpm/pom.xml 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,61 @@
+<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">
+ <parent>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-microcontainer</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>jboss-reliance-jbpm</artifactId>
+ <packaging>jar</packaging>
+ <name>JBoss Microcontainer Reliance jBPM</name>
+ <url>http://www.jboss.com/products/jbossmc</url>
+ <description>JBoss Microcontainer Reliance jBPM</description>
+ <build>
+ <resources>
+ <resource>
+ <directory>src/resources/main</directory>
+ </resource>
+ </resources>
+ <testResources>
+ <testResource>
+ <directory>src/resources/tests</directory>
+ </testResource>
+ </testResources>
+ </build>
+ <!-- Do not add version information here, use ../build/pom.xml instead -->
+ <dependencies>
+ <!-- Global dependencies -->
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jbossxb</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-kernel</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-aop-mc-int</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-deployers-vfs</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jbpm</artifactId>
+ </dependency>
+ <!-- Test dependencies -->
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-test</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-container</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Added: projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/container/JbpmContextContainer.java
===================================================================
--- projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/container/JbpmContextContainer.java (rev 0)
+++ projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/container/JbpmContextContainer.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,35 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.jbpm.container;
+
+import org.jbpm.JbpmContext;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class JbpmContextContainer
+{
+ private JbpmContext jbpmContext;
+ private boolean synchronizationRegistered;
+
+
+}
Added: projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/server/plugins/AbstractConsoleInvoker.java
===================================================================
--- projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/server/plugins/AbstractConsoleInvoker.java (rev 0)
+++ projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/server/plugins/AbstractConsoleInvoker.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,44 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.jbpm.server.plugins;
+
+import org.jboss.reliance.jbpm.server.spi.ConsoleInvoker;
+import org.jboss.reliance.jbpm.server.spi.ConsoleServer;
+import org.jboss.beans.metadata.plugins.annotations.Inject;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractConsoleInvoker implements ConsoleInvoker
+{
+ protected ConsoleServer server;
+
+ @Inject
+ public void setConsoleServer(ConsoleServer server)
+ {
+ this.server = server;
+ if (server != null)
+ afterConsoleServerRegistered();
+ }
+
+ protected abstract void afterConsoleServerRegistered();
+}
Added: projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/server/plugins/AbstractConsolerServer.java
===================================================================
--- projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/server/plugins/AbstractConsolerServer.java (rev 0)
+++ projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/server/plugins/AbstractConsolerServer.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,72 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.jbpm.server.plugins;
+
+import org.jboss.reliance.jbpm.container.JbpmContextContainer;
+import org.jboss.reliance.jbpm.server.spi.ConsoleServer;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class AbstractConsolerServer implements ConsoleServer
+{
+ private JbpmContextContainer container;
+
+ public AbstractConsolerServer(JbpmContextContainer container)
+ {
+ this.container = container;
+ }
+
+ // --- signaling processes/tokens
+
+ public void signalProcessInstance(String processDefinitionName, String key)
+ {
+ }
+
+ public void signalProcessInstance(String processDefinitionName, String key, String transitionName)
+ {
+ }
+
+ public void signalProcessInstance(Long processId)
+ {
+ }
+
+ public void signalProcessInstance(Long processId, String transitionName)
+ {
+ }
+
+ public void signalToken(String processDefinitionName, String key, String tokenName)
+ {
+ }
+
+ public void signalToken(String processDefinitionName, String key, String tokenName, String transitionName)
+ {
+ }
+
+ public void signalToken(Long processId, String tokenName)
+ {
+ }
+
+ public void signalToken(Long processId, String tokenName, String transitionName)
+ {
+ }
+}
Added: projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/server/spi/ConsoleInvoker.java
===================================================================
--- projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/server/spi/ConsoleInvoker.java (rev 0)
+++ projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/server/spi/ConsoleInvoker.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,30 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.jbpm.server.spi;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface ConsoleInvoker
+{
+ void setConsoleServer(ConsoleServer server);
+}
Added: projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/server/spi/ConsoleServer.java
===================================================================
--- projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/server/spi/ConsoleServer.java (rev 0)
+++ projects/microcontainer/trunk/reliance-jbpm/src/main/org/jboss/reliance/jbpm/server/spi/ConsoleServer.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,46 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.jbpm.server.spi;
+
+/**
+ * Console server to manage jBPM tasks.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface ConsoleServer
+{
+ void signalProcessInstance(String processDefinitionName, String key);
+
+ void signalProcessInstance(String processDefinitionName, String key, String transitionName);
+
+ void signalProcessInstance(Long processId);
+
+ void signalProcessInstance(Long processId, String transitionName);
+
+ void signalToken(String processDefinitionName, String key, String tokenName);
+
+ void signalToken(String processDefinitionName, String key, String tokenName, String transitionName);
+
+ void signalToken(Long processId, String tokenName);
+
+ void signalToken(Long processId, String tokenName, String transitionName);
+}
Added: projects/microcontainer/trunk/reliance-rules/pom.xml
===================================================================
--- projects/microcontainer/trunk/reliance-rules/pom.xml (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/pom.xml 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,73 @@
+<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">
+ <parent>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-microcontainer</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>jboss-reliance-rules</artifactId>
+ <packaging>jar</packaging>
+ <name>JBoss Microcontainer Reliance Rules</name>
+ <url>http://www.jboss.com/products/jbossmc</url>
+ <description>JBoss Microcontainer Reliance Rules</description>
+ <build>
+ <resources>
+ <resource>
+ <directory>src/resources/main</directory>
+ </resource>
+ </resources>
+ <testResources>
+ <testResource>
+ <directory>src/resources/tests</directory>
+ </testResource>
+ </testResources>
+ </build>
+ <!-- Do not add version information here, use ../build/pom.xml instead -->
+ <dependencies>
+ <!-- Global dependencies -->
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jbossxb</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-kernel</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-aop-mc-int</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-deployers-vfs</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.drools</groupId>
+ <artifactId>drools-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.drools</groupId>
+ <artifactId>drools-compiler</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.drools</groupId>
+ <artifactId>drools-decisiontables</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-reliance-identity</artifactId>
+ </dependency>
+ <!-- Test dependencies -->
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-test</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-container</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Added: projects/microcontainer/trunk/reliance-rules/src/etc/reliance-deployer-beans.xml
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/etc/reliance-deployer-beans.xml (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/etc/reliance-deployer-beans.xml 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ JBoss Reliance Rules Deployers
+-->
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="DRLDroolsDeployer" class="org.jboss.reliance.drools.deployer.DRLFileDeployer">
+ <!--<property name="configuration"><inject bean="DroolsPackageConfiguration"/></property>-->
+ </bean>
+
+ <bean name="ExcelDroolsDeployer" class="org.jboss.reliance.drools.deployer.ExcelRulesDeployer">
+ <!--<property name="configuration"><inject bean="DroolsPackageConfiguration"/></property>-->
+ </bean>
+
+ <bean name="CSVDroolsDeployer" class="org.jboss.reliance.drools.deployer.CSVRulesDeployer">
+ <!--<property name="configuration"><inject bean="DroolsPackageConfiguration"/></property>-->
+ </bean>
+
+</deployment>
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/ConstantsKernelGlobalResolver.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/ConstantsKernelGlobalResolver.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/ConstantsKernelGlobalResolver.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,46 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core;
+
+import java.util.Map;
+import java.util.HashMap;
+
+import org.drools.spi.GlobalResolver;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
+
+/**
+ * Simplified names for KernelConstants names.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ConstantsKernelGlobalResolver extends NamingKernelGlobalResolver
+{
+ public ConstantsKernelGlobalResolver(GlobalResolver delegate, Controller controller)
+ {
+ super(delegate, controller);
+ Map<String, String> names = new HashMap<String, String>();
+ names.put("kernel", KernelConstants.KERNEL_NAME);
+ names.put("controller", KernelConstants.KERNEL_CONTROLLER_NAME);
+ setNames(names);
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/KernelGlobalResolver.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/KernelGlobalResolver.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/KernelGlobalResolver.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,71 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core;
+
+import org.drools.spi.GlobalResolver;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+
+/**
+ * Resolves Microcontainer context's as Drools globals.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class KernelGlobalResolver implements GlobalResolver
+{
+ private GlobalResolver delegate;
+ private Controller controller;
+
+ public KernelGlobalResolver(GlobalResolver delegate, Controller controller)
+ {
+ if (delegate == null)
+ throw new IllegalArgumentException("Null global resolver delegate!");
+ if (controller == null)
+ throw new IllegalArgumentException("Null controller!");
+ this.delegate = delegate;
+ this.controller = controller;
+ }
+
+ /**
+ * Transform Drools global name.
+ *
+ * @param name the name
+ * @return transformed name
+ */
+ protected Object transformName(String name)
+ {
+ return name;
+ }
+
+ public Object resolveGlobal(String name)
+ {
+ ControllerContext context = controller.getInstalledContext(transformName(name));
+ if (context != null)
+ return context.getTarget();
+ return delegate.resolveGlobal(name);
+ }
+
+ public void setGlobal(String name, Object value)
+ {
+ delegate.setGlobal(name, value);
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/ManagedWorkingMemory.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/ManagedWorkingMemory.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/ManagedWorkingMemory.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,133 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core;
+
+import java.io.Serializable;
+import java.util.Map;
+
+import org.drools.RuleBase;
+import org.drools.StatefulSession;
+import org.drools.event.AgendaEventListener;
+import org.drools.event.RuleFlowEventListener;
+import org.drools.event.WorkingMemoryEventListener;
+import org.drools.spi.GlobalResolver;
+import org.jboss.beans.metadata.plugins.annotations.Destroy;
+import org.jboss.beans.metadata.plugins.annotations.Inject;
+import org.jboss.beans.metadata.plugins.annotations.Install;
+import org.jboss.beans.metadata.plugins.annotations.Uninstall;
+import org.jboss.beans.metadata.plugins.annotations.Constructor;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
+
+/**
+ * Managed working memory.
+ *
+ * @author Gavin King
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ManagedWorkingMemory implements Serializable
+{
+ private static final long serialVersionUID = -1746942080571374743L;
+
+ private transient RuleBase ruleBase;
+ private transient Controller controller;
+
+ private transient Map<String, String> names;
+
+ private StatefulSession statefulSession;
+
+ @Constructor
+ public ManagedWorkingMemory(
+ @Inject RuleBase ruleBase,
+ @Inject(bean = KernelConstants.KERNEL_CONTROLLER_NAME) Controller controller)
+ {
+ this.ruleBase = ruleBase;
+ this.controller = controller;
+ }
+
+ public void setNames(Map<String, String> names)
+ {
+ this.names = names;
+ }
+
+ public StatefulSession getStatefulSession()
+ {
+ if (statefulSession == null)
+ {
+ statefulSession = ruleBase.newStatefulSession();
+ statefulSession.setGlobalResolver(createGlobalResolver(statefulSession.getGlobalResolver()));
+ }
+ return statefulSession;
+ }
+
+ @Install
+ public void addEventListener(AgendaEventListener agendaEventListener)
+ {
+ getStatefulSession().addEventListener(agendaEventListener);
+ }
+
+ @Install
+ public void addEventListener(WorkingMemoryEventListener workingMemoryEventListener)
+ {
+ getStatefulSession().addEventListener(workingMemoryEventListener);
+ }
+
+ @Install
+ public void addEventListener(RuleFlowEventListener ruleFlowEventListener)
+ {
+ getStatefulSession().addEventListener(ruleFlowEventListener);
+ }
+
+ @Uninstall
+ public void removeEventListener(AgendaEventListener agendaEventListener)
+ {
+ getStatefulSession().removeEventListener(agendaEventListener);
+ }
+
+ @Uninstall
+ public void removeEventListener(WorkingMemoryEventListener workingMemoryEventListener)
+ {
+ getStatefulSession().removeEventListener(workingMemoryEventListener);
+ }
+
+ @Uninstall
+ public void removeEventListener(RuleFlowEventListener ruleFlowEventListener)
+ {
+ getStatefulSession().removeEventListener(ruleFlowEventListener);
+ }
+
+ protected GlobalResolver createGlobalResolver(GlobalResolver delegate)
+ {
+ NamingKernelGlobalResolver resolver = new ConstantsKernelGlobalResolver(delegate, controller);
+ if (names != null)
+ resolver.addNames(names);
+ return resolver;
+ }
+
+ @Destroy
+ public void destroy()
+ {
+ if (statefulSession != null)
+ statefulSession.dispose();
+ }
+
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/NamingKernelGlobalResolver.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/NamingKernelGlobalResolver.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/NamingKernelGlobalResolver.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,69 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core;
+
+import java.util.Map;
+import java.util.Collections;
+
+import org.drools.spi.GlobalResolver;
+import org.jboss.dependency.spi.Controller;
+
+/**
+ * Map alias names for rules globals --> microcontainer names.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class NamingKernelGlobalResolver extends KernelGlobalResolver
+{
+ private Map<String, String> names = Collections.emptyMap();
+
+ public NamingKernelGlobalResolver(GlobalResolver delegate, Controller controller)
+ {
+ super(delegate, controller);
+ }
+
+ /**
+ * Set the names map.
+ *
+ * @param names the names map
+ */
+ public void setNames(Map<String, String> names)
+ {
+ this.names = names;
+ }
+
+ /**
+ * Add additional names.
+ *
+ * @param additionalNames additional names
+ */
+ public void addNames(Map<String, String> additionalNames)
+ {
+ names.putAll(additionalNames);
+ }
+
+ protected Object transformName(String name)
+ {
+ String mappedName = names.get(name);
+ return mappedName != null ? mappedName : super.transformName(name);
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/PackageGenerator.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/PackageGenerator.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/PackageGenerator.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,130 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core;
+
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.UUID;
+
+import org.drools.compiler.PackageBuilder;
+import org.drools.compiler.PackageBuilderConfiguration;
+import org.jboss.beans.metadata.plugins.annotations.Constructor;
+import org.jboss.beans.metadata.plugins.annotations.Inject;
+import org.jboss.beans.metadata.plugins.builder.BeanMetaDataBuilderFactory;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.w3c.dom.Element;
+
+/**
+ * Package generator.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class PackageGenerator
+{
+ private KernelController controller;
+
+ private String name;
+ private String fromDRL;
+ private Element fromXML;
+ private String dslTemplate;
+
+ private PackageBuilderConfiguration configuration;
+ private String uuidName;
+
+ @Constructor
+ public PackageGenerator(@Inject(bean= KernelConstants.KERNEL_CONTROLLER_NAME) KernelController controller)
+ {
+ this.controller = controller;
+ }
+
+ /**
+ * Start package creation.
+ *
+ * @throws Throwable for any error
+ */
+ public void start() throws Throwable
+ {
+ PackageBuilder builder = new PackageBuilder(configuration);
+ Reader dslReader = null;
+ if (dslTemplate != null)
+ dslReader = new StringReader(dslTemplate);
+ if (fromDRL != null)
+ {
+ Reader drlReader = new StringReader(fromDRL);
+ if (dslReader != null)
+ builder.addPackageFromDrl(drlReader, dslReader);
+ else
+ builder.addPackageFromDrl(drlReader);
+ }
+ if (fromXML != null)
+ {
+ Reader xmlReader = new StringReader(fromXML.toString());
+ builder.addPackageFromXml(xmlReader);
+ }
+ uuidName = UUID.randomUUID().toString();
+ BeanMetaDataBuilder beanBuilder = BeanMetaDataBuilderFactory.createBuilder(
+ uuidName,
+ PackageWrapper.class.getName()
+ );
+ beanBuilder
+ .addConstructorParameter(String.class.getName(), name)
+ .addConstructorParameter(org.drools.rule.Package.class.getName(), builder.getPackage());
+ controller.install(beanBuilder.getBeanMetaData());
+ }
+
+ /**
+ * Stop package creation,
+ * uninstall package from Controller
+ */
+ public void stop()
+ {
+ controller.uninstall(uuidName);
+ uuidName = null;
+ }
+
+ public void setConfiguration(PackageBuilderConfiguration configuration)
+ {
+ this.configuration = configuration;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public void setFromDRL(String fromDRL)
+ {
+ this.fromDRL = fromDRL;
+ }
+
+ public void setFromXML(Element fromXML)
+ {
+ this.fromXML = fromXML;
+ }
+
+ public void setDslTemplate(String dslTemplate)
+ {
+ this.dslTemplate = dslTemplate;
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/PackageWrapper.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/PackageWrapper.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/PackageWrapper.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,66 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core;
+
+/**
+ * Package wrapper.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class PackageWrapper
+{
+ private String name;
+ private org.drools.rule.Package pckg;
+
+ public PackageWrapper(org.drools.rule.Package pckg)
+ {
+ this(null, pckg);
+ }
+
+ public PackageWrapper(String name, org.drools.rule.Package pckg)
+ {
+ if (pckg == null)
+ throw new IllegalArgumentException("Null package.");
+ this.name = name;
+ this.pckg = pckg;
+ }
+
+ /**
+ * Get the name.
+ *
+ * @return name
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * Get the package.
+ *
+ * @return package
+ */
+ public org.drools.rule.Package getPackage()
+ {
+ return pckg;
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/RuleBaseBean.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/RuleBaseBean.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/RuleBaseBean.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,171 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.drools.RuleBase;
+import org.drools.RuleBaseConfiguration;
+import org.drools.RuleBaseFactory;
+import org.drools.StatefulSession;
+import org.drools.StatelessSession;
+import org.drools.rule.Package;
+import org.jboss.beans.metadata.plugins.annotations.Constructor;
+import org.jboss.beans.metadata.plugins.annotations.FromContext;
+import org.jboss.beans.metadata.plugins.annotations.Inject;
+import org.jboss.beans.metadata.plugins.annotations.Install;
+import org.jboss.beans.metadata.plugins.annotations.Uninstall;
+import org.jboss.logging.Logger;
+
+/**
+ * RuleBase bean delegate.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class RuleBaseBean implements RuleBase
+{
+ protected Logger log = Logger.getLogger(getClass());
+
+ private String name;
+ private RuleBaseConfiguration configuration;
+ private org.drools.RuleBase ruleBase;
+
+ @Constructor
+ public RuleBaseBean(@Inject(fromContext = FromContext.NAME) String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * Set the configuration.
+ *
+ * @param configuration the configuration
+ */
+ public void setConfiguration(RuleBaseConfiguration configuration)
+ {
+ this.configuration = configuration;
+ }
+
+ public void create() throws Exception
+ {
+ ruleBase = RuleBaseFactory.newRuleBase(configuration);
+ }
+
+ public void destroy()
+ {
+ ruleBase = null;
+ }
+
+ /**
+ * Does name match wrapper's name.
+ *
+ * @param pw package wrapper
+ * @return true if name matches
+ */
+ protected boolean matchPackage(PackageWrapper pw)
+ {
+ return pw.getName() == null || pw.getName().equals(name);
+ }
+
+ @Install(whenRequired = "Start", cardinality = "1..n")
+ public void addPackage(PackageWrapper pckg) throws Exception
+ {
+ // no need to synch - drools already do that
+ if (matchPackage(pckg))
+ ruleBase.addPackage(pckg.getPackage());
+ }
+
+ @Uninstall(whenRequired = "Start")
+ public void removePackage(PackageWrapper pckg)
+ {
+ if (matchPackage(pckg))
+ ruleBase.removePackage(pckg.getPackage().getName());
+ }
+
+ // delegate
+
+ public StatelessSession newStatelessSession()
+ {
+ return ruleBase.newStatelessSession();
+ }
+
+ public StatefulSession newStatefulSession()
+ {
+ return ruleBase.newStatefulSession();
+ }
+
+ public StatefulSession newStatefulSession(boolean keepReference)
+ {
+ return ruleBase.newStatefulSession(keepReference);
+ }
+
+ public StatefulSession newStatefulSession(InputStream inputStream) throws IOException, ClassNotFoundException
+ {
+ return ruleBase.newStatefulSession(inputStream);
+ }
+
+ public StatefulSession newStatefulSession(InputStream inputStream, boolean b) throws IOException, ClassNotFoundException
+ {
+ return ruleBase.newStatefulSession(inputStream);
+ }
+
+ public Package[] getPackages()
+ {
+ return ruleBase.getPackages();
+ }
+
+ public Package getPackage(String name)
+ {
+ return ruleBase.getPackage(name);
+ }
+
+ public void addPackage(Package pckg) throws Exception
+ {
+ ruleBase.addPackage(pckg);
+ }
+
+ public void removePackage(String name)
+ {
+ ruleBase.removePackage(name);
+ }
+
+ public void removeRule(String name, String ruleName)
+ {
+ ruleBase.removeRule(name, ruleName);
+ }
+
+ public void removeFunction(String packageName, String functionName)
+ {
+ ruleBase.removeFunction(packageName, functionName);
+ }
+
+ public void removeProcess(String id)
+ {
+ ruleBase.removeProcess(id);
+ }
+
+ public StatefulSession[] getStatefulSessions()
+ {
+ return ruleBase.getStatefulSessions();
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/RuleDependencyCheck.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/RuleDependencyCheck.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/RuleDependencyCheck.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core;
+
+/**
+ * Rule dependency checker interface.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface RuleDependencyCheck
+{
+ /**
+ * Performs a check for the specified name and action
+ * if they can be resolved.
+ *
+ * @param name Object The permission name
+ * @param action Obejct The permission action
+ * @param arg Object Optional object parameter used to make a permission decision
+ * @return boolean true if the user has the specified permission
+ */
+ boolean canResolve(Object name, Object action, Object... arg);
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/CRUDAwareAspect.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/CRUDAwareAspect.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/CRUDAwareAspect.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,47 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core.aspects;
+
+import java.lang.reflect.Method;
+
+/**
+ * Fire all rules after crud.
+ * Can be made redundant with extended pointcut.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class CRUDAwareAspect extends FlagAwareAspect
+{
+ public CRUDAwareAspect()
+ {
+ super();
+ }
+
+ protected boolean shouldFileAllRules(Method method, Object[] args)
+ {
+ String methodName = method.getName();
+ return super.shouldFileAllRules(method, args) &&
+ (methodName.regionMatches(true, 0, "insert", 0, 6) ||
+ methodName.regionMatches(true, 0, "update", 0, 6) ||
+ methodName.regionMatches(true, 0, "retract", 0, 7));
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/DisableFireAllRules.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/DisableFireAllRules.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/DisableFireAllRules.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core.aspects;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Fire all rules marker.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({ElementType.METHOD, ElementType.TYPE})
+public @interface DisableFireAllRules
+{
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/DisableFireAllRulesInterceptor.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/DisableFireAllRulesInterceptor.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/DisableFireAllRulesInterceptor.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,70 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core.aspects;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ * Disable fire all rules interceptor.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class DisableFireAllRulesInterceptor implements Interceptor
+{
+ public String getName()
+ {
+ return "DisableFireAllRulesInterceptor";
+ }
+
+ /**
+ * Disable rules flag.
+ *
+ * @param invocation the invocation
+ * @return invocation's result
+ * @throws Throwable for any exception
+ */
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ // no need to check for annotation, always disable
+ FireAllRulesFlag.disableFileAllRules();
+ try
+ {
+ Object result = invocation.invokeNext();
+ invokeAfterResult(result);
+ return result;
+ }
+ finally
+ {
+ FireAllRulesFlag.enableFileAllRules();
+ }
+ }
+
+ /**
+ * Invoke after invocation invocation.
+ *
+ * @param result the invocation's result
+ */
+ protected void invokeAfterResult(Object result)
+ {
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/FireAllRulesAfter.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/FireAllRulesAfter.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/FireAllRulesAfter.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core.aspects;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+/**
+ * Fire all rules marker.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({ElementType.METHOD, ElementType.TYPE})
+public @interface FireAllRulesAfter
+{
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/FireAllRulesAfterInvocationInterceptor.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/FireAllRulesAfterInvocationInterceptor.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/FireAllRulesAfterInvocationInterceptor.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,57 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core.aspects;
+
+import org.drools.WorkingMemory;
+
+/**
+ * Disable fire all rules during invocation,
+ * only invoke fireAllRules after invocation.
+ *
+ * @see DisableFireAllRulesInterceptor
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class FireAllRulesAfterInvocationInterceptor extends DisableFireAllRulesInterceptor
+{
+ private WorkingMemory workingMemory;
+
+ public FireAllRulesAfterInvocationInterceptor(WorkingMemory workingMemory)
+ {
+ this.workingMemory = workingMemory;
+ }
+
+ public String getName()
+ {
+ return "FireAllRulesAfterInvocationInterceptor";
+ }
+
+ /**
+ * File all rules after invocation.
+ *
+ * @param result the invocation's result
+ */
+ protected void invokeAfterResult(Object result)
+ {
+ workingMemory.fireAllRules();
+ }
+
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/FireAllRulesAspect.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/FireAllRulesAspect.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/FireAllRulesAspect.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,111 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core.aspects;
+
+import java.lang.reflect.Method;
+
+import org.drools.Agenda;
+import org.drools.WorkingMemory;
+import org.drools.spi.AgendaFilter;
+import org.jboss.aop.joinpoint.MethodInvocation;
+
+/**
+ * Invocation aware working memory handler.
+ * Checking if we need to fire all rules.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class FireAllRulesAspect
+{
+ private AgendaFilter filter;
+ private Integer limit;
+
+ /**
+ * Check if we should fire all rules.
+ *
+ * @param method the method
+ * @param args the arguments
+ * @return true if we should fire
+ */
+ protected boolean shouldFileAllRules(Method method, Object[] args)
+ {
+ return method.getName().startsWith("fireAllRules") == false;
+ }
+
+ /**
+ * Inovke method on working memory instance,
+ * and conditionally fire all rules.
+ *
+ * @param invocation the invocation
+ * @return invocation's result
+ * @throws Throwable for any error
+ */
+ public Object invoke(MethodInvocation invocation) throws Throwable
+ {
+ Object target = invocation.getTargetObject();
+ if (target instanceof WorkingMemory == false)
+ throw new IllegalArgumentException("Target must implement WorkingMemory.");
+ WorkingMemory delegate = (WorkingMemory)target;
+ Object result = invocation.invokeNext();
+ if (shouldFileAllRules(invocation.getActualMethod(), invocation.getArguments()))
+ {
+ if (filter != null && limit != null)
+ {
+ delegate.fireAllRules(filter, limit);
+ }
+ else if (filter != null)
+ {
+ delegate.fireAllRules(filter);
+ }
+ else if (limit != null)
+ {
+ delegate.fireAllRules(limit);
+ }
+ else
+ {
+ delegate.fireAllRules();
+ }
+ Agenda agenda = delegate.getAgenda();
+ }
+ return result;
+ }
+
+ /**
+ * Set the filter.
+ *
+ * @param filter the agenda filter
+ */
+ public void setFilter(AgendaFilter filter)
+ {
+ this.filter = filter;
+ }
+
+ /**
+ * Set the limit.
+ *
+ * @param limit the fire limit
+ */
+ public void setLimit(Integer limit)
+ {
+ this.limit = limit;
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/FireAllRulesFlag.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/FireAllRulesFlag.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/FireAllRulesFlag.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,59 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core.aspects;
+
+/**
+ * Simple thread local flag.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class FireAllRulesFlag
+{
+ private static Object DISABLE_FLAG = new Object();
+ private static ThreadLocal<Object> threadLocal = new ThreadLocal<Object>();
+
+ /**
+ * Check if flag doesn't exists.
+ *
+ * @return true if flag exists
+ */
+ public static boolean shouldFileAllRules()
+ {
+ return threadLocal.get() == null;
+ }
+
+ /**
+ * Enable flag.
+ */
+ public static void enableFileAllRules()
+ {
+ threadLocal.set(null);
+ }
+
+ /**
+ * Disable flag.
+ */
+ public static void disableFileAllRules()
+ {
+ threadLocal.set(DISABLE_FLAG);
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/FlagAwareAspect.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/FlagAwareAspect.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/FlagAwareAspect.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,42 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core.aspects;
+
+import java.lang.reflect.Method;
+
+/**
+ * Fire all rules flag aware invocation handler.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class FlagAwareAspect extends FireAllRulesAspect
+{
+ public FlagAwareAspect()
+ {
+ super();
+ }
+
+ protected boolean shouldFileAllRules(Method method, Object[] args)
+ {
+ return super.shouldFileAllRules(method, args) && FireAllRulesFlag.shouldFileAllRules();
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/StatefulSessionCreationInterceptor.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/StatefulSessionCreationInterceptor.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/aspects/StatefulSessionCreationInterceptor.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,56 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core.aspects;
+
+import org.drools.StatefulSession;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.microcontainer.aspects.util.ProxyUtils;
+
+/**
+ * Statefull session wrapper interceptor.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class StatefulSessionCreationInterceptor implements Interceptor
+{
+ public String getName()
+ {
+ return "StatefulSessionInterceptor";
+ }
+
+ /**
+ * Wrap stateful session.
+ *
+ * @param invocation the invocation
+ * @return invocation's result
+ * @throws Throwable for any exception
+ */
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ Object result = invocation.invokeNext();
+ if (result instanceof StatefulSession == false)
+ throw new IllegalArgumentException("Interceptor should only used on methods the return StatefulSession instance!");
+
+ return ProxyUtils.createProxy((StatefulSession)result, StatefulSession.class);
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/rules/Flag.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/rules/Flag.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/rules/Flag.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,37 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core.rules;
+
+/**
+ * Flag to mark state in rules.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class Flag extends Nameable
+{
+ private static final long serialVersionUID = -1808636908879199650L;
+
+ public Flag(Object name)
+ {
+ super(name);
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/rules/Nameable.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/rules/Nameable.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/rules/Nameable.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,56 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core.rules;
+
+import java.io.Serializable;
+
+/**
+ * Name holder;
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class Nameable implements Serializable
+{
+ private static final long serialVersionUID = -1808636908879199650L;
+
+ private Object name;
+
+ protected Nameable(Object name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * Get the name.
+ *
+ * @return name
+ */
+ public Object getName()
+ {
+ return name;
+ }
+
+ public String toString()
+ {
+ return getClass().getSimpleName() + "(" + name + ")";
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/security/PermissionCheck.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/security/PermissionCheck.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/security/PermissionCheck.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,77 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core.security;
+
+import org.jboss.reliance.drools.core.rules.Nameable;
+
+/**
+ * Used to assert permission requirements into a WorkingMemory when evaluating
+ * a @Restrict expression. The consequence of the rule is responsible for
+ * granting the permission.
+ *
+ * @author Shane Bryzak
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class PermissionCheck extends Nameable
+{
+ private Object action;
+ private boolean granted;
+
+ public PermissionCheck(Object name, Object action)
+ {
+ super(name);
+ this.action = action;
+ }
+
+ /**
+ * Get the action.
+ *
+ * @return action
+ */
+ public Object getAction()
+ {
+ return action;
+ }
+
+ /**
+ * Set grant to true.
+ */
+ public void grant()
+ {
+ granted = true;
+ }
+
+ /**
+ * Is permission granted.
+ *
+ * @return true for granted
+ */
+ public boolean isGranted()
+ {
+ return granted;
+ }
+
+ public String toString()
+ {
+ return "PermissionCheck(" + getName() + ", " + action + ", " + granted + ")";
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/security/Role.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/security/Role.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/security/Role.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core.security;
+
+import org.jboss.reliance.drools.core.rules.Nameable;
+
+/**
+ * Represents a user role exclusively within the scope of security rules.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class Role extends Nameable
+{
+ private static final long serialVersionUID = -1808636908879199650L;
+
+ public Role(Object name)
+ {
+ super(name);
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/security/RoleTracker.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/security/RoleTracker.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/security/RoleTracker.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,67 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core.security;
+
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.logging.Logger;
+import org.jboss.reliance.drools.core.rules.Nameable;
+
+/**
+ * Role tracker.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class RoleTracker extends Nameable
+{
+ protected static Logger log = Logger.getLogger(RoleTracker.class);
+ private static final long serialVersionUID = 3855075694271934392L;
+
+ public RoleTracker(Object name)
+ {
+ super(name);
+ }
+
+ public static void change(Controller controller, Object name, String stateString)
+ {
+ if (controller == null)
+ {
+ log.warn("Null Controller, set global variable or use ManagedWorkingMemory.");
+ return;
+ }
+
+ ControllerContext context = controller.getContext(name, null);
+ if (context != null)
+ {
+ ControllerState state = new ControllerState(stateString);
+ try
+ {
+ controller.change(context, state);
+ }
+ catch (Throwable t)
+ {
+ log.error("Exception while unwinding context: " + context, t);
+ }
+ }
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/security/RuleBasedIdentity.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/security/RuleBasedIdentity.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/core/security/RuleBasedIdentity.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,268 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.core.security;
+
+import java.security.Principal;
+import java.security.acl.Group;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.security.auth.login.LoginException;
+import javax.security.auth.login.LoginContext;
+
+import org.drools.FactHandle;
+import org.drools.RuleBase;
+import org.drools.StatefulSession;
+import org.drools.base.ClassObjectFilter;
+import org.jboss.reliance.drools.core.RuleDependencyCheck;
+import org.jboss.reliance.drools.core.aspects.DisableFireAllRules;
+import org.jboss.reliance.drools.core.aspects.FireAllRulesAfter;
+import org.jboss.reliance.identity.Identity;
+
+/**
+ * Drools based identity.
+ *
+ * @author Shane Bryzak
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class RuleBasedIdentity extends Identity implements RuleDependencyCheck
+{
+ private StatefulSession securityContext;
+ private RuleBase securityRules;
+
+ @Override
+ public void create()
+ {
+ super.create();
+
+ if (securityContext == null && securityRules != null)
+ {
+ securityContext = securityRules.newStatefulSession(false);
+ }
+
+ if (securityContext == null)
+ {
+ log.warn("No security rule base available - please install a RuleBase if permission checks are required.");
+ }
+ }
+
+ @Override
+ protected void postAuthenticate()
+ {
+ super.postAuthenticate();
+
+ StatefulSession securityContext = getSecurityContext();
+
+ if (securityContext != null)
+ {
+ // Populate the working memory with the user's principals
+ for (Principal p : getSubject().getPrincipals())
+ {
+ if ((p instanceof Group) && ROLES_GROUP.equals(p.getName()))
+ {
+ Enumeration e = ((Group)p).members();
+ while (e.hasMoreElements())
+ {
+ Principal role = (Principal)e.nextElement();
+ securityContext.insert(new Role(role.getName()));
+ }
+ }
+ }
+
+ securityContext.insert(getPrincipal());
+ }
+ }
+
+ @DisableFireAllRules
+ public boolean canResolve(Object name, Object action, Object... arg)
+ {
+ StatefulSession securityContext = getSecurityContext();
+ if (securityContext == null)
+ return false;
+
+ List<FactHandle> handles = new ArrayList<FactHandle>();
+ PermissionCheck check = new PermissionCheck(name, action);
+ synchronized (securityContext)
+ {
+ try
+ {
+ handles.add(securityContext.insert(check));
+
+ for (int i = 0; i < arg.length; i++)
+ {
+ if (i == 0 && arg[0] instanceof Collection)
+ {
+ for (Object value : (Collection)arg[i])
+ {
+ if (securityContext.getFactHandle(value) == null)
+ {
+ handles.add(securityContext.insert(value));
+ }
+ }
+ }
+ else
+ {
+ handles.add(securityContext.insert(arg[i]));
+ }
+ }
+
+ securityContext.fireAllRules();
+ }
+ finally
+ {
+ for (FactHandle handle : handles)
+ securityContext.retract(handle);
+ }
+ }
+ return check.isGranted();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected void unAuthenticate()
+ {
+ StatefulSession securityContext = getSecurityContext();
+
+ if (securityContext != null)
+ {
+ Iterator<Role> iter = securityContext.iterateObjects(new ClassObjectFilter(Role.class));
+ while (iter.hasNext())
+ {
+ securityContext.retract(securityContext.getFactHandle(iter.next()));
+ }
+ }
+
+ super.unAuthenticate();
+ }
+
+ @Override
+ public boolean addRole(String role)
+ {
+ if (super.addRole(role))
+ {
+ StatefulSession securityContext = getSecurityContext();
+
+ if (securityContext != null)
+ {
+ securityContext.insert(new Role(role));
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void removeRole(String role)
+ {
+ StatefulSession securityContext = getSecurityContext();
+
+ if (securityContext != null)
+ {
+ Iterator<Role> iter = securityContext.iterateObjects(new ClassObjectFilter(Role.class));
+ while (iter.hasNext())
+ {
+ Role r = iter.next();
+ if (r.getName().equals(role))
+ {
+ FactHandle fh = securityContext.getFactHandle(r);
+ securityContext.retract(fh);
+ break;
+ }
+ }
+ }
+
+ super.removeRole(role);
+ }
+
+ /**
+ * Get the statefull session.
+ *
+ * @return statefull session
+ */
+ public StatefulSession getSecurityContext()
+ {
+ return securityContext;
+ }
+
+ /**
+ * Set statefull session.
+ *
+ * @param securityContext the session
+ */
+ public void setSecurityContext(StatefulSession securityContext)
+ {
+ this.securityContext = securityContext;
+ }
+
+ /**
+ * Set the rule base.
+ *
+ * @param securityRules the rule base instance
+ */
+ public void setSecurityRules(RuleBase securityRules)
+ {
+ this.securityRules = securityRules;
+ }
+
+ //--- fire all rules after
+
+ @FireAllRulesAfter
+ public boolean login()
+ {
+ return super.login();
+ }
+
+ @FireAllRulesAfter
+ public void quietLogin()
+ {
+ super.quietLogin();
+ }
+
+ @FireAllRulesAfter
+ public void authenticate() throws LoginException
+ {
+ super.authenticate();
+ }
+
+ @FireAllRulesAfter
+ public void authenticate(LoginContext loginContext) throws LoginException
+ {
+ super.authenticate(loginContext);
+ }
+
+ @FireAllRulesAfter
+ public boolean isLoggedIn()
+ {
+ return super.isLoggedIn();
+ }
+
+ @FireAllRulesAfter
+ public boolean isLoggedIn(boolean attemptLogin)
+ {
+ return super.isLoggedIn(attemptLogin);
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/DependencyItemFactory.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/DependencyItemFactory.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/DependencyItemFactory.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,42 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.dependency;
+
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.dependency.spi.ControllerContext;
+
+/**
+ * Dependency item factory.
+ *
+ * @param <T> exact controller context type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface DependencyItemFactory<T extends ControllerContext>
+{
+ /**
+ * Create new dependency item.
+ *
+ * @param context the context
+ * @return new dependency item
+ */
+ DependencyItem createDependencyItem(T context);
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/RuleBasedDependencyItem.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/RuleBasedDependencyItem.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/RuleBasedDependencyItem.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,100 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.dependency;
+
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.plugins.AbstractDependencyItem;
+import org.jboss.reliance.drools.core.RuleDependencyCheck;
+
+/**
+ * Drools based dependency.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class RuleBasedDependencyItem extends AbstractDependencyItem
+{
+ private Object action;
+ private Object[] args;
+ private String checkName = "identity";
+ private boolean resolvedOnNullIdentity;
+
+ public RuleBasedDependencyItem(Object name, Object action, Object... args)
+ {
+ this(name, action, null, null, args);
+ }
+
+ public RuleBasedDependencyItem(Object name, Object action, ControllerState whenRequired, ControllerState dependentState, Object... args)
+ {
+ super(name, null, whenRequired, dependentState);
+ this.action = action;
+ this.args = args;
+ }
+
+ public boolean resolve(Controller controller)
+ {
+ ControllerContext checkContext;
+ if (getDependentState() == null)
+ checkContext = controller.getInstalledContext(checkName);
+ else
+ checkContext = controller.getContext(checkName, getDependentState());
+
+ if (checkContext != null)
+ {
+ Object checkObject = checkContext.getTarget();
+ if (checkObject instanceof RuleDependencyCheck == false)
+ throw new IllegalArgumentException("ControllerContext target not RuleDependencyCheck instance: " + checkContext);
+ setIDependOn(checkContext.getName());
+ setResolved(((RuleDependencyCheck)checkObject).canResolve(getName(), action, args));
+ if (isResolved())
+ {
+ addDependsOnMe(controller, checkContext);
+ }
+ }
+ else
+ {
+ setResolved(resolvedOnNullIdentity);
+ }
+ return isResolved();
+ }
+
+ /**
+ * Set the check name.
+ *
+ * @param checkName the context check name
+ */
+ public void setCheckName(String checkName)
+ {
+ this.checkName = checkName;
+ }
+
+ /**
+ * Set is resolved on null context.
+ *
+ * @param resolvedOnNullIdentity null on null context lookup
+ */
+ public void setResolvedOnNullIdentity(boolean resolvedOnNullIdentity)
+ {
+ this.resolvedOnNullIdentity = resolvedOnNullIdentity;
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/RuleBasedDependencyItemFactory.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/RuleBasedDependencyItemFactory.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/RuleBasedDependencyItemFactory.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,94 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.dependency;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyItem;
+
+/**
+ * Rule dependency item factory.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class RuleBasedDependencyItemFactory implements DependencyItemFactory<ControllerContext>
+{
+ // dependency item attributes
+ private Object name;
+ private Object action;
+ private ControllerState whenRequired = ControllerState.PRE_INSTALL;
+ private ControllerState dependentState = ControllerState.INSTALLED;
+ private Object[] args = new Object[0];
+ private String identityName;
+ private Boolean resolvedOnNullIdentity;
+
+ public DependencyItem createDependencyItem(ControllerContext context)
+ {
+ Object currentName = name;
+ if (currentName == null)
+ currentName = context.getName();
+ Object currentAction = action;
+ if (currentAction == null)
+ currentAction = whenRequired.getStateString();
+ RuleBasedDependencyItem item = new RuleBasedDependencyItem(currentName, currentAction, whenRequired, dependentState, args);
+ if (identityName != null)
+ item.setCheckName(identityName);
+ if (resolvedOnNullIdentity != null)
+ item.setResolvedOnNullIdentity(resolvedOnNullIdentity);
+ return item;
+ }
+
+ public void setName(Object name)
+ {
+ this.name = name;
+ }
+
+ public void setAction(Object action)
+ {
+ this.action = action;
+ }
+
+ public void setWhenRequired(String whenRequired)
+ {
+ this.whenRequired = new ControllerState(whenRequired);
+ }
+
+ public void setDependentState(ControllerState dependentState)
+ {
+ this.dependentState = dependentState;
+ }
+
+ public void setArgs(Object[] args)
+ {
+ this.args = args;
+ }
+
+ public void setIdentityName(String identityName)
+ {
+ this.identityName = identityName;
+ }
+
+ public void setResolvedOnNullIdentity(boolean resolvedOnNullIdentity)
+ {
+ this.resolvedOnNullIdentity = resolvedOnNullIdentity;
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/RuleDependencyMapper.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/RuleDependencyMapper.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/RuleDependencyMapper.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,59 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.dependency;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.dependency.spi.DependencyItem;
+
+/**
+ * Applys rule dependency to injected ControllerContext.
+ *
+ * @param <T> exact controller context type
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class RuleDependencyMapper<T extends ControllerContext>
+{
+ private DependencyItemFactory<T> factory;
+
+ public void create()
+ {
+ if (factory == null)
+ throw new IllegalArgumentException("DependencyFactory is null!");
+ }
+
+ public void install(T context)
+ {
+ DependencyInfo dependencyInfo = context.getDependencyInfo();
+ DependencyItem item = factory.createDependencyItem(context);
+ dependencyInfo.addIDependOn(item);
+ }
+
+ public void uninstall(T context)
+ {
+ }
+
+ public void setFactory(DependencyItemFactory<T> factory)
+ {
+ this.factory = factory;
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/RulesAware.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/RulesAware.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/dependency/RulesAware.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.dependency;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Rules aware marker annotation.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at Target({ElementType.TYPE})
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface RulesAware
+{
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/CSVRulesDeployer.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/CSVRulesDeployer.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/CSVRulesDeployer.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.deployer;
+
+/**
+ * CSV defined rules.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class CSVRulesDeployer extends SpreadsheetRulesDeployer
+{
+ public CSVRulesDeployer()
+ {
+ super();
+ }
+
+ protected InputTypeInfo getInputTypeInfo()
+ {
+ return InputTypeInfo.CSV;
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/DRLFileDeployer.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/DRLFileDeployer.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/DRLFileDeployer.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,124 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.deployer;
+
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.InputStream;
+
+import org.drools.compiler.PackageBuilder;
+import org.drools.compiler.PackageBuilderConfiguration;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.beans.metadata.plugins.builder.BeanMetaDataBuilderFactory;
+import org.jboss.deployers.vfs.spi.deployer.AbstractVFSParsingDeployer;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.reliance.drools.core.PackageWrapper;
+
+/**
+ * DRL file defined rules.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class DRLFileDeployer extends AbstractVFSParsingDeployer<BeanMetaData>
+{
+ private static final String BEANS = "-beans.";
+ private static final String DSL = BEANS + ".dsl";
+
+ private PackageBuilderConfiguration configuration;
+
+ public DRLFileDeployer()
+ {
+ super(BeanMetaData.class);
+ setSuffix(BEANS + getFileSuffix());
+ }
+
+ /**
+ * Set the configuration.
+ *
+ * @param configuration the configuration
+ */
+ public void setConfiguration(PackageBuilderConfiguration configuration)
+ {
+ this.configuration = configuration;
+ }
+
+ /**
+ * Get the file suffix.
+ *
+ * @return the file suffix
+ */
+ protected String getFileSuffix()
+ {
+ return "drl";
+ }
+
+ /**
+ * Get the DRL reader.
+ *
+ * @param inputStream the input stream
+ * @return reader
+ */
+ protected Reader getDRLReader(InputStream inputStream)
+ {
+ return new InputStreamReader(inputStream);
+ }
+
+ protected BeanMetaData parse(VFSDeploymentUnit unit, VirtualFile file, BeanMetaData root) throws Exception
+ {
+ String name = file.getName();
+ // check for dsl - with <name>.dsl
+ VirtualFile dslFile = unit.getMetaDataFile(name.replaceFirst(getSuffix(), DSL));
+ PackageBuilder builder = new PackageBuilder(configuration);
+ Reader drlReader = getDRLReader(file.openStream());
+ try
+ {
+ if (dslFile != null)
+ {
+ Reader dslReader = new InputStreamReader(dslFile.openStream());
+ try
+ {
+ builder.addPackageFromDrl(drlReader, dslReader);
+ }
+ finally
+ {
+ dslFile.closeStreams();
+ }
+ }
+ else
+ {
+ builder.addPackageFromDrl(drlReader);
+ }
+ }
+ finally
+ {
+ file.closeStreams();
+ }
+ BeanMetaDataBuilder beanBuilder = BeanMetaDataBuilderFactory.createBuilder(
+ unit.getName() + "_PackageWrapper",
+ PackageWrapper.class.getName()
+ );
+ beanBuilder.addCreateParameter(org.drools.rule.Package.class.getName(), builder.getPackage());
+ return beanBuilder.getBeanMetaData();
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/ExcelRulesDeployer.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/ExcelRulesDeployer.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/ExcelRulesDeployer.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.deployer;
+
+/**
+ * Excel (xsl) defined rules.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ExcelRulesDeployer extends SpreadsheetRulesDeployer
+{
+ public ExcelRulesDeployer()
+ {
+ super();
+ }
+
+ protected InputTypeInfo getInputTypeInfo()
+ {
+ return InputTypeInfo.XSL;
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/InputTypeInfo.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/InputTypeInfo.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/InputTypeInfo.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,64 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.deployer;
+
+import org.drools.decisiontable.InputType;
+
+/**
+ * InputType info.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public enum InputTypeInfo
+{
+ CSV(InputType.CSV, "csv"),
+ XSL(InputType.XLS, "xls");
+
+ private InputType type;
+ private String suffix;
+
+ InputTypeInfo(InputType type, String suffix)
+ {
+ this.type = type;
+ this.suffix = suffix;
+ }
+
+ /**
+ * Get the InputType.
+ *
+ * @return input type
+ */
+ public InputType getType()
+ {
+ return type;
+ }
+
+ /**
+ * Get the input type suffix.
+ *
+ * @return the suffix
+ */
+ public String getSuffix()
+ {
+ return suffix;
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/SpreadsheetRulesDeployer.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/SpreadsheetRulesDeployer.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/main/org/jboss/reliance/drools/deployer/SpreadsheetRulesDeployer.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,60 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.reliance.drools.deployer;
+
+import java.io.Reader;
+import java.io.InputStream;
+import java.io.StringReader;
+
+import org.drools.decisiontable.SpreadsheetCompiler;
+
+/**
+ * Spreadsheet decision tables rules definition.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class SpreadsheetRulesDeployer extends DRLFileDeployer
+{
+ private SpreadsheetCompiler compiler = new SpreadsheetCompiler();
+
+ protected SpreadsheetRulesDeployer()
+ {
+ super();
+ }
+
+ /**
+ * Get the InputType info.
+ *
+ * @return input type info
+ */
+ protected abstract InputTypeInfo getInputTypeInfo();
+
+ protected String getFileSuffix()
+ {
+ return getInputTypeInfo().getSuffix();
+ }
+
+ protected Reader getDRLReader(InputStream inputStream)
+ {
+ return new StringReader(compiler.compile(inputStream, getInputTypeInfo().getType()));
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/resources/main/schema/reliance_1_0.xsd
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/resources/main/schema/reliance_1_0.xsd (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/resources/main/schema/reliance_1_0.xsd 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- A prototype xsd schema for rules
+$Id: rules-beans_1_0.xsd 61194 2007-08-31 14:36:24Z ales.justin at jboss.com $
+ -->
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="urn:jboss:aop-beans:1.0"
+ xmlns="urn:jboss:rules-beans:1.0"
+ xmlns:mc="urn:jboss:bean-deployer:2.0"
+ elementFormDefault="qualified"
+ attributeFormDefault="unqualified"
+ version="1.0"
+>
+
+ <xsd:import namespace="urn:jboss:bean-deployer:2.0"/>
+
+</xsd:schema>
Added: projects/microcontainer/trunk/reliance-rules/src/resources/tests/org/jboss/test/reliance/drools/test/ConceptTestCase.xml
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/resources/tests/org/jboss/test/reliance/drools/test/ConceptTestCase.xml (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/resources/tests/org/jboss/test/reliance/drools/test/ConceptTestCase.xml 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <!-- aspects -->
+
+ <bean name="AspectManager" class="org.jboss.aop.AspectManager">
+ <constructor factoryClass="org.jboss.aop.AspectManager" factoryMethod="instance"/>
+ </bean>
+
+ <!-- intercepts any StatefulSession creation from our RuleBase bean -->
+ <aop:aspect xmlns:aop="urn:jboss:aop-beans:1.0"
+ name="WrapStatefulSessionAdvice"
+ class="org.jboss.reliance.drools.core.aspects.StatefulSessionCreationInterceptor"
+ pointcut="execution(* org.jboss.reliance.drools.core.RuleBaseBean->newStatefulSession(..))"/>
+
+ <!-- invokes fireAllRules after any CRUD method invocation on WorkingMemory instance -->
+ <aop:aspect xmlns:aop="urn:jboss:aop-beans:1.0"
+ name="FireAllRulesCheckAdvice"
+ class="org.jboss.reliance.drools.core.aspects.CRUDAwareAspect"
+ pointcut="execution(* $instanceof{org.drools.StatefulSession}->$implements{org.drools.WorkingMemory}(..))" />
+
+ <!-- disables fireAllRules if @DisableFireAllRules is present -->
+ <aop:aspect xmlns:aop="urn:jboss:aop-beans:1.0"
+ name="DisableFireAllRulesAdvice"
+ class="org.jboss.reliance.drools.core.aspects.DisableFireAllRulesInterceptor"
+ pointcut="execution(* @org.jboss.reliance.drools.core.aspects.DisableFireAllRules->*(..)) OR execution(* *->@org.jboss.reliance.drools.core.aspects.DisableFireAllRulesAllRules(..))" />
+
+ <!-- only invokes fireAllRules at the end of invocation -->
+ <aop:aspect xmlns:aop="urn:jboss:aop-beans:1.0"
+ name="FireAllRulesAfterInvocationAdvice"
+ class="org.jboss.reliance.drools.core.aspects.FireAllRulesAfterInvocationInterceptor"
+ pointcut="execution(* @org.jboss.reliance.drools.core.aspects.FireAllRulesAfter->*(..)) OR execution(* *->@org.jboss.reliance.drools.core.aspects.FireAllRulesAfterlesAfter(..))">
+ <constructor>
+ <parameter><inject bean="WorkingMemory" property="statefulSession"/></parameter>
+ </constructor>
+ </aop:aspect>
+
+ <!-- applies RuleBasedDependencyItem to all @RulesAware beans -->
+ <aop:lifecycle-describe xmlns:aop="urn:jboss:aop-beans:1.0"
+ name="RulesMapper"
+ class="org.jboss.reliance.drools.dependency.RuleDependencyMapper"
+ classes="@org.jboss.reliance.drools.dependency.RulesAware">
+ <property name="factory"><inject bean="RuleBasedDependencyFactory"/></property>
+ </aop:lifecycle-describe>
+
+ <bean name="RuleBasedDependencyFactory" class="org.jboss.reliance.drools.dependency.RuleBasedDependencyItemFactory">
+ <property name="whenRequired">Create</property>
+ </bean>
+
+ <!-- drools beans -->
+
+ <bean name="WorkingMemory" class="org.jboss.reliance.drools.core.ManagedWorkingMemory">
+ <constructor>
+ <parameter><inject bean="RuleBase"/></parameter>
+ <parameter><inject bean="jboss.kernel:service=KernelController"/></parameter>
+ </constructor>
+ <incallback method="addEventListener" signature="org.drools.event.AgendaEventListener"/>
+ <incallback method="addEventListener" signature="org.drools.event.WorkingMemoryEventListener"/>
+ <uncallback method="removeEventListener" signature="org.drools.event.AgendaEventListener"/>
+ <uncallback method="removeEventListener" signature="org.drools.event.WorkingMemoryEventListener"/>
+ </bean>
+
+ <bean name="debugAgendaEventListener" class="org.drools.event.DebugAgendaEventListener"/>
+ <bean name="debugWorkingMemoryEventListener" class="org.drools.event.DebugWorkingMemoryEventListener"/>
+
+ <bean name="RuleBase" class="org.jboss.reliance.drools.core.RuleBaseBean">
+ <demand>packageGenerator</demand>
+ </bean>
+
+ <bean name="packageGenerator" class="org.jboss.reliance.drools.core.PackageGenerator">
+ <property name="fromDRL">
+ <value>
+ package SimplePermissions;
+
+ import org.jboss.reliance.drools.core.security.PermissionCheck;
+ import org.jboss.reliance.drools.core.security.RoleTracker;
+ import org.jboss.reliance.drools.core.security.Role;
+ import org.jboss.reliance.drools.core.rules.Flag;
+
+ global org.jboss.dependency.spi.Controller controller;
+
+ rule TesterCanBeCreated
+ when
+ c: PermissionCheck(name == "tester", action == "Create")
+ Role(name == "admin")
+ then
+ c.grant();
+ end;
+
+ rule RoleTrackerAddition
+ salience 10
+ when
+ Role(name == "admin")
+ then
+ insert( new Flag("admin_flag") );
+ insertLogical( new RoleTracker("admin") );
+ end;
+
+ rule RoleTrackerRemovalTrigger
+ when
+ f : Flag(name == "admin_flag")
+ not( RoleTracker(name == "admin") )
+ then
+ retract( f );
+ RoleTracker.change(controller, "tester", "Configured");
+ end;
+ </value>
+ </property>
+ </bean>
+
+ <bean name="configuration" class="org.jboss.reliance.identity.Configuration"/>
+
+ <bean name="identity" class="org.jboss.reliance.drools.core.security.RuleBasedIdentity">
+ <property name="securityContext"><inject bean="WorkingMemory" property="statefulSession"/></property>
+ <property name="configuration"><inject bean="configuration"/></property>
+ </bean>
+
+ <!-- user beans -->
+
+ <bean name="roles" class="org.jboss.test.reliance.drools.support.RolesAdapter">
+ <constructor>
+ <parameter><inject bean="identity"/></parameter>
+ </constructor>
+ <property name="username">alesj</property>
+ <property name="password">qwert</property>
+ <property name="roles">
+ <set elementClass="java.lang.String">
+ <value>guest</value>
+ </set>
+ </property>
+ </bean>
+
+ <bean name="tester" class="org.jboss.test.reliance.drools.support.Tester">
+ <annotation>@org.jboss.reliance.drools.dependency.RulesAware</annotation>
+ <demand state="PreInstall">roles</demand>
+ </bean>
+
+</deployment>
Added: projects/microcontainer/trunk/reliance-rules/src/tests/org/jboss/test/reliance/drools/support/RolesAdapter.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/tests/org/jboss/test/reliance/drools/support/RolesAdapter.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/tests/org/jboss/test/reliance/drools/support/RolesAdapter.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,96 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.test.reliance.drools.support;
+
+import java.util.Set;
+import java.util.Collections;
+
+import org.jboss.reliance.identity.Identity;
+import org.jboss.beans.metadata.plugins.annotations.Constructor;
+import org.jboss.beans.metadata.plugins.annotations.Inject;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class RolesAdapter
+{
+ private Identity identity;
+ private String username;
+ private String password;
+ private Set<String> roles = Collections.emptySet();
+
+ @Constructor
+ public RolesAdapter(@Inject Identity identity)
+ {
+ this.identity = identity;
+ }
+
+ public void create()
+ {
+ identity.setUsername(username);
+ identity.setPassword(password);
+ identity.login();
+ }
+
+ public void start()
+ {
+ for(String role : roles)
+ addRole(role);
+ }
+
+ public void addRole(String role)
+ {
+ identity.addRole(role);
+ }
+
+ public void removeRole(String role)
+ {
+ identity.removeRole(role);
+ }
+
+ public void stop()
+ {
+ for(String role : roles)
+ removeRole(role);
+ }
+
+ public void destroy()
+ {
+ identity.logout();
+ identity = null;
+ }
+
+ public void setUsername(String username)
+ {
+ this.username = username;
+ }
+
+ public void setPassword(String password)
+ {
+ this.password = password;
+ }
+
+ public void setRoles(Set<String> roles)
+ {
+ this.roles = roles;
+ }
+}
Added: projects/microcontainer/trunk/reliance-rules/src/tests/org/jboss/test/reliance/drools/support/Tester.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/tests/org/jboss/test/reliance/drools/support/Tester.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/tests/org/jboss/test/reliance/drools/support/Tester.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,29 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.test.reliance.drools.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class Tester
+{
+}
Added: projects/microcontainer/trunk/reliance-rules/src/tests/org/jboss/test/reliance/drools/test/ConceptTestCase.java
===================================================================
--- projects/microcontainer/trunk/reliance-rules/src/tests/org/jboss/test/reliance/drools/test/ConceptTestCase.java (rev 0)
+++ projects/microcontainer/trunk/reliance-rules/src/tests/org/jboss/test/reliance/drools/test/ConceptTestCase.java 2007-09-03 22:19:29 UTC (rev 65022)
@@ -0,0 +1,89 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., 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.test.reliance.drools.test;
+
+import junit.framework.Test;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.test.kernel.junit.MicrocontainerTest;
+import org.jboss.test.kernel.junit.MicrocontainerTestDelegate;
+import org.jboss.test.reliance.drools.support.RolesAdapter;
+
+/**
+ * Initial concept test case.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ConceptTestCase extends MicrocontainerTest
+{
+ public ConceptTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ConceptTestCase.class);
+ }
+
+ public void testRulesConcept() throws Throwable
+ {
+ // only in Configured state, since there is no admin role present
+ KernelControllerContext testerContext = getControllerContext("tester", ControllerState.CONFIGURED);
+ assertEquals(ControllerState.CONFIGURED, testerContext.getState());
+
+ RolesAdapter rolesAdapter = (RolesAdapter)getBean("roles");
+ rolesAdapter.addRole("admin");
+
+ // should be Installed now, since admin role is present
+ change(testerContext, ControllerState.INSTALLED);
+ assertEquals(ControllerState.INSTALLED, testerContext.getState());
+
+ rolesAdapter.removeRole("admin");
+ // should be unwinded to Configured, since the admin role was removed
+ assertEquals(ControllerState.CONFIGURED, testerContext.getState());
+
+ KernelControllerContext identityContext = getControllerContext("identity");
+ change(identityContext, ControllerState.NOT_INSTALLED);
+
+ // should be uninstalled as well, since it relies on identity
+ assertEquals(ControllerState.NOT_INSTALLED, testerContext.getState());
+ }
+
+ public static AbstractTestDelegate getDelegate(Class clazz) throws Exception
+ {
+ return new NonValidatingDelegate(clazz);
+ }
+
+ private static class NonValidatingDelegate extends MicrocontainerTestDelegate
+ {
+ public NonValidatingDelegate(Class clazz) throws Exception
+ {
+ super(clazz);
+ }
+
+ protected void validate() throws Exception
+ {
+ }
+ }
+}
More information about the jboss-cvs-commits
mailing list