directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1648206 - in /directory/escimo/trunk: common/src/main/java/org/apache/directory/scim/ json2java/src/main/java/org/apache/directory/scim/ ldap/src/main/java/org/apache/directory/scim/ldap/ schema/src/main/java/org/apache/directory/scim/sche...
Date Sun, 28 Dec 2014 14:06:31 GMT
Author: kayyagari
Date: Sun Dec 28 14:06:30 2014
New Revision: 1648206

URL: http://svn.apache.org/r1648206
Log:
o serve resource provider configuration
o minor improvements

Modified:
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ScimUtil.java
    directory/escimo/trunk/json2java/src/main/java/org/apache/directory/scim/JsonToJava.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/schema/src/main/java/org/apache/directory/scim/schema/JsonSchema.java
    directory/escimo/trunk/schema/src/main/java/org/apache/directory/scim/schema/SchemaUtil.java
    directory/escimo/trunk/schema/src/main/resources/serviceproviderconfig-schema.json
    directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/MetaSchemaService.java

Modified: directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ScimUtil.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ScimUtil.java?rev=1648206&r1=1648205&r2=1648206&view=diff
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ScimUtil.java (original)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ScimUtil.java Sun
Dec 28 14:06:30 2014
@@ -20,9 +20,6 @@ package org.apache.directory.scim;
 
 
 import static org.apache.directory.scim.schema.ErrorCode.*;
-import static org.apache.directory.scim.schema.ErrorCode.CONFLICT;
-import static org.apache.directory.scim.schema.ErrorCode.INTERNAL_SERVER_ERROR;
-import static org.apache.directory.scim.schema.ErrorCode.NOT_FOUND;
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
@@ -34,6 +31,7 @@ import org.apache.directory.scim.json.Re
 import org.apache.directory.scim.schema.ErrorCode;
 import org.apache.directory.scim.schema.ErrorResponse;
 import org.apache.directory.scim.schema.ErrorResponse.ScimError;
+import org.apache.directory.scim.schema.SchemaUtil;
 
 /**
  * 
@@ -41,10 +39,6 @@ import org.apache.directory.scim.schema.
  */
 public class ScimUtil
 {
-    public static final String CORE_USER_URI = "urn:ietf:params:scim:schemas:core:2.0:User";
-    public static final String CORE_GROUP_URI = "urn:ietf:params:scim:schemas:core:2.0:Group";
-    public static final String CORE_EXT_USER_URI = "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User";
-
     public static String exceptionToStr( Exception e )
     {
         StringWriter sw = new StringWriter();
@@ -67,8 +61,8 @@ public class ScimUtil
     
     public static boolean isCoreAttribute( String uri )
     {
-        return ( CORE_USER_URI.equals( uri ) || 
-                 CORE_GROUP_URI.equals( uri ) );
+        return ( SchemaUtil.CORE_USER_ID.equals( uri ) || 
+                 SchemaUtil.CORE_GROUP_ID.equals( uri ) );
     }
 
     

Modified: directory/escimo/trunk/json2java/src/main/java/org/apache/directory/scim/JsonToJava.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/json2java/src/main/java/org/apache/directory/scim/JsonToJava.java?rev=1648206&r1=1648205&r2=1648206&view=diff
==============================================================================
--- directory/escimo/trunk/json2java/src/main/java/org/apache/directory/scim/JsonToJava.java
(original)
+++ directory/escimo/trunk/json2java/src/main/java/org/apache/directory/scim/JsonToJava.java
Sun Dec 28 14:06:30 2014
@@ -123,7 +123,15 @@ public class JsonToJava extends Abstract
         for ( URL url : lst )
         {
             String schemaJson = getSchemaJson( url );
-            compileAndSave( schemaJson, srcDir );
+            try
+            {
+                compileAndSave( schemaJson, srcDir );
+            }
+            catch( Exception e )
+            {
+                e.printStackTrace();
+                throw new RuntimeException( e );
+            }
         }
     }
 
@@ -172,7 +180,30 @@ public class JsonToJava extends Abstract
         JsonParser parser = new JsonParser();
         JsonObject json = ( JsonObject ) parser.parse( schema );
 
-        String className = json.get( "name" ).getAsString();
+        JsonElement nameEl = json.get( "name" );
+        
+        if( nameEl == null )
+        {
+            JsonElement scEl = json.get( "schemas" );
+            if( ( scEl != null ) && ( scEl.isJsonArray() ) )
+            {
+                JsonArray ja = scEl.getAsJsonArray();
+                if( ja.size() > 0 )
+                {
+                    String scName = ja.get( 0 ).getAsString();
+                    if( scName.contains( "ServiceProviderConfig" ) )
+                    {
+                        // no need to print a warning, just return
+                        return;
+                    }
+                }
+            }
+            
+            System.out.println( "Ignoring " + schema + " it is not a valid SCIM resource
schema" );
+            return;
+        }
+        
+        String className = nameEl.getAsString();
         
         List<String> innerClasses = new ArrayList<String>();
 

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=1648206&r1=1648205&r2=1648206&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 Dec 28 14:06:30 2014
@@ -183,8 +183,9 @@ public class LdapResourceProvider implem
             {
                 for ( URL u : urls )
                 {
-                    JsonSchema json = SchemaUtil.getSchemaJson( u );
-                    schemas.put( json.getId(), json );
+                    String json = SchemaUtil.getSchemaJson( u );
+                    JsonSchema schema = JsonSchema.parse( json );
+                    schemas.put( schema.getId(), schema );
                 }
             }
 

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=1648206&r1=1648205&r2=1648206&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 Dec 28 14:06:30 2014
@@ -54,6 +54,7 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
+@SuppressWarnings("unchecked")
 public class LdapSchemaMapper implements SchemaMapper
 {
     private SchemaManager ldapSchema;
@@ -62,7 +63,7 @@ public class LdapSchemaMapper implements
 
     private List<ResourceSchema> resourceSchemas = new ArrayList<ResourceSchema>();
 
-    private Map<String,ResourceSchema> uriToResSchema;
+    private Map<String,ResourceSchema> idToResSchema;
     
     private Map<String,JsonSchema> jsonSchemas;
     
@@ -132,7 +133,7 @@ public class LdapSchemaMapper implements
             List<Element> elmResources = root.elements( "resourceType" );
             List<Element> lstSchema = root.elements( "schema" );
             
-            uriToResSchema = new HashMap<String, ResourceSchema>();
+            idToResSchema = new HashMap<String, ResourceSchema>();
             Map<String, AttributeHandler> atHandlersMap = loadAtHandlers( root.element(
"atHandlers" ) );
             
             for( Element resElem : elmResources )
@@ -187,9 +188,9 @@ public class LdapSchemaMapper implements
                 if ( refId.equals( schemaId ) )
                 {
                     parseSchema( elmSchema, resourceSchema, atHandlersMap );
-                    for( String uri : resourceSchema.getSchemaIds() )
+                    for( String id : resourceSchema.getSchemaIds() )
                     {
-                        uriToResSchema.put( uri, resourceSchema );
+                        idToResSchema.put( id, resourceSchema );
                     }
                     break;
                 }

Modified: directory/escimo/trunk/schema/src/main/java/org/apache/directory/scim/schema/JsonSchema.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/schema/src/main/java/org/apache/directory/scim/schema/JsonSchema.java?rev=1648206&r1=1648205&r2=1648206&view=diff
==============================================================================
--- directory/escimo/trunk/schema/src/main/java/org/apache/directory/scim/schema/JsonSchema.java
(original)
+++ directory/escimo/trunk/schema/src/main/java/org/apache/directory/scim/schema/JsonSchema.java
Sun Dec 28 14:06:30 2014
@@ -49,8 +49,6 @@ public class JsonSchema
 
     private boolean core;
 
-    private static String CORE_SCHEMA_ID_PREFIX = "urn:ietf:params:scim:schemas:core:2.0";
-
     private Map<String, JsonObject> attributes;
 
 
@@ -64,24 +62,40 @@ public class JsonSchema
     public static JsonSchema parse( String rawJson )
     {
         JsonSchema schema = new JsonSchema( rawJson );
-        schema._parse();
+        boolean result = schema._parse();
 
+        if ( !result )
+        {
+            schema = null;
+        }
+        
         return schema;
     }
 
 
-    private void _parse()
+    private boolean _parse()
     {
         JsonParser parser = new JsonParser();
         JsonObject obj = ( JsonObject ) parser.parse( rawJson );
 
-        this.id = obj.get( "id" ).getAsString();
+        JsonElement idEl = obj.get( "id" );
+        
+        if ( idEl == null )
+        {
+            JsonElement scEl = obj.get( "schemas" );
+            System.out.println( "Ignoring schema with schemas " + scEl + " , it is not a
valid SCIM resource schema" );
+            return false;
+        }
+        
+        this.id = idEl.getAsString();
         this.name = obj.get( "name" ).getAsString();
         this.desc = obj.get( "description" ).getAsString();
 
-        core = id.startsWith( CORE_SCHEMA_ID_PREFIX );
+        core = id.startsWith( SchemaUtil.CORE_SCHEMA_ID_PREFIX );
 
         _readAttributeDef( obj );
+        
+        return true;
     }
 
 
@@ -220,15 +234,6 @@ public class JsonSchema
     @Override
     public String toString()
     {
-        return "JsonSchema [id=" + id + ", name=" + name + ", desc=" + desc + "]";
+        return "JsonSchema [id=" + id + ", name=" + name + ", desc=" + desc + ", core=" +
core + "]";
     }
-
-
-    public static void main( String[] args ) throws Exception
-    {
-        URL url = SchemaUtil.getDefaultSchemas().get( 0 );
-        JsonSchema json = SchemaUtil.getSchemaJson( url );
-        System.out.println( json );
-    }
-
 }

Modified: directory/escimo/trunk/schema/src/main/java/org/apache/directory/scim/schema/SchemaUtil.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/schema/src/main/java/org/apache/directory/scim/schema/SchemaUtil.java?rev=1648206&r1=1648205&r2=1648206&view=diff
==============================================================================
--- directory/escimo/trunk/schema/src/main/java/org/apache/directory/scim/schema/SchemaUtil.java
(original)
+++ directory/escimo/trunk/schema/src/main/java/org/apache/directory/scim/schema/SchemaUtil.java
Sun Dec 28 14:06:30 2014
@@ -32,6 +32,14 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+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;
+
 
 /**
  * TODO SchemaUtil.
@@ -41,9 +49,21 @@ import java.util.Map;
 public class SchemaUtil
 {
     private static String[] stockNames =
-        { "user-schema.json", "group-schema.json", "enterprise-user-schema.json" };
-    
+        { "user-schema.json", "group-schema.json", "enterprise-user-schema.json", "serviceproviderconfig-schema.json"
};
+
+    public static final String PROVIDER_SERVICE_SCHEMA_ID = "urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig";
+
+    public static final String CORE_USER_ID = "urn:ietf:params:scim:schemas:core:2.0:User";
+
+    public static final String CORE_GROUP_ID = "urn:ietf:params:scim:schemas:core:2.0:Group";
+
+    public static final String CORE_EXT_USER_ID = "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User";
+
+    public static final String CORE_SCHEMA_ID_PREFIX = "urn:ietf:params:scim:schemas:core:2.0";
+
+    private static final Logger LOG = LoggerFactory.getLogger( SchemaUtil.class );
     
+
     public static List<URL> getSchemas( File schemaDir )
     {
         File[] files = schemaDir.listFiles();
@@ -78,8 +98,14 @@ public class SchemaUtil
         
         for( URL u : urls )
         {
-            JsonSchema json = getSchemaJson( u );
-            schemas.put( json.getId(), json );
+            String json = getSchemaJson( u );
+            
+            JsonSchema schema = JsonSchema.parse( json );
+            
+            if ( schema != null )
+            {
+                schemas.put( schema.getId(), schema );
+            }
             
             String name = u.getFile();
             int pos = name.lastIndexOf( File.separator );
@@ -89,7 +115,7 @@ public class SchemaUtil
             }
             
             FileWriter fw = new FileWriter( new File( schemaDir, name ) );
-            fw.write( json.getRawJson() );
+            fw.write( json );
             fw.close();
         }
         
@@ -112,7 +138,7 @@ public class SchemaUtil
     }
 
 
-    public static JsonSchema getSchemaJson( URL url ) throws IOException
+    public static String getSchemaJson( URL url ) throws IOException
     {
         BufferedReader br = null;
         try
@@ -127,7 +153,7 @@ public class SchemaUtil
                 sb.append( s );
             }
 
-            return JsonSchema.parse( sb.toString() );
+            return sb.toString();
         }
         finally
         {
@@ -145,4 +171,49 @@ public class SchemaUtil
         }
     }
 
+    
+    public static JsonObject getResourceProviderConfig()
+    {
+        String jsonSchemaDir = System.getProperty( "escimo.json.schema.dir", null );
+
+        if ( jsonSchemaDir == null )
+        {
+            return null;
+        }
+        
+        File schemaDir = new File( jsonSchemaDir );
+
+        List<URL> urls = SchemaUtil.getSchemas( schemaDir );
+        
+        try
+        {
+            JsonParser parser = new JsonParser();
+
+            for( URL u : urls )
+            {
+                String json = SchemaUtil.getSchemaJson( u );
+                JsonObject obj = ( JsonObject ) parser.parse( json );
+                JsonElement scEl = obj.get( "schemas" );
+                if( ( scEl != null ) && ( scEl.isJsonArray() ) )
+                {
+                    JsonArray ja = scEl.getAsJsonArray();
+                    if( ja.size() > 0 )
+                    {
+                        String scName = ja.get( 0 ).getAsString();
+                        if( scName.equals( PROVIDER_SERVICE_SCHEMA_ID ) )
+                        {
+                            return obj;
+                        }
+                    }
+                }
+            }
+        }
+        catch( Exception e )
+        {
+            LOG.warn( "Failed to get ResourceProviderConfig from the directory {}", jsonSchemaDir
);
+            LOG.warn( "", e );
+        }
+        
+        return null;
+    }
 }

Modified: directory/escimo/trunk/schema/src/main/resources/serviceproviderconfig-schema.json
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/schema/src/main/resources/serviceproviderconfig-schema.json?rev=1648206&r1=1648205&r2=1648206&view=diff
==============================================================================
--- directory/escimo/trunk/schema/src/main/resources/serviceproviderconfig-schema.json (original)
+++ directory/escimo/trunk/schema/src/main/resources/serviceproviderconfig-schema.json Sun
Dec 28 14:06:30 2014
@@ -44,7 +44,7 @@
        }
     ],
     "meta": {
-      "location":"http://localhost:8080/v2/ServiceProviderConfig",
+      "location":"http://example.com/ServiceProviderConfig",
       "resourceType": "ServiceProviderConfig",
       "created": "2010-01-23T04:56:22Z",
       "lastModified": "2011-05-13T04:42:34Z",

Modified: directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/MetaSchemaService.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/MetaSchemaService.java?rev=1648206&r1=1648205&r2=1648206&view=diff
==============================================================================
--- directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/MetaSchemaService.java
(original)
+++ directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/MetaSchemaService.java
Sun Dec 28 14:06:30 2014
@@ -40,9 +40,11 @@ import org.apache.directory.scim.schema.
 import org.apache.directory.scim.schema.ErrorResponse;
 import org.apache.directory.scim.schema.ErrorResponse.ScimError;
 import org.apache.directory.scim.schema.JsonSchema;
+import org.apache.directory.scim.schema.SchemaUtil;
 
 import com.google.gson.JsonArray;
 import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
 
 
@@ -55,14 +57,13 @@ import com.google.gson.JsonParser;
 public class MetaSchemaService
 {
 
-    private static String PROVIDER_SERVICE_SCHEMA_ID = "urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig";
-
     @Context
     private ServletContext servletCtx;
 
     // variable to cache the schema object
-    private String jsonSchemas;
-    
+    private static String jsonSchemas;
+
+    private static String resProviderSchema;
 
     @GET
     @Produces(
@@ -108,22 +109,30 @@ public class MetaSchemaService
     @Produces(
         { MediaType.APPLICATION_JSON })
     @Path("/ServiceProviderConfig")
-    public Response getSrviceProviderSchema()
+    public Response getSrviceProviderSchema( @Context UriInfo uriInfo )
     {
         ResponseBuilder rb = null;
 
-        ResourceProvider provider = ( ResourceProvider ) servletCtx
-            .getAttribute( ResourceProvider.SERVLET_CONTEXT_ATTRIBUTE_KEY );
-        JsonSchema jsonSchema = provider.getJsonSchemaById( PROVIDER_SERVICE_SCHEMA_ID );
+        if ( resProviderSchema == null )
+        {
+            JsonObject obj = SchemaUtil.getResourceProviderConfig();
+            
+            JsonObject meta = obj.get( "meta" ).getAsJsonObject();
+            meta.remove( "location" );
+            
+            meta.addProperty( "location", uriInfo.getBaseUri().toString() + "ServiceProviderConfig"
);
+            
+            resProviderSchema = obj.toString();
+        }
 
-        if ( jsonSchema != null )
+        if ( resProviderSchema != null )
         {
-            rb = Response.ok( jsonSchema.getRawJson(), MediaType.APPLICATION_JSON );
+            rb = Response.ok( resProviderSchema, MediaType.APPLICATION_JSON );
         }
         else
         {
             ScimError err = new ScimError( ErrorCode.NOT_FOUND, "No schema found with the
URI "
-                + PROVIDER_SERVICE_SCHEMA_ID );
+                + SchemaUtil.PROVIDER_SERVICE_SCHEMA_ID );
 
             ErrorResponse resp = new ErrorResponse( err );
             String json = ResourceSerializer.serialize( resp );



Mime
View raw message