directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1538553 - in /directory/escimo/trunk: common/src/main/java/org/apache/directory/scim/RequestContext.java ldap/src/main/java/org/apache/directory/scim/ldap/LdapResourceProvider.java
Date Mon, 04 Nov 2013 11:11:08 GMT
Author: kayyagari
Date: Mon Nov  4 11:11:08 2013
New Revision: 1538553

URL: http://svn.apache.org/r1538553
Log:
handle the 'attributes' parameter for all list and query methods

Modified:
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/RequestContext.java
    directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapResourceProvider.java

Modified: directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/RequestContext.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/RequestContext.java?rev=1538553&r1=1538552&r2=1538553&view=diff
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/RequestContext.java
(original)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/RequestContext.java
Mon Nov  4 11:11:08 2013
@@ -93,4 +93,17 @@ public class RequestContext
         
         return lst.get( 0 );
     }
+    
+    
+    public String getParamAttributes()
+    {
+        List<String> attributes = uriInfo.getQueryParameters().get( "attributes" );
+        
+        if( ( attributes == null ) || attributes.isEmpty() )
+        {
+            return null;
+        }
+        
+        return attributes.get( 0 );
+    }
 }

Modified: directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapResourceProvider.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapResourceProvider.java?rev=1538553&r1=1538552&r2=1538553&view=diff
==============================================================================
--- directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapResourceProvider.java
(original)
+++ directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapResourceProvider.java
Mon Nov  4 11:11:08 2013
@@ -324,23 +324,8 @@ public class LdapResourceProvider implem
         sr.setFilter( ldapFilter );
         sr.setScope( SearchScope.SUBTREE );
         
-        List<String> ldapAtNames = new ArrayList<String>();
-        ldapAtNames.add( SchemaConstants.ENTRY_UUID_AT );
-        
-        if( Strings.isNotEmpty( attributes ) )
-        {
-            String[] names = attributes.split( "," );
-            for( String n : names )
-            {
-                AttributeType at = getLdapType( n, scimSchema );
-                if( at != null )
-                {
-                    ldapAtNames.add( at.getName() );
-                }
-            }
-        }
-        
-        sr.addAttributes( ldapAtNames.toArray( new String[1] ) );
+        String[] requested = getRequestedAttributes( attributes, scimSchema );
+        sr.addAttributes( requested );
         
         SearchCursor cursor = connection.search( sr );
         
@@ -373,10 +358,33 @@ public class LdapResourceProvider implem
         return lr;
     }
 
+    
+    private String[] getRequestedAttributes( String attributes, ResourceSchema scimSchema
)
+    {
+        List<String> ldapAtNames = new ArrayList<String>();
+        ldapAtNames.add( SchemaConstants.ENTRY_UUID_AT );
+        
+        if( Strings.isNotEmpty( attributes ) )
+        {
+            String[] names = attributes.split( "," );
+            for( String n : names )
+            {
+                AttributeType at = getLdapType( n, scimSchema );
+                if( at != null )
+                {
+                    ldapAtNames.add( at.getName() );
+                }
+            }
+            
+            return ldapAtNames.toArray( new String[1] );
+        }
+        
+        return ALL_ATTRIBUTES_ARRAY;
+    }
 
     public UserResource getUser( RequestContext ctx, String id ) throws ResourceNotFoundException
     {
-        Entry entry = fetchEntryById( id, userSchema );
+        Entry entry = fetchEntryById( id, userSchema, ctx );
 
         if ( entry == null )
         {
@@ -452,7 +460,7 @@ public class LdapResourceProvider implem
 
     public GroupResource getGroup( RequestContext ctx, String groupId ) throws ResourceNotFoundException
     {
-        Entry entry = fetchEntryById( groupId, groupSchema );
+        Entry entry = fetchEntryById( groupId, groupSchema, ctx );
 
         if ( entry == null )
         {
@@ -665,7 +673,7 @@ public class LdapResourceProvider implem
         
         _resourceToEntry( entry, obj, ctx, resourceSchema );
         
-        Entry existingEntry = fetchEntryById( resourceId, resourceSchema );
+        Entry existingEntry = fetchEntryById( resourceId, resourceSchema, ctx );
         
         // save a reference to the existing password attribute
         Attribute existingPwdAt = existingEntry.get( SchemaConstants.USER_PASSWORD_AT );
@@ -773,7 +781,7 @@ public class LdapResourceProvider implem
             }
         }
         
-        entry = fetchEntryById( resourceId, resourceSchema );
+        entry = fetchEntryById( resourceId, resourceSchema, ctx );
         
         ServerResource resource = null;
         
@@ -799,7 +807,7 @@ public class LdapResourceProvider implem
         JsonParser parser = new JsonParser();
         JsonObject obj = ( JsonObject ) parser.parse( jsonData );
 
-        Entry existingEntry = fetchEntryById( resourceId, resourceSchema );
+        Entry existingEntry = fetchEntryById( resourceId, resourceSchema, ctx );
         
         if( existingEntry == null )
         {
@@ -856,7 +864,7 @@ public class LdapResourceProvider implem
             
             if( hasAttributesInMeta )
             {
-                Entry entry = fetchEntryById( resourceId, resourceSchema );
+                Entry entry = fetchEntryById( resourceId, resourceSchema, ctx );
                 
                 ServerResource resource = null;
                 
@@ -1191,9 +1199,13 @@ public class LdapResourceProvider implem
         return null;
     }
 
-
     public Entry fetchEntryById( String id, ResourceSchema resourceSchema )
     {
+        return fetchEntryById( id, resourceSchema, null );
+    }
+    
+    public Entry fetchEntryById( String id, ResourceSchema resourceSchema, RequestContext
ctx )
+    {
         EntryCursor cursor = null;
 
         SimpleType st = ( SimpleType ) resourceSchema.getCoreAttribute( "id" );
@@ -1203,9 +1215,16 @@ public class LdapResourceProvider implem
 
         Entry entry = null;
 
+        String[] attributes = ALL_ATTRIBUTES_ARRAY;
+        
+        if( ctx != null )
+        {
+            attributes = getRequestedAttributes( ctx.getParamAttributes(), resourceSchema
);
+        }
+        
         try
         {
-            cursor = connection.search( resourceSchema.getBaseDn(), filter, SUBTREE, ALL_ATTRIBUTES_ARRAY
);
+            cursor = connection.search( resourceSchema.getBaseDn(), filter, SUBTREE, attributes
);
 
             if ( cursor.next() )
             {



Mime
View raw message