directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1532356 - in /directory/escimo/trunk: common/src/main/java/org/apache/directory/scim/ common/src/main/java/org/apache/directory/scim/json/ ldap/src/main/java/org/apache/directory/scim/ldap/ ldap/src/main/java/org/apache/directory/scim/ldap...
Date Tue, 15 Oct 2013 14:21:06 GMT
Author: kayyagari
Date: Tue Oct 15 14:21:05 2013
New Revision: 1532356

URL: http://svn.apache.org/r1532356
Log:
o renamed Resource to ServerResource
o added support for PUT and PATCH

Added:
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ServerResource.java
      - copied, changed from r1531583, directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/Resource.java
Removed:
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/Resource.java
Modified:
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/GroupResource.java
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ProviderService.java
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/RequestContext.java
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/UserResource.java
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/json/ResourceSerializer.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/handlers/MetaAttributeHandler.java
    directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/PhotosAttributeHandler.java
    directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/schema/ResourceSchema.java
    directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/schema/SimpleTypeGroup.java
    directory/escimo/trunk/ldap/src/main/resources/escimo-ldap-mapping.xml
    directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/GroupService.java
    directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/UserService.java

Modified: directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/GroupResource.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/GroupResource.java?rev=1532356&r1=1532355&r2=1532356&view=diff
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/GroupResource.java
(original)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/GroupResource.java
Tue Oct 15 14:21:05 2013
@@ -25,7 +25,7 @@ package org.apache.directory.scim;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class GroupResource extends Resource
+public class GroupResource extends ServerResource
 {
     @Override
     public String toString()

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=1532356&r1=1532355&r2=1532356&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
Tue Oct 15 14:21:05 2013
@@ -41,4 +41,6 @@ public interface ProviderService 
     JsonSchema getSchema( String uriId );
     
     UserResource addUser( String jsonData, RequestContext ctx ) throws Exception;
+    
+    GroupResource addGroup( String jsonData, RequestContext ctx ) throws Exception;
 }

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=1532356&r1=1532355&r2=1532356&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
Tue Oct 15 14:21:05 2013
@@ -20,9 +20,9 @@
 package org.apache.directory.scim;
 
 
-import java.util.HashMap;
-import java.util.Map;
+import java.util.List;
 
+import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.UriInfo;
 
 
@@ -37,23 +37,25 @@ public class RequestContext
 
     private UriInfo uriInfo;
 
-    private Resource resource;
-
-    private Map<String,String> reqParams;
+    private HttpHeaders headers;
+    
+    private ServerResource resource;
 
-    public RequestContext( ProviderService providerService )
+    public RequestContext( ProviderService providerService, UriInfo uriInfo, HttpHeaders
headers )
     {
         this.providerService = providerService;
+        this.uriInfo = uriInfo;
+        this.headers = headers;
     }
 
 
-    public Resource getCoreResource()
+    public ServerResource getCoreResource()
     {
         return resource;
     }
 
 
-    public void setCoreResource( Resource resource )
+    public void setCoreResource( ServerResource resource )
     {
         this.resource = resource;
     }
@@ -65,9 +67,12 @@ public class RequestContext
     }
 
 
-    public void setUriInfo( UriInfo uriInfo )
+    /**
+     * @return the headers
+     */
+    public HttpHeaders getHeaders()
     {
-        this.uriInfo = uriInfo;
+        return headers;
     }
 
 
@@ -77,24 +82,15 @@ public class RequestContext
     }
 
     
-    public void addReqParam( String name, String value )
+    public String getHeaderValue( String name )
     {
-        if( reqParams == null )
-        {
-            reqParams = new HashMap<String, String>();
-        }
+        List<String> lst = headers.getRequestHeader( name );
         
-        reqParams.put( name, value );
-    }
-    
-    
-    public String getReqParam( String name )
-    {
-        if( reqParams == null )
+        if( ( lst == null ) || ( lst.isEmpty() ) )
         {
             return null;
         }
         
-        return reqParams.get( name );
+        return lst.get( 0 );
     }
 }

Copied: directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ServerResource.java
(from r1531583, directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/Resource.java)
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ServerResource.java?p2=directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ServerResource.java&p1=directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/Resource.java&r1=1531583&r2=1532356&rev=1532356&view=diff
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/Resource.java (original)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ServerResource.java
Tue Oct 15 14:21:05 2013
@@ -25,11 +25,11 @@ import java.util.List;
 import java.util.Map;
 
 /**
- * TODO Resource.
+ * TODO ServerResource.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public abstract class Resource
+public abstract class ServerResource
 {
     private Map<String,List<AbstractAttribute>> uriAtMap = new HashMap<String,
List<AbstractAttribute>>();
     

Modified: directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/UserResource.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/UserResource.java?rev=1532356&r1=1532355&r2=1532356&view=diff
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/UserResource.java
(original)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/UserResource.java
Tue Oct 15 14:21:05 2013
@@ -25,7 +25,7 @@ package org.apache.directory.scim;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class UserResource extends Resource
+public class UserResource extends ServerResource
 {
     @Override
     public String toString()

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=1532356&r1=1532355&r2=1532356&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
Tue Oct 15 14:21:05 2013
@@ -25,7 +25,7 @@ import java.util.Map;
 
 import org.apache.directory.scim.AbstractAttribute;
 import org.apache.directory.scim.ComplexAttribute;
-import org.apache.directory.scim.Resource;
+import org.apache.directory.scim.ServerResource;
 import org.apache.directory.scim.GroupResource;
 import org.apache.directory.scim.MultiValAttribute;
 import org.apache.directory.scim.SimpleAttribute;
@@ -49,7 +49,7 @@ public class ResourceSerializer
     public static final String CORE_EXT_USER_URI = "urn:scim:schemas:extension:enterprise:2.0:User";
     
 
-    public static String serialize( Resource resource )
+    public static String serialize( ServerResource resource )
     {
         JsonObject root = new JsonObject();
 

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=1532356&r1=1532355&r2=1532356&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
Tue Oct 15 14:21:05 2013
@@ -38,11 +38,14 @@ 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.entry.Attribute;
-import org.apache.directory.api.ldap.model.entry.DefaultAttribute;
 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.LdapException;
+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;
@@ -65,12 +68,12 @@ import org.apache.directory.ldap.client.
 import org.apache.directory.ldap.client.api.LdapNetworkConnection;
 import org.apache.directory.scim.AttributeHandler;
 import org.apache.directory.scim.ComplexAttribute;
-import org.apache.directory.scim.Resource;
 import org.apache.directory.scim.GroupResource;
 import org.apache.directory.scim.MissingParameterException;
 import org.apache.directory.scim.MultiValAttribute;
 import org.apache.directory.scim.ProviderService;
 import org.apache.directory.scim.RequestContext;
+import org.apache.directory.scim.ServerResource;
 import org.apache.directory.scim.ResourceNotFoundException;
 import org.apache.directory.scim.SimpleAttribute;
 import org.apache.directory.scim.SimpleAttributeGroup;
@@ -81,7 +84,6 @@ import org.apache.directory.scim.ldap.sc
 import org.apache.directory.scim.ldap.schema.ResourceSchema;
 import org.apache.directory.scim.ldap.schema.SimpleType;
 import org.apache.directory.scim.ldap.schema.SimpleTypeGroup;
-import org.apache.directory.scim.ldap.schema.TypedType;
 import org.apache.directory.scim.ldap.schema.UserSchema;
 import org.apache.directory.scim.schema.BaseType;
 import org.apache.directory.scim.schema.JsonSchema;
@@ -90,6 +92,7 @@ import org.apache.directory.scim.util.Re
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.gson.JsonArray;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
@@ -102,6 +105,7 @@ import com.google.gson.JsonParser;
  */
 public class LdapResourceProvider implements ProviderService
 {
+
     private LdapConnection connection;
 
     private LdapSchemaMapper schemaMapper;
@@ -116,6 +120,7 @@ public class LdapResourceProvider implem
 
     private static final Logger LOG = LoggerFactory.getLogger( LdapResourceProvider.class
);
 
+    private static final String ENTRYDN_HEADER = "X-ENTRYDN";
 
     public LdapResourceProvider()
     {
@@ -288,7 +293,7 @@ public class LdapResourceProvider implem
     }
 
     
-    private void addAttributes( Entry entry, JsonObject obj, RequestContext ctx ) throws
LdapException
+    private void addAttributes( Entry entry, JsonObject obj, RequestContext ctx, ResourceSchema
resourceSchema ) throws LdapException
     {
         for( java.util.Map.Entry<String, JsonElement> e : obj.entrySet() )
         {
@@ -299,7 +304,7 @@ public class LdapResourceProvider implem
                 continue;
             }
             
-            BaseType bt = userSchema.getAttribute( name );
+            BaseType bt = resourceSchema.getAttribute( name );
             
             if( bt == null )
             {
@@ -311,7 +316,7 @@ public class LdapResourceProvider implem
                 continue;
             }
 
-            AttributeHandler handler = userSchema.getHandler( bt.getAtHandlerName() );
+            AttributeHandler handler = resourceSchema.getHandler( bt.getAtHandlerName() );
             
             if( handler != null )
             {
@@ -332,31 +337,12 @@ public class LdapResourceProvider implem
             JsonParser parser = new JsonParser();
             JsonObject obj = ( JsonObject ) parser.parse( json );
             
-            Entry entry = new DefaultEntry();
-            
-            // process the core attributes first
-            addAttributes( entry, obj, ctx );
-            
-            List<String> uris = userSchema.getUris();
-            
-            for( String u : uris )
-            {
-                JsonObject userAtObj = ( JsonObject ) obj.get( u );
-                if( userAtObj != null )
-                {
-                    addAttributes( entry, userAtObj, ctx );
-                }
-            }
-
-            for( String oc : userSchema.getObjectClasses() )
-            {
-                entry.add( SchemaConstants.OBJECT_CLASS, oc );
-            }
-            
+            Entry entry = new DefaultEntry( ldapSchema );
+         
             SimpleType st = ( SimpleType ) userSchema.getCoreAttribute( "userName" );
             String userIdName = st.getMappedTo();
 
-            String dn = ctx.getReqParam( "userDn" );
+            String dn = ctx.getHeaderValue( ENTRYDN_HEADER );
             
             if( Strings.isEmpty( dn ) )
             {
@@ -370,9 +356,7 @@ public class LdapResourceProvider implem
                 dn = userIdName + "=" + userName + "," + userSchema.getBaseDn();
             }
             
-            entry.setDn( dn );
-            
-            connection.add( entry );
+            _resourceToEntry( entry, obj, ctx, userSchema, dn );
             
             entry = connection.lookup( entry.getDn(), SchemaConstants.ALL_ATTRIBUTES_ARRAY
);
 
@@ -383,13 +367,308 @@ public class LdapResourceProvider implem
             _loadCoreResource( ctx, entry, userSchema );
             
             return addedUser;
+
+        }
+        catch( Exception e )
+        {
+            LOG.warn( "Failed to create User resource", e );
+            throw e;
+        }
+    }
+    
+    
+    public GroupResource addGroup( String jsonData, RequestContext ctx ) throws Exception
+    {
+        try
+        {
+            JsonParser parser = new JsonParser();
+            JsonObject obj = ( JsonObject ) parser.parse( jsonData );
+            
+            Entry entry = new DefaultEntry( ldapSchema );
+         
+            SimpleType st = ( SimpleType ) groupSchema.getCoreAttribute( "displayName" );
+            String groupNameAt = st.getMappedTo();
+
+            String dn = ctx.getHeaderValue( ENTRYDN_HEADER );
+            
+            if( Strings.isEmpty( dn ) )
+            {
+                dn = null;
+            }
+            
+            if( dn == null )
+            {
+                String groupName = obj.get( "displayName" ).getAsString();
+                
+                dn = groupNameAt + "=" + groupName + "," + groupSchema.getBaseDn();
+            }
+            
+            _resourceToEntry( entry, obj, ctx, groupSchema, dn );
+            
+            entry = connection.lookup( entry.getDn(), SchemaConstants.ALL_ATTRIBUTES_ARRAY
);
+
+            GroupResource addedGroup = new GroupResource();
+
+            ctx.setCoreResource( addedGroup );
+
+            _loadCoreResource( ctx, entry, groupSchema );
+            
+            return addedGroup;
+
         }
         catch( Exception e )
         {
-            e.printStackTrace();
+            LOG.warn( "Failed to create Group resource", e );
             throw e;
         }
     }
+
+
+    private void _resourceToEntry( Entry entry, JsonObject obj, RequestContext ctx, ResourceSchema
resourceSchema, String dn ) throws Exception
+    {
+
+        // process the core attributes first
+        addAttributes( entry, obj, ctx, resourceSchema );
+        
+        List<String> uris = resourceSchema.getUris();
+        
+        for( String u : uris )
+        {
+            JsonObject userAtObj = ( JsonObject ) obj.get( u );
+            if( userAtObj != null )
+            {
+                addAttributes( entry, userAtObj, ctx, resourceSchema );
+            }
+        }
+
+        for( String oc : resourceSchema.getObjectClasses() )
+        {
+            entry.add( SchemaConstants.OBJECT_CLASS, oc );
+        }
+        
+        
+        entry.setDn( dn );
+        
+        connection.add( entry );
+    }
+    
+    
+    // TODO can userName be changed for a user?? likewise displayName for a Group
+    public ServerResource replaceResource( String jsonData, RequestContext ctx, ResourceSchema
resourceSchema ) throws Exception
+    {
+        JsonParser parser = new JsonParser();
+        JsonObject obj = ( JsonObject ) parser.parse( jsonData );
+        
+        String resourceId = obj.get( "id" ).getAsString();
+        
+        Entry entry = new DefaultEntry( ldapSchema );
+        
+        _resourceToEntry( entry, obj, ctx, resourceSchema, "" );
+        
+        Entry existingEntry = fetchEntryById( resourceId, resourceSchema );
+        
+        // save a reference to the existing password attribute
+        Attribute existingPwdAt = existingEntry.get( SchemaConstants.USER_PASSWORD_AT );
+        Attribute newPwdAt = entry.get( SchemaConstants.USER_PASSWORD_AT );
+        
+        if( existingPwdAt != null )
+        {
+            existingEntry.remove( existingPwdAt );
+        }
+        
+        if( newPwdAt != null )
+        {
+            entry.remove( newPwdAt );
+        }
+        
+        Attribute existingUserNameAt = null;
+        Attribute newUserNameAt = null;
+        SimpleType st = null;
+        
+        if( resourceSchema == userSchema )
+        {
+            st = ( SimpleType ) resourceSchema.getAttribute( "userName" );
+        }
+        else if( resourceSchema == groupSchema )
+        {
+            st = ( SimpleType ) resourceSchema.getAttribute( "displayName" );
+        }
+        
+        if( st != null )
+        {
+            existingUserNameAt = existingEntry.get( st.getMappedTo() );
+            newUserNameAt = entry.get( st.getMappedTo() );
+            
+            if( newUserNameAt != null )
+            {
+                entry.remove( newUserNameAt );
+            }
+        }
+        
+        ModifyRequest modReq = new ModifyRequestImpl();
+        modReq.setName( existingEntry.getDn() );
+        
+        Iterator<Attribute> itr = existingEntry.iterator();
+        while( itr.hasNext() )
+        {
+            Attribute ldapAt = itr.next();
+            
+            AttributeType type = ldapAt.getAttributeType();
+            
+            if( !type.isUserModifiable() )
+            {
+                continue;
+            }
+            
+            if( entry.containsAttribute( type ) )
+            {
+                ldapAt = entry.get( type );
+                entry.removeAttributes( type );
+                modReq.replace( ldapAt );
+            }
+            else
+            {
+                modReq.remove( ldapAt );
+            }
+        }
+        
+        // iterate over the remaining attributes of new entry and add them to modlist as
'add' modifications
+        
+        for( Attribute newAt : entry )
+        {
+            modReq.add( newAt );
+        }
+        
+        if( newPwdAt != null )
+        {
+            if( existingPwdAt != null )
+            {
+                modReq.replace( newPwdAt );
+            }
+            else
+            {
+                modReq.add( newPwdAt );
+            }
+        }
+        
+        ModifyResponse modResp = connection.modify( modReq );
+        
+        if( modResp.getLdapResult().getResultCode() != ResultCodeEnum.SUCCESS )
+        {
+            throw new Exception( "Failed to replace the resource " + modResp.getLdapResult().getDiagnosticMessage()
);
+        }
+        
+        if( newUserNameAt != null )
+        {
+            if( !existingUserNameAt.contains( newUserNameAt.getString() ) )
+            {
+                // a modDN needs to be performed
+                connection.rename( existingEntry.getDn().getName(), newUserNameAt.getUpId()
+ "=" + newUserNameAt.getString(), true );
+            }
+        }
+        
+        entry = fetchEntryById( resourceId, resourceSchema );
+        
+        ServerResource resource = null;
+        
+        if( resourceSchema == userSchema )
+        {
+            resource = new UserResource();
+        }
+        else
+        {
+            resource = new GroupResource();
+        }
+
+        ctx.setCoreResource( resource );
+
+        _loadCoreResource( ctx, entry, resourceSchema );
+        
+        return resource;
+    }
+    
+    
+    public void patchResource( String jsonData, RequestContext ctx, ResourceSchema resourceSchema
) throws Exception
+    {
+        JsonParser parser = new JsonParser();
+        JsonObject obj = ( JsonObject ) parser.parse( jsonData );
+
+        String resourceId = obj.get( "id" ).getAsString();
+        
+        Entry existingEntry = fetchEntryById( resourceId, resourceSchema );
+        
+        if( existingEntry == null )
+        {
+            throw new ResourceNotFoundException( "No resource found with the id " + resourceId
);
+        }
+        
+        
+        ModifyRequest modReq = new ModifyRequestImpl();
+        modReq.setName( existingEntry.getDn() );
+        
+        List<String> deleteModAtOids = new ArrayList<String>();
+        
+        JsonObject metaObj = ( JsonObject ) obj.get( "meta" );
+        if( metaObj != null )
+        {
+            JsonArray metaAtNames = ( JsonArray ) metaObj.get( "attributes" );
+            if( metaAtNames != null )
+            {
+                for( JsonElement e : metaAtNames )
+                {
+                    String name = e.getAsString();
+                    BaseType bt = resourceSchema.getAttribute( name );
+                    
+                    if( bt == null )
+                    {
+                        //FIXME should throw attribute not found exception
+                        throw new ResourceNotFoundException( "No definition found for the
attribute " + name );
+                    }
+                    
+                    if( bt.isReadOnly() || ( ! ( bt instanceof SimpleType ) ) )
+                    {
+                        continue;
+                    }
+                    
+                    SimpleType st = ( SimpleType ) bt;
+                    
+                    name = st.getMappedTo();
+                    
+                    if( !Strings.isEmpty( name ) )
+                    {
+                        Attribute ldapAt = existingEntry.get( name );
+                        modReq.remove( ldapAt );
+                        deleteModAtOids.add( ldapAt.getAttributeType().getOid() );
+                    }
+                }
+            }
+        }
+
+        Entry entry = new DefaultEntry( ldapSchema );
+        
+        _resourceToEntry( entry, obj, ctx, resourceSchema, "" );
+
+        for( Attribute ldapAt : entry )
+        {
+            AttributeType type = ldapAt.getAttributeType();
+            
+            if( deleteModAtOids.contains( type.getOid() ) )
+            {
+                modReq.add( ldapAt );
+            }
+            else if( existingEntry.containsAttribute( type ) )
+            {
+                if( type.isSingleValued() )
+                {
+                    modReq.replace( ldapAt );
+                }
+                else
+                {
+                    modReq.add( ldapAt );
+                }
+            }
+        }
+    }
     
     public UserResource toUser( RequestContext ctx, Entry entry ) throws Exception
     {
@@ -416,7 +695,7 @@ public class LdapResourceProvider implem
 
     private void _loadCoreResource( RequestContext ctx, Entry entry, ResourceSchema resourceSchema
) throws Exception
     {
-        Resource resource = ctx.getCoreResource();
+        ServerResource resource = ctx.getCoreResource();
 
         // first fill in the id, we need this for deriving location
         SimpleType idType = ( SimpleType ) resourceSchema.getCoreAttribute( "id" );
@@ -433,7 +712,7 @@ public class LdapResourceProvider implem
     private void _loadAttributes( RequestContext ctx, Entry entry, Collection<BaseType>
types, SimpleType idType )
         throws Exception
     {
-        Resource user = ctx.getCoreResource();
+        ServerResource user = ctx.getCoreResource();
 
         for ( BaseType bt : types )
         {

Modified: directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MetaAttributeHandler.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MetaAttributeHandler.java?rev=1532356&r1=1532355&r2=1532356&view=diff
==============================================================================
--- directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MetaAttributeHandler.java
(original)
+++ directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MetaAttributeHandler.java
Tue Oct 15 14:21:05 2013
@@ -28,7 +28,7 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.exception.LdapException;
 import org.apache.directory.scim.AttributeHandler;
 import org.apache.directory.scim.ComplexAttribute;
-import org.apache.directory.scim.Resource;
+import org.apache.directory.scim.ServerResource;
 import org.apache.directory.scim.GroupResource;
 import org.apache.directory.scim.RequestContext;
 import org.apache.directory.scim.SimpleAttribute;
@@ -84,7 +84,7 @@ public class MetaAttributeHandler extend
                 atList.add( lastModified );
             }
 
-            Resource resource = ctx.getCoreResource();
+            ServerResource resource = ctx.getCoreResource();
             
             String resourceType = "User";
             

Modified: directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/PhotosAttributeHandler.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/PhotosAttributeHandler.java?rev=1532356&r1=1532355&r2=1532356&view=diff
==============================================================================
--- directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/PhotosAttributeHandler.java
(original)
+++ directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/PhotosAttributeHandler.java
Tue Oct 15 14:21:05 2013
@@ -27,7 +27,7 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.entry.Entry;
 import org.apache.directory.api.ldap.model.entry.Value;
 import org.apache.directory.scim.AttributeHandler;
-import org.apache.directory.scim.Resource;
+import org.apache.directory.scim.ServerResource;
 import org.apache.directory.scim.MultiValAttribute;
 import org.apache.directory.scim.RequestContext;
 import org.apache.directory.scim.SimpleAttribute;
@@ -63,7 +63,7 @@ public class PhotosAttributeHandler exte
             return;
         }
 
-        Resource user = ctx.getCoreResource();
+        ServerResource user = ctx.getCoreResource();
 
         Entry entry = ( Entry ) srcResource;
 
@@ -95,7 +95,7 @@ public class PhotosAttributeHandler exte
     }
 
 
-    private SimpleAttribute getPhotoUrlValue( SimpleTypeGroup stg, Entry entry, String photoUrlBase,
Resource user )
+    private SimpleAttribute getPhotoUrlValue( SimpleTypeGroup stg, Entry entry, String photoUrlBase,
ServerResource user )
     {
         SimpleType valType = stg.getValueType();
         if ( valType != null )

Modified: directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/schema/ResourceSchema.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/schema/ResourceSchema.java?rev=1532356&r1=1532355&r2=1532356&view=diff
==============================================================================
--- directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/schema/ResourceSchema.java
(original)
+++ directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/schema/ResourceSchema.java
Tue Oct 15 14:21:05 2013
@@ -80,8 +80,42 @@ public abstract class ResourceSchema
 
     public BaseType getAttribute( String name )
     {
+        if( name.contains( "." ) )
+        {
+            String[] atPath = name.split( "." );
+            
+            BaseType b = _findAtType( atPath[0] );
+            
+            
+            SimpleTypeGroup stg = null;
+            
+            if ( b instanceof ComplexType )
+            {
+                ComplexType c = ( ComplexType ) b;
+                stg = c.getAtGroup();
+            }
+            else if ( b instanceof MultiValType )
+            {
+                MultiValType m = ( MultiValType ) b;
+                stg = m.getAtGroup();
+            }
+            
+            if( stg != null )
+            {
+                return stg.getType( atPath[1] );
+            }
+            
+            return null;
+        }
+
+        return _findAtType( name );
+    }
+
+    
+    private BaseType _findAtType( String name )
+    {
         BaseType bt = coreTypes.get( name );
-       
+        
         if ( bt == null )
         {
             bt = extendedTypes.get( name );
@@ -90,7 +124,6 @@ public abstract class ResourceSchema
         return bt;
     }
 
-
     public void addAttributeType( String name, BaseType type )
     {
         if ( type != null )

Modified: directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/schema/SimpleTypeGroup.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/schema/SimpleTypeGroup.java?rev=1532356&r1=1532355&r2=1532356&view=diff
==============================================================================
--- directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/schema/SimpleTypeGroup.java
(original)
+++ directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/schema/SimpleTypeGroup.java
Tue Oct 15 14:21:05 2013
@@ -36,6 +36,7 @@ public class SimpleTypeGroup
     /** used for setting the value of "formatted" attribute */
     private String format;
 
+
     public SimpleTypeGroup( List<SimpleType> subTypes, String format )
     {
         this.subTypes = subTypes;
@@ -60,20 +61,32 @@ public class SimpleTypeGroup
         return Collections.unmodifiableList( subTypes );
     }
 
-    
+
     public SimpleType getValueType()
     {
-        for( SimpleType st : subTypes )
+        return getType( "value" );
+    }
+
+
+    public SimpleType getType( String name )
+    {
+        if( subTypes == null )
         {
-            if( "value".equals( st.getName() ))
+            return null;
+        }
+        
+        for ( SimpleType st : subTypes )
+        {
+            if ( name.equals( st.getName() ) )
             {
                 return st;
             }
         }
-        
+
         return null;
     }
 
+
     /* (non-Javadoc)
      * @see java.lang.Object#toString()
      */
@@ -82,5 +95,5 @@ public class SimpleTypeGroup
     {
         return "SimpleTypeGroup [subTypes=" + subTypes + ", format=" + format + "]";
     }
-    
+
 }

Modified: directory/escimo/trunk/ldap/src/main/resources/escimo-ldap-mapping.xml
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/ldap/src/main/resources/escimo-ldap-mapping.xml?rev=1532356&r1=1532355&r2=1532356&view=diff
==============================================================================
--- directory/escimo/trunk/ldap/src/main/resources/escimo-ldap-mapping.xml (original)
+++ directory/escimo/trunk/ldap/src/main/resources/escimo-ldap-mapping.xml Tue Oct 15 14:21:05
2013
@@ -93,6 +93,7 @@
     </schema>
 
     <schema id="group" uri="urn:scim:schemas:core:2.0:Group">
+        <!-- the 'displayName' MUST be mapped to the RDN attribute otherwise creation
of new groups fails -->
         <attribute name="displayName" mappedTo="cn" />
         <attribute name="id" mappedTo="entryUUID" />
         <multival-attribute name="members" handlerRef="membersHandler"/>

Modified: directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/GroupService.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/GroupService.java?rev=1532356&r1=1532355&r2=1532356&view=diff
==============================================================================
--- directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/GroupService.java
(original)
+++ directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/GroupService.java
Tue Oct 15 14:21:05 2013
@@ -20,11 +20,15 @@
 package org.apache.directory.scim.rest;
 
 
+import java.net.URI;
+
 import javax.ws.rs.GET;
+import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
@@ -34,9 +38,13 @@ import javax.ws.rs.core.UriInfo;
 import org.apache.directory.scim.GroupResource;
 import org.apache.directory.scim.ProviderService;
 import org.apache.directory.scim.RequestContext;
+import org.apache.directory.scim.ServerResource;
 import org.apache.directory.scim.ResourceNotFoundException;
 import org.apache.directory.scim.json.ResourceSerializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+import static org.apache.directory.scim.ScimUtil.*;
 
 /**
  * TODO GroupService.
@@ -47,26 +55,63 @@ import org.apache.directory.scim.json.Re
 public class GroupService
 {
     private ProviderService provider = ServerInitializer.getProvider();
+
+    private static final Logger LOG = LoggerFactory.getLogger( GroupService.class );
     
     @GET
     @Produces({MediaType.APPLICATION_JSON})
     @Path("{id}")
-    public Response getUser( @PathParam("id") String userId, @Context UriInfo uriInfo )
+    public Response getGroup( @PathParam("id") String groupId, @Context UriInfo uriInfo,
@Context HttpHeaders headers )
     {
         ResponseBuilder rb = null;
         
         try
         {
-            RequestContext ctx = new RequestContext( provider );
-            ctx.setUriInfo( uriInfo );
+            RequestContext ctx = new RequestContext( provider, uriInfo, headers );
             
-            GroupResource group = provider.getGroup( ctx, userId );
+            GroupResource group = provider.getGroup( ctx, groupId );
             String json = ResourceSerializer.serialize( group );
             rb = Response.ok( json, MediaType.APPLICATION_JSON );
         }
         catch( ResourceNotFoundException e )
         {
-            rb = Response.status( Status.INTERNAL_SERVER_ERROR );
+            rb = Response.status( Status.INTERNAL_SERVER_ERROR ).entity( exceptionToStr(
e ) );
+        }
+        
+        return rb.build();
+    }
+
+    @POST
+    @Produces({MediaType.APPLICATION_JSON})
+    public Response addGroup( String jsonData, @Context UriInfo uriInfo, @Context HttpHeaders
headers )
+    {
+        ResponseBuilder rb = null;
+
+        if( ( jsonData == null ) || ( jsonData.trim().length() == 0 ) )
+        {
+            rb = Response.status( Status.BAD_REQUEST ).entity( "No data is present with the
call to " + uriInfo.getAbsolutePath() );
+            return rb.build();
+        }
+        
+        LOG.debug( "Data received at the URI {}\n{}", uriInfo.getAbsolutePath(), jsonData
);
+        
+        try
+        {
+            RequestContext ctx = new RequestContext( provider, uriInfo, headers );
+            
+            provider.addGroup( jsonData, ctx );
+            
+            ServerResource res = ctx.getCoreResource();
+            
+            String json = ResourceSerializer.serialize( res );
+            
+            URI location = uriInfo.getBaseUriBuilder().build( res.getId() );
+            
+            rb = Response.created( location ).entity( json );
+        }
+        catch( Exception e )
+        {
+            rb = Response.status( Status.INTERNAL_SERVER_ERROR ).entity( exceptionToStr(
e ) );
         }
         
         return rb.build();

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=1532356&r1=1532355&r2=1532356&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
Tue Oct 15 14:21:05 2013
@@ -18,9 +18,12 @@
  */
 package org.apache.directory.scim.rest;
 
+import static org.apache.directory.scim.ScimUtil.exceptionToStr;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.net.URI;
 
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
@@ -30,6 +33,7 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
@@ -40,9 +44,12 @@ import javax.ws.rs.core.UriInfo;
 import org.apache.directory.scim.MissingParameterException;
 import org.apache.directory.scim.ProviderService;
 import org.apache.directory.scim.RequestContext;
+import org.apache.directory.scim.ServerResource;
 import org.apache.directory.scim.ResourceNotFoundException;
 import org.apache.directory.scim.UserResource;
 import org.apache.directory.scim.json.ResourceSerializer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * 
@@ -53,18 +60,19 @@ public class UserService
 {
 
     private ProviderService provider = ServerInitializer.getProvider();
+
+    private static final Logger LOG = LoggerFactory.getLogger( UserService.class );
     
     @GET
     @Produces({MediaType.APPLICATION_JSON})
     @Path("{id}")
-    public Response getUser( @PathParam("id") String userId, @Context UriInfo uriInfo )
+    public Response getUser( @PathParam("id") String userId, @Context UriInfo uriInfo, @Context
HttpHeaders headers )
     {
         ResponseBuilder rb = null;
         
         try
         {
-            RequestContext ctx = new RequestContext( provider );
-            ctx.setUriInfo( uriInfo );
+            RequestContext ctx = new RequestContext( provider, uriInfo, headers );
             
             UserResource user = provider.getUser( ctx, userId );
             String json = ResourceSerializer.serialize( user );
@@ -72,7 +80,7 @@ public class UserService
         }
         catch( ResourceNotFoundException e )
         {
-            rb = Response.status( Status.INTERNAL_SERVER_ERROR );
+            rb = Response.status( Status.INTERNAL_SERVER_ERROR ).entity( exceptionToStr(
e ) );
         }
         
         return rb.build();
@@ -81,29 +89,35 @@ public class UserService
     
     @POST
     @Produces({MediaType.APPLICATION_JSON})
-    public Response addUser( String jsonData, @Context UriInfo uriInfo )
+    public Response addUser( String jsonData, @Context UriInfo uriInfo, @Context HttpHeaders
headers )
     {
         ResponseBuilder rb = null;
 
         if( ( jsonData == null ) || ( jsonData.trim().length() == 0 ) )
         {
-            rb = Response.status( Status.BAD_REQUEST ).entity( "No data is present with the
call to " + uriInfo.getPath() );
+            rb = Response.status( Status.BAD_REQUEST ).entity( "No data is present with the
call to " + uriInfo.getAbsolutePath() );
             return rb.build();
         }
         
+        LOG.debug( "Data received at the URI {}\n{}", uriInfo.getAbsolutePath(), jsonData
);
+        
         try
         {
-            RequestContext ctx = new RequestContext( provider );
-            ctx.setUriInfo( uriInfo );
+            RequestContext ctx = new RequestContext( provider, uriInfo, headers );
             
             provider.addUser( jsonData, ctx );
             
-            String json = ResourceSerializer.serialize( ctx.getCoreResource() );
-            rb = Response.ok( json, MediaType.APPLICATION_JSON );
+            ServerResource res = ctx.getCoreResource();
+            
+            String json = ResourceSerializer.serialize( res );
+            
+            URI location = uriInfo.getBaseUriBuilder().build( res.getId() );
+            
+            rb = Response.created( location ).entity( json );
         }
         catch( Exception e )
         {
-            rb = Response.status( Status.INTERNAL_SERVER_ERROR );
+            rb = Response.status( Status.INTERNAL_SERVER_ERROR ).entity( exceptionToStr(
e ) );
         }
         
         return rb.build();
@@ -147,7 +161,7 @@ public class UserService
                         }
                         catch( IOException e )
                         {
-                            rb.status( Status.INTERNAL_SERVER_ERROR );
+                            rb.status( Status.INTERNAL_SERVER_ERROR ).entity( exceptionToStr(
e ) );
                         }
                         finally
                         {
@@ -161,7 +175,7 @@ public class UserService
         }
         catch( MissingParameterException e )
         {
-            rb.status( Status.BAD_REQUEST );
+            rb.status( Status.BAD_REQUEST ).entity( exceptionToStr( e ) );
         }
         
         return rb.build();



Mime
View raw message