Scarab commit: svn commit: r11061 - trunk: . src/java/org/tigris/scarab/om

[email protected] Wed, 21 Dec 2011 18:58:57 -0800 (PST)
Newsgroups gmane.comp.java.scarab.cvs
Message-ID <[email protected]>
Author: dabbous
Date: 2011-12-21 18:58:57-0800
New Revision: 11061

Modified:
   trunk/minimal.properties
   trunk/project.properties
   trunk/scarab_properties.xml
   trunk/src/java/org/tigris/scarab/om/ScarabUserImpl.java

Log:
Added new property scarab.default.role for situations where a new user registers but has no role yet. when the parameter is set, a user is guaranteed to have at least the default role.
"work in progress". 
Idea is to make this a module setting.

Modified: trunk/minimal.properties
Url: http://scarab.tigris.org/source/browse/scarab/trunk/minimal.properties?view=diff&pathrev=11061&r1=11060&r2=11061
==============================================================================
--- trunk/minimal.properties	(original)
+++ trunk/minimal.properties	2011-12-21 18:58:57-0800
@@ -428,6 +428,30 @@
 
 scarab.automatic.role.approval=
 
+# -------------------
+# scarab.default.role
+# -------------------
+#
+# 
+#  When a user gets registered, no role will be granted automatically
+#  for any module. This leads to a problem when the user wants to 
+#  request roles for the module. When this property is set, the
+#  given role will be auto approved to the user if the user has NO role
+#  assigned yet.
+# 
+#  example:  
+#  
+#  scarab.default.role=Observer
+#  
+#  This setting will ensure that users with no role for a particular module
+#  will get the role "Observer".
+# 
+#  Since all roles can be freely customized in Scarab, we cant't set any
+#  default here.
+# 
+
+scarab.default.role=
+
 
 # ================
 # Group: appserver

Modified: trunk/project.properties
Url: http://scarab.tigris.org/source/browse/scarab/trunk/project.properties?view=diff&pathrev=11061&r1=11060&r2=11061
==============================================================================
--- trunk/project.properties	(original)
+++ trunk/project.properties	2011-12-21 18:58:57-0800
@@ -688,6 +688,30 @@
 
 scarab.automatic.role.approval=
 
+# -------------------
+# scarab.default.role
+# -------------------
+#
+# 
+#  When a user gets registered, no role will be granted automatically
+#  for any module. This leads to a problem when the user wants to 
+#  request roles for the module. When this property is set, the
+#  given role will be auto approved to the user if the user has NO role
+#  assigned yet.
+# 
+#  example:  
+#  
+#  scarab.default.role=Observer
+#  
+#  This setting will ensure that users with no role for a particular module
+#  will get the role "Observer".
+# 
+#  Since all roles can be freely customized in Scarab, we cant't set any
+#  default here.
+# 
+
+scarab.default.role=
+
 # ----------------------
 # locale.default.charset
 # ----------------------

Modified: trunk/scarab_properties.xml
Url: http://scarab.tigris.org/source/browse/scarab/trunk/scarab_properties.xml?view=diff&pathrev=11061&r1=11060&r2=11061
==============================================================================
--- trunk/scarab_properties.xml	(original)
+++ trunk/scarab_properties.xml	2011-12-21 18:58:57-0800
@@ -717,6 +717,32 @@
     </property>
 
     <property>
+      <name>scarab.default.role</name>
+      <default/>
+      <type>Runtime</type>
+       <customization modification="optional">basic</customization>
+      <file/>
+      <details>
+          When a user gets registered, no role will be granted automatically
+          for any module. This leads to a problem when the user wants to 
+          request roles for the module. When this property is set, the
+          given role will be auto approved to the user if the user has NO role
+          assigned yet.
+
+          example:  
+          
+          scarab.default.role=Observer
+          
+          This setting will ensure that users with no role for a particular module
+          will get the role "Observer".
+
+          Since all roles can be freely customized in Scarab, we cant't set any
+          default here.
+      </details>
+    </property>
+
+
+    <property>
         <name>locale.default.charset</name>
         <default>UTF-8</default>
         <type>Runtime</type>type>

Modified: trunk/src/java/org/tigris/scarab/om/ScarabUserImpl.java
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/java/org/tigris/scarab/om/ScarabUserImpl.java?view=diff&pathrev=11061&r1=11060&r2=11061
==============================================================================
--- trunk/src/java/org/tigris/scarab/om/ScarabUserImpl.java	(original)
+++ trunk/src/java/org/tigris/scarab/om/ScarabUserImpl.java	2011-12-21 18:58:57-0800
@@ -83,6 +83,7 @@
 import org.tigris.scarab.reports.ReportBridge;
 import org.tigris.scarab.services.cache.ScarabCache;
 import org.tigris.scarab.services.security.ScarabSecurity;
+import org.tigris.scarab.tools.ScarabGlobalTool;
 import org.tigris.scarab.util.Log;
 import org.tigris.scarab.util.ScarabException;
 import org.xbill.DNS.Record;
@@ -412,7 +413,7 @@
                      TurbineRolePermissionPeer.PERMISSION_ID);
             crit.addJoin(TurbineRolePermissionPeer.ROLE_ID, 
                          TurbineUserGroupRolePeer.ROLE_ID);
-            crit.add(TurbineUserGroupRolePeer.USER_ID, getUserId());
+            //crit.add(TurbineUserGroupRolePeer.USER_ID, getUserId());
             crit.addJoin(ScarabModulePeer.MODULE_ID, 
                          TurbineUserGroupRolePeer.GROUP_ID);
             
@@ -422,16 +423,42 @@
                 // check for permissions in global, if so get all modules
                 for (int i=scarabModules.size()-1; i>=0; i--) 
                 {
-                    if (Module.ROOT_ID.equals(
-                     ((Module)scarabModules.get(i)).getModuleId())) 
+                    ScarabModule module = (ScarabModule)scarabModules.get(i);
+                    Integer moduleId = module.getModuleId();
+                    boolean hasRoles = this.hasAnyRoleIn(module);
+                    
+                    if(!hasRoles)
+                    {
+                        String defaultRoleName = ScarabGlobalTool.getTurbineProperty("scarab.default.role");
+                        if(defaultRoleName != null)
+                        {
+                            Role role = TurbineSecurity.getRole(defaultRoleName);
+                            if(role != null)
+                            {
+                                User x = null;
+                                ScarabUser su = (ScarabUser)this;
+                                TurbineSecurity.grant(su, module, role);
+                                hasRoles = true;
+        
+                                // TODO: Needs to be refactored into the Users system?
+                                ScarabUserManager.getMethodResult().remove(this, ScarabUserManager.GET_ACL);
+                                ScarabUserManager.getMethodResult().remove(this, ScarabUserManager.HAS_ROLE_IN_MODULE, (Serializable)role, module);
+                            }
+                        }
+                    }
+                    
+                    if(hasRoles)
                     {
-                        crit = new Criteria();
-                        if (!showDeletedModules)
+                        if (Module.ROOT_ID.equals(moduleId)) 
                         {
-                            crit.add(ScarabModulePeer.DELETED, 0);
+                            crit = new Criteria();
+                            if (!showDeletedModules)
+                            {
+                                crit.add(ScarabModulePeer.DELETED, 0);
+                            }
+                            scarabModules = ScarabModulePeer.doSelect(crit);
+                            break;
                         }
-                        scarabModules = ScarabModulePeer.doSelect(crit);
-                        break;
                     }
                 }

------------------------------------------------------
http://scarab.tigris.org/ds/viewMessage.do?dsForumId=3577&dsMessageId=2898948