You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2011/10/15 00:36:15 UTC

svn commit: r1183537 [3/11] - in /directory/apacheds/trunk/interceptors: admin/ admin/.settings/ authn/ authn/.settings/ authz/.settings/ changelog/ changelog/src/ changelog/src/main/ changelog/src/main/java/ changelog/src/main/java/org/ changelog/src/...

Added: directory/apacheds/trunk/interceptors/exception/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/exception/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/exception/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java (added)
+++ directory/apacheds/trunk/interceptors/exception/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,453 @@
+/*
+ *  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.server.core.exception;
+
+
+import org.apache.commons.collections.map.LRUMap;
+import org.apache.directory.server.core.shared.SchemaService;
+import org.apache.directory.server.core.api.DirectoryService;
+import org.apache.directory.server.core.api.entry.ClonedServerEntry;
+import org.apache.directory.server.core.api.filtering.BaseEntryFilteringCursor;
+import org.apache.directory.server.core.api.filtering.EntryFilteringCursor;
+import org.apache.directory.server.core.api.interceptor.BaseInterceptor;
+import org.apache.directory.server.core.api.interceptor.NextInterceptor;
+import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.DeleteOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.EntryOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.ListOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.MoveAndRenameOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.MoveOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.OperationContext;
+import org.apache.directory.server.core.api.interceptor.context.RenameOperationContext;
+import org.apache.directory.server.core.api.partition.ByPassConstants;
+import org.apache.directory.server.core.api.partition.Partition;
+import org.apache.directory.server.core.api.partition.PartitionNexus;
+import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.cursor.EmptyCursor;
+import org.apache.directory.shared.ldap.model.entry.Attribute;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.entry.Value;
+import org.apache.directory.shared.ldap.model.exception.LdapAliasException;
+import org.apache.directory.shared.ldap.model.exception.LdapEntryAlreadyExistsException;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.exception.LdapNoSuchObjectException;
+import org.apache.directory.shared.ldap.model.exception.LdapUnwillingToPerformException;
+import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.model.name.Dn;
+
+
+/**
+ * An {@link org.apache.directory.server.core.api.interceptor.Interceptor} that detects any operations that breaks integrity
+ * of {@link Partition} and terminates the current invocation chain by
+ * throwing a {@link Exception}. Those operations include when an entry
+ * already exists at a Dn and is added once again to the same Dn.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ExceptionInterceptor extends BaseInterceptor
+{
+    private PartitionNexus nexus;
+    private Dn subschemSubentryDn;
+
+    /**
+     * A cache to store entries which are not aliases.
+     * It's a speedup, we will be able to avoid backend lookups.
+     *
+     * Note that the backend also use a cache mechanism, but for performance gain, it's good
+     * to manage a cache here. The main problem is that when a user modify the parent, we will
+     * have to update it at three different places :
+     * - in the backend,
+     * - in the partition cache,
+     * - in this cache.
+     *
+     * The update of the backend and partition cache is already correctly handled, so we will
+     * just have to offer an access to refresh the local cache. This should be done in
+     * delete, modify and move operations.
+     *
+     * We need to be sure that frequently used DNs are always in cache, and not discarded.
+     * We will use a LRU cache for this purpose.
+     */
+    private final LRUMap notAliasCache = new LRUMap( DEFAULT_CACHE_SIZE );
+
+    /** Declare a default for this cache. 100 entries seems to be enough */
+    private static final int DEFAULT_CACHE_SIZE = 100;
+
+    /**
+     * Creates an interceptor that is also the exception handling service.
+     */
+    public ExceptionInterceptor()
+    {
+    }
+
+
+    public void init( DirectoryService directoryService ) throws LdapException
+    {
+        super.init( directoryService );
+        nexus = directoryService.getPartitionNexus();
+        Value<?> attr = nexus.getRootDSE( null ).get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).get();
+        subschemSubentryDn = directoryService.getDnFactory().create( attr.getString() );
+    }
+
+
+    public void destroy()
+    {
+    }
+
+
+    /**
+     * In the pre-invocation state this interceptor method checks to see if the entry to be added already exists.  If it
+     * does an exception is raised.
+     */
+    public void add( NextInterceptor nextInterceptor, AddOperationContext addContext ) throws LdapException
+    {
+        Dn name = addContext.getDn();
+
+        if ( subschemSubentryDn.equals( name ) )
+        {
+            throw new LdapEntryAlreadyExistsException( I18n.err( I18n.ERR_249 ) );
+        }
+
+        Dn suffix = nexus.getSuffixDn( name );
+
+        // we're adding the suffix entry so just ignore stuff to mess with the parent
+        if ( suffix.equals( name ) )
+        {
+            nextInterceptor.add( addContext );
+            return;
+        }
+
+        Dn parentDn = name.getParent();
+
+        // check if we're trying to add to a parent that is an alias
+        boolean notAnAlias;
+
+        synchronized ( notAliasCache )
+        {
+            notAnAlias = notAliasCache.containsKey( parentDn.getNormName() );
+        }
+
+        if ( !notAnAlias )
+        {
+            // We don't know if the parent is an alias or not, so we will launch a
+            // lookup, and update the cache if it's not an alias
+            Entry attrs;
+
+            try
+            {
+                attrs = addContext.lookup( parentDn, ByPassConstants.LOOKUP_BYPASS, SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+            }
+            catch ( Exception e )
+            {
+                LdapNoSuchObjectException e2 = new LdapNoSuchObjectException(
+                    I18n.err( I18n.ERR_251_PARENT_NOT_FOUND, parentDn.getName() ) );
+                throw e2;
+            }
+
+            Attribute objectClass = ( ( ClonedServerEntry ) attrs ).getOriginalEntry().get(
+                OBJECT_CLASS_AT );
+
+            if ( objectClass.contains( SchemaConstants.ALIAS_OC ) )
+            {
+                String msg = I18n.err( I18n.ERR_252_ALIAS_WITH_CHILD_NOT_ALLOWED, name.getName(), parentDn.getName() );
+                LdapAliasException e = new LdapAliasException( msg );
+                //e.setResolvedName( DNFactory.create( parentDn.getName() ) );
+                throw e;
+            }
+            else
+            {
+                synchronized ( notAliasCache )
+                {
+                    notAliasCache.put( parentDn.getNormName(), parentDn );
+                }
+            }
+        }
+
+        nextInterceptor.add( addContext );
+    }
+
+
+    /**
+     * Checks to make sure the entry being deleted exists, and has no children, otherwise throws the appropriate
+     * LdapException.
+     */
+    public void delete( NextInterceptor nextInterceptor, DeleteOperationContext deleteContext ) throws LdapException
+    {
+        Dn dn = deleteContext.getDn();
+
+        if ( dn.equals( subschemSubentryDn ) )
+        {
+            throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_253,
+                subschemSubentryDn ) );
+        }
+
+        nextInterceptor.delete( deleteContext );
+
+        // Update the alias cache
+        synchronized ( notAliasCache )
+        {
+            if ( notAliasCache.containsKey( dn.getNormName() ) )
+            {
+                notAliasCache.remove( dn.getNormName() );
+            }
+        }
+    }
+
+
+    /**
+     * Checks to see the base being searched exists, otherwise throws the appropriate LdapException.
+     */
+    public EntryFilteringCursor list( NextInterceptor nextInterceptor, ListOperationContext listContext )
+        throws LdapException
+    {
+        if ( listContext.getDn().getNormName().equals( subschemSubentryDn.getNormName() ) )
+        {
+            // there is nothing under the schema subentry
+            return new BaseEntryFilteringCursor( new EmptyCursor<Entry>(), listContext );
+        }
+
+        // check if entry to search exists
+        //String msg = "Attempt to search under non-existant entry: ";
+        //assertHasEntry( listContext, msg, listContext.getDn() );
+
+        return nextInterceptor.list( listContext );
+    }
+
+
+    /**
+     * Checks to see the base being searched exists, otherwise throws the appropriate LdapException.
+     */
+    public Entry lookup( NextInterceptor nextInterceptor, LookupOperationContext lookupContext ) throws LdapException
+    {
+        Dn dn = lookupContext.getDn();
+
+        if ( dn.equals( subschemSubentryDn ) )
+        {
+            Entry serverEntry = SchemaService.getSubschemaEntry( directoryService, lookupContext.getAttrsIdArray() );
+            serverEntry.setDn( dn );
+
+            return serverEntry;
+        }
+
+        Entry result = nextInterceptor.lookup( lookupContext );
+
+        return result;
+    }
+
+
+    /**
+     * Checks to see the entry being modified exists, otherwise throws the appropriate LdapException.
+     */
+    public void modify( NextInterceptor nextInterceptor, ModifyOperationContext modifyContext ) throws LdapException
+    {
+        // check if entry to modify exists
+        String msg = "Attempt to modify non-existant entry: ";
+
+        // handle operations against the schema subentry in the schema service
+        // and never try to look it up in the nexus below
+        if ( modifyContext.getDn().equals( subschemSubentryDn ) )
+        {
+            nextInterceptor.modify( modifyContext );
+            return;
+        }
+
+        // Check that the entry we read at the beginning exists. If
+        // not, we will throw an exception here
+        assertHasEntry( modifyContext, msg );
+
+        // Let's assume that the new modified entry may be an alias,
+        // but we don't want to check that now...
+        // We will simply remove the Dn from the NotAlias cache.
+        // It would be smarter to check the modified attributes, but
+        // it would also be more complex.
+        synchronized ( notAliasCache )
+        {
+            if ( notAliasCache.containsKey( modifyContext.getDn().getNormName() ) )
+            {
+                notAliasCache.remove( modifyContext.getDn().getNormName() );
+            }
+        }
+
+        nextInterceptor.modify( modifyContext );
+    }
+
+
+    /**
+     * Checks to see the entry being renamed exists, otherwise throws the appropriate LdapException.
+     */
+    public void rename( NextInterceptor nextInterceptor, RenameOperationContext renameContext ) throws LdapException
+    {
+        Dn dn = renameContext.getDn();
+
+        if ( dn.equals( subschemSubentryDn ) )
+        {
+            throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_255,
+                subschemSubentryDn, subschemSubentryDn ) );
+        }
+
+        // check to see if target entry exists
+        Dn newDn = renameContext.getNewDn();
+
+        if ( nextInterceptor.hasEntry( new EntryOperationContext( renameContext.getSession(), newDn ) ) )
+        {
+            LdapEntryAlreadyExistsException e;
+            e = new LdapEntryAlreadyExistsException( I18n.err( I18n.ERR_250_ENTRY_ALREADY_EXISTS, newDn.getName() ) );
+            //e.setResolvedName( DNFactory.create( newDn.getName() ) );
+            throw e;
+        }
+
+        // Remove the previous entry from the notAnAlias cache
+        synchronized ( notAliasCache )
+        {
+            if ( notAliasCache.containsKey( dn.getNormName() ) )
+            {
+                notAliasCache.remove( dn.getNormName() );
+            }
+        }
+
+        nextInterceptor.rename( renameContext );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void move( NextInterceptor nextInterceptor, MoveOperationContext moveContext ) throws LdapException
+    {
+        Dn oriChildName = moveContext.getDn();
+
+        if ( oriChildName.equals( subschemSubentryDn ) )
+        {
+            throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_258,
+                subschemSubentryDn, subschemSubentryDn ) );
+        }
+
+        nextInterceptor.move( moveContext );
+
+        // Remove the original entry from the NotAlias cache, if needed
+        synchronized ( notAliasCache )
+        {
+            if ( notAliasCache.containsKey( oriChildName.getNormName() ) )
+            {
+                notAliasCache.remove( oriChildName.getNormName() );
+            }
+        }
+    }
+
+
+    /**
+     * Checks to see the entry being moved exists, and so does its parent, otherwise throws the appropriate
+     * LdapException.
+     */
+    public void moveAndRename( NextInterceptor nextInterceptor, MoveAndRenameOperationContext moveAndRenameContext )
+        throws LdapException
+    {
+        Dn oldDn = moveAndRenameContext.getDn();
+
+        // Don't allow M&R in the SSSE
+        if ( oldDn.equals( subschemSubentryDn ) )
+        {
+            throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_258,
+                subschemSubentryDn, subschemSubentryDn ) );
+        }
+
+        // Remove the original entry from the NotAlias cache, if needed
+        synchronized ( notAliasCache )
+        {
+            if ( notAliasCache.containsKey( oldDn.getNormName() ) )
+            {
+                notAliasCache.remove( oldDn.getNormName() );
+            }
+        }
+
+        nextInterceptor.moveAndRename( moveAndRenameContext );
+    }
+
+
+    /**
+     * Asserts that an entry is present and as a side effect if it is not, creates a LdapNoSuchObjectException, which is
+     * used to set the before exception on the invocation - eventually the exception is thrown.
+     *
+     * @param msg        the message to prefix to the distinguished name for explanation
+     * @throws Exception if the entry does not exist
+     * @param nextInterceptor the next interceptor in the chain
+     */
+    private void assertHasEntry( OperationContext opContext, String msg ) throws LdapException
+    {
+        Dn dn = opContext.getDn();
+
+        if ( subschemSubentryDn.equals( dn ) )
+        {
+            return;
+        }
+
+        if ( opContext.getEntry() == null )
+        {
+            LdapNoSuchObjectException e;
+
+            if ( msg != null )
+            {
+                e = new LdapNoSuchObjectException( msg + dn.getName() );
+            }
+            else
+            {
+                e = new LdapNoSuchObjectException( dn.getName() );
+            }
+
+            throw e;
+        }
+    }
+
+
+    /**
+     * Asserts that an entry is present and as a side effect if it is not, creates a LdapNoSuchObjectException, which is
+     * used to set the before exception on the invocation - eventually the exception is thrown.
+     *
+     * @param msg        the message to prefix to the distinguished name for explanation
+     * @param dn         the distinguished name of the entry that is asserted
+     * @throws Exception if the entry does not exist
+     * @param nextInterceptor the next interceptor in the chain
+     *
+    private void assertHasEntry( OperationContext opContext, String msg, Dn dn ) throws LdapException
+    {
+        if ( subschemSubentryDn.equals( dn ) )
+        {
+            return;
+        }
+
+        if ( !opContext.hasEntry( dn, ByPassConstants.HAS_ENTRY_BYPASS ) )
+        {
+            LdapNoSuchObjectException e;
+
+            if ( msg != null )
+            {
+                e = new LdapNoSuchObjectException( msg + dn.getName() );
+            }
+            else
+            {
+                e = new LdapNoSuchObjectException( dn.getName() );
+            }
+
+            throw e;
+        }
+    }*/
+}

Propchange: directory/apacheds/trunk/interceptors/hash/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Oct 14 22:36:08 2011
@@ -0,0 +1,11 @@
+target
+.project
+.classpath
+.settings
+eclipse-classes
+*.log
+*.iml
+*.ipr
+dependency-reduced-pom.xml
+META-INF
+

Added: directory/apacheds/trunk/interceptors/hash/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/hash/pom.xml?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/hash/pom.xml (added)
+++ directory/apacheds/trunk/interceptors/hash/pom.xml Fri Oct 14 22:36:08 2011
@@ -0,0 +1,183 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.directory.server</groupId>
+    <artifactId>apacheds-interceptors</artifactId>
+    <version>2.0.0-M4-SNAPSHOT</version>
+  </parent>
+  
+  <artifactId>apacheds-interceptors-hash</artifactId>
+  <name>ApacheDS Password Hashing Interceptor</name>
+  <packaging>jar</packaging>
+
+  <description>
+    Password Hashing interceptor
+  </description>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.directory.junit</groupId>
+      <artifactId>junit-addons</artifactId>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>apacheds-i18n</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>apacheds-core-api</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>apacheds-core-api</artifactId>
+      <classifier>tests</classifier>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>apacheds-interceptors-authn</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>commons-collections</groupId>
+      <artifactId>commons-collections</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-client-api</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-i18n</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-codec-standalone</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-codec-core</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-extras-aci</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-extras-trigger</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-extras-util</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-model</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-schema-data</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-util</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>bouncycastle</groupId>
+      <artifactId>bcprov-jdk15</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>net.sf.ehcache</groupId>
+      <artifactId>ehcache-core</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-extras-codec</artifactId>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration> 
+          <systemPropertyVariables>
+            <workingDirectory>${basedir}/target/server-work</workingDirectory>
+          </systemPropertyVariables>
+        </configuration>
+      </plugin>
+      
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-source-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>attach-sources</id>
+            <phase>verify</phase>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+
+    <resources>
+      <resource>
+        <directory>src/main/resources</directory>
+        <filtering>true</filtering>
+        <excludes>
+          <exclude>**/*.gif</exclude>
+        </excludes>
+      </resource>
+    </resources>
+  </build>
+</project>
+

Added: directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/CryptPasswordHashingInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/CryptPasswordHashingInterceptor.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/CryptPasswordHashingInterceptor.java (added)
+++ directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/CryptPasswordHashingInterceptor.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,36 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+
+package org.apache.directory.server.core.hash;
+
+import org.apache.directory.shared.ldap.model.constants.LdapSecurityConstants;
+
+/**
+ * PasswordHashingInterceptor using CRYPT hashing algorithm.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class CryptPasswordHashingInterceptor extends PasswordHashingInterceptor
+{
+    public CryptPasswordHashingInterceptor()
+    {
+        super( LdapSecurityConstants.HASH_METHOD_CRYPT );
+    }
+}

Added: directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Md5PasswordHashingInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Md5PasswordHashingInterceptor.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Md5PasswordHashingInterceptor.java (added)
+++ directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Md5PasswordHashingInterceptor.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,36 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+
+package org.apache.directory.server.core.hash;
+
+import org.apache.directory.shared.ldap.model.constants.LdapSecurityConstants;
+
+/**
+ * PasswordHashingInterceptor using MD5 hashing algorithm.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class Md5PasswordHashingInterceptor extends PasswordHashingInterceptor
+{
+    public Md5PasswordHashingInterceptor()
+    {
+        super( LdapSecurityConstants.HASH_METHOD_MD5 );
+    }
+}

Added: directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/PasswordHashingInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/PasswordHashingInterceptor.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/PasswordHashingInterceptor.java (added)
+++ directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/PasswordHashingInterceptor.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,148 @@
+/*
+ *   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.server.core.hash;
+
+
+import java.util.List;
+
+import org.apache.directory.server.core.api.interceptor.BaseInterceptor;
+import org.apache.directory.server.core.api.interceptor.NextInterceptor;
+import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext;
+import org.apache.directory.server.core.authn.PasswordUtil;
+import org.apache.directory.shared.ldap.model.constants.LdapSecurityConstants;
+import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.entry.BinaryValue;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.entry.Attribute;
+import org.apache.directory.shared.ldap.model.entry.Modification;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+
+
+/**
+ * An interceptor to hash plain text password according to the configured
+ * hashing algorithm.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class PasswordHashingInterceptor extends BaseInterceptor
+{
+
+    /** the hashing algorithm to be used, if null then the password won't be changed */
+    private LdapSecurityConstants algorithm;
+
+
+    /**
+     * Creates a new instance of PasswordHashingInterceptor which does not hash the passwords.
+     */
+    public PasswordHashingInterceptor()
+    {
+        this( null );
+    }
+
+
+    /**
+     * 
+     * Creates a new instance of PasswordHashingInterceptor which hashes the
+     * incoming non-hashed password using the given algorithm.
+     * If the password is found already hashed then it will skip hashing it.
+     *  
+     * @param algorithm the name of the algorithm to be used
+     */
+    public PasswordHashingInterceptor( LdapSecurityConstants algorithm )
+    {
+        this.algorithm = algorithm;
+    }
+
+
+    @Override
+    public void add( NextInterceptor next, AddOperationContext addContext ) throws LdapException
+    {
+        if ( algorithm == null )
+        {
+            next.add( addContext );
+            return;
+        }
+
+        Entry entry = addContext.getEntry();
+
+        Attribute pwdAt = entry.get( SchemaConstants.USER_PASSWORD_AT );
+
+        includeHashedPassword( pwdAt );
+
+        next.add( addContext );
+    }
+
+
+    @Override
+    public void modify( NextInterceptor next, ModifyOperationContext modifyContext ) throws LdapException
+    {
+        if ( algorithm == null )
+        {
+            next.modify( modifyContext );
+            return;
+        }
+
+        List<Modification> mods = modifyContext.getModItems();
+
+        for ( Modification mod : mods )
+        {
+            String oid = mod.getAttribute().getAttributeType().getOid();
+
+            // check for modification on 'userPassword' AT 
+            if ( SchemaConstants.USER_PASSWORD_AT_OID.equals( oid ) )
+            {
+                includeHashedPassword( mod.getAttribute() );
+                break;
+            }
+        }
+
+        next.modify( modifyContext );
+    }
+
+
+    /**
+     * hash the password if it was <i>not</i> already hashed
+     *
+     * @param pwdAt the password attribute
+     */
+    private void includeHashedPassword( Attribute pwdAt ) throws LdapException
+    {
+        if ( pwdAt == null )
+        {
+            return;
+        }
+
+        BinaryValue userPassword = ( BinaryValue ) pwdAt.get();
+
+        // check if the given password is already hashed
+        LdapSecurityConstants existingAlgo = PasswordUtil.findAlgorithm( userPassword.getValue() );
+
+        // if there exists NO algorithm, then hash the password
+        if ( existingAlgo == null )
+        {
+            byte[] hashedPassword = PasswordUtil.createStoragePassword( userPassword.getValue(), algorithm );
+
+            pwdAt.clear();
+            pwdAt.add( hashedPassword );
+        }
+    }
+}

Added: directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Sha256PasswordHashingInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Sha256PasswordHashingInterceptor.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Sha256PasswordHashingInterceptor.java (added)
+++ directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Sha256PasswordHashingInterceptor.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,36 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+
+package org.apache.directory.server.core.hash;
+
+import org.apache.directory.shared.ldap.model.constants.LdapSecurityConstants;
+
+/**
+ * PasswordHashingInterceptor using SHA-256 hashing algorithm.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class Sha256PasswordHashingInterceptor extends PasswordHashingInterceptor
+{
+    public Sha256PasswordHashingInterceptor()
+    {
+        super( LdapSecurityConstants.HASH_METHOD_SHA256 );
+    }
+}

Added: directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Sha384PasswordHashingInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Sha384PasswordHashingInterceptor.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Sha384PasswordHashingInterceptor.java (added)
+++ directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Sha384PasswordHashingInterceptor.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,36 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+
+package org.apache.directory.server.core.hash;
+
+import org.apache.directory.shared.ldap.model.constants.LdapSecurityConstants;
+
+/**
+ * PasswordHashingInterceptor using SHA-384 hashing algorithm.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class Sha384PasswordHashingInterceptor extends PasswordHashingInterceptor
+{
+    public Sha384PasswordHashingInterceptor()
+    {
+        super( LdapSecurityConstants.HASH_METHOD_SHA384 );
+    }
+}

Added: directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Sha512PasswordHashingInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Sha512PasswordHashingInterceptor.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Sha512PasswordHashingInterceptor.java (added)
+++ directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Sha512PasswordHashingInterceptor.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,36 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+
+package org.apache.directory.server.core.hash;
+
+import org.apache.directory.shared.ldap.model.constants.LdapSecurityConstants;
+
+/**
+ * PasswordHashingInterceptor using SHA-512 hashing algorithm.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class Sha512PasswordHashingInterceptor extends PasswordHashingInterceptor
+{
+    public Sha512PasswordHashingInterceptor()
+    {
+        super( LdapSecurityConstants.HASH_METHOD_SHA512 );
+    }
+}

Added: directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/ShaPasswordHashingInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/ShaPasswordHashingInterceptor.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/ShaPasswordHashingInterceptor.java (added)
+++ directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/ShaPasswordHashingInterceptor.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,36 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+
+package org.apache.directory.server.core.hash;
+
+import org.apache.directory.shared.ldap.model.constants.LdapSecurityConstants;
+
+/**
+ * PasswordHashingInterceptor using SHA hashing algorithm.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ShaPasswordHashingInterceptor extends PasswordHashingInterceptor
+{
+    public ShaPasswordHashingInterceptor()
+    {
+        super( LdapSecurityConstants.HASH_METHOD_SHA );
+    }
+}

Added: directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Smd5PasswordHashingInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Smd5PasswordHashingInterceptor.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Smd5PasswordHashingInterceptor.java (added)
+++ directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Smd5PasswordHashingInterceptor.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,36 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+
+package org.apache.directory.server.core.hash;
+
+import org.apache.directory.shared.ldap.model.constants.LdapSecurityConstants;
+
+/**
+ * PasswordHashingInterceptor using SMD5 hashing algorithm.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class Smd5PasswordHashingInterceptor extends PasswordHashingInterceptor
+{
+    public Smd5PasswordHashingInterceptor()
+    {
+        super( LdapSecurityConstants.HASH_METHOD_SMD5 );
+    }
+}

Added: directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Ssha256PasswordHashingInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Ssha256PasswordHashingInterceptor.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Ssha256PasswordHashingInterceptor.java (added)
+++ directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Ssha256PasswordHashingInterceptor.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,36 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+
+package org.apache.directory.server.core.hash;
+
+import org.apache.directory.shared.ldap.model.constants.LdapSecurityConstants;
+
+/**
+ * PasswordHashingInterceptor using SSHA-256 hashing algorithm.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class Ssha256PasswordHashingInterceptor extends PasswordHashingInterceptor
+{
+    public Ssha256PasswordHashingInterceptor()
+    {
+        super( LdapSecurityConstants.HASH_METHOD_SSHA256 );
+    }
+}

Added: directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Ssha384PasswordHashingInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Ssha384PasswordHashingInterceptor.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Ssha384PasswordHashingInterceptor.java (added)
+++ directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Ssha384PasswordHashingInterceptor.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,36 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+
+package org.apache.directory.server.core.hash;
+
+import org.apache.directory.shared.ldap.model.constants.LdapSecurityConstants;
+
+/**
+ * PasswordHashingInterceptor using SSHA-384 hashing algorithm.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class Ssha384PasswordHashingInterceptor extends PasswordHashingInterceptor
+{
+    public Ssha384PasswordHashingInterceptor()
+    {
+        super( LdapSecurityConstants.HASH_METHOD_SSHA384 );
+    }
+}

Added: directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Ssha512PasswordHashingInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Ssha512PasswordHashingInterceptor.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Ssha512PasswordHashingInterceptor.java (added)
+++ directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/Ssha512PasswordHashingInterceptor.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,36 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+
+package org.apache.directory.server.core.hash;
+
+import org.apache.directory.shared.ldap.model.constants.LdapSecurityConstants;
+
+/**
+ * PasswordHashingInterceptor using SSHA-512 hashing algorithm.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class Ssha512PasswordHashingInterceptor extends PasswordHashingInterceptor
+{
+    public Ssha512PasswordHashingInterceptor()
+    {
+        super( LdapSecurityConstants.HASH_METHOD_SSHA512 );
+    }
+}

Added: directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/SshaPasswordHashingInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/SshaPasswordHashingInterceptor.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/SshaPasswordHashingInterceptor.java (added)
+++ directory/apacheds/trunk/interceptors/hash/src/main/java/org/apache/directory/server/core/hash/SshaPasswordHashingInterceptor.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,36 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+
+package org.apache.directory.server.core.hash;
+
+import org.apache.directory.shared.ldap.model.constants.LdapSecurityConstants;
+
+/**
+ * PasswordHashingInterceptor using SSHA hashing algorithm.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SshaPasswordHashingInterceptor extends PasswordHashingInterceptor
+{
+    public SshaPasswordHashingInterceptor()
+    {
+        super( LdapSecurityConstants.HASH_METHOD_SSHA );
+    }
+}

Propchange: directory/apacheds/trunk/interceptors/journal/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Oct 14 22:36:08 2011
@@ -0,0 +1,9 @@
+asspath
+.settings
+eclipse-classes
+*.log
+*.iml
+*.ipr
+dependency-reduced-pom.xml
+META-INF
+

Added: directory/apacheds/trunk/interceptors/journal/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/journal/pom.xml?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/journal/pom.xml (added)
+++ directory/apacheds/trunk/interceptors/journal/pom.xml Fri Oct 14 22:36:08 2011
@@ -0,0 +1,178 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.directory.server</groupId>
+    <artifactId>apacheds-interceptors</artifactId>
+    <version>2.0.0-M4-SNAPSHOT</version>
+  </parent>
+  
+  <artifactId>apacheds-interceptors-journal</artifactId>
+  <name>ApacheDS Journal Interceptor</name>
+  <packaging>jar</packaging>
+
+  <description>
+    Journal interceptor
+  </description>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.directory.junit</groupId>
+      <artifactId>junit-addons</artifactId>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>apacheds-i18n</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>apacheds-core-api</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>apacheds-core-api</artifactId>
+      <classifier>tests</classifier>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>commons-collections</groupId>
+      <artifactId>commons-collections</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-client-api</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-i18n</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-codec-standalone</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-codec-core</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-extras-aci</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-extras-trigger</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-extras-util</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-model</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-schema-data</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-util</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>bouncycastle</groupId>
+      <artifactId>bcprov-jdk15</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>net.sf.ehcache</groupId>
+      <artifactId>ehcache-core</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-extras-codec</artifactId>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration> 
+          <systemPropertyVariables>
+            <workingDirectory>${basedir}/target/server-work</workingDirectory>
+          </systemPropertyVariables>
+        </configuration>
+      </plugin>
+      
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-source-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>attach-sources</id>
+            <phase>verify</phase>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+
+    <resources>
+      <resource>
+        <directory>src/main/resources</directory>
+        <filtering>true</filtering>
+        <excludes>
+          <exclude>**/*.gif</exclude>
+        </excludes>
+      </resource>
+    </resources>
+  </build>
+</project>
+

Added: directory/apacheds/trunk/interceptors/journal/src/main/java/org/apache/directory/server/core/journal/DefaultJournal.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/journal/src/main/java/org/apache/directory/server/core/journal/DefaultJournal.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/journal/src/main/java/org/apache/directory/server/core/journal/DefaultJournal.java (added)
+++ directory/apacheds/trunk/interceptors/journal/src/main/java/org/apache/directory/server/core/journal/DefaultJournal.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,161 @@
+/*
+ * 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.server.core.journal;
+
+import org.apache.directory.server.core.api.DirectoryService;
+import org.apache.directory.server.core.api.LdapPrincipal;
+import org.apache.directory.server.core.api.journal.Journal;
+import org.apache.directory.server.core.api.journal.JournalStore;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.ldif.LdifEntry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The default journal implementation. It stores the operation and the
+ * associated status (acked or nacked) in a file which will be used to
+ * restore the server if it crashes.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DefaultJournal implements Journal
+{
+    /** The class logger */
+    private static final Logger LOG = LoggerFactory.getLogger( DefaultJournal.class );
+
+    /** Tells if the service is activated or not */ 
+    private boolean enabled;
+
+    /** An instance of the Journal store */
+    private JournalStore store;
+
+    /** 
+     * A parameter indicating the number of operations stored in a journal
+     * before it is rotated. If set to 0, no rotation is done
+     */ 
+    private int rotation;
+    
+    /**
+     * {@inheritDoc}
+     */
+    public void destroy() throws Exception
+    {
+        LOG.debug( "Stopping the journal" );
+        
+        // We have to release the file, otherwise Windows won't be able
+        // to stop the server
+        if ( store != null )
+        {
+            store.destroy();
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public JournalStore getJournalStore()
+    {
+        return store;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void init( DirectoryService directoryService ) throws Exception
+    {
+        LOG.debug( "Starting the journal" );
+
+        if( store == null )
+        {
+            store = new DefaultJournalStore();
+        }
+
+        store.init( directoryService );
+
+        LOG.debug( "The Journal service has been initialized" );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isEnabled()
+    {
+        return enabled;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void log( LdapPrincipal principal, long revision, LdifEntry entry ) throws LdapException
+    {
+        store.log( principal, revision, entry );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void ack( long revision )
+    {
+        store.ack( revision );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void nack( long revision )
+    {
+        store.nack( revision );
+    }
+
+
+    /**
+     * @return the rotation
+     */
+    public int getRotation()
+    {
+        return rotation;
+    }
+
+
+    /**
+     * @param rotation the rotation to set
+     */
+    public void setRotation( int rotation )
+    {
+        this.rotation = rotation;
+    }
+
+    
+    public void setEnabled( boolean enabled )
+    {
+        this.enabled = enabled; 
+    }
+
+
+    public void setJournalStore( JournalStore store )
+    {
+        this.store = store;
+    }
+}

Added: directory/apacheds/trunk/interceptors/journal/src/main/java/org/apache/directory/server/core/journal/DefaultJournalStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/journal/src/main/java/org/apache/directory/server/core/journal/DefaultJournalStore.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/journal/src/main/java/org/apache/directory/server/core/journal/DefaultJournalStore.java (added)
+++ directory/apacheds/trunk/interceptors/journal/src/main/java/org/apache/directory/server/core/journal/DefaultJournalStore.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,236 @@
+/*
+ *   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.server.core.journal;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.Writer;
+
+import org.apache.directory.server.core.api.DirectoryService;
+import org.apache.directory.server.core.api.LdapPrincipal;
+import org.apache.directory.server.core.api.journal.JournalStore;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.ldif.LdifEntry;
+import org.apache.directory.shared.ldap.model.ldif.LdifUtils;
+
+/**
+ * @todo : Missing Javadoc
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+*/
+public class DefaultJournalStore implements JournalStore
+{
+    /** The directory where the journal is stored */
+    private File workingDirectory;
+    
+    /** The journal file name */
+    private String fileName;
+    
+    /** The file containing the journal */
+    private File journal;
+    
+    /** The stream used to write data into the journal */
+    private Writer writer;
+
+    
+    /**
+     * {@inheritDoc}
+     */
+    public void destroy() throws Exception
+    {
+        if ( writer != null )
+        {
+            writer.close();
+        }
+    }
+    
+    
+    /**
+     * Initialize the interceptor
+     */
+    public void init( DirectoryService service ) throws Exception
+    {
+        if ( workingDirectory == null )
+        {
+            workingDirectory = service.getInstanceLayout().getLogDirectory();
+        }
+
+        /** Load or create the journal file */
+        if ( fileName == null )
+        {
+            fileName = "journal.ldif";
+        }
+        
+        journal = new File( workingDirectory, fileName );
+        
+        // The new requests are added at the end of the existing journal
+        writer = new PrintWriter( 
+            new OutputStreamWriter(
+                new FileOutputStream( journal, true ) ) );
+    }
+    
+    
+    /**
+     * Stores an event into the journal.
+     * 
+     * @param principal The principal who is logging the change
+     * @param revision The operation revision
+     * @param forward The change to log
+     */
+    public boolean log( LdapPrincipal principal, long revision, LdifEntry forward )
+    {
+        synchronized ( writer )
+        {
+            try
+            {
+                // Write the LdapPrincipal
+                writer.write( "# principal: " );
+                writer.write( principal.getName() );
+                writer.write( '\n' );
+                
+                // Write the timestamp
+                writer.write( "# timestamp: " );
+                writer.write( Long.toString( System.currentTimeMillis() ) );
+                writer.write( '\n' );
+                
+                // Write the revision
+                writer.write( "# revision: " );
+                writer.write( Long.toString( revision ) );
+                writer.write( "\n" );
+                
+                // Write the entry
+                writer.write( LdifUtils.convertToLdif(forward, 80) );
+                writer.flush();
+            }
+            catch ( LdapException ne )
+            {
+                return false;
+            }
+            catch ( IOException ioe )
+            {
+                return false;
+            }
+        }
+        
+        return true;
+    }
+    
+    
+    /**
+     * Records a ack for a change
+     *
+     * @param revision The change revision which is acked
+     * @return <code>true</code> if the ack has been written
+     * @throws Exception if there are problems logging the ack
+     */
+    public boolean ack( long revision )
+    {
+        synchronized ( writer )
+        {
+            try
+            {
+                // Write the revision
+                writer.write( "# ack-revision: " );
+                writer.write( Long.toString( revision ) );
+                writer.write( "\n\n" );
+
+                writer.flush();
+            }
+            catch ( IOException ioe )
+            {
+                return false;
+            }
+        }
+        
+        return true;
+    }
+    
+    
+    /**
+     * Records a nack for a change
+     *
+     * @param revision The change revision which is nacked
+     * @return <code>true</code> if the nack has been written
+     * @throws Exception if there are problems logging the nack
+     */
+    public boolean nack( long revision )
+    {
+        synchronized ( writer )
+        {
+            try
+            {
+                // Write the revision
+                writer.write( "# nack-revision: " );
+                writer.write( Long.toString( revision ) );
+                writer.write( "\n\n" );
+
+                writer.flush();
+            }
+            catch ( IOException ioe )
+            {
+                return false;
+            }
+        }
+        
+        return true;
+    }
+
+    
+    public void sync() throws Exception
+    {
+        // TODO Auto-generated method stub
+        
+    }
+    
+    public long getCurrentRevision()
+    {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+
+    /**
+     * @return the fileName
+     */
+    public String getFileName()
+    {
+        return fileName;
+    }
+
+
+    /**
+     * @param fileName the fileName to set
+     */
+    public void setFileName( String fileName )
+    {
+        this.fileName = fileName;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void setWorkingDirectory( String workingDirectoryName )
+    {
+        this.workingDirectory = new File( workingDirectoryName );
+    }
+}

Added: directory/apacheds/trunk/interceptors/journal/src/main/java/org/apache/directory/server/core/journal/JournalInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/journal/src/main/java/org/apache/directory/server/core/journal/JournalInterceptor.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/journal/src/main/java/org/apache/directory/server/core/journal/JournalInterceptor.java (added)
+++ directory/apacheds/trunk/interceptors/journal/src/main/java/org/apache/directory/server/core/journal/JournalInterceptor.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,371 @@
+/*
+ * 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.server.core.journal;
+
+
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.directory.server.core.api.DirectoryService;
+import org.apache.directory.server.core.api.interceptor.BaseInterceptor;
+import org.apache.directory.server.core.api.interceptor.NextInterceptor;
+import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.DeleteOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.MoveAndRenameOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.MoveOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.RenameOperationContext;
+import org.apache.directory.server.core.api.journal.Journal;
+import org.apache.directory.shared.ldap.model.entry.Attribute;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.entry.Modification;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.ldif.ChangeType;
+import org.apache.directory.shared.ldap.model.ldif.LdifEntry;
+import org.apache.directory.shared.ldap.model.schema.AttributeType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * An interceptor which intercepts write operations to the directory and
+ * logs them into a journal.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class JournalInterceptor extends BaseInterceptor
+{
+    /** for debugging */
+    private static final Logger LOG = LoggerFactory.getLogger( JournalInterceptor.class );
+    
+    /** A flag set to true if the journal interceptor is enabled */
+    private boolean journalEnabled;
+    
+    /** A shared number stored within each change */ 
+    private AtomicLong revision;
+    
+    /** the Journal service to log changes to */
+    private Journal journal;
+    
+
+    // -----------------------------------------------------------------------
+    // Overridden init() and destroy() methods
+    // -----------------------------------------------------------------------
+    /**
+     * The init method will initialize the local variables and load the 
+     * entryDeleted AttributeType.
+     */
+    public void init( DirectoryService directoryService ) throws LdapException
+    {
+        super.init( directoryService );
+        
+        if ( directoryService.getJournal().isEnabled() )
+        {
+            journalEnabled = true; 
+            journal = directoryService.getJournal();
+            revision = new AtomicLong( System.currentTimeMillis() );
+        }
+
+        LOG.debug( "JournalInterceptor has been initialized" );
+    }
+    
+    
+    /**
+     * Log the operation, manage the logs rotations.
+     */
+    private void log( long revision, LdifEntry ldif ) throws LdapException
+    {
+        journal.log( getPrincipal(), revision, ldif );
+    }
+    
+    
+    // -----------------------------------------------------------------------
+    // Overridden (only change inducing) intercepted methods
+    // -----------------------------------------------------------------------
+    /**
+     * {@inheritDoc}
+     */
+    public void add( NextInterceptor next, AddOperationContext addContext ) throws LdapException
+    {
+        long opRevision = 0;
+        
+        if ( journalEnabled )
+        {
+            opRevision = revision.incrementAndGet();
+            
+            // Store the added entry
+            Entry addEntry = addContext.getEntry();
+
+            LdifEntry ldif = new LdifEntry();
+            ldif.setChangeType( ChangeType.Add );
+            ldif.setDn( addContext.getDn() );
+
+            for ( Attribute attribute:addEntry.getAttributes() )
+            {
+                AttributeType attributeType = attribute.getAttributeType();
+                ldif.addAttribute( addEntry.get( attributeType).clone() );
+            }
+            
+            log( opRevision, ldif );
+        }
+
+        try
+        {
+            next.add( addContext );
+
+            if ( journalEnabled )
+            {
+                // log the ACK
+                journal.ack( opRevision );
+            }
+        }
+        catch( LdapException le )
+        {
+            if ( journalEnabled )
+            {
+                // log the NACK
+                journal.nack( opRevision );
+            }
+            
+            throw le;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void delete( NextInterceptor next, DeleteOperationContext deleteContext ) throws LdapException
+    {
+        long opRevision = 0;
+        
+        if ( journalEnabled )
+        {
+            opRevision = revision.incrementAndGet();
+            
+            // Store the deleted entry
+            LdifEntry ldif = new LdifEntry();
+            ldif.setChangeType( ChangeType.Delete );
+            ldif.setDn( deleteContext.getDn() );
+            
+            journal.log( getPrincipal(), opRevision, ldif );
+        }
+
+        try
+        {
+            next.delete( deleteContext );
+
+            if ( journalEnabled )
+            {
+                // log the ACK
+                journal.ack( opRevision );
+            }
+        }
+        catch( LdapException e )
+        {
+            if ( journalEnabled )
+            {
+                // log the NACK
+                journal.nack( opRevision );
+            }
+            
+            throw e;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void modify( NextInterceptor next, ModifyOperationContext modifyContext ) throws LdapException
+    {
+        long opRevision = 0;
+        
+        if ( journalEnabled )
+        {
+            opRevision = revision.incrementAndGet();
+            
+            // Store the modified entry
+            LdifEntry ldif = new LdifEntry();
+            ldif.setChangeType( ChangeType.Modify );
+            ldif.setDn( modifyContext.getDn() );
+            
+            // Store the modifications 
+            for ( Modification modification:modifyContext.getModItems() )
+            {
+                ldif.addModification( modification );
+            }
+            
+            journal.log( getPrincipal(), opRevision, ldif );
+        }
+        
+        try
+        {
+            next.modify( modifyContext );
+
+            if ( journalEnabled )
+            {
+                // log the ACK
+                journal.ack( opRevision );
+            }
+        }
+        catch( LdapException e )
+        {
+            if ( journalEnabled )
+            {
+                // log the NACK
+                journal.nack( opRevision );
+            }
+            throw e;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void rename ( NextInterceptor next, RenameOperationContext renameContext ) throws LdapException
+    {
+        long opRevision = 0;
+        
+        if ( journalEnabled )
+        {
+            opRevision = revision.incrementAndGet();
+            
+            // Store the renamed entry
+            LdifEntry ldif = new LdifEntry();
+            ldif.setChangeType( ChangeType.ModRdn );
+            ldif.setDn( renameContext.getDn() );
+            ldif.setNewRdn( renameContext.getNewRdn().getNormName() );
+            ldif.setDeleteOldRdn( renameContext.getDeleteOldRdn() );
+            
+            journal.log( getPrincipal(), opRevision, ldif );
+        }
+        
+        try
+        {
+            next.rename( renameContext );
+    
+            if ( journalEnabled )
+            {
+                // log the ACK
+                journal.ack( opRevision );
+            }
+        }
+        catch( LdapException e )
+        {
+            if ( journalEnabled )
+            {
+                // log the NACK
+                journal.nack( opRevision );
+            }
+            
+            throw e;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void moveAndRename( NextInterceptor next, MoveAndRenameOperationContext moveAndRenameContext )
+        throws LdapException
+    {
+        long opRevision = 0;
+        
+        if ( journalEnabled )
+        {
+            opRevision = revision.incrementAndGet();
+            
+            // Store the renamed entry
+            LdifEntry ldif = new LdifEntry();
+            ldif.setChangeType( ChangeType.ModDn );
+            ldif.setDn( moveAndRenameContext.getDn() );
+            ldif.setNewRdn( moveAndRenameContext.getNewRdn().getNormName() );
+            ldif.setDeleteOldRdn( moveAndRenameContext.getDeleteOldRdn() );
+            ldif.setNewSuperior( moveAndRenameContext.getNewDn().getNormName() );
+            
+            journal.log( getPrincipal(), opRevision, ldif );
+        }
+        
+        try
+        {
+            next.moveAndRename( moveAndRenameContext );
+            
+            if ( journalEnabled )
+            {
+                // log the ACK
+                journal.ack( opRevision );
+            }
+        }
+        catch( LdapException e )
+        {
+            if ( journalEnabled )
+            {
+                // log the NACK
+                journal.nack( opRevision );
+            }
+            
+            throw e;
+        }
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void move( NextInterceptor next, MoveOperationContext moveContext ) throws LdapException
+    {
+        long opRevision = 0;
+        
+        if ( journalEnabled )
+        {
+            opRevision = revision.incrementAndGet();
+            
+            // Store the moved entry
+            LdifEntry ldif = new LdifEntry();
+            ldif.setChangeType( ChangeType.ModDn );
+            ldif.setDn( moveContext.getDn() );
+            ldif.setNewSuperior( moveContext.getNewSuperior().getNormName() );
+            
+            journal.log( getPrincipal(), opRevision, ldif );
+        }
+        
+        try
+        {
+            next.move( moveContext );
+            
+            if ( journalEnabled )
+            {
+                // log the ACK
+                journal.ack( opRevision );
+            }
+        }
+        catch( LdapException e )
+        {
+            if ( journalEnabled )
+            {
+                // log the NACK
+                journal.nack( opRevision );
+            }
+            
+            throw e;
+        }
+   }
+}
\ No newline at end of file

Propchange: directory/apacheds/trunk/interceptors/logger/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Oct 14 22:36:08 2011
@@ -0,0 +1,11 @@
+target
+.project
+.classpath
+.settings
+eclipse-classes
+*.log
+*.iml
+*.ipr
+dependency-reduced-pom.xml
+META-INF
+

Added: directory/apacheds/trunk/interceptors/logger/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/logger/pom.xml?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/logger/pom.xml (added)
+++ directory/apacheds/trunk/interceptors/logger/pom.xml Fri Oct 14 22:36:08 2011
@@ -0,0 +1,178 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.directory.server</groupId>
+    <artifactId>apacheds-interceptors</artifactId>
+    <version>2.0.0-M4-SNAPSHOT</version>
+  </parent>
+  
+  <artifactId>apacheds-interceptors-logger</artifactId>
+  <name>ApacheDS Logger Interceptor</name>
+  <packaging>jar</packaging>
+
+  <description>
+    Logger interceptor
+  </description>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.directory.junit</groupId>
+      <artifactId>junit-addons</artifactId>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>apacheds-i18n</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>apacheds-core-api</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>apacheds-core-api</artifactId>
+      <classifier>tests</classifier>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>commons-collections</groupId>
+      <artifactId>commons-collections</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-client-api</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-i18n</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-codec-standalone</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-codec-core</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-extras-aci</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-extras-trigger</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-extras-util</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-model</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-schema-data</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-util</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>bouncycastle</groupId>
+      <artifactId>bcprov-jdk15</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>net.sf.ehcache</groupId>
+      <artifactId>ehcache-core</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.directory.shared</groupId>
+      <artifactId>shared-ldap-extras-codec</artifactId>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration> 
+          <systemPropertyVariables>
+            <workingDirectory>${basedir}/target/server-work</workingDirectory>
+          </systemPropertyVariables>
+        </configuration>
+      </plugin>
+      
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-source-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>attach-sources</id>
+            <phase>verify</phase>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+
+    <resources>
+      <resource>
+        <directory>src/main/resources</directory>
+        <filtering>true</filtering>
+        <excludes>
+          <exclude>**/*.gif</exclude>
+        </excludes>
+      </resource>
+    </resources>
+  </build>
+</project>
+