directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1513911 - 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 Wed, 14 Aug 2013 14:46:25 GMT
Author: kayyagari
Date: Wed Aug 14 14:46:24 2013
New Revision: 1513911

URL: http://svn.apache.org/r1513911
Log:
o support for Groups service
o a bit of refactoring

Added:
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/CoreResource.java
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/Group.java
    directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/GroupService.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/RequestContext.java
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/User.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/LdapSchemaMapper.java
    directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/ActiveAttributeHandler.java
    directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/GroupsAttributeHandler.java
    directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MembersAttributeHandler.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/resources/escimo-ldap-mapping.xml
    directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/EscimoApplication.java

Added: directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/CoreResource.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/CoreResource.java?rev=1513911&view=auto
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/CoreResource.java
(added)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/CoreResource.java
Wed Aug 14 14:46:24 2013
@@ -0,0 +1,65 @@
+/*
+ *   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.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * TODO CoreResource.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public abstract class CoreResource
+{
+    private Map<String,List<AbstractAttribute>> uriAtMap = new HashMap<String,
List<AbstractAttribute>>();
+    
+    private String id;
+    
+    public void addAttribute( String uri, AbstractAttribute at )
+    {
+        List<AbstractAttribute> atList = uriAtMap.get( uri );
+        
+        if( atList == null )
+        {
+            atList = new ArrayList<AbstractAttribute>();
+            uriAtMap.put( uri, atList );
+        }
+        
+        atList.add( at );
+    }
+
+    public Map<String,List<AbstractAttribute>> getAttributes()
+    {
+        return uriAtMap;
+    }
+
+    public void setId( String id )
+    {
+        this.id = id;
+    }
+
+    public String getId()
+    {
+        return id;
+    }
+}

Added: directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/Group.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/Group.java?rev=1513911&view=auto
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/Group.java (added)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/Group.java Wed Aug
14 14:46:24 2013
@@ -0,0 +1,36 @@
+/*
+ *   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;
+
+
+/**
+ * TODO Group.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class Group extends CoreResource
+{
+    @Override
+    public String toString()
+    {
+        return "Group [attributes=" + super.getAttributes() + "]";
+    }
+    
+}

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=1513911&r1=1513910&r2=1513911&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
Wed Aug 14 14:46:24 2013
@@ -33,4 +33,6 @@ public interface ProviderService 
     User getUser( RequestContext ctx, String userId ) throws ResourceNotFoundException;
     
     InputStream getUserPhoto( String id, String atName ) throws MissingParameterException;
+    
+    Group getGroup( RequestContext ctx, String groupId ) throws ResourceNotFoundException;
 }

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=1513911&r1=1513910&r2=1513911&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
Wed Aug 14 14:46:24 2013
@@ -34,7 +34,7 @@ public class RequestContext
 
     private UriInfo uriInfo;
 
-    private User user;
+    private CoreResource resource;
 
 
     public RequestContext( ProviderService providerService )
@@ -43,15 +43,15 @@ public class RequestContext
     }
 
 
-    public User getUser()
+    public CoreResource getCoreResource()
     {
-        return user;
+        return resource;
     }
 
 
-    public void setUser( User user )
+    public void setCoreResource( CoreResource resource )
     {
-        this.user = user;
+        this.resource = resource;
     }
 
 

Modified: directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/User.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/User.java?rev=1513911&r1=1513910&r2=1513911&view=diff
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/User.java (original)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/User.java Wed Aug
14 14:46:24 2013
@@ -19,54 +19,18 @@
  */
 package org.apache.directory.scim;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
 
 /**
  * TODO User.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class User
+public class User extends CoreResource
 {
-    private Map<String,List<AbstractAttribute>> uriAtMap = new HashMap<String,
List<AbstractAttribute>>();
-    
-    private String id;
-    
-    public void addAttribute( String uri, AbstractAttribute at )
-    {
-        List<AbstractAttribute> atList = uriAtMap.get( uri );
-        
-        if( atList == null )
-        {
-            atList = new ArrayList<AbstractAttribute>();
-            uriAtMap.put( uri, atList );
-        }
-        
-        atList.add( at );
-    }
-
-    public Map<String,List<AbstractAttribute>> getAttributes()
-    {
-        return uriAtMap;
-    }
-
-    public void setId( String id )
-    {
-        this.id = id;
-    }
-
-    public String getId()
-    {
-        return id;
-    }
-
     @Override
     public String toString()
     {
-        return "User [uriAtMap=" + uriAtMap + "]";
+        return "User [attributes=" + super.getAttributes() + "]";
     }
     
 }

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=1513911&r1=1513910&r2=1513911&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
Wed Aug 14 14:46:24 2013
@@ -25,6 +25,8 @@ import java.util.Map;
 
 import org.apache.directory.scim.AbstractAttribute;
 import org.apache.directory.scim.ComplexAttribute;
+import org.apache.directory.scim.CoreResource;
+import org.apache.directory.scim.Group;
 import org.apache.directory.scim.MultiValAttribute;
 import org.apache.directory.scim.SimpleAttribute;
 import org.apache.directory.scim.SimpleAttributeGroup;
@@ -43,31 +45,44 @@ import com.google.gson.JsonPrimitive;
 public class ResourceSerializer
 {
     public static final String CORE_URI = "urn:scim:schemas:core:1.0";
-    
+
+
     public static String serialize( User user )
     {
+        return _serialize( user );
+    }
+
+
+    public static String serialize( Group group )
+    {
+        return _serialize( group );
+    }
+
+
+    private static String _serialize( CoreResource resource )
+    {
         JsonObject root = new JsonObject();
 
-        Map<String, List<AbstractAttribute>> attributes = user.getAttributes();
-        
+        Map<String, List<AbstractAttribute>> attributes = resource.getAttributes();
+
         JsonArray schemas = new JsonArray();
         root.add( "schemas", schemas );
-        
+
         for ( String uri : attributes.keySet() )
         {
             schemas.add( new JsonPrimitive( uri ) );
-            
+
             JsonObject parent = root;
-            
-            if( !uri.equals( CORE_URI ) )
+
+            if ( !uri.equals( CORE_URI ) )
             {
                 parent = new JsonObject();
                 root.add( uri, parent );
             }
-            
+
             serialize( parent, attributes.get( uri ) );
         }
-        
+
         return root.toString();
     }
 
@@ -91,31 +106,31 @@ public class ResourceSerializer
         {
             ComplexAttribute ct = ( ComplexAttribute ) at;
             JsonObject json = new JsonObject();
-            for( SimpleAttribute t : ct.getAtList() )
+            for ( SimpleAttribute t : ct.getAtList() )
             {
                 serializeSimpleAt( json, t );
             }
-            
+
             parent.add( ct.getName(), json );
         }
         else if ( at instanceof MultiValAttribute )
         {
             MultiValAttribute mv = ( MultiValAttribute ) at;
             List<SimpleAttributeGroup> lstGrp = mv.getAtGroupList();
-            
+
             JsonArray array = new JsonArray();
-            
-            for( SimpleAttributeGroup stg : lstGrp )
+
+            for ( SimpleAttributeGroup stg : lstGrp )
             {
                 JsonObject json = new JsonObject();
-                for( SimpleAttribute t : stg.getAtList() )
+                for ( SimpleAttribute t : stg.getAtList() )
                 {
                     serializeSimpleAt( json, t );
                 }
-                
+
                 array.add( json );
             }
-            
+
             parent.add( mv.getName(), array );
         }
     }

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=1513911&r1=1513910&r2=1513911&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
Wed Aug 14 14:46:24 2013
@@ -34,7 +34,6 @@ import java.util.Properties;
 
 import org.apache.directory.api.ldap.codec.standalone.StandaloneLdapApiService;
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
-import org.apache.directory.api.ldap.model.cursor.CursorException;
 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;
@@ -63,6 +62,8 @@ 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.CoreResource;
+import org.apache.directory.scim.Group;
 import org.apache.directory.scim.MissingParameterException;
 import org.apache.directory.scim.MultiValAttribute;
 import org.apache.directory.scim.ProviderService;
@@ -73,7 +74,9 @@ import org.apache.directory.scim.SimpleA
 import org.apache.directory.scim.User;
 import org.apache.directory.scim.json.ResourceSerializer;
 import org.apache.directory.scim.ldap.schema.ComplexType;
+import org.apache.directory.scim.ldap.schema.GroupSchema;
 import org.apache.directory.scim.ldap.schema.MultiValType;
+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;
@@ -93,10 +96,12 @@ public class LdapResourceProvider implem
 {
     private LdapConnection connection;
 
-    private LdapSchemaMapper schema;
+    private LdapSchemaMapper schemaMapper;
 
     private UserSchema userSchema;
 
+    private GroupSchema groupSchema;
+
     private static final Logger LOG = LoggerFactory.getLogger( LdapResourceProvider.class
);
 
 
@@ -124,16 +129,17 @@ public class LdapResourceProvider implem
             ( ( LdapNetworkConnection ) connection ).loadSchema( new JarLdifSchemaLoader()
);
         }
 
-        schema = new LdapSchemaMapper();
-        schema.loadMappings();
-        userSchema = schema.getUserSchema();
+        schemaMapper = new LdapSchemaMapper();
+        schemaMapper.loadMappings();
+        userSchema = schemaMapper.getUserSchema();
+        groupSchema = schemaMapper.getGroupSchema();
     }
 
 
     public void stop()
     {
         LOG.info( "Closing the LDAP server connection" );
-        
+
         if ( connection != null )
         {
             try
@@ -151,7 +157,7 @@ public class LdapResourceProvider implem
     private void createConnection() throws IOException, LdapException
     {
         LOG.info( "Creating LDAP server connection" );
-        
+
         InputStream in = this.getClass().getClassLoader().getResourceAsStream( "ldap-server.properties"
);
         Properties prop = new Properties();
         prop.load( in );
@@ -177,7 +183,7 @@ public class LdapResourceProvider implem
 
     public User getUser( RequestContext ctx, String id ) throws ResourceNotFoundException
     {
-        Entry entry = fetchEntryById( id );
+        Entry entry = fetchEntryById( id, userSchema );
 
         if ( entry == null )
         {
@@ -198,61 +204,102 @@ public class LdapResourceProvider implem
     @Override
     public InputStream getUserPhoto( String id, String atName ) throws MissingParameterException
     {
-        if( Strings.isEmpty( id ) )
+        if ( Strings.isEmpty( id ) )
         {
             throw new MissingParameterException( "id cannot be null or empty" );
         }
-        
-        if( Strings.isEmpty( atName ) )
+
+        if ( Strings.isEmpty( atName ) )
         {
             throw new MissingParameterException( "atName cannot be null or empty" );
         }
 
-        Entry entry = fetchEntryById( id );
-        
-        if( entry == null )
+        Entry entry = fetchEntryById( id, userSchema );
+
+        if ( entry == null )
         {
             return null;
         }
-        
+
         Attribute phtoAt = entry.get( atName );
-        
-        if( phtoAt == null )
+
+        if ( phtoAt == null )
         {
             return null;
         }
-        
+
         ByteArrayInputStream bin = new ByteArrayInputStream( phtoAt.get().getBytes() );
-        
+
         return bin;
     }
 
 
-    public User toUser( RequestContext ctx, Entry entry ) throws Exception
+    @Override
+    public Group getGroup( RequestContext ctx, String groupId ) throws ResourceNotFoundException
     {
+        Entry entry = fetchEntryById( groupId, groupSchema );
+
+        if ( entry == null )
+        {
+            throw new ResourceNotFoundException( "No Group resource found with the ID " +
groupId );
+        }
+
+        try
+        {
+            return toGroup( ctx, entry );
+        }
+        catch ( Exception e )
+        {
+            throw new ResourceNotFoundException( e );
+        }
+
+    }
+
 
+    public User toUser( RequestContext ctx, Entry entry ) throws Exception
+    {
         User user = new User();
 
-        ctx.setUser( user );
-        
+        ctx.setCoreResource( user );
+
+        _loadCoreResource( ctx, entry, userSchema );
+
+        return user;
+    }
+
+
+    public Group toGroup( RequestContext ctx, Entry entry ) throws Exception
+    {
+        Group group = new Group();
+        ctx.setCoreResource( group );
+
+        _loadCoreResource( ctx, entry, groupSchema );
+
+        return group;
+    }
+
+
+    private void _loadCoreResource( RequestContext ctx, Entry entry, ResourceSchema resourceSchema
) throws Exception
+    {
+        CoreResource resource = ctx.getCoreResource();
+
         // first fill in the id, we need this for deriving location
-        SimpleType idType = ( SimpleType ) userSchema.getCoreAttribute( "id" );
+        SimpleType idType = ( SimpleType ) resourceSchema.getCoreAttribute( "id" );
         SimpleAttribute idAttribute = getValueForSimpleType( idType, entry, ctx );
-        user.addAttribute( idType.getUri(), idAttribute );
-        
-        user.setId( ( String ) idAttribute.getValue() );
-        
-        _loadAttributes( ctx, entry, userSchema.getCoreTypes(), idType );
-        _loadAttributes( ctx, entry, userSchema.getExtendedTypes(), idType );
-        
-        return user;
+        resource.addAttribute( idType.getUri(), idAttribute );
+
+        resource.setId( ( String ) idAttribute.getValue() );
+
+        _loadAttributes( ctx, entry, resourceSchema.getCoreTypes(), idType );
+        _loadAttributes( ctx, entry, resourceSchema.getExtendedTypes(), idType );
     }
-    
-    
-    private User _loadAttributes( RequestContext ctx, Entry entry, Collection<BaseType>
types, SimpleType idType ) throws Exception
+
+
+    private void _loadAttributes( RequestContext ctx, Entry entry, Collection<BaseType>
types, SimpleType idType )
+        throws Exception
     {
-        User user = ctx.getUser();
-        
+        CoreResource user = ctx.getCoreResource();
+
         for ( BaseType bt : types )
         {
             if ( bt instanceof SimpleType )
@@ -265,11 +312,11 @@ public class LdapResourceProvider implem
                 }
 
                 // skip id attribute, it was already added above
-                if( st == idType )
+                if ( st == idType )
                 {
                     continue;
                 }
-                
+
                 SimpleAttribute at = getValueForSimpleType( st, entry, ctx );
                 if ( at != null )
                 {
@@ -286,8 +333,8 @@ public class LdapResourceProvider implem
                 }
 
                 String atHandler = ct.getAtHandlerName();
-                
-                if( atHandler != null )
+
+                if ( atHandler != null )
                 {
                     AttributeHandler handler = userSchema.getHandler( atHandler );
                     handler.handle( ct, entry, ctx );
@@ -312,8 +359,8 @@ public class LdapResourceProvider implem
                 }
 
                 String atHandler = bt.getAtHandlerName();
-                
-                if( atHandler != null )
+
+                if ( atHandler != null )
                 {
                     AttributeHandler handler = userSchema.getHandler( atHandler );
                     handler.handle( bt, entry, ctx );
@@ -360,8 +407,6 @@ public class LdapResourceProvider implem
                 }
             }
         }
-
-        return user;
     }
 
 
@@ -426,8 +471,8 @@ public class LdapResourceProvider implem
     public SimpleAttribute getValueForSimpleType( SimpleType st, Entry entry, RequestContext
ctx ) throws LdapException
     {
         String atHandler = st.getAtHandlerName();
-        
-        if( atHandler != null )
+
+        if ( atHandler != null )
         {
             AttributeHandler handler = userSchema.getHandler( atHandler );
             handler.handle( st, entry, ctx );
@@ -438,7 +483,8 @@ public class LdapResourceProvider implem
             return getValueForSimpleType( st, entry );
         }
     }
-    
+
+
     public SimpleAttribute getValueForSimpleType( SimpleType st, Entry entry ) throws LdapException
     {
         String name = st.getName();
@@ -489,29 +535,28 @@ public class LdapResourceProvider implem
     }
 
 
+    //    public List<SimpleAttribute> getValuesInto( SimpleTypeGroup stg, RequestContext
ctx ) throws LdapException
+    //    {
+    //        
+    //    }
 
-//    public List<SimpleAttribute> getValuesInto( SimpleTypeGroup stg, RequestContext
ctx ) throws LdapException
-//    {
-//        
-//    }
-    
     public List<SimpleAttribute> getValuesInto( SimpleTypeGroup stg, Entry entry )
throws LdapException
     {
         List<SimpleAttribute> lstAts = new ArrayList<SimpleAttribute>();
 
         // format="$givenName $familyName"
         boolean hasFormat = !Strings.isEmpty( stg.getFormat() );
-        
+
         String format = stg.getFormat();
-        
+
         for ( SimpleType st : stg.getLstSTypes() )
         {
             SimpleAttribute at = getValueForSimpleType( st, entry );
             if ( at != null )
             {
                 lstAts.add( at );
-                
-                if( hasFormat )
+
+                if ( hasFormat )
                 {
                     format = format.replaceAll( "\\$" + st.getName(), String.valueOf( at.getValue()
) );
                 }
@@ -519,12 +564,12 @@ public class LdapResourceProvider implem
 
         }
 
-        if( hasFormat )
+        if ( hasFormat )
         {
             SimpleAttribute atFormat = new SimpleAttribute( "formatted", format );
             lstAts.add( atFormat );
         }
-        
+
         return lstAts;
 
     }
@@ -542,28 +587,29 @@ public class LdapResourceProvider implem
         {
             return connection.lookup( dn, ALL_ATTRIBUTES_ARRAY );
         }
-        catch( LdapException e )
+        catch ( LdapException e )
         {
             LOG.debug( "Couldn't find the entry with dn {}", dn, e );
         }
-        
+
         return null;
     }
-    
-    public Entry fetchEntryById( String id )
+
+
+    public Entry fetchEntryById( String id, ResourceSchema resourceSchema )
     {
         EntryCursor cursor = null;
-        
-        SimpleType st = ( SimpleType ) userSchema.getCoreAttribute( "id" );
-        String userIdName = st.getMappedTo();
 
-        String filter = "(" + userIdName + "=" + id + ")";
+        SimpleType st = ( SimpleType ) resourceSchema.getCoreAttribute( "id" );
+        String resourceIdName = st.getMappedTo();
+
+        String filter = "(" + resourceIdName + "=" + id + ")";
 
         Entry entry = null;
 
         try
         {
-            cursor = connection.search( userSchema.getBaseDn(), filter, SUBTREE, ALL_ATTRIBUTES_ARRAY
);
+            cursor = connection.search( resourceSchema.getBaseDn(), filter, SUBTREE, ALL_ATTRIBUTES_ARRAY
);
 
             if ( cursor.next() )
             {
@@ -578,52 +624,40 @@ public class LdapResourceProvider implem
         {
             cursor.close();
         }
-        
+
         return entry;
     }
-    
-    
+
+
     public static void main( String[] args ) throws Exception
     {
-        System.setProperty( StandaloneLdapApiService.CONTROLS_LIST,
-            "org.apache.directory.api.ldap.codec.controls.cascade.CascadeFactory," +
-                "org.apache.directory.api.ldap.codec.controls.manageDsaIT.ManageDsaITFactory,"
+
-                "org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeFactory,"
+
-                "org.apache.directory.api.ldap.codec.controls.search.pagedSearch.PagedResultsFactory,"
+
-                "org.apache.directory.api.ldap.codec.controls.search.persistentSearch.PersistentSearchFactory,"
+
-                "org.apache.directory.api.ldap.codec.controls.search.subentries.SubentriesFactory"
);
+//        System.setProperty( StandaloneLdapApiService.CONTROLS_LIST,
+//            "org.apache.directory.api.ldap.codec.controls.cascade.CascadeFactory," +
+//                "org.apache.directory.api.ldap.codec.controls.manageDsaIT.ManageDsaITFactory,"
+
+//                "org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeFactory,"
+
+//                "org.apache.directory.api.ldap.codec.controls.search.pagedSearch.PagedResultsFactory,"
+
+//                "org.apache.directory.api.ldap.codec.controls.search.persistentSearch.PersistentSearchFactory,"
+
+//                "org.apache.directory.api.ldap.codec.controls.search.subentries.SubentriesFactory"
);
 
         LdapNetworkConnection c = new LdapNetworkConnection( "localhost", 10389 );
         c.setTimeOut( Long.MAX_VALUE );
         c.bind( "uid=admin,ou=system", "secret" );
-        c.loadSchema( new JarLdifSchemaLoader() );
+        //c.loadSchema( new JarLdifSchemaLoader() );
 
         //        PersistentSearch ps = new PersistentSearchImpl();
         //        ps.setChangesOnly( false );
         //        ps.setReturnECs( true );
 
-        SearchRequest searchRequest = new SearchRequestImpl().setBase( new Dn(
-            "uid=kirana,ou=users,dc=signon,dc=mirth,dc=com" ) ).setFilter( "(objectclass=*)"
).setScope(
-            SearchScope.OBJECT );
-        searchRequest.addAttributes( SchemaConstants.ALL_ATTRIBUTES_ARRAY );
-
-        SearchCursor cursor = c.search( searchRequest );
+        EntryCursor cursor = c.search( "", "(entryUUID=7ca31977-ba2d-4cdc-a86d-ba9fba06cd15)",
SearchScope.SUBTREE, "*" );
+        System.out.println("searching");
 
-        Entry entry = null;
         while ( cursor.next() )
         {
-            Response response = cursor.get();
-            SearchResultEntry se = ( SearchResultEntry ) response;
-            entry = se.getEntry();
+            Entry entry = cursor.get();
+            System.out.println( entry );
         }
 
         cursor.close();
-
-        System.out.println( entry );
-        LdapResourceProvider lr = new LdapResourceProvider( c );
-        User user = lr.toUser( new RequestContext( lr ), entry );
-        System.out.println( user );
-        System.out.println( ResourceSerializer.serialize( user ) );
         c.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=1513911&r1=1513910&r2=1513911&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
Wed Aug 14 14:46:24 2013
@@ -158,7 +158,7 @@ public class LdapSchemaMapper implements
             String groupBaseDn = elmGroup.attributeValue( "baseDn" );
             String groupFilter = elmGroup.attributeValue( "filter" );
 
-            groupSchema = new GroupSchema( baseDn, filter );
+            groupSchema = new GroupSchema( groupBaseDn, groupFilter );
             List<Element> lstGroupRef = elmGroup.elements( "schemaRef" );
             parseResourceSchema( lstGroupRef, lstSchema, groupSchema );
         }

Modified: directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/ActiveAttributeHandler.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/ActiveAttributeHandler.java?rev=1513911&r1=1513910&r2=1513911&view=diff
==============================================================================
--- directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/ActiveAttributeHandler.java
(original)
+++ directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/ActiveAttributeHandler.java
Wed Aug 14 14:46:24 2013
@@ -75,7 +75,7 @@ public class ActiveAttributeHandler impl
             st = new SimpleAttribute( bt.getName(), Boolean.TRUE );
         }
         
-        ctx.getUser().addAttribute( bt.getUri(), st );
+        ctx.getCoreResource().addAttribute( bt.getUri(), st );
     }
 
     }

Modified: directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/GroupsAttributeHandler.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/GroupsAttributeHandler.java?rev=1513911&r1=1513910&r2=1513911&view=diff
==============================================================================
--- directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/GroupsAttributeHandler.java
(original)
+++ directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/GroupsAttributeHandler.java
Wed Aug 14 14:46:24 2013
@@ -123,7 +123,7 @@ public class GroupsAttributeHandler impl
                 }
             }
 
-            ctx.getUser().addAttribute( bt.getUri(), mv );
+            ctx.getCoreResource().addAttribute( bt.getUri(), mv );
         }
     }
 

Modified: directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MembersAttributeHandler.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MembersAttributeHandler.java?rev=1513911&r1=1513910&r2=1513911&view=diff
==============================================================================
--- directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MembersAttributeHandler.java
(original)
+++ directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MembersAttributeHandler.java
Wed Aug 14 14:46:24 2013
@@ -102,7 +102,7 @@ public class MembersAttributeHandler imp
         if ( !lstAtGroup.isEmpty() )
         {
             MultiValAttribute mv = new MultiValAttribute( bt.getName(), lstAtGroup );
-            ctx.getUser().addAttribute( bt.getUri(), mv );
+            ctx.getCoreResource().addAttribute( bt.getUri(), mv );
         }
     }
 

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=1513911&r1=1513910&r2=1513911&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
Wed Aug 14 14:46:24 2013
@@ -30,6 +30,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.CoreResource;
 import org.apache.directory.scim.RequestContext;
 import org.apache.directory.scim.SimpleAttribute;
 import org.apache.directory.scim.User;
@@ -85,7 +86,7 @@ public class MetaAttributeHandler implem
                 atList.add( lastModified );
             }
 
-            User user = ctx.getUser();
+            CoreResource user = ctx.getCoreResource();
             
             SimpleAttribute location = new SimpleAttribute( "location" );
             String locationVal = ctx.getUriInfo().getBaseUri().toString();

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=1513911&r1=1513910&r2=1513911&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
Wed Aug 14 14:46:24 2013
@@ -27,6 +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.CoreResource;
 import org.apache.directory.scim.MultiValAttribute;
 import org.apache.directory.scim.RequestContext;
 import org.apache.directory.scim.SimpleAttribute;
@@ -62,7 +63,7 @@ public class PhotosAttributeHandler impl
             return;
         }
 
-        User user = ctx.getUser();
+        CoreResource user = ctx.getCoreResource();
 
         Entry entry = ( Entry ) srcResource;
 
@@ -126,7 +127,7 @@ public class PhotosAttributeHandler impl
     }
 
 
-    private SimpleAttribute getPhotoUrlValue( SimpleTypeGroup stg, Entry entry, String photoUrlBase,
User user )
+    private SimpleAttribute getPhotoUrlValue( SimpleTypeGroup stg, Entry entry, String photoUrlBase,
CoreResource 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=1513911&r1=1513910&r2=1513911&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
Wed Aug 14 14:46:24 2013
@@ -28,6 +28,7 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.directory.api.util.Strings;
 import org.apache.directory.scim.AttributeHandler;
 import org.apache.directory.scim.schema.BaseType;
 
@@ -53,6 +54,11 @@ public abstract class ResourceSchema
 
     public ResourceSchema( String baseDn, String filter )
     {
+        if( Strings.isEmpty( baseDn ) )
+        {
+            baseDn = ""; // RootDSE
+        }
+        
         this.baseDn = baseDn;
         this.filter = filter;
     }

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=1513911&r1=1513910&r2=1513911&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 Wed Aug 14 14:46:24
2013
@@ -71,7 +71,7 @@
             </type>
         </multival-attribute>
 
-        <multival-attribute name="groups" basedDn="ou=system"
+        <multival-attribute name="groups" baseDn="ou=system"
             filter="(uniqueMember = $entryDn)" handlerRef="groupsHandler" />
 
         <multival-attribute name="entitlements" />
@@ -111,12 +111,12 @@
         <multival-attribute name="members" handlerRef="membersHandler"/>
     </schema>
 
-    <userType basedDn="ou=system" filter="(objectClass = inetOrgPerson)">
+    <userType baseDn="" filter="(objectClass = inetOrgPerson)">
         <schemaRef id="user-core" />
         <schemaRef id="enterprise-user" />
     </userType>
 
-    <groupType basedDn="ou=system" filter="(objectClass = inetOrgPerson)">
+    <groupType baseDn="" filter="(objectClass = inetOrgPerson)">
         <schemaRef id="group" />
     </groupType>
 

Modified: directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/EscimoApplication.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/EscimoApplication.java?rev=1513911&r1=1513910&r2=1513911&view=diff
==============================================================================
--- directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/EscimoApplication.java
(original)
+++ directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/EscimoApplication.java
Wed Aug 14 14:46:24 2013
@@ -37,6 +37,7 @@ public class EscimoApplication extends A
     public EscimoApplication()
     {
         resources.add( UserService.class );
+        resources.add( GroupService.class );
     }
     
     @Override

Added: 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=1513911&view=auto
==============================================================================
--- directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/GroupService.java
(added)
+++ directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/GroupService.java
Wed Aug 14 14:46:24 2013
@@ -0,0 +1,75 @@
+/*
+ *   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.rest;
+
+
+import javax.ws.rs.GET;
+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.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.directory.scim.Group;
+import org.apache.directory.scim.ProviderService;
+import org.apache.directory.scim.RequestContext;
+import org.apache.directory.scim.ResourceNotFoundException;
+import org.apache.directory.scim.json.ResourceSerializer;
+
+
+/**
+ * TODO GroupService.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@Path( "Groups" )
+public class GroupService
+{
+    private ProviderService provider = ServerInitializer.getProvider();
+    
+    @GET
+    @Produces({MediaType.APPLICATION_JSON})
+    @Path("{id}")
+    public Response getUser( @PathParam("id") String userId, @Context UriInfo uriInfo )
+    {
+        ResponseBuilder rb = null;
+        
+        try
+        {
+            RequestContext ctx = new RequestContext( provider );
+            ctx.setUriInfo( uriInfo );
+            
+            Group group = provider.getGroup( ctx, userId );
+            String json = ResourceSerializer.serialize( group );
+            rb = Response.ok( json, MediaType.APPLICATION_JSON );
+        }
+        catch( ResourceNotFoundException e )
+        {
+            rb = Response.status( Status.INTERNAL_SERVER_ERROR );
+        }
+        
+        return rb.build();
+    }
+
+}



Mime
View raw message