directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1538365 - in /directory/escimo/trunk: common/src/main/java/org/apache/directory/scim/ common/src/main/java/org/apache/directory/scim/json/ common/src/test/java/org/apache/directory/scim/search/ ldap/src/main/java/org/apache/directory/scim/...
Date Sun, 03 Nov 2013 13:50:09 GMT
Author: kayyagari
Date: Sun Nov  3 13:50:09 2013
New Revision: 1538365

URL: http://svn.apache.org/r1538365
Log:
search functionality with filter

Added:
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ListResponse.java
Modified:
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ProviderService.java
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ScimUtil.java
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/json/ResourceSerializer.java
    directory/escimo/trunk/common/src/test/java/org/apache/directory/scim/search/FilterParserTest.java
    directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapResourceProvider.java
    directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapSchemaMapper.java
    directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapUtil.java
    directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/LdapAttributeHandler.java
    directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/UserService.java

Added: directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ListResponse.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ListResponse.java?rev=1538365&view=auto
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ListResponse.java
(added)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ListResponse.java
Sun Nov  3 13:50:09 2013
@@ -0,0 +1,91 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you 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.
+ *
+ */
+package org.apache.directory.scim;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * TODO ListResponse.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ListResponse
+{
+    private int totalResults = 0;
+
+    private List<ServerResource> Resources;
+
+    private int startIndex = -1;
+
+    private int itemsPerPage = -1;
+
+
+    public ListResponse()
+    {
+        Resources = new ArrayList<ServerResource>();
+    }
+
+
+    public void addResource( ServerResource res )
+    {
+        Resources.add( res );
+        totalResults++;
+    }
+
+
+    /**
+     * @return the totalResults
+     */
+    public int getTotalResults()
+    {
+        return totalResults;
+    }
+
+
+    /**
+     * @return the resources
+     */
+    public List<ServerResource> getResources()
+    {
+        return Resources;
+    }
+
+
+    /**
+     * @return the startIndex
+     */
+    public int getStartIndex()
+    {
+        return startIndex;
+    }
+
+
+    /**
+     * @return the itemsPerPage
+     */
+    public int getItemsPerPage()
+    {
+        return itemsPerPage;
+    }
+
+}

Modified: directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ProviderService.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ProviderService.java?rev=1538365&r1=1538364&r2=1538365&view=diff
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ProviderService.java
(original)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ProviderService.java
Sun Nov  3 13:50:09 2013
@@ -55,4 +55,6 @@ public interface ProviderService 
     UserResource patchUser( String userId, String jsonData, RequestContext ctx ) throws Exception;
     
     GroupResource patchGroup( String groupId, String jsonData, RequestContext ctx ) throws
Exception;
+    
+    ListResponse search( String filter, String attributes, RequestContext ctx ) throws Exception;
 }

Modified: directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ScimUtil.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ScimUtil.java?rev=1538365&r1=1538364&r2=1538365&view=diff
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ScimUtil.java (original)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ScimUtil.java Sun
Nov  3 13:50:09 2013
@@ -50,7 +50,11 @@ public class ScimUtil
 
         PrintWriter pw = new PrintWriter( sw );
 
-        pw.write( e.getMessage() );
+        String msg = e.getMessage();
+        if( msg != null )
+        {
+            pw.write( msg );
+        }
         
         e.printStackTrace( pw );
 

Modified: directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/json/ResourceSerializer.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/json/ResourceSerializer.java?rev=1538365&r1=1538364&r2=1538365&view=diff
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/json/ResourceSerializer.java
(original)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/json/ResourceSerializer.java
Sun Nov  3 13:50:09 2013
@@ -25,6 +25,7 @@ import java.util.Map;
 
 import org.apache.directory.scim.AbstractAttribute;
 import org.apache.directory.scim.ComplexAttribute;
+import org.apache.directory.scim.ListResponse;
 import org.apache.directory.scim.MultiValAttribute;
 import org.apache.directory.scim.ScimUtil;
 import org.apache.directory.scim.ServerResource;
@@ -55,6 +56,11 @@ public class ResourceSerializer
 
     public static String serialize( ServerResource resource )
     {
+        return _serialize( resource ).toString();
+    }
+    
+    private static JsonObject _serialize( ServerResource resource )
+    {
         JsonObject root = new JsonObject();
 
         Map<String, List<AbstractAttribute>> attributes = resource.getAttributes();
@@ -77,7 +83,7 @@ public class ResourceSerializer
             serialize( parent, attributes.get( uri ) );
         }
 
-        return root.toString();
+        return root;
     }
 
 
@@ -157,4 +163,34 @@ public class ResourceSerializer
         
         return jo.toString();
     }
+    
+    
+    public static String serialize( ListResponse lr )
+    {
+        JsonObject json = new JsonObject();
+        json.addProperty( "totalResults", lr.getTotalResults() );
+        
+        if( lr.getItemsPerPage() > -1 )
+        {
+            json.addProperty( "itemsPerPage", lr.getItemsPerPage() );
+        }
+        
+        if( lr.getStartIndex() > -1 )
+        {
+            json.addProperty( "startIndex", lr.getStartIndex() );
+        }
+        
+        JsonArray resArray = new JsonArray();
+        
+        for( ServerResource sr : lr.getResources() )
+        {
+            JsonObject resObj = _serialize( sr );
+            resObj.remove( "schemas" );
+            resArray.add( resObj );
+        }
+        
+        json.add( "Resources", resArray );
+        
+        return json.toString();
+    }
 }

Modified: directory/escimo/trunk/common/src/test/java/org/apache/directory/scim/search/FilterParserTest.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/test/java/org/apache/directory/scim/search/FilterParserTest.java?rev=1538365&r1=1538364&r2=1538365&view=diff
==============================================================================
--- directory/escimo/trunk/common/src/test/java/org/apache/directory/scim/search/FilterParserTest.java
(original)
+++ directory/escimo/trunk/common/src/test/java/org/apache/directory/scim/search/FilterParserTest.java
Sun Nov  3 13:50:09 2013
@@ -67,6 +67,29 @@ public class FilterParserTest
         assertEquals( ( ( TerminalNode ) bn.getRightNode() ) .getAttribute(), "id" );
         assertEquals( ( ( TerminalNode ) bn.getRightNode() ) .getValue(), "xx-yy" );
 
+        filter = "(userName eq x and ((groups.value gt xx-yy ) or (id eq y))) or active eq
\"true\"";
+        node = FilterParser.parse( filter );
+        assertNotNull( node );
+        assertTrue( node instanceof BranchNode );
+        assertEquals( Operator.OR, node.getOperator() );
+        bn = ( BranchNode ) node;
+        
+        BranchNode left = ( BranchNode ) bn.getLeftNode();
+        assertEquals( ( ( TerminalNode ) left.getLeftNode() ) .getAttribute(), "userName"
);
+        assertEquals( ( ( TerminalNode ) left.getLeftNode() ) .getValue(), "x" );
+        
+        BranchNode right = ( BranchNode ) left.getRightNode();
+        assertEquals( ( ( TerminalNode ) right.getLeftNode() ) .getAttribute(), "groups.value"
);
+        assertEquals( ( ( TerminalNode ) right.getLeftNode() ) .getValue(), "xx-yy" );
+        
+        assertEquals( ( ( TerminalNode ) right.getRightNode() ) .getAttribute(), "id" );
+        assertEquals( ( ( TerminalNode ) right.getRightNode() ) .getValue(), "y" );
+        
+        
+        TerminalNode extremeRight = ( TerminalNode ) bn.getRightNode();
+        assertEquals( extremeRight.getAttribute(), "active" );
+        assertEquals( extremeRight.getValue(), "true" );
+
     }
     
 }

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=1538365&r1=1538364&r2=1538365&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
Sun Nov  3 13:50:09 2013
@@ -37,17 +37,23 @@ import java.util.Properties;
 
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
 import org.apache.directory.api.ldap.model.cursor.EntryCursor;
+import org.apache.directory.api.ldap.model.cursor.SearchCursor;
 import org.apache.directory.api.ldap.model.entry.Attribute;
 import org.apache.directory.api.ldap.model.entry.DefaultEntry;
 import org.apache.directory.api.ldap.model.entry.Entry;
 import org.apache.directory.api.ldap.model.entry.Value;
 import org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException;
 import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.filter.ExprNode;
 import org.apache.directory.api.ldap.model.message.LdapResult;
 import org.apache.directory.api.ldap.model.message.ModifyRequest;
 import org.apache.directory.api.ldap.model.message.ModifyRequestImpl;
 import org.apache.directory.api.ldap.model.message.ModifyResponse;
 import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
+import org.apache.directory.api.ldap.model.message.SearchRequest;
+import org.apache.directory.api.ldap.model.message.SearchRequestImpl;
+import org.apache.directory.api.ldap.model.message.SearchScope;
+import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.api.ldap.model.schema.AttributeType;
 import org.apache.directory.api.ldap.model.schema.LdapSyntax;
 import org.apache.directory.api.ldap.model.schema.SchemaManager;
@@ -68,18 +74,19 @@ import org.apache.directory.scim.Attribu
 import org.apache.directory.scim.AttributeNotFoundException;
 import org.apache.directory.scim.ComplexAttribute;
 import org.apache.directory.scim.GroupResource;
+import org.apache.directory.scim.ListResponse;
 import org.apache.directory.scim.MissingParameterException;
 import org.apache.directory.scim.MultiValAttribute;
-import org.apache.directory.scim.OperationException;
 import org.apache.directory.scim.ProviderService;
 import org.apache.directory.scim.RequestContext;
 import org.apache.directory.scim.ResourceConflictException;
 import org.apache.directory.scim.ResourceNotFoundException;
+import org.apache.directory.scim.ScimUtil;
 import org.apache.directory.scim.ServerResource;
 import org.apache.directory.scim.SimpleAttribute;
 import org.apache.directory.scim.SimpleAttributeGroup;
 import org.apache.directory.scim.UserResource;
-import org.apache.directory.scim.ldap.handlers.MembersAttributeHandler;
+import org.apache.directory.scim.ldap.handlers.LdapAttributeHandler;
 import org.apache.directory.scim.ldap.schema.ComplexType;
 import org.apache.directory.scim.ldap.schema.GroupSchema;
 import org.apache.directory.scim.ldap.schema.MultiValType;
@@ -90,6 +97,8 @@ import org.apache.directory.scim.ldap.sc
 import org.apache.directory.scim.schema.BaseType;
 import org.apache.directory.scim.schema.JsonSchema;
 import org.apache.directory.scim.schema.SchemaUtil;
+import org.apache.directory.scim.search.FilterNode;
+import org.apache.directory.scim.search.FilterParser;
 import org.apache.directory.scim.util.ResourceUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -222,6 +231,119 @@ public class LdapResourceProvider implem
     }
 
 
+    public AttributeType getLdapType( String scimAtName, ResourceSchema schema )
+    {
+        scimAtName = scimAtName.trim();
+        int colonPos = scimAtName.lastIndexOf( ":" );
+        if( colonPos > 0 )
+        {
+            scimAtName = scimAtName.substring( colonPos + 1 );
+        }
+
+        
+//        String schemaUri = scimAtName.substring( 0, colonPos );
+//        if( schema == null )
+//        {
+//            throw new IllegalArgumentException( "No resource schema exists with the URI
" + schemaUri );
+//        }
+        
+        SimpleType st = ( SimpleType ) schema.getAttribute( scimAtName );
+        
+        if ( st != null  )
+        {
+            if( Strings.isNotEmpty( st.getMappedTo() ) )
+            {
+                return ldapSchema.getAttributeType( st.getMappedTo() );
+            }
+            else if ( st.getAtHandlerName() != null )
+            {
+                LdapAttributeHandler atHandler = ( LdapAttributeHandler ) schema.getHandler(
st.getAtHandlerName() );
+                return atHandler.getLdapAtType( st, "", schema, ldapSchema );
+            }
+        }
+        else // a complex or multivalued attribute with a handler
+        {
+            int pos = scimAtName.indexOf( '.' );
+            
+            if( pos <= 0 )
+            {
+                return null;
+            }
+            
+            BaseType bt = schema.getAttribute( scimAtName.substring( 0, pos ) );
+            
+            if( bt == null )
+            {
+                return null;
+            }
+            
+            LdapAttributeHandler atHandler = ( LdapAttributeHandler ) schema.getHandler(
bt.getAtHandlerName() );
+            
+            if( atHandler != null )
+            {
+                String remainingScimAttributePath = scimAtName.substring( pos + 1 );
+                return atHandler.getLdapAtType( bt, remainingScimAttributePath, schema, ldapSchema
);
+            }
+        }
+        
+        return null;
+    }
+    
+    
+    public ListResponse search( String scimFilter, String attributes, RequestContext ctx
) throws Exception
+    {
+        FilterNode filter = FilterParser.parse( scimFilter );
+        
+        String path = ctx.getUriInfo().getPath();
+        String uri = ScimUtil.CORE_USER_URI;
+        if( path.endsWith( "/Groups" ) )
+        {
+            uri = ScimUtil.CORE_GROUP_URI;
+        }
+        
+        ResourceSchema scimSchema = schemaMapper.getSchemaWithUri( uri );
+        
+        ExprNode ldapFilter = LdapUtil._scimToLdapFilter( filter, scimSchema, ldapSchema,
this );
+        LOG.debug( "LDAP filter {}", ldapFilter );
+        
+        SearchRequest sr = new SearchRequestImpl();
+        sr.setBase( new Dn( scimSchema.getBaseDn() ) );
+        sr.setFilter( ldapFilter );
+        sr.setScope( SearchScope.SUBTREE );
+        sr.addAttributes( ALL_ATTRIBUTES_ARRAY );
+        
+        SearchCursor cursor = connection.search( sr );
+        
+        ListResponse lr = new ListResponse();
+        
+        while( cursor.next() )
+        {
+            Entry entry = cursor.getEntry();
+            
+            ServerResource res = null;
+            
+            if( uri.equals( ScimUtil.CORE_USER_URI ) )
+            {
+                res = new UserResource();
+            }
+            else
+            {
+                res = new GroupResource();
+            }
+            
+            ctx.setCoreResource( res );
+
+            _loadCoreResource( ctx, entry, scimSchema );
+
+            lr.addResource( res );
+        }
+        
+        cursor.close();
+        
+        return lr;
+    }
+
+
     public UserResource getUser( RequestContext ctx, String id ) throws ResourceNotFoundException
     {
         Entry entry = fetchEntryById( id, userSchema );
@@ -1121,4 +1243,24 @@ public class LdapResourceProvider implem
     {
         return groupSchema;
     }
+    
+    public static void main( String[] args ) throws Exception
+    {
+        LdapResourceProvider provider = new LdapResourceProvider();
+        
+        try
+        {
+            provider.init();
+            
+            FilterNode scimFilter = FilterParser.parse( "(userName eq x and ((userName gt
xx-yy ) or (id eq y))) or userName eq \"true\"" );
+            System.out.println("SCIM filter: " + scimFilter);
+            
+            ExprNode ldapFilter = LdapUtil._scimToLdapFilter( scimFilter, provider.getUserSchema(),
provider.getLdapSchema(), provider );
+            System.out.println("LDAP filter: " + ldapFilter);
+        }
+        finally
+        {
+            provider.connection.close();
+        }
+    }
 }

Modified: directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapSchemaMapper.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapSchemaMapper.java?rev=1538365&r1=1538364&r2=1538365&view=diff
==============================================================================
--- directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapSchemaMapper.java
(original)
+++ directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapSchemaMapper.java
Sun Nov  3 13:50:09 2013
@@ -67,6 +67,8 @@ public class LdapSchemaMapper implements
 
     private UserSchema userSchema;
 
+    private Map<String,ResourceSchema> uriToResSchema;
+    
     private Map<String,JsonSchema> jsonSchemas;
     
     public LdapSchemaMapper( Map<String,JsonSchema> jsonSchemas, SchemaManager ldapSchema
)
@@ -90,6 +92,12 @@ public class LdapSchemaMapper implements
         return groupSchema;
     }
 
+    
+    public ResourceSchema getSchemaWithUri( String uri )
+    {
+        return uriToResSchema.get( uri );
+    }
+    
 
     /**
      * @return the ldapSchema
@@ -149,6 +157,8 @@ public class LdapSchemaMapper implements
 
             Map<String, AttributeHandler> atHandlersMap = loadAtHandlers( root.element(
"atHandlers" ) );
             
+            uriToResSchema = new HashMap<String, ResourceSchema>();
+            
             userSchema = new UserSchema( baseDn, filter );
             userSchema.setAtHandlers( atHandlersMap );
 
@@ -206,6 +216,10 @@ public class LdapSchemaMapper implements
                 if ( refId.equals( schemaId ) )
                 {
                     parseSchema( elmSchema, resourceSchema );
+                    for( String uri : resourceSchema.getUris() )
+                    {
+                        uriToResSchema.put( uri, resourceSchema );
+                    }
                     break;
                 }
             }

Modified: directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapUtil.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapUtil.java?rev=1538365&r1=1538364&r2=1538365&view=diff
==============================================================================
--- directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapUtil.java
(original)
+++ directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapUtil.java
Sun Nov  3 13:50:09 2013
@@ -19,11 +19,22 @@
  */
 package org.apache.directory.scim.ldap;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.directory.api.ldap.model.entry.Attribute;
 import org.apache.directory.api.ldap.model.entry.DefaultAttribute;
 import org.apache.directory.api.ldap.model.entry.Entry;
-import org.apache.directory.api.ldap.model.entry.ModificationOperation;
+import org.apache.directory.api.ldap.model.entry.StringValue;
 import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.filter.AndNode;
+import org.apache.directory.api.ldap.model.filter.EqualityNode;
+import org.apache.directory.api.ldap.model.filter.ExprNode;
+import org.apache.directory.api.ldap.model.filter.GreaterEqNode;
+import org.apache.directory.api.ldap.model.filter.LessEqNode;
+import org.apache.directory.api.ldap.model.filter.OrNode;
+import org.apache.directory.api.ldap.model.filter.PresenceNode;
+import org.apache.directory.api.ldap.model.filter.SubstringNode;
 import org.apache.directory.api.ldap.model.message.ModifyRequest;
 import org.apache.directory.api.ldap.model.schema.AttributeType;
 import org.apache.directory.api.ldap.model.schema.SchemaManager;
@@ -37,13 +48,15 @@ import org.apache.directory.scim.ldap.sc
 import org.apache.directory.scim.ldap.schema.SimpleType;
 import org.apache.directory.scim.ldap.schema.SimpleTypeGroup;
 import org.apache.directory.scim.schema.BaseType;
+import org.apache.directory.scim.search.BranchNode;
+import org.apache.directory.scim.search.FilterNode;
+import org.apache.directory.scim.search.TerminalNode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.gson.JsonArray;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
-import static org.apache.directory.api.ldap.model.entry.ModificationOperation.*;
 
 /**
  * TODO LdapUtil.
@@ -413,4 +426,105 @@ public class LdapUtil
             }
         }
     }
+    
+    
+    //------------------ search filter processing -----------------
+    
+//    public static ExprNode scimToLdapFilter( FilterNode scimFilter )
+//    {
+//        
+//    }
+    
+    
+    public static ExprNode _scimToLdapFilter( FilterNode scimFilter, ResourceSchema scimSchema,
SchemaManager ldapSchema, LdapResourceProvider provider )
+    {
+        ExprNode ldapFilter = null;
+        
+        if( scimFilter instanceof TerminalNode )
+        {
+            TerminalNode tn = ( TerminalNode ) scimFilter;
+
+            AttributeType at = provider.getLdapType( tn.getAttribute(), scimSchema );
+            
+            if( at == null )
+            {
+                return null;
+            }
+            
+            switch( scimFilter.getOperator() )
+            {
+                case EQ:
+                    ldapFilter = new EqualityNode<String>( at, new StringValue( tn.getValue()
) );
+                    break;
+                  
+                case CO:
+                    List<String> anyPattern = new ArrayList<String>();
+                    anyPattern.add( tn.getValue() );
+                    ldapFilter = new SubstringNode( anyPattern, at, null, null );
+                    break;
+                
+                case GT:
+                case GE:
+                    ldapFilter = new GreaterEqNode<String>( at, new StringValue( tn.getValue()
) );
+                    break;
+                    
+                case LT:
+                case LE:
+                    ldapFilter = new LessEqNode<String>( at, new StringValue( tn.getValue()
) );
+                    break;
+                    
+                case PR:
+                    ldapFilter = new PresenceNode( at );
+                    break;
+                    
+                case SW:
+                    ldapFilter = new SubstringNode( at, tn.getValue(), null );
+                    break;
+            }
+        }
+        else if( scimFilter instanceof BranchNode )
+        {
+            BranchNode bn = ( BranchNode ) scimFilter;
+            
+            ExprNode child1 = _scimToLdapFilter( bn.getLeftNode(), scimSchema, ldapSchema,
provider );
+            
+            ExprNode child2 = _scimToLdapFilter( bn.getRightNode(), scimSchema, ldapSchema,
provider );
+            
+            switch( scimFilter.getOperator() )
+            {
+                case AND:
+                    AndNode andNode = new AndNode();
+                    if( child1 != null )
+                    {
+                        andNode.addNode( child1 );
+                    }
+                    
+                    if( child2 != null )
+                    {
+                        andNode.addNode( child2 );
+                    }
+                    
+                    ldapFilter = andNode;
+                    break;
+                    
+                case OR:
+                    OrNode orNode = new OrNode();
+                    if( child1 != null )
+                    {
+                        orNode.addNode( child1 );
+                    }
+                    
+                    if( child2 != null )
+                    {
+                        orNode.addNode( child2 );
+                    }
+                    
+                    ldapFilter = orNode;
+                    break;
+            }
+        }
+        
+        return ldapFilter;
+    }
+
 }

Modified: directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/LdapAttributeHandler.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/LdapAttributeHandler.java?rev=1538365&r1=1538364&r2=1538365&view=diff
==============================================================================
--- directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/LdapAttributeHandler.java
(original)
+++ directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/LdapAttributeHandler.java
Sun Nov  3 13:50:09 2013
@@ -21,9 +21,13 @@ package org.apache.directory.scim.ldap.h
 
 import org.apache.directory.api.ldap.model.entry.Entry;
 import org.apache.directory.api.ldap.model.message.ModifyRequest;
+import org.apache.directory.api.ldap.model.schema.AttributeType;
+import org.apache.directory.api.ldap.model.schema.SchemaManager;
 import org.apache.directory.scim.AttributeHandler;
 import org.apache.directory.scim.RequestContext;
 import org.apache.directory.scim.ldap.LdapUtil;
+import org.apache.directory.scim.ldap.schema.ResourceSchema;
+import org.apache.directory.scim.ldap.schema.SimpleType;
 import org.apache.directory.scim.schema.BaseType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -68,4 +72,15 @@ public abstract class LdapAttributeHandl
     {
         LdapUtil.deleteAttribute( atType, (Entry) targetEntry, ( ModifyRequest ) patchCtx
);
     }
+    
+    
+    public AttributeType getLdapAtType( BaseType bt, String remainingScimAttributePath, ResourceSchema
schema, SchemaManager ldapSchema )
+    {
+        if( !( bt instanceof SimpleType ) )
+        {
+            return null;
+        }
+        
+        return ldapSchema.getAttributeType( ( ( SimpleType ) bt ).getMappedTo() );
+    }
 }

Modified: directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/UserService.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/UserService.java?rev=1538365&r1=1538364&r2=1538365&view=diff
==============================================================================
--- directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/UserService.java
(original)
+++ directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/UserService.java
Sun Nov  3 13:50:09 2013
@@ -41,6 +41,7 @@ import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.core.StreamingOutput;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.directory.scim.ListResponse;
 import org.apache.directory.scim.MissingParameterException;
 import org.apache.directory.scim.ProviderService;
 import org.apache.directory.scim.RequestContext;
@@ -218,6 +219,39 @@ public class UserService
         return rb.build();
     }
 
+
+    @GET
+    @Produces({MediaType.APPLICATION_JSON})
+    public Response search( @QueryParam("filter") String filter, @QueryParam("attributes")
String attributes, @Context UriInfo uriInfo, @Context HttpHeaders headers )
+    {
+        ResponseBuilder rb = null;
+
+        if( ( ( filter == null ) || ( filter.trim().length() == 0 ) ) &&
+            ( ( attributes == null ) || ( attributes.trim().length() == 0 ) ) )
+        {
+            rb = Response.status( Status.BAD_REQUEST ).entity( "Neither filter nor attributes
parameters are present with the call to " + uriInfo.getAbsolutePath() );
+            return rb.build();
+        }
+        
+        LOG.debug( "Filter : {}", filter );
+        LOG.debug( "Attributes : {}", attributes );
+    
+        try
+        {
+            RequestContext ctx = new RequestContext( provider, uriInfo, headers );
+            ListResponse lr = provider.search( filter, attributes, ctx );
+
+            String json = ResourceSerializer.serialize( lr );
+            rb = Response.ok().entity( json );
+        }
+        catch( Exception e )
+        {
+            rb = ScimUtil.buildError( e );
+        }
+
+        return rb.build();
+    }
+
     
     @GET
     @Produces({MediaType.APPLICATION_OCTET_STREAM})



Mime
View raw message