[Carbon-dev] svn commit r42136 - in trunk/carbon/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/temp: authorization internal model

dimuthul at wso2.com dimuthul at wso2.com
Wed Jul 29 20:16:40 PDT 2009


Author: dimuthul
Date: Wed Jul 29 20:16:39 2009
New Revision: 42136
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=42136

Log:
This is the final um commit before integration.
After this my next commit will be the complete integration of carbon core...



Added:
   trunk/carbon/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/temp/model/
   trunk/carbon/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/temp/model/SystemPermissions.java
Modified:
   trunk/carbon/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/temp/authorization/JDBCAuthorizationManager.java
   trunk/carbon/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/temp/internal/Activator.java

Modified: trunk/carbon/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/temp/authorization/JDBCAuthorizationManager.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/temp/authorization/JDBCAuthorizationManager.java?rev=42136&r1=42135&r2=42136&view=diff
==============================================================================
--- trunk/carbon/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/temp/authorization/JDBCAuthorizationManager.java	(original)
+++ trunk/carbon/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/temp/authorization/JDBCAuthorizationManager.java	Wed Jul 29 20:16:39 2009
@@ -9,8 +9,13 @@
 
 import javax.sql.DataSource;
 
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Element;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.user.core.UserCoreConstants;
 import org.wso2.carbon.user.core.temp.AuthorizationReader;
 import org.wso2.carbon.user.core.temp.AuthorizationWriter;
 import org.wso2.carbon.user.core.temp.RealmConfiguration;
@@ -23,7 +28,8 @@
     private DataSource dataSource = null;
     private UserStoreReader reader = null;
     private PermissionTree permissionTree = null;
-    
+    private CacheManager cacheManager = null;
+    private String systemUserName = null;
     /**
      * The root node of the tree
      */
@@ -31,8 +37,14 @@
 
     public JDBCAuthorizationManager(DataSource dataSource, RealmConfiguration realmConfig,
             UserStoreReader reader) throws UserStoreException {
+        cacheManager = new CacheManager();
+        Cache cache1 = new Cache(UserCoreConstants.AUTHZ_CACHE,
+                UserCoreConstants.MAX_OBJECTS_IN_CACHE, false, false, UserCoreConstants.TTL_CACHE,
+                UserCoreConstants.IDLE_TIME_IN_CACHE);
+        cacheManager.addCache(cache1);
         this.dataSource = dataSource;
         this.reader = reader;
+        this.systemUserName = realmConfig.getSystemUserName();
         this.permissionTree = new PermissionTree();
         this.populatePermissionTreeFromDB();   
     }
@@ -50,6 +62,19 @@
 
     public boolean isUserAuthorized(String userName, String resourceId, String action)
             throws UserStoreException {
+        
+        if(systemUserName.equals(userName)){
+            return true;
+        }
+        
+        Cache cache = cacheManager.getCache(UserCoreConstants.AUTHZ_CACHE);
+        Element element = cache.get(userName + resourceId + action);
+        
+        if (element != null) {
+            Boolean bool = (Boolean) element.getObjectValue();
+            return bool.booleanValue();
+        }
+        
         SearchResult sr = permissionTree.getUserPermission(userName, PermissionTreeUtil
                 .actionToPermission(action), null, null, PermissionTreeUtil
                 .toComponenets(resourceId));

Modified: trunk/carbon/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/temp/internal/Activator.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/temp/internal/Activator.java?rev=42136&r1=42135&r2=42136&view=diff
==============================================================================
--- trunk/carbon/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/temp/internal/Activator.java	(original)
+++ trunk/carbon/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/temp/internal/Activator.java	Wed Jul 29 20:16:39 2009
@@ -22,7 +22,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
-import org.wso2.carbon.user.core.model.SystemPermissions;
+import org.wso2.carbon.user.core.temp.model.SystemPermissions;
 import org.wso2.carbon.user.core.temp.AuthorizationReader;
 import org.wso2.carbon.user.core.temp.AuthorizationWriter;
 import org.wso2.carbon.user.core.temp.RealmConfiguration;
@@ -61,6 +61,7 @@
             UserRealm realm = initializeRealm(bc, realmConfig, dataSource);
             addInitialData(realm, parentElement);
             exposeRealmAsServcie(bc, realm);
+            System.out.println("******** Success **********");
         } catch (Throwable e) {
             String msg = "Cannot start User Manager Core bundle";
             log.fatal(msg, e);

Added: trunk/carbon/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/temp/model/SystemPermissions.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/temp/model/SystemPermissions.java?pathrev=42136
==============================================================================
--- (empty file)
+++ trunk/carbon/org.wso2.carbon.user.core/src/main/java/org/wso2/carbon/user/core/temp/model/SystemPermissions.java	Wed Jul 29 20:16:39 2009
@@ -0,0 +1,19 @@
+package org.wso2.carbon.user.core.temp.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SystemPermissions {
+    
+    private static List<String> permissions = new ArrayList<String>();
+    
+    public static void addSystemPermission(String value){
+	permissions.add(value);
+    }
+    
+    public static List<String> getSystemPermission(){
+	return permissions;
+    }
+    
+
+}



More information about the Carbon-dev mailing list