directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1546811 - in /directory/escimo/trunk: ./ common/src/main/java/org/apache/directory/scim/ ldap/ ldap/src/main/java/org/apache/directory/scim/ldap/ ldap/src/main/java/org/apache/directory/scim/ldap/handlers/ ldap/src/main/resources/ schema/s...
Date Sun, 01 Dec 2013 12:37:36 GMT
Author: kayyagari
Date: Sun Dec  1 12:37:36 2013
New Revision: 1546811

URL: http://svn.apache.org/r1546811
Log:
o a lot of refactoring done to handle the authenticated and non-authenticated modes
o support for setting a config directory in web.xml and storing the default schemas and LDAP server config

Added:
    directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/UnauthorizedException.java
    directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapRequestContext.java
    directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/ConfigurationFilter.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/ScimUtil.java
    directory/escimo/trunk/ldap/pom.xml
    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/GroupsAttributeHandler.java
    directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/handlers/MembersAttributeHandler.java
    directory/escimo/trunk/ldap/src/main/resources/ldap-server.properties
    directory/escimo/trunk/pom.xml
    directory/escimo/trunk/schema/src/main/java/org/apache/directory/scim/schema/SchemaUtil.java
    directory/escimo/trunk/server/pom.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/ServerInitializer.java
    directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/UserService.java
    directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/auth/AuthenticationFilter.java
    directory/escimo/trunk/server/src/main/webapp/WEB-INF/web.xml

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=1546811&r1=1546810&r2=1546811&view=diff
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ProviderService.java (original)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/ProviderService.java Sun Dec  1 12:37:36 2013
@@ -20,6 +20,9 @@ package org.apache.directory.scim;
 
 import java.io.InputStream;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.UriInfo;
+
 import org.apache.directory.scim.schema.JsonSchema;
 
 /**
@@ -32,9 +35,11 @@ public interface ProviderService 
     
     void stop();
     
+    RequestContext createCtx( UriInfo uriInfo, HttpServletRequest httpReq ) throws Exception;
+    
     UserResource getUser( RequestContext ctx, String userId ) throws ResourceNotFoundException;
     
-    InputStream getUserPhoto( String id, String atName ) throws MissingParameterException;
+    InputStream getUserPhoto( String id, String atName, RequestContext ctx ) throws MissingParameterException;
     
     GroupResource getGroup( RequestContext ctx, String groupId ) throws ResourceNotFoundException;
     
@@ -44,9 +49,9 @@ public interface ProviderService 
     
     GroupResource addGroup( String jsonData, RequestContext ctx ) throws Exception;
     
-    void deleteUser( String id ) throws Exception;
+    void deleteUser( String id, RequestContext ctx ) throws Exception;
     
-    void deleteGroup( String id ) throws Exception;
+    void deleteGroup( String id, RequestContext ctx ) throws Exception;
     
     UserResource putUser( String userId, String jsonData, RequestContext ctx ) throws Exception;
     
@@ -59,4 +64,8 @@ public interface ProviderService 
     ListResponse search( String filter, String attributes, RequestContext ctx ) throws Exception;
     
     String authenticate( String userName, String password ) throws Exception;
+    
+    void setAllowAuthorizedUsers( boolean allowAuthorizedUsers );
+    
+    boolean isAllowAuthorizedUsers();
 }

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=1546811&r1=1546810&r2=1546811&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 Sun Dec  1 12:37:36 2013
@@ -48,7 +48,7 @@ public class RequestContext
     
     private HttpServletRequest httpReq;
     
-    public RequestContext( ProviderService providerService, UriInfo uriInfo, HttpServletRequest httpReq )
+    protected RequestContext( ProviderService providerService, UriInfo uriInfo, HttpServletRequest httpReq )
     {
         this.providerService = providerService;
         this.uriInfo = uriInfo;

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=1546811&r1=1546810&r2=1546811&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  1 12:37:36 2013
@@ -19,7 +19,7 @@
 package org.apache.directory.scim;
 
 
-import static org.apache.directory.scim.schema.ErrorCode.BAD_REQUEST;
+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;
@@ -90,6 +90,10 @@ public class ScimUtil
         {
             ec = CONFLICT;
         }
+        else if ( e instanceof UnauthorizedException )
+        {
+            ec = UNAUTHORIZED;
+        }
         
         if ( desc == null )
         {

Added: directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/UnauthorizedException.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/UnauthorizedException.java?rev=1546811&view=auto
==============================================================================
--- directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/UnauthorizedException.java (added)
+++ directory/escimo/trunk/common/src/main/java/org/apache/directory/scim/UnauthorizedException.java Sun Dec  1 12:37:36 2013
@@ -0,0 +1,47 @@
+/*
+ *   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 UnauthorizedException.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class UnauthorizedException extends Exception
+{
+    public UnauthorizedException( String message )
+    {
+        super( message );
+    }
+
+
+    public UnauthorizedException( Throwable t )
+    {
+        super( t );
+    }
+
+
+    public UnauthorizedException( String message, Throwable t )
+    {
+        super( message, t );
+    }
+
+}

Modified: directory/escimo/trunk/ldap/pom.xml
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/ldap/pom.xml?rev=1546811&r1=1546810&r2=1546811&view=diff
==============================================================================
--- directory/escimo/trunk/ldap/pom.xml (original)
+++ directory/escimo/trunk/ldap/pom.xml Sun Dec  1 12:37:36 2013
@@ -20,6 +20,11 @@
     </dependency>   
 
     <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+    </dependency>
+
+    <dependency>
       <groupId>org.apache.directory.api</groupId>
       <artifactId>api-ldap-client-api</artifactId>
       <version>${ldap.api.version}</version>

Added: directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapRequestContext.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapRequestContext.java?rev=1546811&view=auto
==============================================================================
--- directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapRequestContext.java (added)
+++ directory/escimo/trunk/ldap/src/main/java/org/apache/directory/scim/ldap/LdapRequestContext.java Sun Dec  1 12:37:36 2013
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2006-2011 Mirth Corporation.
+ * All rights reserved.
+ *
+ * NOTICE:  All information contained herein is, and remains, the
+ * property of Mirth Corporation. The intellectual and technical
+ * concepts contained herein are proprietary and confidential to
+ * Mirth Corporation and may be covered by U.S. and Foreign
+ * Patents, patents in process, and are protected by trade secret
+ * and/or copyright law. Dissemination of this information or reproduction
+ * of this material is strictly forbidden unless prior written permission
+ * is obtained from Mirth Corporation.
+ */
+
+package org.apache.directory.scim.ldap;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.scim.ProviderService;
+import org.apache.directory.scim.RequestContext;
+
+/**
+ *
+ * @author Kiran Ayyagari
+ */
+public class LdapRequestContext extends RequestContext
+{
+    private LdapConnection connection;
+    
+    public LdapRequestContext( ProviderService providerService, LdapConnection connection, UriInfo uriInfo, HttpServletRequest httpReq )
+    {
+        super( providerService, uriInfo, httpReq );
+        this.connection = connection;
+    }
+
+    public LdapConnection getConnection() 
+    {
+        return connection;
+    }
+}

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=1546811&r1=1546810&r2=1546811&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  1 12:37:36 2013
@@ -23,9 +23,14 @@ package org.apache.directory.scim.ldap;
 import static org.apache.directory.api.ldap.model.constants.SchemaConstants.ALL_ATTRIBUTES_ARRAY;
 import static org.apache.directory.api.ldap.model.message.SearchScope.SUBTREE;
 
+import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -36,7 +41,12 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.commons.lang.StringUtils;
 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;
@@ -66,7 +76,6 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.schema.syntaxCheckers.JavaIntegerSyntaxChecker;
 import org.apache.directory.api.ldap.model.schema.syntaxCheckers.JavaLongSyntaxChecker;
 import org.apache.directory.api.ldap.model.schema.syntaxCheckers.JavaShortSyntaxChecker;
-import org.apache.directory.api.ldap.schemaloader.JarLdifSchemaLoader;
 import org.apache.directory.api.util.Base64;
 import org.apache.directory.api.util.Strings;
 import org.apache.directory.ldap.client.api.LdapConnection;
@@ -87,6 +96,7 @@ import org.apache.directory.scim.ScimUti
 import org.apache.directory.scim.ServerResource;
 import org.apache.directory.scim.SimpleAttribute;
 import org.apache.directory.scim.SimpleAttributeGroup;
+import org.apache.directory.scim.UnauthorizedException;
 import org.apache.directory.scim.UserResource;
 import org.apache.directory.scim.ldap.handlers.LdapAttributeHandler;
 import org.apache.directory.scim.ldap.schema.ComplexType;
@@ -119,7 +129,7 @@ import com.google.gson.JsonParser;
 public class LdapResourceProvider implements ProviderService
 {
 
-    private LdapConnection connection;
+    private LdapConnection adminConnection;
 
     private LdapSchemaMapper schemaMapper;
 
@@ -137,7 +147,15 @@ public class LdapResourceProvider implem
 
     private static final String ENTRYDN_HEADER = "X-ENTRYDN";
 
-    private Map<String, LdapConnection> connMap = new HashMap<String, LdapConnection>();
+    private final Map<String, ConnectionSession> connMap = new ConcurrentHashMap<String, ConnectionSession>();
+    
+    private boolean allowAuthorizedUsers = false;
+    
+    private boolean initialized = false;
+
+    private volatile boolean stop;
+    
+    private long sessionTimeout = 2 * 60 * 1000;
     
     public LdapResourceProvider()
     {
@@ -146,7 +164,7 @@ public class LdapResourceProvider implem
 
     public LdapResourceProvider( LdapConnection connection )
     {
-        this.connection = connection;
+        this.adminConnection = connection;
     }
 
 
@@ -156,14 +174,25 @@ public class LdapResourceProvider implem
         
         try
         {
-            List<URL> urls = SchemaUtil.getDefaultSchemas();
-            for( URL u : urls )
+            String jsonSchemaDir = System.getProperty( "escimo.json.schema.dir", null );
+            
+            File schemaDir = new File( jsonSchemaDir );
+            
+            List<URL> urls = SchemaUtil.getSchemas( schemaDir );
+            
+            if( urls.isEmpty() )
             {
-                JsonSchema json = SchemaUtil.getSchemaJson( u );
-                schemas.put( json.getId(), json );
+                LOG.info( "No schemas found at {} , extracting and loading the default schemas", jsonSchemaDir );
+                schemas = SchemaUtil.storeDefaultSchemas( schemaDir );
+            }
+            else
+            {
+                for( URL u : urls )
+                {
+                    JsonSchema json = SchemaUtil.getSchemaJson( u );
+                    schemas.put( json.getId(), json );
+                }
             }
-            
-            // TODO load custom schemas
         }
         catch( Exception e )
         {
@@ -172,35 +201,112 @@ public class LdapResourceProvider implem
             throw re;
         }
         
-        if ( connection == null )
+        Runnable r = new Runnable() 
+        {
+            public void run() 
+            {
+                List<String> keys = new ArrayList<String>();
+                
+                while( !stop )
+                {
+                    long now = System.currentTimeMillis();
+                    
+                    for( String key : connMap.keySet() )
+                    {
+                        ConnectionSession cs = connMap.get( key );
+                        
+                        if( ( now - cs.lastAccessed ) >= sessionTimeout )
+                        {
+                            try
+                            {
+                                LOG.debug( "Closing an inactive connection associated with the userDn {} and key {}", cs.userDn, key );
+                                
+                                keys.add( key );
+                                
+                                cs.connection.unBind();
+                                cs.connection.close();
+                            }
+                            catch( Exception e )
+                            {
+                                //ignore
+                                LOG.info( "Errors occurred while unbinding and closing an inactive connection", e );
+                            }
+                        }
+                    }
+                    
+                    for( String k : keys )
+                    {
+                        connMap.remove( k );
+                    }
+                    
+                    keys.clear();
+                    
+                    try
+                    {
+                        Thread.sleep( 60 * 1000 );
+                    }
+                    catch( InterruptedException e )
+                    {
+                        // ignore
+                        LOG.warn( "Connection cleaner thread was interrupted", e );
+                    }
+                }
+            }
+        };
+        
+        Thread connCleaner = new Thread( r );
+        connCleaner.start();
+    }
+
+    
+    public RequestContext createCtx( UriInfo uriInfo, HttpServletRequest httpReq ) throws Exception
+    {
+        LdapConnection connection = getConnection(httpReq);
+        LdapRequestContext ctx = new LdapRequestContext(this, connection, uriInfo, httpReq );
+        return ctx;
+    }
+
+
+    private void _initInternal() throws Exception
+    {
+        if( initialized )
+        {
+            return;
+        }
+
+        if ( adminConnection == null )
         {
             createConnection();
         }
 
-        if ( connection instanceof LdapNetworkConnection )
+        if ( adminConnection instanceof LdapNetworkConnection )
         {
-            ( ( LdapNetworkConnection ) connection ).loadSchema( new JarLdifSchemaLoader() );
+            ( ( LdapNetworkConnection ) adminConnection ).loadSchema();// new JarLdifSchemaLoader() );
         }
 
-        ldapSchema = connection.getSchemaManager();
+        ldapSchema = adminConnection.getSchemaManager();
         
         Map<String,JsonSchema> jsonSchemaCopy = new HashMap<String, JsonSchema>( schemas );
         schemaMapper = new LdapSchemaMapper( jsonSchemaCopy, ldapSchema );
         schemaMapper.loadMappings();
         userSchema = schemaMapper.getUserSchema();
         groupSchema = schemaMapper.getGroupSchema();
+        
+        initialized = true;
     }
 
-
+    
     public void stop()
     {
         LOG.info( "Closing the LDAP server connection" );
 
-        if ( connection != null )
+        stop = true;
+        
+        if ( adminConnection != null )
         {
             try
             {
-                connection.close();
+                adminConnection.close();
             }
             catch ( Exception e )
             {
@@ -214,10 +320,38 @@ public class LdapResourceProvider implem
     {
         LOG.info( "Creating LDAP server connection" );
 
-        InputStream in = this.getClass().getClassLoader().getResourceAsStream( "ldap-server.properties" );
-        Properties prop = new Properties();
-        prop.load( in );
+        String configDir = System.getProperty( "escimo.config.dir" );
+        
+        File ldapServerProps = new File( new File( configDir ), "ldap-server.properties" );
+        
+        Properties prop = null;
+        InputStream in = null;
+        
+        if( !ldapServerProps.exists() )
+        {
+            in = this.getClass().getClassLoader().getResourceAsStream( ldapServerProps.getName() );
+            FileWriter fw = new FileWriter( ldapServerProps );
+            
+            BufferedReader br = new BufferedReader( new InputStreamReader( in ) );
+            
+            String s = null;
+            
+            while( ( s = br.readLine() ) != null )
+            {
+                fw.write( s + "\n" );
+            }
+            
+            fw.close();
+            br.close();
+        }
 
+        in = new FileInputStream( ldapServerProps );
+        
+        prop = new Properties();
+        prop.load( in );
+        
+        in.close();
+        
         String host = prop.getProperty( "escimo.ldap.server.host" );
         String portVal = prop.getProperty( "escimo.ldap.server.port" );
         int port = Integer.parseInt( portVal );
@@ -232,13 +366,15 @@ public class LdapResourceProvider implem
         config.setName( user );
         config.setCredentials( password );
 
-        connection = new LdapNetworkConnection( config );
-        connection.bind();
+        adminConnection = new LdapNetworkConnection( config );
+        adminConnection.bind();
     }
 
 
     public String authenticate( String userName, String password ) throws Exception
     {
+        _initInternal();
+        
         if( ( userName == null ) || ( password == null ) )
         {
             LOG.debug( "Missing username and/or password" );
@@ -256,7 +392,7 @@ public class LdapResourceProvider implem
         
         try
         {
-            cursor = connection.search( userSchema.getBaseDn(), filter, SUBTREE, "1.1" );
+            cursor = adminConnection.search( userSchema.getBaseDn(), filter, SUBTREE, "1.1" );
 
             if ( cursor.next() )
             {
@@ -278,11 +414,11 @@ public class LdapResourceProvider implem
         
         LdapConnection conn = new LdapNetworkConnection( config );
         conn.bind( userDn, password );
-        conn.loadSchema();
+        conn.setSchemaManager( ldapSchema );
         
         String sessionId = UUID.randomUUID().toString();
         
-        connMap.put( sessionId, conn );
+        connMap.put( sessionId, new ConnectionSession( conn, userDn ) );
         
         return sessionId;
     }
@@ -405,7 +541,7 @@ public class LdapResourceProvider implem
         String[] requested = getRequestedAttributes( attributes, scimSchema );
         sr.addAttributes( requested );
         
-        LdapConnection conn = getConnection( ctx );
+        LdapConnection conn = ( ( LdapRequestContext ) ctx ).getConnection();
         
         SearchCursor cursor = conn.search( sr );
         
@@ -509,7 +645,7 @@ public class LdapResourceProvider implem
     }
 
     
-    public InputStream getUserPhoto( String id, String atName ) throws MissingParameterException
+    public InputStream getUserPhoto( String id, String atName, RequestContext ctx ) throws MissingParameterException
     {
         if ( Strings.isEmpty( id ) )
         {
@@ -521,7 +657,7 @@ public class LdapResourceProvider implem
             throw new MissingParameterException( "parameter 'atName' cannot be null or empty" );
         }
 
-        Entry entry = fetchEntryById( id, userSchema );
+        Entry entry = fetchEntryById( id, userSchema, ctx );
 
         if ( entry == null )
         {
@@ -633,9 +769,12 @@ public class LdapResourceProvider implem
             _resourceToEntry( entry, obj, ctx, userSchema );
             
             entry.setDn( dn );
-            connection.add( entry );
+            
+            LdapConnection conn = ( ( LdapRequestContext ) ctx ).getConnection();
+            
+            conn.add( entry );
 
-            entry = connection.lookup( entry.getDn(), SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+            entry = conn.lookup( entry.getDn(), SchemaConstants.ALL_ATTRIBUTES_ARRAY );
 
             UserResource addedUser = new UserResource();
 
@@ -691,9 +830,11 @@ public class LdapResourceProvider implem
             
             entry.setDn( dn );
             
-            connection.add( entry );
+            LdapConnection conn = ( ( LdapRequestContext ) ctx ).getConnection();
+            
+            conn.add( entry );
             
-            entry = connection.lookup( entry.getDn(), SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+            entry = conn.lookup( entry.getDn(), SchemaConstants.ALL_ATTRIBUTES_ARRAY );
 
             GroupResource addedGroup = new GroupResource();
 
@@ -848,7 +989,9 @@ public class LdapResourceProvider implem
             }
         }
         
-        ModifyResponse modResp = connection.modify( modReq );
+        LdapConnection conn = ( ( LdapRequestContext ) ctx ).getConnection();
+        
+        ModifyResponse modResp = conn.modify( modReq );
         
         if( modResp.getLdapResult().getResultCode() != ResultCodeEnum.SUCCESS )
         {
@@ -860,7 +1003,7 @@ public class LdapResourceProvider implem
             if( !existingUserNameAt.contains( newUserNameAt.getString() ) )
             {
                 // a modDN needs to be performed
-                connection.rename( existingEntry.getDn().getName(), newUserNameAt.getUpId() + "=" + newUserNameAt.getString(), true );
+                conn.rename( existingEntry.getDn().getName(), newUserNameAt.getUpId() + "=" + newUserNameAt.getString(), true );
             }
         }
         
@@ -929,11 +1072,13 @@ public class LdapResourceProvider implem
             }
         }
 
+        LdapConnection conn = ( ( LdapRequestContext ) ctx ).getConnection();
+        
         try
         {
             LdapUtil.patchAttributes( existingEntry, obj, ctx, resourceSchema, modReq );
             
-            ModifyResponse modResp = connection.modify( modReq );
+            ModifyResponse modResp = conn.modify( modReq );
             
             LdapResult result = modResp.getLdapResult();
             if( result.getResultCode() != ResultCodeEnum.SUCCESS )
@@ -985,21 +1130,22 @@ public class LdapResourceProvider implem
     }
 
     
-    public void deleteUser( String id ) throws Exception
+    public void deleteUser( String id, RequestContext ctx ) throws Exception
     {
-        deleteResource( id, userSchema );
+        deleteResource( id, userSchema, ctx );
     }
     
-    public void deleteGroup( String id ) throws Exception
+    public void deleteGroup( String id, RequestContext ctx ) throws Exception
     {
-        deleteResource( id, groupSchema );
+        deleteResource( id, groupSchema, ctx );
     }
     
     
-    private void deleteResource( String id, ResourceSchema schema ) throws LdapException
+    private void deleteResource( String id, ResourceSchema schema, RequestContext ctx ) throws LdapException
     {
-        Entry entry = fetchEntryById( id, schema );
-        connection.delete( entry.getDn() );
+        Entry entry = fetchEntryById( id, schema, ctx );
+        LdapConnection conn = ( ( LdapRequestContext ) ctx ).getConnection();
+        conn.delete( entry.getDn() );
     }
 
     public GroupResource toGroup( RequestContext ctx, Entry entry ) throws Exception
@@ -1259,17 +1405,13 @@ public class LdapResourceProvider implem
     }
 
 
-    public LdapConnection getConnection()
-    {
-        return connection;
-    }
-
-
-    public Entry fetchEntryByDn( String dn )
+    public Entry fetchEntryByDn( String dn, RequestContext ctx )
     {
         try
         {
-            return connection.lookup( dn, ALL_ATTRIBUTES_ARRAY );
+            LdapConnection conn = ( ( LdapRequestContext ) ctx ).getConnection();
+            
+            return conn.lookup( dn, ALL_ATTRIBUTES_ARRAY );
         }
         catch ( LdapException e )
         {
@@ -1279,11 +1421,6 @@ public class LdapResourceProvider implem
         return null;
     }
 
-    public Entry fetchEntryById( String id, ResourceSchema resourceSchema )
-    {
-        return fetchEntryById( id, resourceSchema, null );
-    }
-    
     public Entry fetchEntryById( String id, ResourceSchema resourceSchema, RequestContext ctx )
     {
         EntryCursor cursor = null;
@@ -1302,9 +1439,11 @@ public class LdapResourceProvider implem
             attributes = getRequestedAttributes( ctx.getParamAttributes(), resourceSchema );
         }
         
+        LdapConnection conn = ( ( LdapRequestContext ) ctx ).getConnection();
+        
         try
         {
-            cursor = connection.search( resourceSchema.getBaseDn(), filter, SUBTREE, attributes );
+            cursor = conn.search( resourceSchema.getBaseDn(), filter, SUBTREE, attributes );
 
             if ( cursor.next() )
             {
@@ -1357,11 +1496,66 @@ public class LdapResourceProvider implem
     }
     
     
-    private LdapConnection getConnection( RequestContext ctx )
+    public LdapConnection getConnection( HttpServletRequest httpReq ) throws Exception
     {
-        return connMap.get( ctx.getReqHeaderValue( RequestContext.USER_AUTH_HEADER ) );
+        
+        if( allowAuthorizedUsers )
+        {
+            ConnectionSession cs = connMap.get( httpReq.getHeader( RequestContext.USER_AUTH_HEADER ) );
+            
+            if( cs == null )
+            {
+                throw new UnauthorizedException( "Not Authenticated" );
+            }
+            
+            cs.touch();
+            
+            return cs.connection;
+        }
+        
+        _initInternal();
+        
+        return adminConnection;
     }
     
+    /**
+     * @return the allowAuthorizedUsers
+     */
+    public boolean isAllowAuthorizedUsers()
+    {
+        return allowAuthorizedUsers;
+    }
+
+
+    /**
+     * @param allowAuthorizedUsers the allowAuthorizedUsers to set
+     */
+    public void setAllowAuthorizedUsers( boolean allowAuthorizedUsers )
+    {
+        this.allowAuthorizedUsers = allowAuthorizedUsers;
+    }
+
+    class ConnectionSession
+    {
+        private String userDn;
+        
+        private LdapConnection connection;
+        
+        private long lastAccessed;
+        
+        public ConnectionSession( LdapConnection connection, String userDn )
+        {
+            this.userDn = userDn;
+            this.connection = connection;
+            touch();
+        }
+        
+        public void touch()
+        {
+            lastAccessed = System.currentTimeMillis();
+        }
+    }
+
     public static void main( String[] args ) throws Exception
     {
         LdapResourceProvider provider = new LdapResourceProvider();
@@ -1378,7 +1572,7 @@ public class LdapResourceProvider implem
         }
         finally
         {
-            provider.connection.close();
+            provider.adminConnection.close();
         }
     }
 }

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=1546811&r1=1546810&r2=1546811&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 Sun Dec  1 12:37:36 2013
@@ -41,10 +41,12 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.schema.AttributeType;
 import org.apache.directory.api.ldap.model.schema.SchemaManager;
 import org.apache.directory.api.util.Strings;
+import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.scim.MultiValAttribute;
 import org.apache.directory.scim.RequestContext;
 import org.apache.directory.scim.SimpleAttribute;
 import org.apache.directory.scim.SimpleAttributeGroup;
+import org.apache.directory.scim.ldap.LdapRequestContext;
 import org.apache.directory.scim.ldap.LdapResourceProvider;
 import org.apache.directory.scim.ldap.schema.MultiValType;
 import org.apache.directory.scim.ldap.schema.ResourceSchema;
@@ -94,14 +96,13 @@ public class GroupsAttributeHandler exte
         Attribute memberAt = userEntry.get( SchemaConstants.MEMBER_AT );
         if ( memberAt != null )
         {
-            members = getMemberEntries( memberAt, ( LdapResourceProvider ) ctx.getProviderService() );
+            members = getMemberEntries( memberAt, ctx);
         }
         else
         // query members based on the filter and base DN
         {
             MultiValType mvt = ( MultiValType ) bt;
-            members = getMemberEntriesUsingFilter( mvt.getFilter(), mvt.getBaseDn(), userEntry,
-                ( LdapResourceProvider ) ctx.getProviderService() );
+            members = getMemberEntriesUsingFilter( mvt.getFilter(), mvt.getBaseDn(), userEntry, ctx );
         }
 
         if ( ( members != null ) && ( !members.isEmpty() ) )
@@ -145,15 +146,17 @@ public class GroupsAttributeHandler exte
     }
 
 
-    private List<Entry> getMemberEntries( Attribute memberAt, LdapResourceProvider provider )
+    private List<Entry> getMemberEntries( Attribute memberAt, RequestContext ctx )
     {
+        LdapResourceProvider provider = ( LdapResourceProvider ) ctx.getProviderService();
+        
         List<Entry> members = new ArrayList<Entry>();
 
         Iterator<Value<?>> itr = memberAt.iterator();
         while ( itr.hasNext() )
         {
             Value<?> dn = itr.next();
-            Entry entry = provider.fetchEntryByDn( dn.getString() );
+            Entry entry = provider.fetchEntryByDn( dn.getString(), ctx );
             if ( entry != null )
             {
                 members.add( entry );
@@ -165,7 +168,7 @@ public class GroupsAttributeHandler exte
 
 
     private List<Entry> getMemberEntriesUsingFilter( String filter, String baseDn, Entry userEntry,
-        LdapResourceProvider provider ) throws Exception
+        RequestContext ctx ) throws Exception
     {
         if ( Strings.isEmpty( baseDn ) )
         {
@@ -181,12 +184,14 @@ public class GroupsAttributeHandler exte
 
         try
         {
+            LdapConnection conn = ( ( LdapRequestContext ) ctx ).getConnection();
+            
             ExprNode rootNode = FilterParser.parse( filter );
 
             FilterTokenVisitor tv = new FilterTokenVisitor( userEntry );
             tv.visit( rootNode );
 
-            EntryCursor cursor = provider.getConnection().search( baseDn, rootNode.toString(), SearchScope.SUBTREE,
+            EntryCursor cursor = conn.search( baseDn, rootNode.toString(), SearchScope.SUBTREE,
                 SchemaConstants.ALL_ATTRIBUTES_ARRAY );
             while ( cursor.next() )
             {

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=1546811&r1=1546810&r2=1546811&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 Sun Dec  1 12:37:36 2013
@@ -43,10 +43,12 @@ import org.apache.directory.api.ldap.mod
 import org.apache.directory.api.ldap.model.schema.AttributeType;
 import org.apache.directory.api.ldap.model.schema.SchemaManager;
 import org.apache.directory.api.util.Strings;
+import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.scim.MultiValAttribute;
 import org.apache.directory.scim.RequestContext;
 import org.apache.directory.scim.SimpleAttribute;
 import org.apache.directory.scim.SimpleAttributeGroup;
+import org.apache.directory.scim.ldap.LdapRequestContext;
 import org.apache.directory.scim.ldap.LdapResourceProvider;
 import org.apache.directory.scim.ldap.schema.ResourceSchema;
 import org.apache.directory.scim.schema.BaseType;
@@ -140,7 +142,7 @@ public class MembersAttributeHandler ext
         {
             JsonObject jo = ( JsonObject ) je;
             
-            String dn = getMemberDn( jo, provider );
+            String dn = getMemberDn( jo, ctx );
             
             if( dn == null )
             {
@@ -185,7 +187,7 @@ public class MembersAttributeHandler ext
         {
             JsonObject jo = ( JsonObject ) je;
             
-            String dn = getMemberDn( jo, provider );
+            String dn = getMemberDn( jo, ctx );
             
             if( dn == null )
             {
@@ -237,8 +239,10 @@ public class MembersAttributeHandler ext
     }
 
 
-    private String getMemberDn( JsonObject jo, LdapResourceProvider provider )
+    private String getMemberDn( JsonObject jo, RequestContext ctx )
     {
+        LdapResourceProvider provider = ( LdapResourceProvider ) ctx.getProviderService();
+        
         String resId = jo.get( "value" ).getAsString();
         String resRef = jo.get( "$ref" ).getAsString();
         
@@ -249,7 +253,7 @@ public class MembersAttributeHandler ext
             resSchema = provider.getGroupSchema();
         }
         
-        Entry resEntry = provider.fetchEntryById( resId, resSchema );
+        Entry resEntry = provider.fetchEntryById( resId, resSchema, ctx );
         
         if( resEntry == null )
         {
@@ -282,8 +286,8 @@ public class MembersAttributeHandler ext
     private SimpleAttributeGroup getMemberDetails( String dn, RequestContext ctx ) throws Exception
     {
         LdapResourceProvider provider = ( LdapResourceProvider ) ctx.getProviderService();
-
-        Entry memberEntry = provider.fetchEntryByDn( dn );
+        
+        Entry memberEntry = provider.fetchEntryByDn( dn, ctx );
 
         if ( memberEntry == null )
         {
@@ -323,7 +327,7 @@ public class MembersAttributeHandler ext
 
 
     private List<Entry> getMemberEntriesUsingFilter( String filter, String baseDn, Entry userEntry,
-        LdapResourceProvider provider ) throws Exception
+        RequestContext ctx ) throws Exception
     {
         if ( Strings.isEmpty( baseDn ) )
         {
@@ -344,7 +348,9 @@ public class MembersAttributeHandler ext
             FilterTokenVisitor tv = new FilterTokenVisitor( userEntry );
             tv.visit( rootNode );
 
-            EntryCursor cursor = provider.getConnection().search( baseDn, rootNode.toString(), SearchScope.SUBTREE,
+            LdapConnection conn = ( ( LdapRequestContext ) ctx ).getConnection();
+            
+            EntryCursor cursor = conn.search( baseDn, rootNode.toString(), SearchScope.SUBTREE,
                 SchemaConstants.ALL_ATTRIBUTES_ARRAY );
             while ( cursor.next() )
             {

Modified: directory/escimo/trunk/ldap/src/main/resources/ldap-server.properties
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/ldap/src/main/resources/ldap-server.properties?rev=1546811&r1=1546810&r2=1546811&view=diff
==============================================================================
--- directory/escimo/trunk/ldap/src/main/resources/ldap-server.properties (original)
+++ directory/escimo/trunk/ldap/src/main/resources/ldap-server.properties Sun Dec  1 12:37:36 2013
@@ -20,3 +20,4 @@ escimo.ldap.server.port = 10389
 escimo.ldap.server.user = uid=admin,ou=system
 escimo.ldap.server.password = secret
 escimo.ldap.server.useTls = false
+escimo.resource.provider = org.apache.directory.scim.ldap.LdapResourceProvider

Modified: directory/escimo/trunk/pom.xml
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/pom.xml?rev=1546811&r1=1546810&r2=1546811&view=diff
==============================================================================
--- directory/escimo/trunk/pom.xml (original)
+++ directory/escimo/trunk/pom.xml Sun Dec  1 12:37:36 2013
@@ -25,8 +25,8 @@
   <name>Apache Directory SCIM</name>
   
   <properties>
-    <ldap.api.version>1.0.0-M20</ldap.api.version>
-    <apacheds.version>2.0.0-M15</apacheds.version>
+    <ldap.api.version>1.0.0-M21-SNAPSHOT</ldap.api.version>
+    <apacheds.version>2.0.0-M16-SNAPSHOT</apacheds.version>
     <jetty.version>7.5.0.v20110901</jetty.version>
     <wink.version>1.4</wink.version>
     <httpclient.version>4.3</httpclient.version>

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=1546811&r1=1546810&r2=1546811&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  1 12:37:36 2013
@@ -21,11 +21,16 @@ package org.apache.directory.scim.schema
 
 
 import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 
 /**
@@ -35,10 +40,65 @@ import java.util.List;
  */
 public class SchemaUtil
 {
+    private static String[] stockNames =
+        { "user-schema.json", "group-schema.json", "enterprise-user-schema.json" };
+    
+    
+    public static List<URL> getSchemas( File schemaDir )
+    {
+        File[] files = schemaDir.listFiles();
+        
+        List<URL> urls = new ArrayList<URL>();
+        
+        for( File f : files )
+        {
+            if( f.getName().endsWith( "-schema.json" ) )
+            {
+                try
+                {
+                    urls.add( f.toURI().toURL() );
+                }
+                catch( MalformedURLException e )
+                {
+                    // should never happen
+                    throw new RuntimeException( e );
+                }
+            }
+        }
+        
+        return urls;
+    }
+    
+    
+    public static Map<String,JsonSchema> storeDefaultSchemas( File schemaDir ) throws IOException
+    {
+        List<URL> urls = SchemaUtil.getDefaultSchemas();
+        
+        Map<String,JsonSchema> schemas = new HashMap<String, JsonSchema>();
+        
+        for( URL u : urls )
+        {
+            JsonSchema json = getSchemaJson( u );
+            schemas.put( json.getId(), json );
+            
+            String name = u.getFile();
+            int pos = name.lastIndexOf( File.separator );
+            if( pos > 0 )
+            {
+                name = name.substring( pos, name.length() );
+            }
+            
+            FileWriter fw = new FileWriter( new File( schemaDir, name ) );
+            fw.write( json.getRawJson() );
+            fw.close();
+        }
+        
+        return schemas;
+    }
+    
+    
     public static List<URL> getDefaultSchemas()
     {
-        String[] stockNames =
-            { "user-schema.json", "group-schema.json", "enterprise-user-schema.json" };
         List<URL> lst = new ArrayList<URL>();
 
         ClassLoader cl = Thread.currentThread().getContextClassLoader();

Modified: directory/escimo/trunk/server/pom.xml
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/server/pom.xml?rev=1546811&r1=1546810&r2=1546811&view=diff
==============================================================================
--- directory/escimo/trunk/server/pom.xml (original)
+++ directory/escimo/trunk/server/pom.xml Sun Dec  1 12:37:36 2013
@@ -37,5 +37,12 @@
             <artifactId>commons-codec</artifactId>
             <version>1.8</version>
         </dependency>
+
+        <!-- adding the LDAP backend support by default -->
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>escimo-ldap</artifactId>
+            <version>${project.version}</version>
+        </dependency>
     </dependencies>
 </project>

Added: directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/ConfigurationFilter.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/ConfigurationFilter.java?rev=1546811&view=auto
==============================================================================
--- directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/ConfigurationFilter.java (added)
+++ directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/ConfigurationFilter.java Sun Dec  1 12:37:36 2013
@@ -0,0 +1,125 @@
+/*
+ *   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 java.io.File;
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * TODO ConfigurationFilter.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ConfigurationFilter implements Filter
+{
+
+    public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain ) throws IOException,
+        ServletException
+    {
+        // do not do anything else here 
+        chain.doFilter( request, response );
+    }
+
+    public void destroy()
+    {
+    }
+
+    public void init( FilterConfig filterConfig ) throws ServletException
+    {
+        String configDir = filterConfig.getInitParameter( "configDir" );
+        
+        if( StringUtils.isBlank( configDir ) )
+        {
+            throw new IllegalArgumentException( "Mandatory parameter 'configDir' is missing in ConfigurationFilter declaration in web.xml" );
+        }
+        
+        if( configDir.startsWith( "/WEB-INF" ) )
+        {
+            configDir = filterConfig.getServletContext().getRealPath( configDir );
+        }
+        
+        File dir = new File( configDir );
+        
+        if( !dir.exists() )
+        {
+            boolean created = dir.mkdirs();
+            
+            if( !created )
+            {
+                throw new IllegalArgumentException( "Could not create the given config directory " + configDir );
+            }
+        }
+        
+        System.setProperty( "escimo.config.dir", dir.getAbsolutePath() );
+        
+        File jsonSchemaDir = new File( dir, "json-schema" );
+        jsonSchemaDir.mkdir();
+        
+        System.setProperty( "escimo.json.schema.dir", jsonSchemaDir.getAbsolutePath() );
+        /*
+        File[] propFiles = dir.listFiles();
+        
+        for( File f : propFiles )
+        {
+            if( f.getName().endsWith( ".properties" ) )
+            {
+                Properties props = new Properties();
+                
+                FileInputStream fin = null;
+                
+                try
+                {
+                    fin = new FileInputStream( f );
+                    props.load( fin );
+                    System.setProperties( props );
+                }
+                catch( Exception e )
+                {
+                    throw new RuntimeException( e );
+                }
+                finally
+                {
+                    if( fin != null )
+                    {
+                        try
+                        {
+                            fin.close();
+                        }
+                        catch( IOException e )
+                        {
+                            //ignore
+                        }
+                    }
+                }
+            }
+        } 
+        */
+    }
+
+}

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=1546811&r1=1546810&r2=1546811&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 Sun Dec  1 12:37:36 2013
@@ -75,13 +75,13 @@ public class GroupService
         
         try
         {
-            RequestContext ctx = new RequestContext( provider, uriInfo, httpReq );
+            RequestContext ctx = provider.createCtx( uriInfo, httpReq );
             
             GroupResource group = provider.getGroup( ctx, groupId );
             String json = ResourceSerializer.serialize( group );
             rb = Response.ok( json, MediaType.APPLICATION_JSON );
         }
-        catch( ResourceNotFoundException e )
+        catch( Exception e )
         {
             rb = buildError( e );
         }
@@ -98,7 +98,8 @@ public class GroupService
         
         try
         {
-            provider.deleteGroup( groupId );
+            RequestContext ctx = provider.createCtx( uriInfo, httpReq );
+            provider.deleteGroup( groupId, ctx );
         }
         catch( Exception e )
         {
@@ -124,7 +125,7 @@ public class GroupService
         
         try
         {
-            RequestContext ctx = new RequestContext( provider, uriInfo, httpReq );
+            RequestContext ctx = provider.createCtx( uriInfo, httpReq );
             
             provider.addGroup( jsonData, ctx );
             
@@ -161,7 +162,7 @@ public class GroupService
         
         try
         {
-            RequestContext ctx = new RequestContext( provider, uriInfo, httpReq );
+            RequestContext ctx = provider.createCtx( uriInfo, httpReq );
             
             ServerResource res = provider.putGroup( groupId, jsonData, ctx );
             
@@ -195,7 +196,7 @@ public class GroupService
         
         try
         {
-            RequestContext ctx = new RequestContext( provider, uriInfo, httpReq );
+            RequestContext ctx = provider.createCtx( uriInfo, httpReq );
             
             ServerResource resource = provider.patchGroup( groupId, jsonData, ctx );
             
@@ -234,7 +235,7 @@ public class GroupService
     
         try
         {
-            RequestContext ctx = new RequestContext( provider, uriInfo, httpReq );
+            RequestContext ctx = provider.createCtx( uriInfo, httpReq );
             ListResponse lr = provider.search( filter, attributes, ctx );
 
             String json = ResourceSerializer.serialize( lr );

Modified: directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/ServerInitializer.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/ServerInitializer.java?rev=1546811&r1=1546810&r2=1546811&view=diff
==============================================================================
--- directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/ServerInitializer.java (original)
+++ directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/ServerInitializer.java Sun Dec  1 12:37:36 2013
@@ -19,17 +19,8 @@
  */
 package org.apache.directory.scim.rest;
 
-import java.net.URL;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 import org.apache.commons.lang.StringUtils;
 import org.apache.directory.scim.ProviderService;
-import org.apache.directory.scim.schema.SchemaUtil;
-
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
 
 /**
  * TODO ServerInitializer.

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=1546811&r1=1546810&r2=1546811&view=diff
==============================================================================
--- directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/UserService.java (original)
+++ directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/UserService.java Sun Dec  1 12:37:36 2013
@@ -78,7 +78,7 @@ public class UserService
         
         try
         {
-            RequestContext ctx = new RequestContext( provider, uriInfo, httpReq );
+            RequestContext ctx = provider.createCtx( uriInfo, httpReq );
             
             UserResource user = provider.getUser( ctx, userId );
             String json = ResourceSerializer.serialize( user );
@@ -101,7 +101,8 @@ public class UserService
         
         try
         {
-            provider.deleteUser( userId );
+            RequestContext ctx = provider.createCtx( uriInfo, httpReq );
+            provider.deleteUser( userId, ctx );
         }
         catch( Exception e )
         {
@@ -127,7 +128,7 @@ public class UserService
         
         try
         {
-            RequestContext ctx = new RequestContext( provider, uriInfo, httpReq );
+            RequestContext ctx = provider.createCtx( uriInfo, httpReq );
             
             provider.addUser( jsonData, ctx );
             
@@ -164,7 +165,7 @@ public class UserService
         
         try
         {
-            RequestContext ctx = new RequestContext( provider, uriInfo, httpReq );
+            RequestContext ctx = provider.createCtx( uriInfo, httpReq );
             
             ServerResource res = provider.putUser( userId, jsonData, ctx );
             
@@ -199,7 +200,7 @@ public class UserService
         
         try
         {
-            RequestContext ctx = new RequestContext( provider, uriInfo, httpReq );
+            RequestContext ctx = provider.createCtx( uriInfo, httpReq );
             
             ServerResource resource = provider.patchUser( userId, jsonData, ctx );
             
@@ -239,7 +240,7 @@ public class UserService
     
         try
         {
-            RequestContext ctx = new RequestContext( provider, uriInfo, httpReq );
+            RequestContext ctx = provider.createCtx( uriInfo, httpReq );
             ListResponse lr = provider.search( filter, attributes, ctx );
 
             String json = ResourceSerializer.serialize( lr );
@@ -257,13 +258,16 @@ public class UserService
     @GET
     @Produces({MediaType.APPLICATION_OCTET_STREAM})
     @Path("photo")
-    public Response getPhoto( @QueryParam("atName") String atName, @QueryParam("id") String id )
+    public Response getPhoto( @QueryParam("atName") String atName, @QueryParam("id") String id, @Context UriInfo uriInfo )
     {
         ResponseBuilder rb = Response.ok();
         
         try
         {
-            final InputStream in = provider.getUserPhoto( id, atName );
+            RequestContext ctx = provider.createCtx( uriInfo, httpReq );
+            
+            final InputStream in = provider.getUserPhoto( id, atName, ctx );
+            
             if( in == null )
             {
                 rb.status( Status.NOT_FOUND ).entity( "No photo found for the resource with ID " + id + " and attribute name " + atName );
@@ -300,7 +304,7 @@ public class UserService
                 rb.entity( streamOut );
             }
         }
-        catch( MissingParameterException e )
+        catch( Exception e )
         {
             rb = buildError( e );
         }

Modified: directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/auth/AuthenticationFilter.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/auth/AuthenticationFilter.java?rev=1546811&r1=1546810&r2=1546811&view=diff
==============================================================================
--- directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/auth/AuthenticationFilter.java (original)
+++ directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/auth/AuthenticationFilter.java Sun Dec  1 12:37:36 2013
@@ -146,7 +146,11 @@ public class AuthenticationFilter implem
             authenticator = new BasicAuthenticator();
         }
         
-        provider = ServerInitializer.getProvider();
+        if( authenticator != null )
+        {
+            provider = ServerInitializer.getProvider();
+            provider.setAllowAuthorizedUsers( true );
+        }
     }
 
 }

Modified: directory/escimo/trunk/server/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/server/src/main/webapp/WEB-INF/web.xml?rev=1546811&r1=1546810&r2=1546811&view=diff
==============================================================================
--- directory/escimo/trunk/server/src/main/webapp/WEB-INF/web.xml (original)
+++ directory/escimo/trunk/server/src/main/webapp/WEB-INF/web.xml Sun Dec  1 12:37:36 2013
@@ -4,6 +4,16 @@
     "http://java.sun.com/dtd/web-app_2_3.dtd">
 
 <web-app>
+
+    <filter>
+     <filter-name>escimoConfigServlet</filter-name>
+     <filter-class>org.apache.directory.scim.rest.ConfigurationFilter</filter-class>
+        <init-param>
+            <param-name>configDir</param-name>
+            <param-value>/WEB-INF/conf</param-value>
+        </init-param>
+    </filter>
+
     <filter>
      <filter-name>AuthenticationFilter</filter-name>
      <filter-class>org.apache.directory.scim.rest.auth.AuthenticationFilter</filter-class>



Mime
View raw message