directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smckin...@apache.org
Subject directory-fortress-core git commit: FC-105 - [fortress-core] - redundant null check && convert to use stringbuffer.
Date Mon, 18 May 2015 18:12:37 GMT
Repository: directory-fortress-core
Updated Branches:
  refs/heads/master 4cddeac50 -> 4e8e259ab


FC-105 - [fortress-core] - redundant null check && convert to use stringbuffer.


Project: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/commit/4e8e259a
Tree: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/tree/4e8e259a
Diff: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/diff/4e8e259a

Branch: refs/heads/master
Commit: 4e8e259abe9a5b925addee41e0eaee272b008434
Parents: 4cddeac
Author: Shawn McKinney <smckinney@apache.org>
Authored: Mon May 18 13:12:14 2015 -0500
Committer: Shawn McKinney <smckinney@apache.org>
Committed: Mon May 18 13:12:14 2015 -0500

----------------------------------------------------------------------
 .../directory/fortress/core/rbac/PermDAO.java   | 71 ++++++++++++++------
 1 file changed, 49 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/4e8e259a/src/main/java/org/apache/directory/fortress/core/rbac/PermDAO.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/rbac/PermDAO.java b/src/main/java/org/apache/directory/fortress/core/rbac/PermDAO.java
index 2637b0c..8935235 100755
--- a/src/main/java/org/apache/directory/fortress/core/rbac/PermDAO.java
+++ b/src/main/java/org/apache/directory/fortress/core/rbac/PermDAO.java
@@ -733,13 +733,12 @@ final class PermDAO extends ApacheDsDataProvider
         {
             ld = getAdminConnection();
             Entry findEntry = read( ld, dn, PERMISSION_OP_ATRS );
-            entity = unloadPopLdapEntry( findEntry, 0, permission.isAdmin() );
-
-            if ( entity == null )
+            if ( findEntry == null )
             {
                 String warning = "getPerm no entry found dn [" + dn + "]";
                 throw new FinderException( GlobalErrIds.PERM_OP_NOT_FOUND, warning );
             }
+            entity = unloadPopLdapEntry( findEntry, 0, permission.isAdmin() );
         }
         catch ( LdapNoSuchObjectException e )
         {
@@ -777,13 +776,12 @@ final class PermDAO extends ApacheDsDataProvider
         {
             ld = getAdminConnection();
             Entry findEntry = read( ld, dn, PERMISION_OBJ_ATRS );
-            entity = unloadPobjLdapEntry( findEntry, 0,permObj.isAdmin() );
-
-            if ( entity == null )
+            if ( findEntry == null )
             {
                 String warning = "getPerm Obj no entry found dn [" + dn + "]";
                 throw new FinderException( GlobalErrIds.PERM_OBJ_NOT_FOUND, warning );
             }
+            entity = unloadPobjLdapEntry( findEntry, 0,permObj.isAdmin() );
         }
         catch ( LdapNoSuchObjectException e )
         {
@@ -1222,7 +1220,10 @@ final class PermDAO extends ApacheDsDataProvider
         try
         {
             String roleVal = encodeSafeText( role.getName(), GlobalIds.ROLE_LEN );
-            String filter = GlobalIds.FILTER_PREFIX + PERM_OP_OBJECT_CLASS_NAME + ")(";
+            StringBuffer filterbuf = new StringBuffer();
+            filterbuf.append( GlobalIds.FILTER_PREFIX );
+            filterbuf.append( PERM_OP_OBJECT_CLASS_NAME );
+            filterbuf.append( ")(" );
             Set<String> roles;
 
             if ( role.getClass().equals( AdminRole.class ) )
@@ -1236,24 +1237,33 @@ final class PermDAO extends ApacheDsDataProvider
 
             if ( VUtil.isNotNullOrEmpty( roles ) )
             {
-                filter += "|(" + ROLES + "=" + roleVal + ")";
-
+                filterbuf.append( "|(" );
+                filterbuf.append( ROLES );
+                filterbuf.append( "=" );
+                filterbuf.append( roleVal );
+                filterbuf.append( ")" );
                 for ( String uRole : roles )
                 {
-                    filter += "(" + ROLES + "=" + uRole + ")";
+                    filterbuf.append( "(" );
+                    filterbuf.append( ROLES );
+                    filterbuf.append( "=" );
+                    filterbuf.append( uRole );
+                    filterbuf.append( ")" );
                 }
-
-                filter += ")";
+                filterbuf.append( ")" );
             }
             else
             {
-                filter += ROLES + "=" + roleVal + ")";
+                filterbuf.append( ROLES );
+                filterbuf.append( "=" );
+                filterbuf.append( roleVal );
+                filterbuf.append( ")" );
             }
 
-            filter += ")";
+            filterbuf.append( ")" );
             ld = getAdminConnection();
             SearchCursor searchResults = search( ld, permRoot,
-                SearchScope.SUBTREE, filter, PERMISSION_OP_ATRS, false, GlobalIds.BATCH_SIZE
);
+                SearchScope.SUBTREE, filterbuf.toString(), PERMISSION_OP_ATRS, false, GlobalIds.BATCH_SIZE
);
             long sequence = 0;
 
             while ( searchResults.next() )
@@ -1294,21 +1304,32 @@ final class PermDAO extends ApacheDsDataProvider
 
         try
         {
-            String filter = GlobalIds.FILTER_PREFIX + PERM_OP_OBJECT_CLASS_NAME + ")(|";
+            StringBuffer filterbuf = new StringBuffer();
+            filterbuf.append( GlobalIds.FILTER_PREFIX );
+            filterbuf.append( PERM_OP_OBJECT_CLASS_NAME );
+            filterbuf.append( ")(|" );
             Set<String> roles = RoleUtil.getInheritedRoles( user.getRoles(), user.getContextId()
);
 
             if ( VUtil.isNotNullOrEmpty( roles ) )
             {
                 for ( String uRole : roles )
                 {
-                    filter += "(" + ROLES + "=" + uRole + ")";
+                    filterbuf.append( "(" );
+                    filterbuf.append( ROLES );
+                    filterbuf.append( "=" );
+                    filterbuf.append( uRole );
+                    filterbuf.append( ")" );
                 }
             }
 
-            filter += "(" + USERS + "=" + user.getUserId() + ")))";
+            filterbuf.append( "(" );
+            filterbuf.append( USERS );
+            filterbuf.append( "=" );
+            filterbuf.append( user.getUserId() );
+            filterbuf.append( ")))" );
             ld = getAdminConnection();
             SearchCursor searchResults = search( ld, permRoot,
-                SearchScope.SUBTREE, filter, PERMISSION_OP_ATRS, false, GlobalIds.BATCH_SIZE
);
+                SearchScope.SUBTREE, filterbuf.toString(), PERMISSION_OP_ATRS, false, GlobalIds.BATCH_SIZE
);
             long sequence = 0;
 
             while ( searchResults.next() )
@@ -1351,11 +1372,17 @@ final class PermDAO extends ApacheDsDataProvider
 
         try
         {
-            String filter = GlobalIds.FILTER_PREFIX + PERM_OP_OBJECT_CLASS_NAME + ")";
-            filter += "(" + USERS + "=" + user.getUserId() + "))";
+            StringBuffer filterbuf = new StringBuffer();
+            filterbuf.append( GlobalIds.FILTER_PREFIX );
+            filterbuf.append( PERM_OP_OBJECT_CLASS_NAME );
+            filterbuf.append( "){" );
+            filterbuf.append( USERS );
+            filterbuf.append( "=" );
+            filterbuf.append( user.getUserId() );
+            filterbuf.append(  "))" );
             ld = getAdminConnection();
             SearchCursor searchResults = search( ld, permRoot,
-                SearchScope.SUBTREE, filter, PERMISSION_OP_ATRS, false, GlobalIds.BATCH_SIZE
);
+                SearchScope.SUBTREE, filterbuf.toString(), PERMISSION_OP_ATRS, false, GlobalIds.BATCH_SIZE
);
             long sequence = 0;
 
             while ( searchResults.next() )


Mime
View raw message