directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1525388 - in /directory/escimo/trunk: client/ common/src/main/java/org/apache/directory/scim/ common/src/main/java/org/apache/directory/scim/json/ common/src/main/java/org/apache/directory/scim/schema/ ldap/src/main/java/org/apache/directo...
Date Sun, 22 Sep 2013 16:25:16 GMT
Author: kayyagari
Date: Sun Sep 22 16:25:16 2013
New Revision: 1525388

URL: http://svn.apache.org/r1525388
Log:
o support for add operation (not completed yet)
o numerous improvements

Modified:
    directory/escimo/trunk/client/pom.xml
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/CoreResource.java
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/json/ResourceSerializer.java
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/schema/BaseType.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/MetaAttributeHandler.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

Modified: directory/escimo/trunk/client/pom.xml
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/client/pom.xml?rev=1525388&r1=1525387&r2=1525388&view=diff
==============================================================================
--- directory/escimo/trunk/client/pom.xml (original)
+++ directory/escimo/trunk/client/pom.xml Sun Sep 22 16:25:16 2013
@@ -24,15 +24,21 @@
     <version>1.0-SNAPSHOT</version>
   </parent>
   <artifactId>escimo-client</artifactId>
-  <packaging>jar</packaging>
-  <version>1.0-SNAPSHOT</version>
   <name>eSCIMo client</name>
 
   <dependencies>
+
    <dependency>
-    <groupId>org.apache.wink</groupId>
-    <artifactId>wink-client</artifactId>
-    <version>${wink.version}</version>
+     <groupId>org.apache.wink</groupId>
+     <artifactId>wink-client</artifactId>
+     <version>${wink.version}</version>
    </dependency>
+
+   <dependency>
+     <groupId>${project.groupId}</groupId>
+     <artifactId>escimo-common</artifactId>
+     <version>${project.version}</version>
+   </dependency>   
+   
   </dependencies>
 </project>

Modified: 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=1525388&r1=1525387&r2=1525388&view=diff
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/CoreResource.java
(original)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/CoreResource.java
Sun Sep 22 16:25:16 2013
@@ -62,4 +62,33 @@ public abstract class CoreResource
     {
         return id;
     }
+    
+    public AbstractAttribute get( String name )
+    {
+        for( List<AbstractAttribute> atList : uriAtMap.values() )
+        {
+            for( AbstractAttribute at : atList )
+            {
+                if( at.getName().equals( name ) )
+                {
+                    return at;
+                }
+            }
+        }
+        
+        return null;
+    }
+    
+    
+    public Object getVal( String name )
+    {
+        AbstractAttribute at = get( name );
+
+        if( at instanceof SimpleAttribute )
+        {
+            return ( ( SimpleAttribute ) at ).getValue();
+        }
+        
+        return null;
+    }
 }

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=1525388&r1=1525387&r2=1525388&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 Sep 22 16:25:16 2013
@@ -44,9 +44,10 @@ import com.google.gson.JsonPrimitive;
  */
 public class ResourceSerializer
 {
-    public static final String CORE_URI = "urn:scim:schemas:core:1.0";
-
-
+    public static final String CORE_USER_URI = "urn:scim:schemas:core:2.0:User";
+    public static final String CORE_GROUP_URI = "urn:scim:schemas:core:2.0:Group";
+    public static final String CORE_EXT_USER_URI = "urn:scim:schemas:extension:enterprise:2.0:User";
+    
     public static String serialize( User user )
     {
         return _serialize( user );
@@ -74,7 +75,7 @@ public class ResourceSerializer
 
             JsonObject parent = root;
 
-            if ( !uri.equals( CORE_URI ) )
+            if ( !uri.equals( CORE_USER_URI ) )
             {
                 parent = new JsonObject();
                 root.add( uri, parent );

Modified: directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/schema/BaseType.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/schema/BaseType.java?rev=1525388&r1=1525387&r2=1525388&view=diff
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/schema/BaseType.java
(original)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/schema/BaseType.java
Sun Sep 22 16:25:16 2013
@@ -20,6 +20,7 @@
 package org.apache.directory.scim.schema;
 
 import org.apache.directory.scim.json.ResourceSerializer;
+import static org.apache.directory.scim.json.ResourceSerializer.*;
 
 
 /**
@@ -76,7 +77,9 @@ public abstract class BaseType
 
     public boolean isCoreAttribute()
     {
-        return ResourceSerializer.CORE_URI.equals( uri );
+        return ( CORE_USER_URI.equals( uri ) || 
+                 CORE_GROUP_URI.equals( uri ) ||
+                 CORE_EXT_USER_URI.equals( uri ) );
     }
 
     /**

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=1525388&r1=1525387&r2=1525388&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 Sep 22 16:25:16 2013
@@ -32,21 +32,21 @@ import java.util.Iterator;
 import java.util.List;
 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.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.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.Response;
 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.SearchResultEntry;
 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.message.controls.ManageDsaITImpl;
+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;
 import org.apache.directory.api.ldap.model.schema.SyntaxChecker;
 import org.apache.directory.api.ldap.model.schema.syntaxCheckers.GeneralizedTimeSyntaxChecker;
 import org.apache.directory.api.ldap.model.schema.syntaxCheckers.IntegerSyntaxChecker;
@@ -72,7 +72,6 @@ import org.apache.directory.scim.Resourc
 import org.apache.directory.scim.SimpleAttribute;
 import org.apache.directory.scim.SimpleAttributeGroup;
 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;
@@ -86,6 +85,10 @@ import org.apache.directory.scim.util.Re
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+
 
 /**
  * TODO LdapResourceProvider.
@@ -102,6 +105,8 @@ public class LdapResourceProvider implem
 
     private GroupSchema groupSchema;
 
+    private SchemaManager ldapSchema;
+    
     private static final Logger LOG = LoggerFactory.getLogger( LdapResourceProvider.class
);
 
 
@@ -133,6 +138,7 @@ public class LdapResourceProvider implem
         schemaMapper.loadMappings();
         userSchema = schemaMapper.getUserSchema();
         groupSchema = schemaMapper.getGroupSchema();
+        ldapSchema = connection.getSchemaManager();
     }
 
 
@@ -255,7 +261,112 @@ public class LdapResourceProvider implem
 
     }
 
+    
+    public void addUser( String json )
+    {
+        JsonParser parser = new JsonParser();
+        JsonObject obj = ( JsonObject ) parser.parse( json );
+        
+        List<String> uris = userSchema.getUris();
+        for( String u : uris )
+        {
+            JsonObject userAtObj = ( JsonObject ) obj.get( u );
+        }
+    }
 
+    private void addAttributes( Entry entry, JsonObject obj )
+    {
+        for( java.util.Map.Entry<String, JsonElement> e : obj.entrySet() )
+        {
+            String name = e.getKey();
+            
+            BaseType bt = userSchema.getAttribute( name );
+            
+            if( bt == null )
+            {
+                throw new IllegalArgumentException( "Unknown attribute name "  + name + "
is present in the JSON payload" );
+            }
+            
+            String value = e.getValue().getAsString();
+        }
+    }
+    
+    
+    private void processAttributeData( BaseType bt, JsonElement el, Entry entry ) throws
LdapException
+    {
+        if( bt instanceof SimpleType )
+        {
+            SimpleType st = ( SimpleType ) bt;
+            String ldapAtName = st.getMappedTo();
+            if( Strings.isEmpty( ldapAtName ) )
+            {
+                throw new IllegalArgumentException( "Attribute " + bt.getName() + " is not
mapped to any LDAP attribute in the config" );
+            }
+            
+            AttributeType ldapType = ldapSchema.getAttributeType( ldapAtName );
+            
+            Attribute ldapAt = entry.get( ldapType );
+            if( ldapAt == null )
+            {
+                ldapAt = new DefaultAttribute( ldapAtName );
+            }
+            
+            if( !ldapType.getSyntax().isHumanReadable() )
+            {
+                byte[] value = Base64.decode( el.getAsString().toCharArray() );
+                ldapAt.add( value );
+            }
+            else
+            {
+                ldapAt.add( el.getAsString() );
+            }
+        }
+    }
+    
+    public void addUser( User user, RequestContext ctx )
+    {
+        try
+        {
+            Entry entry = new DefaultEntry();
+            
+            for( String oc : userSchema.getObjectClasses() )
+            {
+                entry.add( SchemaConstants.OBJECT_CLASS, oc );
+            }
+            
+            String dn = null;
+            
+            SimpleAttribute at = ( SimpleAttribute ) user.get( "userDn" );
+            if( at != null )
+            {
+                dn = String.valueOf( at.getValue() );
+                if( Strings.isEmpty( dn ) )
+                {
+                    dn = null;
+                }
+            }
+            
+            if( dn == null )
+            {
+                SimpleType st = ( SimpleType ) userSchema.getCoreAttribute( "userName" );
+                String userIdName = st.getMappedTo();
+
+                dn = userIdName + "=" + String.valueOf( user.getVal( "userName" ) ) + ","
+ userSchema.getBaseDn();
+            }
+            
+            if( dn != null )
+            {
+                entry.setDn( dn );
+            }
+            
+            
+        }
+        catch( LdapException e )
+        {
+            e.printStackTrace();
+        }
+    }
+    
     public User toUser( RequestContext ctx, Entry entry ) throws Exception
     {
         User user = new User();
@@ -641,14 +752,16 @@ public class LdapResourceProvider implem
 
         LdapNetworkConnection c = new LdapNetworkConnection( "localhost", 10389 );
         c.setTimeOut( Long.MAX_VALUE );
-        c.bind( "uid=admin,ou=system", "secret" );
+        c.bind( "cn=mta,dc=example,dc=com", "secret" );
+        c.loadSchema();
         //c.loadSchema( new JarLdifSchemaLoader() );
 
-        //        PersistentSearch ps = new PersistentSearchImpl();
-        //        ps.setChangesOnly( false );
-        //        ps.setReturnECs( true );
+        ManageDsaITImpl managedsa = new ManageDsaITImpl();
+        SearchRequest req = new SearchRequestImpl();
+        req.addControl( managedsa );
 
-        EntryCursor cursor = c.search( "", "(entryUUID=7ca31977-ba2d-4cdc-a86d-ba9fba06cd15)",
SearchScope.SUBTREE, "*" );
+        //EntryCursor cursor = c.search( "", "(entryUUID=7ca31977-ba2d-4cdc-a86d-ba9fba06cd15)",
SearchScope.SUBTREE, "*" );
+        EntryCursor cursor = c.search( "dc=example,dc=com", "(objectClass=*)", SearchScope.SUBTREE,
"*" );
         System.out.println("searching");
 
         while ( cursor.next() )

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=1525388&r1=1525387&r2=1525388&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 Sep 22 16:25:16 2013
@@ -151,8 +151,7 @@ public class LdapSchemaMapper implements
 
             List<Element> lstSchema = root.elements( "schema" );
             
-            List<Element> lstRef = elmUser.elements( "schemaRef" );
-            parseResourceSchema( lstRef, lstSchema, userSchema );
+            parseResourceSchema( elmUser, lstSchema, userSchema );
 
             Element elmGroup = root.element( "groupType" );
             String groupBaseDn = elmGroup.attributeValue( "baseDn" );
@@ -160,7 +159,7 @@ public class LdapSchemaMapper implements
 
             groupSchema = new GroupSchema( groupBaseDn, groupFilter );
             List<Element> lstGroupRef = elmGroup.elements( "schemaRef" );
-            parseResourceSchema( lstGroupRef, lstSchema, groupSchema );
+            parseResourceSchema( elmGroup, lstSchema, groupSchema );
         }
         catch ( Exception e )
         {
@@ -184,8 +183,17 @@ public class LdapSchemaMapper implements
     }
 
 
-    private void parseResourceSchema( List<Element> lstRef, List<Element> lstSchema,
ResourceSchema resourceSchema )
+    private void parseResourceSchema( Element elmResourceSchema, List<Element> lstSchema,
ResourceSchema resourceSchema )
     {
+        Element elmObjectClass = elmResourceSchema.element( "objectClasses" );
+        List<Element> elmOcs = elmObjectClass.elements( "objectClass" );
+        for( Element el : elmOcs )
+        {
+            resourceSchema.addObjectClass( el.getText() );
+        }
+        
+        List<Element> lstRef = elmResourceSchema.elements( "schemaRef" );
+        
         for ( Element ref : lstRef )
         {
             String refId = ref.attributeValue( "id" );

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=1525388&r1=1525387&r2=1525388&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
Sun Sep 22 16:25:16 2013
@@ -22,8 +22,6 @@ package org.apache.directory.scim.ldap.h
 import java.util.ArrayList;
 import java.util.List;
 
-import javax.ws.rs.core.PathSegment;
-
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
 import org.apache.directory.api.ldap.model.entry.Attribute;
 import org.apache.directory.api.ldap.model.entry.Entry;
@@ -31,9 +29,9 @@ import org.apache.directory.api.ldap.mod
 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.RequestContext;
 import org.apache.directory.scim.SimpleAttribute;
-import org.apache.directory.scim.User;
 import org.apache.directory.scim.schema.BaseType;
 import org.apache.directory.scim.util.ResourceUtil;
 import org.slf4j.Logger;
@@ -86,17 +84,27 @@ public class MetaAttributeHandler implem
                 atList.add( lastModified );
             }
 
-            CoreResource user = ctx.getCoreResource();
+            CoreResource resource = ctx.getCoreResource();
+            
+            String resourceType = "User";
+            
+            if( resource instanceof Group )
+            {
+                resourceType = "Group";
+            }
+            
+            SimpleAttribute resourceTypeAt = new SimpleAttribute( "resourceType", resourceType
);
+            atList.add( resourceTypeAt );
             
             SimpleAttribute location = new SimpleAttribute( "location" );
             String locationVal = ctx.getUriInfo().getBaseUri().toString();
-            locationVal = locationVal + "Users/" + user.getId();
+            locationVal = locationVal + resourceType + "s/" + resource.getId();
             
             location.setValue( locationVal );
             atList.add( location );
             
             ComplexAttribute ct = new ComplexAttribute( bt.getName(), atList );
-            user.addAttribute( bt.getUri(), ct );
+            resource.addAttribute( bt.getUri(), ct );
         }
         catch( LdapException e )
         {

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=1525388&r1=1525387&r2=1525388&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
Sun Sep 22 16:25:16 2013
@@ -51,14 +51,16 @@ public abstract class ResourceSchema
 
     private Map<String, AttributeHandler> atHandlers = new HashMap<String, AttributeHandler>();
 
+    private List<String> objectClasses = new ArrayList<String>();
+
 
     public ResourceSchema( String baseDn, String filter )
     {
-        if( Strings.isEmpty( baseDn ) )
+        if ( Strings.isEmpty( baseDn ) )
         {
             baseDn = ""; // RootDSE
         }
-        
+
         this.baseDn = baseDn;
         this.filter = filter;
     }
@@ -76,6 +78,19 @@ public abstract class ResourceSchema
     }
 
 
+    public BaseType getAttribute( String name )
+    {
+        BaseType bt = coreTypes.get( name );
+       
+        if ( bt == null )
+        {
+            bt = extendedTypes.get( name );
+        }
+
+        return bt;
+    }
+
+
     public void addAttributeType( String name, BaseType type )
     {
         if ( type != null )
@@ -128,6 +143,21 @@ public abstract class ResourceSchema
     }
 
 
+    public void addObjectClass( String oc )
+    {
+        objectClasses.add( oc );
+    }
+
+
+    /**
+     * @return the objectClasses
+     */
+    public List<String> getObjectClasses()
+    {
+        return Collections.unmodifiableList( objectClasses );
+    }
+
+
     /**
      * @return the baseDn
      */
@@ -145,4 +175,9 @@ public abstract class ResourceSchema
         return filter;
     }
 
+
+    public List<String> getUris()
+    {
+        return new ArrayList<String>( uris );
+    }
 }

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=1525388&r1=1525387&r2=1525388&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 Sun Sep 22 16:25:16
2013
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 <entities>
     <!-- Core User resource schema -->
-    <schema id="user-core" uri="urn:scim:schemas:core:1.0">
+    <schema id="user-core" uri="urn:scim:schemas:core:2.0:User">
         <attribute name="id" mappedTo="entryUUID" />
         <attribute name="userName" mappedTo="uid" />
         <attribute name="displayName" mappedTo="displayName" />
@@ -89,7 +89,7 @@
     </schema>
 
     <!-- Enterprise User resource schema -->
-    <schema id="enterprise-user" uri="urn:scim:schemas:extension:enterprise:1.0">
+    <schema id="enterprise-user" uri="urn:scim:schemas:extension:enterprise:2.0:User">
         <attribute name="employeeNumber" mappedTo="" />
         <attribute name="costCenter" mappedTo="" />
         <attribute name="organization" mappedTo="" />
@@ -105,15 +105,19 @@
         </complex-attribute>
     </schema>
 
-    <schema id="group" uri="urn:scim:schemas:core:1.0">
+    <schema id="group" uri="urn:scim:schemas:core:2.0:Group">
         <attribute name="displayName" mappedTo="cn" />
         <attribute name="id" mappedTo="entryUUID" />
         <multival-attribute name="members" handlerRef="membersHandler"/>
+        <complex-attribute name="meta" handlerRef="metaHandler" />
     </schema>
 
     <userType baseDn="" filter="(objectClass = inetOrgPerson)">
         <schemaRef id="user-core" />
         <schemaRef id="enterprise-user" />
+        <objectClasses>
+         <objectClass>inetOrgPerson</objectClass>
+        </objectClasses>
     </userType>
 
     <groupType baseDn="" filter="(objectClass = inetOrgPerson)">



Mime
View raw message