[jboss-svn-commits] JBL Code SVN: r35941 - in labs/jbossrules/soa_branches/BRMS-5.1.x: drools-guvnor/src/main/resources and 4 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Nov 10 16:27:24 EST 2010


Author: kurt.stam at jboss.com
Date: 2010-11-10 16:27:23 -0500 (Wed, 10 Nov 2010)
New Revision: 35941

Added:
   labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/test/resources/drools_repository.properties
Removed:
   labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/main/resources/drools_repository.properties
Modified:
   labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/main/java/org/drools/guvnor/server/repository/RepositoryStartupService.java
   labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/main/java/org/drools/guvnor/server/repository/RulesRepositoryManager.java
   labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/main/webapp/WEB-INF/components.xml
   labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/test/java/org/drools/guvnor/server/repository/RepositoryStartupServiceTest.java
   labs/jbossrules/soa_branches/BRMS-5.1.x/drools-repo/drools-repository/src/main/java/org/drools/repository/RulesRepositoryConfigurator.java
Log:
BRMS-416, making the passwords for admin and mailman configurable. They can now be set in the components.xml

Modified: labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/main/java/org/drools/guvnor/server/repository/RepositoryStartupService.java
===================================================================
--- labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/main/java/org/drools/guvnor/server/repository/RepositoryStartupService.java	2010-11-10 20:45:03 UTC (rev 35940)
+++ labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/main/java/org/drools/guvnor/server/repository/RepositoryStartupService.java	2010-11-10 21:27:23 UTC (rev 35941)
@@ -33,6 +33,8 @@
 
 
 
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Properties;
 
 import javax.jcr.LoginException;
@@ -50,6 +52,8 @@
 import org.jboss.seam.annotations.Name;
 import org.jboss.seam.annotations.Scope;
 import org.jboss.seam.annotations.Startup;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -61,8 +65,15 @@
 @Name("repositoryConfiguration")
 public class RepositoryStartupService {
 
+	private static final Logger log = LoggerFactory.getLogger(RepositoryStartupService.class);
+	private static final String ADMIN                     = "admin";
+	private static final String ADMIN_PASSWORD_PROPERTY   = "org.drools.repository.admin.password";
+	private static final String MAILMAN                   = "mailman";
+	private static final String MAILMAN_PASSWORD_PROPERTY = "org.drools.repository.mailman.password";
+	
+	
 	private RulesRepositoryConfigurator configurator;
-    Properties properties = new Properties();
+    Map<String,String> properties = new HashMap<String,String>();
 
     Repository repository;
 	private Session sessionForSetup;
@@ -70,11 +81,12 @@
 
     public Repository getRepositoryInstance() {
     	try {
+    		Properties properties = new Properties();
+    		properties.putAll(this.properties);
 			configurator = RulesRepositoryConfigurator.getInstance(properties);
 			repository = configurator.getJCRRepository();
 		} catch (RepositoryException e) {
-			// TODO Kurt Auto-generated catch block
-			e.printStackTrace();
+			log.error(e.getMessage(),e);
 		}
 		return repository;
     }
@@ -82,13 +94,18 @@
     @Create
     public void create() {
     	repository = getRepositoryInstance();
-        sessionForSetup = newSession("admin");
+    	String password = "admin";
+    	if (properties.containsKey(ADMIN_PASSWORD_PROPERTY)) {
+    		password = properties.get(ADMIN_PASSWORD_PROPERTY);
+    	} else {
+    		log.debug("Could not find property " + ADMIN_PASSWORD_PROPERTY + " for user " + ADMIN);
+    	}
+        sessionForSetup = newSession(ADMIN,password);
         create( sessionForSetup );
         startMailboxService();
         registerCheckinListener();
     }
 
-
     /** Listen for changes to the repository - for inbox purposes */
     public static void registerCheckinListener() {
     	System.out.println("Registering check-in listener");
@@ -104,14 +121,17 @@
 
     /** Start up the mailbox, flush out any messages that were left */
     private void startMailboxService() {
-        mailmanSession = new RulesRepository(newSession(MailboxService.MAILMAN));
+    	String password = "mailman";
+    	if (properties.containsKey(MAILMAN_PASSWORD_PROPERTY)) {
+    		password = properties.get(MAILMAN_PASSWORD_PROPERTY);
+    	} else {
+    		log.debug("Could not find property " + MAILMAN_PASSWORD_PROPERTY + " for user " + MAILMAN);
+    	}
+        mailmanSession = new RulesRepository(newSession(MAILMAN, password));
         MailboxService.getInstance().init(mailmanSession);
         MailboxService.getInstance().wakeUp();
     }
 
-
-
-
     void create(Session sessionForSetup) {
     	
     	RulesRepositoryAdministrator admin = new RulesRepositoryAdministrator(sessionForSetup);
@@ -151,17 +171,16 @@
         mailmanSession.logout();
         
     }
-
-
+    
     public void setHomeDirectory(String home) {
     	if (home!=null) {
-    		properties.setProperty(JCRRepositoryConfigurator.REPOSITORY_ROOT_DIRECTORY, home);
+    		properties.put(JCRRepositoryConfigurator.REPOSITORY_ROOT_DIRECTORY, home);
     	}
     }
 
     public void setRepositoryConfigurator(String clazz) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
     	if (clazz!=null) {
-    		properties.setProperty(RulesRepositoryConfigurator.CONFIGURATOR_CLASS, clazz);
+    		properties.put(RulesRepositoryConfigurator.CONFIGURATOR_CLASS, clazz);
     	}
     }
 
@@ -170,10 +189,10 @@
      * This will create a new Session, based on the current user.
      * @return
      */
-    public Session newSession(String userName) {
+    public Session newSession(String userName, String password) {
 
         try {
-            return repository.login( new SimpleCredentials(userName, "password".toCharArray()) );
+            return repository.login( new SimpleCredentials(userName, password.toCharArray()) );
         } catch ( LoginException e ) {
             throw new RulesRepositoryException( "Unable to login to JCR backend." );
         } catch ( RepositoryException e ) {
@@ -181,5 +200,4 @@
         }
     }
 
-
 }
\ No newline at end of file

Modified: labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/main/java/org/drools/guvnor/server/repository/RulesRepositoryManager.java
===================================================================
--- labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/main/java/org/drools/guvnor/server/repository/RulesRepositoryManager.java	2010-11-10 20:45:03 UTC (rev 35940)
+++ labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/main/java/org/drools/guvnor/server/repository/RulesRepositoryManager.java	2010-11-10 21:27:23 UTC (rev 35941)
@@ -66,12 +66,14 @@
     public void create() {
         String userName = READ_ONLY_USER;
         if (Contexts.isApplicationContextActive()) {
-            userName = Identity.instance().getUsername();
+            userName = Identity.instance().getCredentials().getUsername();
         }
         if (userName == null) {
             userName = READ_ONLY_USER;
-        }        
-        repository = new RulesRepository(repositoryConfiguration.newSession(userName) );
+        }
+        //When using JAAS the user is already authenticated, so the password is not looked at.
+        //When not using JAAS JR, will work fine, MS will fail
+        repository = new RulesRepository(repositoryConfiguration.newSession(userName, "password") );
     }
     
     @Unwrap

Deleted: labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/main/resources/drools_repository.properties
===================================================================
--- labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/main/resources/drools_repository.properties	2010-11-10 20:45:03 UTC (rev 35940)
+++ labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/main/resources/drools_repository.properties	2010-11-10 21:27:23 UTC (rev 35941)
@@ -1,16 +0,0 @@
-# This file is used to load the properties passed to the JCR 2.0 RepositoryFactory.
-#
-#
-# JACKRABBIT
-org.drools.repository.configurator = org.drools.repository.jackrabbit.JackrabbitRepositoryConfigurator
-# 
-
-# MODESHAPE
-
-# In deployed configuration, to use ModeShape Service use:
-#org.drools.repository.configurator = org.drools.repository.modeshape.ModeShapeRepositoryConfigurator
-#org.modeshape.jcr.URL = jndi:jcr/local?repositoryName=brms
-
-# To use ModeShape when running the unittests use:
-#org.drools.repository.configurator = org.drools.repository.modeshape.ModeShapeRepositoryConfiguratorWithJAAS
-#org.modeshape.jcr.URL = file:src/test/resources/modeshape/configuration.xml

Modified: labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/main/webapp/WEB-INF/components.xml
===================================================================
--- labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/main/webapp/WEB-INF/components.xml	2010-11-10 20:45:03 UTC (rev 35940)
+++ labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/main/webapp/WEB-INF/components.xml	2010-11-10 21:27:23 UTC (rev 35941)
@@ -1,50 +1,100 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <components xmlns="http://jboss.com/products/seam/components"
-            xmlns:core="http://jboss.com/products/seam/core"
-            xmlns:security="http://jboss.com/products/seam/security"
-            xmlns:web="http://jboss.com/products/seam/web"
-            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-            xmlns:transaction="http://jboss.com/products/seam/transaction"
-            xsi:schemaLocation=
-                "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
+	xmlns:core="http://jboss.com/products/seam/core" xmlns:security="http://jboss.com/products/seam/security"
+	xmlns:web="http://jboss.com/products/seam/web" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xmlns:transaction="http://jboss.com/products/seam/transaction"
+	xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
                  http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                  http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd
                  http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.0.xsd
                  http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.0.xsd">
 
 
-	<core:init transaction-management-enabled="false"/>
-	<transaction:no-transaction/>
+	<core:init transaction-management-enabled="false" />
+	<transaction:no-transaction />
 
-    <component name="repositoryConfiguration">
+	<component name="repositoryConfiguration">
+
+		<!-- JackRabbit  -->
+		<property name="properties">
+			<key>org.drools.repository.configurator</key>
+			<value>org.drools.repository.jackrabbit.JackrabbitRepositoryConfigurator</value>
+		</property>
 		<!--
-		  *** This is for configuring the "home" directory for the repo storage. the directory must exist. 	***
-	      <property name="homeDirectory">/home/michael/RulesRepository_001</property>
-	    -->
+			*** This is for configuring the root directory for the repo storage.
+			the directory must exist. *** 
+			<property name="properties">
+				<key>repository.root.directory</key>
+				<value>/opt/yourpath</value>
+			</property>
+		-->
 
-	    <!--
-	      Optional: this is for creating a configurator for a seperate repository type.
-	      <property name="configurator">org.drools.repository.JackrabbitRepositoryConfigurator</property>
-	    -->
-    </component>
+		<!-- ModeShape 
+			<property name="properties">
+				<key>org.drools.repository.configurator</key>
+				<value>org.drools.repository.modeshape.ModeShapeRepositoryConfigurator</value>
+			</property>
+			<property name="properties">
+				<key>org.modeshape.jcr.URL</key>
+				<value>jndi:jcr/local?repositoryName=brms</value>
+			</property> 
+		-->
+		<!-- passwords for the background users (admin and mailman), these need to match the setting
+			you provided for JAAS (used by ModeShape only). 
+		-->
+		<!--
+			<property name="properties">
+				<key>org.drools.repository.admin.password</key>
+				<value>admin</value>
+			</property>
+			<property name="properties">
+				<key>org.drools.repository.mailman.password</key>
+				<value>mailman</value>
+			</property>
+		-->
+		
+	</component>
 
-    <!-- SECURITY IDENTITY CONFIGURATION -->
+	<!-- SECURITY IDENTITY CONFIGURATION -->
 
-    <!-- default (will take any username, useful if you want to keep track of users but not authenticate -->
-    <security:identity authenticate-method="#{defaultAuthenticator.authenticate}"/>
+	<!--
+		default (will take any username, useful if you want to keep track of
+		users but not authenticate
+	-->
+	<security:identity authenticate-method="#{defaultAuthenticator.authenticate}" />
 
 
-	<!-- NO authentication. This will bypass the login screen when you hit the app. Everyone is "guest" -->
-	<!-- <security:identity authenticate-method="#{nilAuthenticator.authenticate}"/> -->
+	<!--
+		NO authentication. This will bypass the login screen when you hit the
+		app. Everyone is "guest"
+	-->
+	<!--
+		<security:identity
+		authenticate-method="#{nilAuthenticator.authenticate}"/>
+	-->
 
 
-	<!-- FOR EXAMPLE: the following one will use the jaas configuration called "other" - which in jboss AS means you can use properties files for users: -->
-	<!-- <security:identity authenticate-method="#{authenticator.authenticate}" jaas-config-name="other"/> -->
+	<!--
+		FOR EXAMPLE: the following one will use the jaas configuration called
+		"other" - which in jboss AS means you can use properties files for
+		users:
+	-->
+	<!--
+		<security:identity authenticate-method="#{authenticator.authenticate}"
+		jaas-config-name="other"/>
+	-->
 
-    <!-- as JAAS is used you can use container specific ones to link up to your login services, eg LDAP/AD etc -->
+	<!--
+		as JAAS is used you can use container specific ones to link up to your
+		login services, eg LDAP/AD etc
+	-->
 
-    <!-- SECURITY AUTHORIZATION CONFIGURATION -->
-    <!-- This is used to enable or disable role-based authorization. By default it is disabled. -->
-    <security:role-based-permission-resolver enable-role-based-authorization="false"/>
+	<!-- SECURITY AUTHORIZATION CONFIGURATION -->
+	<!--
+		This is used to enable or disable role-based authorization. By default
+		it is disabled.
+	-->
+	<security:role-based-permission-resolver
+		enable-role-based-authorization="false" />
 
 </components>
\ No newline at end of file

Modified: labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/test/java/org/drools/guvnor/server/repository/RepositoryStartupServiceTest.java
===================================================================
--- labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/test/java/org/drools/guvnor/server/repository/RepositoryStartupServiceTest.java	2010-11-10 20:45:03 UTC (rev 35940)
+++ labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/test/java/org/drools/guvnor/server/repository/RepositoryStartupServiceTest.java	2010-11-10 21:27:23 UTC (rev 35941)
@@ -47,15 +47,15 @@
         
         RepositoryStartupService config = new RepositoryStartupService();
         config.setHomeDirectory( "qed" );
-        assertEquals("qed", config.properties.getProperty(JCRRepositoryConfigurator.REPOSITORY_ROOT_DIRECTORY));
+        assertEquals("qed", config.properties.get(JCRRepositoryConfigurator.REPOSITORY_ROOT_DIRECTORY));
         config.setRepositoryConfigurator( MockRepositoryConfigurator.class.getName() );
         
         Repository repository = config.getRepositoryInstance();
         
         assertEquals(MockRepo.class.getSimpleName(),repository.getClass().getSimpleName());
         
-        assertNotNull(config.newSession("foo"));
-        assertNotSame(config.newSession("foo"), config.newSession("foo"));
+        assertNotNull(config.newSession("foo","password"));
+        assertNotSame(config.newSession("foo","password"), config.newSession("foo","password"));
 
     }
 

Copied: labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/test/resources/drools_repository.properties (from rev 35937, labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/main/resources/drools_repository.properties)
===================================================================
--- labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/test/resources/drools_repository.properties	                        (rev 0)
+++ labs/jbossrules/soa_branches/BRMS-5.1.x/drools-guvnor/src/test/resources/drools_repository.properties	2010-11-10 21:27:23 UTC (rev 35941)
@@ -0,0 +1,11 @@
+# This file is used to load the properties passed to the JCR 2.0 RepositoryFactory.
+#
+#
+# JACKRABBIT
+org.drools.repository.configurator = org.drools.repository.jackrabbit.JackrabbitRepositoryConfigurator
+# 
+
+# MODESHAPE
+# To use ModeShape when running the unittests use:
+#org.drools.repository.configurator = org.drools.repository.modeshape.ModeShapeRepositoryConfiguratorWithJAAS
+#org.modeshape.jcr.URL = file:src/test/resources/modeshape/configuration.xml

Modified: labs/jbossrules/soa_branches/BRMS-5.1.x/drools-repo/drools-repository/src/main/java/org/drools/repository/RulesRepositoryConfigurator.java
===================================================================
--- labs/jbossrules/soa_branches/BRMS-5.1.x/drools-repo/drools-repository/src/main/java/org/drools/repository/RulesRepositoryConfigurator.java	2010-11-10 20:45:03 UTC (rev 35940)
+++ labs/jbossrules/soa_branches/BRMS-5.1.x/drools-repo/drools-repository/src/main/java/org/drools/repository/RulesRepositoryConfigurator.java	2010-11-10 21:27:23 UTC (rev 35941)
@@ -30,45 +30,48 @@
 
 	public Repository getJCRRepository() throws RepositoryException 
 	{
-		getInstance(null);
 		return jcrRepository;
 	}
 
+	/**
+	 * Creates an instance of the RulesRepositoryConfigurator, which stores a reference to the under laying JCRRepository.
+	 * 
+	 * @param properties - if null, they will be read from the /drools_repository.properties file.
+	 * @return RulesRepositoryConfigurator
+	 * @throws RepositoryException
+	 */
 	public synchronized static RulesRepositoryConfigurator getInstance(Properties properties) throws RepositoryException 
 	{
 		if (rulesRepositoryConfigurator == null ) {
 			log.info("Creating an instance of the RulesRepositoryConfigurator.");
 			rulesRepositoryConfigurator = new RulesRepositoryConfigurator();
-			if (properties==null) properties = new Properties();
-			Properties fileProperties = new Properties();
-			// Load the properties file ...
-			InputStream propStream = ClassUtil.getResourceAsStream(PROPERTIES_FILE, rulesRepositoryConfigurator.getClass());
-			if (propStream != null) {
-				try {
-					fileProperties.load(propStream);
-					for (Object key : fileProperties.keySet()) {
-						if (!properties.containsKey(key)) {
-							properties.put(key, fileProperties.get(key));
-						}
-					}
-				} catch (IOException ioe) {
-					throw new RepositoryException (ioe);
-				} finally {
+			
+			if (properties==null) { //load from file only when the properties passed in are null
+				properties = new Properties();
+				// Load the properties file ...
+				InputStream propStream = ClassUtil.getResourceAsStream(PROPERTIES_FILE, rulesRepositoryConfigurator.getClass());
+				if (propStream != null) {
 					try {
-						propStream.close();
+						properties.load(propStream);
 					} catch (IOException ioe) {
 						throw new RepositoryException (ioe);
+					} finally {
+						try {
+							propStream.close();
+						} catch (IOException ioe) {
+							throw new RepositoryException (ioe);
+						}
 					}
+				} else {
+					throw new RepositoryException ("Cannot load properties from " + PROPERTIES_FILE);
 				}
-			} else {
-				throw new RepositoryException ("Cannot load properties from " + PROPERTIES_FILE);
 			}
 				
 			try {
 				String configuratorClazz = properties.getProperty(CONFIGURATOR_CLASS);
 				if (configuratorClazz==null) throw new RepositoryException("User must define a '" + 
 						CONFIGURATOR_CLASS + "' property.");
-				Class clazz = ClassUtil.forName(configuratorClazz, rulesRepositoryConfigurator.getClass());
+				Class<?> clazz = ClassUtil.forName(configuratorClazz, rulesRepositoryConfigurator.getClass());
 				jcrRepositoryConfigurator = (JCRRepositoryConfigurator) clazz.newInstance();
 				jcrRepository = jcrRepositoryConfigurator.getJCRRepository(properties);
 			} catch (Exception ex) {



More information about the jboss-svn-commits mailing list