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 [10/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/subtree/src/test/java/org/apache/directory/server/core/subtree/RefinementLeafEvaluatorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/subtree/src/test/java/org/apache/directory/server/core/subtree/RefinementLeafEvaluatorTest.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/subtree/src/test/java/org/apache/directory/server/core/subtree/RefinementLeafEvaluatorTest.java (added)
+++ directory/apacheds/trunk/interceptors/subtree/src/test/java/org/apache/directory/server/core/subtree/RefinementLeafEvaluatorTest.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,203 @@
+/*
+ * 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.subtree;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.entry.DefaultAttribute;
+import org.apache.directory.shared.ldap.model.entry.Attribute;
+import org.apache.directory.shared.ldap.model.entry.StringValue;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.filter.EqualityNode;
+import org.apache.directory.shared.ldap.model.filter.GreaterEqNode;
+import org.apache.directory.shared.ldap.model.schema.AttributeType;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schemaloader.JarLdifSchemaLoader;
+import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.util.exception.Exceptions;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Unit test cases for testing the evaluator for refinement leaf nodes.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class RefinementLeafEvaluatorTest
+{
+ /** the SchemaManager instance */
+ private static SchemaManager schemaManager;
+
+ /** The ObjectClass AttributeType */
+ private static AttributeType OBJECT_CLASS_AT;
+
+ /** The CN AttributeType */
+ private static AttributeType CN_AT;
+
+ /** the refinement leaf evaluator to test */
+ private static RefinementLeafEvaluator evaluator;
+
+
+ /**
+ * Initializes the global registries.
+ * @throws javax.naming.NamingException if there is a failure loading the schema
+ */
+ @BeforeClass
+ public static void init() throws Exception
+ {
+ JarLdifSchemaLoader loader = new JarLdifSchemaLoader();
+
+ schemaManager = new DefaultSchemaManager( loader );
+
+ boolean loaded = schemaManager.loadAllEnabled();
+
+ if ( !loaded )
+ {
+ fail( "Schema load failed : " + Exceptions.printErrors(schemaManager.getErrors()) );
+ }
+
+ OBJECT_CLASS_AT = schemaManager.getAttributeType( SchemaConstants.OBJECT_CLASS_AT );
+ CN_AT = schemaManager.getAttributeType( SchemaConstants.CN_AT );
+
+ evaluator = new RefinementLeafEvaluator( schemaManager );
+ }
+
+
+ /**
+ * Sets evaluator and registries to null.
+ */
+ @AfterClass
+ public static void tearDown()
+ {
+ evaluator = null;
+ }
+
+
+ /**
+ * Test cases for various bad combinations of arguments
+ * @throws Exception if something goes wrongg
+ */
+ @Test
+ public void testForBadArguments() throws Exception
+ {
+ Attribute objectClasses = null;
+
+ try
+ {
+ assertFalse( evaluator.evaluate( null, null ) );
+ fail( "should never get here due to an IAE" );
+ }
+ catch ( IllegalArgumentException iae )
+ {
+ }
+
+ try
+ {
+ assertFalse( evaluator.evaluate( new GreaterEqNode( "", new StringValue( "" ) ), objectClasses ) );
+ fail( "should never get here due to an NE" );
+ }
+ catch ( LdapException ne )
+ {
+ }
+
+ try
+ {
+ assertFalse( evaluator.evaluate( new EqualityNode( "", new StringValue( "" ) ), objectClasses ) );
+ fail( "should never get here due to an NE" );
+ }
+ catch ( IllegalArgumentException iae )
+ {
+ }
+
+ try
+ {
+ assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "" ) ), objectClasses ) );
+ fail( "should never get here due to an IAE" );
+ }
+ catch ( IllegalArgumentException iae )
+ {
+ }
+
+ try
+ {
+ objectClasses = new DefaultAttribute( "cn", OBJECT_CLASS_AT.getName() );
+ assertFalse( evaluator.evaluate( new EqualityNode( CN_AT, new StringValue( "" ) ), objectClasses ) );
+ fail( "should never get here due to an IAE" );
+ }
+ catch ( IllegalArgumentException iae )
+ {
+ assertTrue( true );
+ }
+ }
+
+
+ @Test
+ public void testMatchByName() throws Exception
+ {
+ // positive test
+ Attribute objectClasses = new DefaultAttribute( OBJECT_CLASS_AT, "person" );
+ assertTrue( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "person" ) ), objectClasses ) );
+
+ objectClasses = new DefaultAttribute( OBJECT_CLASS_AT );
+ objectClasses.add( "person" );
+ objectClasses.add( "blah" );
+ assertTrue( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "person" ) ), objectClasses ) );
+
+ // negative tests
+ objectClasses = new DefaultAttribute( OBJECT_CLASS_AT, "person" );
+ assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "blah" ) ), objectClasses ) );
+
+ objectClasses = new DefaultAttribute( OBJECT_CLASS_AT, "blah" );
+ assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "person" ) ), objectClasses ) );
+ }
+
+
+ @Test
+ public void testMatchByOID() throws Exception
+ {
+ Attribute objectClasses = new DefaultAttribute( OBJECT_CLASS_AT, "person" );
+
+ // positive test
+ assertTrue( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "2.5.6.6" ) ), objectClasses ) );
+
+ objectClasses = new DefaultAttribute( OBJECT_CLASS_AT );
+ objectClasses.add( "person" );
+ objectClasses.add( "blah" );
+ assertTrue( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "2.5.6.6" ) ), objectClasses ) );
+
+ // negative tests
+ objectClasses = new DefaultAttribute( OBJECT_CLASS_AT, "person" );
+ assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "2.5.6.5" ) ), objectClasses ) );
+
+ objectClasses = new DefaultAttribute( OBJECT_CLASS_AT, "blah" );
+ assertFalse( evaluator.evaluate( new EqualityNode( OBJECT_CLASS_AT, new StringValue( "2.5.6.5" ) ), objectClasses ) );
+ }
+}
Added: directory/apacheds/trunk/interceptors/subtree/src/test/java/org/apache/directory/server/core/subtree/SubtreeEvaluatorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/subtree/src/test/java/org/apache/directory/server/core/subtree/SubtreeEvaluatorTest.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/subtree/src/test/java/org/apache/directory/server/core/subtree/SubtreeEvaluatorTest.java (added)
+++ directory/apacheds/trunk/interceptors/subtree/src/test/java/org/apache/directory/server/core/subtree/SubtreeEvaluatorTest.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,359 @@
+/*
+ * 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.subtree;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Set;
+
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.CacheManager;
+
+import org.apache.directory.server.core.shared.DefaultDnFactory;
+import org.apache.directory.server.core.api.DnFactory;
+import org.apache.directory.server.core.normalization.FilterNormalizingVisitor;
+import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.filter.ExprNode;
+import org.apache.directory.shared.ldap.model.filter.FilterParser;
+import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.model.schema.normalizers.ConcreteNameComponentNormalizer;
+import org.apache.directory.shared.ldap.model.subtree.SubtreeSpecification;
+import org.apache.directory.shared.ldap.model.subtree.SubtreeSpecificationModifier;
+import org.apache.directory.shared.ldap.schemaextractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schemaloader.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.util.exception.Exceptions;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+
+/**
+ * Unit test cases for the SubtreeEvaluator.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class SubtreeEvaluatorTest
+{
+ private static DnFactory dnFactory;
+ private static SchemaManager schemaManager;
+ private static SubtreeEvaluator evaluator;
+ private static FilterNormalizingVisitor visitor;
+ private static ConcreteNameComponentNormalizer ncn;
+
+ @BeforeClass
+ public static void init() throws Exception
+ {
+ String workingDirectory = System.getProperty( "workingDirectory" );
+
+ if ( workingDirectory == null )
+ {
+ String path = SubtreeEvaluatorTest.class.getResource( "" ).getPath();
+ int targetPos = path.indexOf( "target" );
+ workingDirectory = path.substring( 0, targetPos + 6 );
+ }
+
+ File schemaRepository = new File( workingDirectory, "schema" );
+ SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
+ extractor.extractOrCopy( true );
+ LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+ schemaManager = new DefaultSchemaManager( loader );
+
+ boolean loaded = schemaManager.loadAllEnabled();
+
+ if ( !loaded )
+ {
+ fail( "Schema load failed : " + Exceptions.printErrors(schemaManager.getErrors()) );
+ }
+
+ CacheManager.getInstance().addCacheIfAbsent( "dnCache" );
+ Cache dnCache = CacheManager.getInstance().getCache( "dnCache" );
+ dnFactory = new DefaultDnFactory( schemaManager, dnCache );
+
+ ncn = new ConcreteNameComponentNormalizer( schemaManager );
+
+ visitor = new FilterNormalizingVisitor( ncn, schemaManager );
+ evaluator = new SubtreeEvaluator( schemaManager );
+ }
+
+
+ @AfterClass
+ public static void destroyTest()
+ {
+ visitor = null;
+ evaluator = null;
+ CacheManager.getInstance().getCache( "dnCache" ).removeAll();
+ }
+
+
+ @AfterClass
+ public static void tearDown() throws Exception
+ {
+ schemaManager = null;
+ }
+
+
+ @Test
+ public void testDefaults() throws Exception
+ {
+ SubtreeSpecificationModifier modifier = new SubtreeSpecificationModifier();
+ SubtreeSpecification ss = modifier.getSubtreeSpecification();
+ Dn apDn = dnFactory.create( "ou=system" );
+ Dn entryDn = dnFactory.create( "ou=users,ou=system" );
+ Entry entry = new DefaultEntry( schemaManager, entryDn );
+
+ assertTrue( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=system" );
+ assertTrue( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=abc" );
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+ }
+
+
+ @Test
+ public void testWithBase() throws Exception
+ {
+ SubtreeSpecificationModifier modifier = new SubtreeSpecificationModifier();
+ modifier.setBase( dnFactory.create( "ou=users" ) );
+ SubtreeSpecification ss = modifier.getSubtreeSpecification();
+ Dn apDn = dnFactory.create( "ou=system" );
+ Dn entryDn = dnFactory.create( "ou=users,ou=system" );
+ Entry entry = new DefaultEntry( schemaManager, entryDn );
+
+ assertTrue( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "uid=akarasulu,ou=users,ou=system" );
+ assertTrue( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=system" );
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+ }
+
+
+ @Test
+ public void testWithMinMax() throws Exception
+ {
+ SubtreeSpecificationModifier modifier = new SubtreeSpecificationModifier();
+ modifier.setMinBaseDistance( 1 );
+ modifier.setMaxBaseDistance( 3 );
+ modifier.setBase( dnFactory.create( "ou=users" ) );
+ SubtreeSpecification ss = modifier.getSubtreeSpecification();
+ Dn apDn = dnFactory.create( "ou=system" );
+ Dn entryDn = dnFactory.create( "ou=users,ou=system" );
+ Entry entry = new DefaultEntry( schemaManager, entryDn );
+
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "uid=akarasulu,ou=users,ou=system" );
+ assertTrue( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=system" );
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=twolevels,uid=akarasulu,ou=users,ou=system" );
+ assertTrue( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=threelevels,ou=twolevels,uid=akarasulu,ou=users,ou=system" );
+ assertTrue( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=fourlevels,ou=threelevels,ou=twolevels,uid=akarasulu,ou=users,ou=system" );
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+ }
+
+
+ @Test
+ public void testWithMinMaxAndChopAfter() throws Exception
+ {
+ SubtreeSpecificationModifier modifier = new SubtreeSpecificationModifier();
+ Set<Dn> chopAfter = new HashSet<Dn>();
+ chopAfter.add( dnFactory.create( "uid=Tori Amos" ) );
+ chopAfter.add( dnFactory.create( "ou=twolevels,uid=akarasulu" ) );
+ modifier.setChopAfterExclusions( chopAfter );
+ modifier.setMinBaseDistance( 1 );
+ modifier.setMaxBaseDistance( 3 );
+ modifier.setBase( dnFactory.create( "ou=users" ) );
+ SubtreeSpecification ss = modifier.getSubtreeSpecification();
+ Dn apDn = dnFactory.create( "ou=system" );
+ Dn entryDn = dnFactory.create( "ou=users,ou=system" );
+ Entry entry = new DefaultEntry( schemaManager, entryDn );
+
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "uid=akarasulu,ou=users,ou=system" );
+ assertTrue( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=system" );
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=twolevels,uid=akarasulu,ou=users,ou=system" );
+ assertTrue( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=threelevels,ou=twolevels,uid=akarasulu,ou=users,ou=system" );
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=fourlevels,ou=threelevels,ou=twolevels,uid=akarasulu,ou=users,ou=system" );
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+ }
+
+
+ @Test
+ public void testWithMinMaxAndChopBefore() throws Exception
+ {
+ SubtreeSpecificationModifier modifier = new SubtreeSpecificationModifier();
+ Set<Dn> chopBefore = new HashSet<Dn>();
+ chopBefore.add( dnFactory.create( "uid=Tori Amos" ) );
+ chopBefore.add( dnFactory.create( "ou=threelevels,ou=twolevels,uid=akarasulu" ) );
+ modifier.setChopBeforeExclusions( chopBefore );
+ modifier.setMinBaseDistance( 1 );
+ modifier.setMaxBaseDistance( 3 );
+ modifier.setBase( dnFactory.create( "ou=users" ) );
+ SubtreeSpecification ss = modifier.getSubtreeSpecification();
+ Dn apDn = dnFactory.create( "ou=system" );
+ Dn entryDn = dnFactory.create( "ou=users,ou=system" );
+ Entry entry = new DefaultEntry( schemaManager, entryDn );
+
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "uid=akarasulu,ou=users,ou=system" );
+ assertTrue( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=system" );
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=twolevels,uid=akarasulu,ou=users,ou=system" );
+ assertTrue( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=threelevels,ou=twolevels,uid=akarasulu,ou=users,ou=system" );
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=fourlevels,ou=threelevels,ou=twolevels,uid=akarasulu,ou=users,ou=system" );
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+ }
+
+
+ @Test
+ public void testWithMinMaxAndSimpleRefinement() throws Exception
+ {
+ ExprNode refinement = FilterParser.parse( schemaManager, "(objectClass=person)" );
+ refinement.accept( visitor );
+
+ SubtreeSpecificationModifier modifier = new SubtreeSpecificationModifier();
+ modifier.setRefinement( refinement );
+ modifier.setMinBaseDistance( 1 );
+ modifier.setMaxBaseDistance( 3 );
+ modifier.setBase( dnFactory.create( "ou=users" ) );
+ SubtreeSpecification ss = modifier.getSubtreeSpecification();
+ Dn apDn = dnFactory.create( "ou=system" );
+ Dn entryDn = dnFactory.create( "ou=users,ou=system" );
+ Entry entry = new DefaultEntry( schemaManager, entryDn );
+ entry.put( "objectClass", "person" );
+
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "uid=akarasulu,ou=users,ou=system" );
+ assertTrue( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=system" );
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=twolevels,uid=akarasulu,ou=users,ou=system" );
+ assertTrue( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=threelevels,ou=twolevels,uid=akarasulu,ou=users,ou=system" );
+ assertTrue( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=fourlevels,ou=threelevels,ou=twolevels,uid=akarasulu,ou=users,ou=system" );
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ // now change the refinement so the entry is rejected
+ entry = new DefaultEntry( schemaManager, entryDn );
+ entry.put( "objectClass", "organizationalUnit" );
+
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "uid=akarasulu,ou=users,ou=system" );
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=system" );
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=twolevels,uid=akarasulu,ou=users,ou=system" );
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=threelevels,ou=twolevels,uid=akarasulu,ou=users,ou=system" );
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "ou=fourlevels,ou=threelevels,ou=twolevels,uid=akarasulu,ou=users,ou=system" );
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ }
+
+
+ @Test
+ public void testWithFilter() throws Exception
+ {
+ ExprNode filter = FilterParser.parse( schemaManager, "(&(cn=Ersin)(objectClass=person))" );
+ filter.accept( visitor );
+
+ SubtreeSpecificationModifier modifier = new SubtreeSpecificationModifier();
+ modifier.setRefinement( filter );
+ modifier.setMinBaseDistance( 1 );
+ modifier.setMaxBaseDistance( 3 );
+ modifier.setBase( dnFactory.create( "ou=users" ) );
+ SubtreeSpecification ss = modifier.getSubtreeSpecification();
+ Dn apDn = dnFactory.create( "ou=system" );
+ Dn entryDn = dnFactory.create( "ou=users,ou=system" );
+
+ Entry entry = new DefaultEntry( schemaManager, entryDn );
+ entry.put( "objectClass", "person" );
+ entry.put( "cn", "Ersin" );
+
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "cn=Ersin,ou=users,ou=system" );
+ assertTrue( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ // now change the filter so the entry is rejected
+ entry = new DefaultEntry( schemaManager, entryDn );
+ entry.put( "objectClass", "person" );
+ entry.put( "cn", "Alex" );
+
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+
+ entryDn = dnFactory.create( "cn=Alex,ou=users,ou=system" );
+ assertFalse( evaluator.evaluate( ss, apDn, entryDn, entry ) );
+ }
+}
Propchange: directory/apacheds/trunk/interceptors/trigger/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Oct 14 22:36:08 2011
@@ -0,0 +1,11 @@
+.project
+.classpath
+.settings
+eclipse-classes
+*.log
+*.iml
+*.ipr
+dependency-reduced-pom.xml
+META-INF
+
+
Added: directory/apacheds/trunk/interceptors/trigger/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/trigger/pom.xml?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/trigger/pom.xml (added)
+++ directory/apacheds/trunk/interceptors/trigger/pom.xml Fri Oct 14 22:36:08 2011
@@ -0,0 +1,188 @@
+<?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-trigger</artifactId>
+ <name>ApacheDS Triggers Interceptor</name>
+ <packaging>jar</packaging>
+
+ <description>
+ Triggers 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-core-shared</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>apacheds-interceptors-subtree</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/trigger/src/main/java/org/apache/directory/server/core/trigger/AbstractStoredProcedureParameterInjector.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/AbstractStoredProcedureParameterInjector.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/AbstractStoredProcedureParameterInjector.java (added)
+++ directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/AbstractStoredProcedureParameterInjector.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,117 @@
+/*
+ * 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.trigger;
+
+
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.directory.server.core.api.interceptor.context.OperationContext;
+import org.apache.directory.server.core.api.partition.ByPassConstants;
+import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
+import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.trigger.StoredProcedureParameter;
+import org.apache.directory.shared.ldap.trigger.StoredProcedureParameter.Generic_LDAP_CONTEXT;
+
+
+public abstract class AbstractStoredProcedureParameterInjector implements StoredProcedureParameterInjector
+{
+ private OperationContext opContext;
+ private Map<Class<?>, MicroInjector> injectors;
+
+
+ public AbstractStoredProcedureParameterInjector( OperationContext opContext )
+ {
+ this.opContext = opContext;
+ injectors = new HashMap<Class<?>, MicroInjector>();
+ injectors.put( StoredProcedureParameter.Generic_OPERATION_PRINCIPAL.class, $operationPrincipalInjector );
+ injectors.put( StoredProcedureParameter.Generic_LDAP_CONTEXT.class, $ldapContextInjector );
+ }
+
+
+ protected Dn getOperationPrincipal() throws LdapInvalidDnException
+ {
+ Principal principal = opContext.getSession().getEffectivePrincipal();
+ Dn userName = opContext.getSession().getDirectoryService().getDnFactory().create( principal.getName() );
+ return userName;
+ }
+
+
+ protected Map<Class<?>, MicroInjector> getInjectors()
+ {
+ return injectors;
+ }
+
+
+ public OperationContext getOperationContext()
+ {
+ return opContext;
+ }
+
+
+ public void setOperationContext( OperationContext invocation )
+ {
+ this.opContext = invocation;
+ }
+
+
+ public final List<Object> getArgumentsToInject( OperationContext opContext,
+ List<StoredProcedureParameter> parameterList ) throws LdapException
+ {
+ List<Object> arguments = new ArrayList<Object>();
+
+ Iterator<StoredProcedureParameter> it = parameterList.iterator();
+
+ while ( it.hasNext() )
+ {
+ StoredProcedureParameter spParameter = it.next();
+ MicroInjector injector = injectors.get( spParameter.getClass() );
+ arguments.add( injector.inject( opContext, spParameter ) );
+ }
+
+ return arguments;
+ }
+
+
+ MicroInjector $operationPrincipalInjector = new MicroInjector()
+ {
+ public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapException
+ {
+ return getOperationPrincipal();
+ }
+ };
+
+
+ MicroInjector $ldapContextInjector = new MicroInjector()
+ {
+ public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapException
+ {
+ Generic_LDAP_CONTEXT ldapCtxParam = ( Generic_LDAP_CONTEXT ) param;
+ Dn ldapCtxName = ldapCtxParam.getCtxName();
+ return opContext.lookup( ldapCtxName, ByPassConstants.LOOKUP_BYPASS, SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ }
+ };
+}
Added: directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/AddStoredProcedureParameterInjector.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/AddStoredProcedureParameterInjector.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/AddStoredProcedureParameterInjector.java (added)
+++ directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/AddStoredProcedureParameterInjector.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,69 @@
+/*
+ * 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.trigger;
+
+
+import java.util.Map;
+
+import org.apache.directory.server.core.api.interceptor.context.OperationContext;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
+import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.trigger.StoredProcedureParameter;
+
+
+public class AddStoredProcedureParameterInjector extends AbstractStoredProcedureParameterInjector
+{
+ private Dn addedEntryName;
+ private Entry addedEntry;
+
+
+ public AddStoredProcedureParameterInjector( OperationContext opContext, Dn addedEntryName,
+ Entry addedEntry )
+ {
+ super( opContext );
+ this.addedEntryName = addedEntryName;
+ this.addedEntry = addedEntry;
+ Map<Class<?>, MicroInjector> injectors = super.getInjectors();
+ injectors.put( StoredProcedureParameter.Add_ENTRY.class, $entryInjector );
+ injectors.put( StoredProcedureParameter.Add_ATTRIBUTES.class, $attributesInjector );
+ }
+
+
+ MicroInjector $entryInjector = new MicroInjector()
+ {
+ public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapInvalidDnException
+ {
+ // Return a safe copy constructed with user provided name.
+ return opContext.getSession().getDirectoryService().getDnFactory().create( addedEntryName.getName() );
+ }
+ };
+
+
+ MicroInjector $attributesInjector = new MicroInjector()
+ {
+ public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapException
+ {
+ return addedEntry.clone();
+ }
+ };
+
+}
Added: directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/DeleteStoredProcedureParameterInjector.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/DeleteStoredProcedureParameterInjector.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/DeleteStoredProcedureParameterInjector.java (added)
+++ directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/DeleteStoredProcedureParameterInjector.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,77 @@
+/*
+ * 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.trigger;
+
+
+import java.util.Map;
+
+import org.apache.directory.server.core.api.interceptor.context.OperationContext;
+import org.apache.directory.server.core.api.partition.ByPassConstants;
+import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.trigger.StoredProcedureParameter;
+
+
+public class DeleteStoredProcedureParameterInjector extends AbstractStoredProcedureParameterInjector
+{
+ private Dn deletedEntryName;
+ private Entry deletedEntry;
+
+
+ public DeleteStoredProcedureParameterInjector( OperationContext opContext, Dn deletedEntryName )
+ throws LdapException
+ {
+ super( opContext );
+ this.deletedEntryName = deletedEntryName;
+ this.deletedEntry = getDeletedEntry( opContext );
+ Map<Class<?>, MicroInjector> injectors = super.getInjectors();
+ injectors.put( StoredProcedureParameter.Delete_NAME.class, $nameInjector );
+ injectors.put( StoredProcedureParameter.Delete_DELETED_ENTRY.class, $deletedEntryInjector );
+ }
+
+ MicroInjector $nameInjector = new MicroInjector()
+ {
+ public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapException
+ {
+ // Return a safe copy constructed with user provided name.
+ return opContext.getSession().getDirectoryService().getDnFactory().create( deletedEntryName.getName() );
+ }
+ };
+
+ MicroInjector $deletedEntryInjector = new MicroInjector()
+ {
+ public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapException
+ {
+ return deletedEntry;
+ }
+ };
+
+
+ private Entry getDeletedEntry( OperationContext opContext ) throws LdapException
+ {
+ /**
+ * Using LOOKUP_EXCLUDING_OPR_ATTRS_BYPASS here to exclude operational attributes
+ * especially subentry related ones like "triggerExecutionSubentries".
+ */
+ return opContext.lookup( deletedEntryName, ByPassConstants.LOOKUP_EXCLUDING_OPR_ATTRS_BYPASS, SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ }
+}
Added: directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/ModifyDNStoredProcedureParameterInjector.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/ModifyDNStoredProcedureParameterInjector.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/ModifyDNStoredProcedureParameterInjector.java (added)
+++ directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/ModifyDNStoredProcedureParameterInjector.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,149 @@
+/*
+ * 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.trigger;
+
+
+import java.util.Map;
+
+import org.apache.directory.server.core.api.interceptor.context.OperationContext;
+import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
+import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.model.name.Rdn;
+import org.apache.directory.shared.ldap.trigger.StoredProcedureParameter;
+
+
+public class ModifyDNStoredProcedureParameterInjector extends AbstractStoredProcedureParameterInjector
+{
+ private boolean deleteOldRn;
+ private Rdn oldRdn;
+ private Rdn newRdn;
+ private Dn oldSuperiorDn;
+ private Dn newSuperiorDn;
+ private Dn oldDn;
+ private Dn newDn;
+
+
+ public ModifyDNStoredProcedureParameterInjector( OperationContext opContext, boolean deleteOldRn,
+ Rdn oldRDN, Rdn newRdn, Dn oldSuperiorDn, Dn newSuperiorDn, Dn oldDn, Dn newDn)
+ {
+ super( opContext );
+ this.deleteOldRn = deleteOldRn;
+ this.oldRdn = (Rdn)oldRDN.clone();
+ this.newRdn = (Rdn) newRdn.clone();
+ this.oldSuperiorDn = oldSuperiorDn;
+ this.newSuperiorDn = newSuperiorDn;
+ this.oldDn = oldDn;
+ this.newDn = newDn;
+
+ Map<Class<?>, MicroInjector> injectors = super.getInjectors();
+ injectors.put( StoredProcedureParameter.ModifyDN_ENTRY.class, $entryInjector );
+ injectors.put( StoredProcedureParameter.ModifyDN_NEW_RDN.class, $newrdnInjector );
+ injectors.put( StoredProcedureParameter.ModifyDN_DELETE_OLD_RDN.class, $deleteoldrdnInjector );
+ injectors.put( StoredProcedureParameter.ModifyDN_NEW_SUPERIOR.class, $newSuperiorInjector );
+ injectors.put( StoredProcedureParameter.ModifyDN_OLD_RDN.class, $oldRDNInjector );
+ injectors.put( StoredProcedureParameter.ModifyDN_OLD_SUPERIOR_DN.class, $oldSuperiorDNInjector );
+ injectors.put( StoredProcedureParameter.ModifyDN_NEW_DN.class, $newDNInjector );
+
+ }
+ /**
+ * Injector for 'entry' parameter of ModifyDNRequest as in RFC4511.
+ */
+ MicroInjector $entryInjector = new MicroInjector()
+ {
+ public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapInvalidDnException
+ {
+ // Return a safe copy constructed with user provided name.
+ return opContext.getSession().getDirectoryService().getDnFactory().create( oldDn.getName() );
+ }
+ };
+
+ /**
+ * Injector for 'newrdn' parameter of ModifyDNRequest as in RFC4511.
+ */
+ MicroInjector $newrdnInjector = new MicroInjector()
+ {
+ public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapInvalidDnException
+ {
+ // Return a safe copy constructed with user provided name.
+ return opContext.getSession().getDirectoryService().getDnFactory().create( newRdn.getName() );
+ }
+ };
+
+ /**
+ * Injector for 'newrdn' parameter of ModifyDNRequest as in RFC4511.
+ */
+ MicroInjector $deleteoldrdnInjector = new MicroInjector()
+ {
+ public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapInvalidDnException
+ {
+ // Return a safe copy constructed with user provided name.
+ return deleteOldRn;
+ }
+ };
+
+ /**
+ * Injector for 'newSuperior' parameter of ModifyDNRequest as in RFC4511.
+ */
+ MicroInjector $newSuperiorInjector = new MicroInjector()
+ {
+ public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapInvalidDnException
+ {
+ // Return a safe copy constructed with user provided name.
+ return opContext.getSession().getDirectoryService().getDnFactory().create( newSuperiorDn.getName() );
+ }
+ };
+
+ /**
+ * Extra injector for 'oldRdn' which can be derived from parameters specified for ModifyDNRequest as in RFC4511.
+ */
+ MicroInjector $oldRDNInjector = new MicroInjector()
+ {
+ public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapInvalidDnException
+ {
+ // Return a safe copy constructed with user provided name.
+ return opContext.getSession().getDirectoryService().getDnFactory().create( oldRdn.getName() );
+ }
+ };
+
+ /**
+ * Extra injector for 'oldRdn' which can be derived from parameters specified for ModifyDNRequest as in RFC4511.
+ */
+ MicroInjector $oldSuperiorDNInjector = new MicroInjector()
+ {
+ public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapInvalidDnException
+ {
+ // Return a safe copy constructed with user provided name.
+ return opContext.getSession().getDirectoryService().getDnFactory().create( oldSuperiorDn.getName() );
+ }
+ };
+
+ /**
+ * Extra injector for 'newDn' which can be derived from parameters specified for ModifyDNRequest as in RFC4511.
+ */
+ MicroInjector $newDNInjector = new MicroInjector()
+ {
+ public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapInvalidDnException
+ {
+ // Return a safe copy constructed with user provided name.
+ return opContext.getSession().getDirectoryService().getDnFactory().create( newDn.getName() );
+ }
+ };
+
+}
Added: directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/ModifyStoredProcedureParameterInjector.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/ModifyStoredProcedureParameterInjector.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/ModifyStoredProcedureParameterInjector.java (added)
+++ directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/ModifyStoredProcedureParameterInjector.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,112 @@
+/*
+ * 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.trigger;
+
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.OperationContext;
+import org.apache.directory.server.core.api.partition.ByPassConstants;
+import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+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.exception.LdapInvalidDnException;
+import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.directory.shared.ldap.trigger.StoredProcedureParameter;
+
+
+public class ModifyStoredProcedureParameterInjector extends AbstractStoredProcedureParameterInjector
+{
+ private Dn modifiedEntryName;
+ private List<Modification> modifications;
+ private Entry oldEntry;
+
+
+ public ModifyStoredProcedureParameterInjector( ModifyOperationContext opContext ) throws LdapException
+ {
+ super( opContext );
+ modifiedEntryName = opContext.getDn();
+ modifications = opContext.getModItems();
+ this.oldEntry = getEntry( opContext );
+ Map<Class<?>, MicroInjector> injectors = super.getInjectors();
+ injectors.put( StoredProcedureParameter.Modify_OBJECT.class, $objectInjector );
+ injectors.put( StoredProcedureParameter.Modify_MODIFICATION.class, $modificationInjector );
+ injectors.put( StoredProcedureParameter.Modify_OLD_ENTRY.class, $oldEntryInjector );
+ injectors.put( StoredProcedureParameter.Modify_NEW_ENTRY.class, $newEntryInjector );
+ }
+
+
+ MicroInjector $objectInjector = new MicroInjector()
+ {
+ public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapInvalidDnException
+ {
+ // Return a safe copy constructed with user provided name.
+ return opContext.getSession().getDirectoryService().getDnFactory().create( modifiedEntryName.getName() );
+ }
+ };
+
+
+ MicroInjector $modificationInjector = new MicroInjector()
+ {
+ public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapException
+ {
+ List<Modification> newMods = new ArrayList<Modification>();
+
+ for ( Modification mod:modifications )
+ {
+ newMods.add( mod.clone() );
+ }
+
+ return newMods;
+ }
+ };
+
+
+ MicroInjector $oldEntryInjector = new MicroInjector()
+ {
+ public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapException
+ {
+ return oldEntry;
+ }
+ };
+
+
+ MicroInjector $newEntryInjector = new MicroInjector()
+ {
+ public Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapException
+ {
+ return getEntry( opContext );
+ }
+ };
+
+
+ private Entry getEntry( OperationContext opContext ) throws LdapException
+ {
+ /**
+ * Using LOOKUP_EXCLUDING_OPR_ATTRS_BYPASS here to exclude operational attributes
+ * especially subentry related ones like "triggerExecutionSubentries".
+ */
+ return opContext.lookup( modifiedEntryName, ByPassConstants.LOOKUP_EXCLUDING_OPR_ATTRS_BYPASS, SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+ }
+}
Added: directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/SimpleTriggerExecutionAuthorizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/SimpleTriggerExecutionAuthorizer.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/SimpleTriggerExecutionAuthorizer.java (added)
+++ directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/SimpleTriggerExecutionAuthorizer.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,50 @@
+/*
+ * 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.trigger;
+
+
+import org.apache.directory.server.core.api.interceptor.context.OperationContext;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.name.Dn;
+
+
+public class SimpleTriggerExecutionAuthorizer implements TriggerExecutionAuthorizer
+{
+ // private static Dn adminName;
+
+ static
+ {
+ //try
+ {
+ //adminName = new Dn( ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
+ }
+ //catch ( LdapInvalidDnException e )
+ {
+ // TODO Auto-generated catch block
+ // e.printStackTrace();
+ }
+ }
+
+ public boolean hasPermission( OperationContext opContext ) throws LdapException
+ {
+ Dn principalName = opContext.getSession().getEffectivePrincipal().getDn();
+ return principalName.equals( opContext.getSession().getDirectoryService().getAdminSession().getAuthenticatedPrincipal().getDn() );
+ }
+}
Added: directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/StoredProcedureParameterInjector.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/StoredProcedureParameterInjector.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/StoredProcedureParameterInjector.java (added)
+++ directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/StoredProcedureParameterInjector.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,45 @@
+/*
+ * 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.trigger;
+
+
+import java.util.List;
+
+import org.apache.directory.server.core.api.interceptor.context.OperationContext;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.trigger.StoredProcedureParameter;
+
+
+/**
+ * TODO - can we get some documentation on this?
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface StoredProcedureParameterInjector
+{
+ List<Object> getArgumentsToInject( OperationContext opContext,
+ List<StoredProcedureParameter> parameterList ) throws LdapException;
+
+
+ public interface MicroInjector
+ {
+ Object inject( OperationContext opContext, StoredProcedureParameter param ) throws LdapException;
+ }
+}
Added: directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/TriggerExecutionAuthorizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/TriggerExecutionAuthorizer.java?rev=1183537&view=auto
==============================================================================
--- directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/TriggerExecutionAuthorizer.java (added)
+++ directory/apacheds/trunk/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/TriggerExecutionAuthorizer.java Fri Oct 14 22:36:08 2011
@@ -0,0 +1,30 @@
+/*
+ * 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.trigger;
+
+
+import org.apache.directory.server.core.api.interceptor.context.OperationContext;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+
+
+public interface TriggerExecutionAuthorizer
+{
+ boolean hasPermission( OperationContext opContext ) throws LdapException;
+}