[jboss-svn-commits] JBL Code SVN: r23061 - in labs/jbossrules/trunk/drools-process/drools-process-task: src/main/java/org/drools/task and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Sep 24 20:05:22 EDT 2008
Author: jervisliu
Date: 2008-09-24 20:05:22 -0400 (Wed, 24 Sep 2008)
New Revision: 23061
Added:
labs/jbossrules/trunk/drools-process/drools-process-task/src/main/java/org/drools/task/DroolsTaskUserProfile.java
labs/jbossrules/trunk/drools-process/drools-process-task/src/main/java/org/drools/task/UserProfile.java
labs/jbossrules/trunk/drools-process/drools-process-task/src/main/java/org/drools/task/UserProfileManager.java
labs/jbossrules/trunk/drools-process/drools-process-task/src/main/java/org/drools/task/UserProfileRepository.java
labs/jbossrules/trunk/drools-process/drools-process-task/src/test/java/org/drools/task/MockFileBasedUserProfileRepository.java
labs/jbossrules/trunk/drools-process/drools-process-task/src/test/java/org/drools/task/MockIdentity.java
labs/jbossrules/trunk/drools-process/drools-process-task/src/test/java/org/drools/task/UserProfileManagerTest.java
Modified:
labs/jbossrules/trunk/drools-process/drools-process-task/pom.xml
Log:
User profile management for drools task.
Modified: labs/jbossrules/trunk/drools-process/drools-process-task/pom.xml
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-process-task/pom.xml 2008-09-24 23:46:34 UTC (rev 23060)
+++ labs/jbossrules/trunk/drools-process/drools-process-task/pom.xml 2008-09-25 00:05:22 UTC (rev 23061)
@@ -49,6 +49,13 @@
<artifactId>h2</artifactId>
<version>1.0.77</version>
</dependency>
+
+ <dependency>
+ <groupId>org.jboss.seam</groupId>
+ <artifactId>jboss-seam</artifactId>
+ <version>2.1.0-SNAPSHOT</version>
+ </dependency>
+
<!-- PGSQL -->
<dependency>
<groupId>postgresql</groupId>
Added: labs/jbossrules/trunk/drools-process/drools-process-task/src/main/java/org/drools/task/DroolsTaskUserProfile.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-process-task/src/main/java/org/drools/task/DroolsTaskUserProfile.java (rev 0)
+++ labs/jbossrules/trunk/drools-process/drools-process-task/src/main/java/org/drools/task/DroolsTaskUserProfile.java 2008-09-25 00:05:22 UTC (rev 23061)
@@ -0,0 +1,38 @@
+package org.drools.task;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class DroolsTaskUserProfile extends UserProfile {
+ //TODO: A group is a collection of users and other groups (when nested groups are allowed) ?
+/* List<OrganizationalEntity> organizationalEntities = new ArrayList<OrganizationalEntity>();
+
+ public void addOrganizationalEntity(OrganizationalEntity entity) {
+ organizationalEntities.add(entity);
+ }
+
+ public void removeOrganizationalEntity(OrganizationalEntity entity) {
+ organizationalEntities.remove(entity);
+ }*/
+
+ public String getDisplayName(OrganizationalEntity entity){
+ return null;
+ }
+
+ public Iterator<OrganizationalEntity> getMembersForGroup(Group group){
+ return null;
+ }
+
+ public boolean hasEmail(Group group) {
+ return false;
+ }
+
+ public String getEmailForEntity(OrganizationalEntity entity) {
+ return null;
+ }
+
+ public String getLanguageForEntity(OrganizationalEntity entity) {
+ return null;
+ }
+}
Added: labs/jbossrules/trunk/drools-process/drools-process-task/src/main/java/org/drools/task/UserProfile.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-process-task/src/main/java/org/drools/task/UserProfile.java (rev 0)
+++ labs/jbossrules/trunk/drools-process/drools-process-task/src/main/java/org/drools/task/UserProfile.java 2008-09-25 00:05:22 UTC (rev 23061)
@@ -0,0 +1,19 @@
+package org.drools.task;
+
+/**
+ * UserProfile is a base class to represent user profile related information. As the user profile information various
+ * from application to application, the only common information we have in this base class is user id.
+ * Then it is up to the sub class to provide application specific information, see DroolsTaskUserProfile.
+ *
+ */
+public class UserProfile {
+ String id;
+
+ public String getID(){
+ return id;
+ }
+
+ public void setID(String id){
+ this.id = id;
+ }
+ }
Added: labs/jbossrules/trunk/drools-process/drools-process-task/src/main/java/org/drools/task/UserProfileManager.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-process-task/src/main/java/org/drools/task/UserProfileManager.java (rev 0)
+++ labs/jbossrules/trunk/drools-process/drools-process-task/src/main/java/org/drools/task/UserProfileManager.java 2008-09-25 00:05:22 UTC (rev 23061)
@@ -0,0 +1,54 @@
+package org.drools.task;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.Startup;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.security.Identity;
+
+/**
+ * userProfileManager retrieves and update user profile using a plugable UserProfileRepository.
+ * UserProfileRepository is normally implemented by users based on the persistent mechanism
+ * (for example property file, RMDB, LDAP etc) as well as the data scheam that is used by
+ * users' application.
+ * Following snippet shows how to configure UserProfileRepository in components.xml.
+ <component name="userProfileManager">
+ <property name="userProfileRepository">org.drools.task.MockFileBasedUserProfileRepository</property>
+ </component>
+ *
+ * @author Jervis Lliu
+ */
+
+ at Scope(ScopeType.APPLICATION)
+ at Startup
+ at Name("userProfileManager")
+public class UserProfileManager {
+ UserProfileRepository userProfileRepository = null;
+
+ public UserProfile getUserProfile() {
+ if (userProfileRepository == null) {
+ //TODO: throws exception?
+ return null;
+ }
+
+ String userName = "";
+ if (Contexts.isApplicationContextActive()) {
+ userName = Identity.instance().getCredentials().getUsername();
+ }
+ return userProfileRepository.getUserProfile(userName);
+ }
+
+ public void updateUserProfile(UserProfile info) {
+
+ }
+
+ public UserProfileRepository getUserProfileRepository() {
+ return userProfileRepository;
+ }
+
+ public void setUserProfileRepository(UserProfileRepository userProfileRepository) {
+ this.userProfileRepository = userProfileRepository;
+ }
+
+}
Added: labs/jbossrules/trunk/drools-process/drools-process-task/src/main/java/org/drools/task/UserProfileRepository.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-process-task/src/main/java/org/drools/task/UserProfileRepository.java (rev 0)
+++ labs/jbossrules/trunk/drools-process/drools-process-task/src/main/java/org/drools/task/UserProfileRepository.java 2008-09-25 00:05:22 UTC (rev 23061)
@@ -0,0 +1,6 @@
+package org.drools.task;
+
+public interface UserProfileRepository {
+ UserProfile getUserProfile(String userName);
+ void setUserProfile(UserProfile info);
+}
Added: labs/jbossrules/trunk/drools-process/drools-process-task/src/test/java/org/drools/task/MockFileBasedUserProfileRepository.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-process-task/src/test/java/org/drools/task/MockFileBasedUserProfileRepository.java (rev 0)
+++ labs/jbossrules/trunk/drools-process/drools-process-task/src/test/java/org/drools/task/MockFileBasedUserProfileRepository.java 2008-09-25 00:05:22 UTC (rev 23061)
@@ -0,0 +1,17 @@
+package org.drools.task;
+
+public class MockFileBasedUserProfileRepository implements UserProfileRepository {
+ String configFile = "userinfo.txt";
+
+ public UserProfile getUserProfile(String userName) {
+ //load the property file, get user info.
+ DroolsTaskUserProfile ui = new DroolsTaskUserProfile();
+
+ ui.setID(userName);
+ return ui;
+ }
+
+ public void setUserProfile(UserProfile info) {
+ //NOT IMPLEMENTED;
+ }
+}
Added: labs/jbossrules/trunk/drools-process/drools-process-task/src/test/java/org/drools/task/MockIdentity.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-process-task/src/test/java/org/drools/task/MockIdentity.java (rev 0)
+++ labs/jbossrules/trunk/drools-process/drools-process-task/src/test/java/org/drools/task/MockIdentity.java 2008-09-25 00:05:22 UTC (rev 23061)
@@ -0,0 +1,91 @@
+package org.drools.task;
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.core.Events;
+import org.jboss.seam.security.Credentials;
+import org.jboss.seam.security.Identity;
+import org.jboss.seam.security.permission.PermissionResolver;
+import org.jboss.seam.security.permission.ResolverChain;
+
+public class MockIdentity extends Identity {
+ private boolean hasRole;
+ private Set<String> roles = new HashSet<String>();
+ private List<PermissionResolver> resolvers = new ArrayList<PermissionResolver>();
+
+ @Override
+ public boolean addRole(String r) {
+ roles.add(r);
+ return true;
+ }
+
+ public boolean hasRole(String role) {
+ return hasRole || roles.contains(role);
+ }
+
+
+
+ public void setHasRole(boolean hasRole) {
+ this.hasRole = hasRole;
+ }
+
+ public boolean isLoggedIn(boolean attemptLogin) {
+ return true;
+ }
+
+ public boolean hasPermission(Object target, String action) {
+ for (PermissionResolver resolver : resolvers)
+ {
+ if (resolver.hasPermission(target, action))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public void addPermissionResolver(PermissionResolver r) {
+ resolvers.add(r);
+ }
+
+ /**
+ * Push this mock as the identity to Seam.
+ */
+ public void inject() {
+ Contexts.getSessionContext().set("org.jboss.seam.security.identity",
+ this);
+ }
+
+ public Credentials getCredentials() {
+ return new Credentials() {
+ public String getUsername()
+ {
+ return "mockedUser";
+ }
+ };
+ }
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-process/drools-process-task/src/test/java/org/drools/task/UserProfileManagerTest.java
===================================================================
--- labs/jbossrules/trunk/drools-process/drools-process-task/src/test/java/org/drools/task/UserProfileManagerTest.java (rev 0)
+++ labs/jbossrules/trunk/drools-process/drools-process-task/src/test/java/org/drools/task/UserProfileManagerTest.java 2008-09-25 00:05:22 UTC (rev 23061)
@@ -0,0 +1,37 @@
+package org.drools.task;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.contexts.Lifecycle;
+
+import junit.framework.TestCase;
+
+public class UserProfileManagerTest extends TestCase {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testFileBasedUserProfileRepository() throws Exception {
+ //Mock up SEAM contexts
+ Map application = new HashMap<String, Object>();
+ Lifecycle.beginApplication(application);
+ Lifecycle.beginCall();
+ MockIdentity midentity = new MockIdentity();
+ Contexts.getSessionContext().set("org.jboss.seam.security.identity", midentity);
+
+
+ UserProfileManager upm = new UserProfileManager();
+ upm.setUserProfileRepository(new MockFileBasedUserProfileRepository());
+
+ DroolsTaskUserProfile userProfile = (DroolsTaskUserProfile)upm.getUserProfile();
+ assertEquals(userProfile.getID(), "mockedUser");
+ }
+
+}
More information about the jboss-svn-commits
mailing list