Author: akarasulu
Date: Tue Oct 26 05:40:46 2004
New Revision: 55604
Added:
incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ModifyContextTest.java
Modified:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/EveContextFactory.java
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/ibs/OperationalAttributeService.java
Log:
Changes ...
o added operational attributes for create and modify operations
o added tests to make sure modify operation works
o tests also determine if new operational attributes are introduced
Notes ...
o as soon as the op attr filtering is enabled; meaning where they are
not returned in a search unless explicitly asked for then this modify
test will begin to fail and will need to be modified
Modified:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/EveContextFactory.java
==============================================================================
---
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/EveContextFactory.java
(original)
+++
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/EveContextFactory.java
Tue Oct 26 05:40:46 2004
@@ -15,6 +15,7 @@
import org.apache.eve.RootNexus;
import org.apache.eve.SystemPartition;
import org.apache.eve.jndi.ibs.EveExceptionService;
+import org.apache.eve.jndi.ibs.OperationalAttributeService;
import org.apache.eve.db.*;
import org.apache.eve.db.jdbm.JdbmDatabase;
import org.apache.eve.schema.bootstrap.BootstrapRegistries;
@@ -203,9 +204,9 @@
*/
state = new InvocationStateEnum[]{
InvocationStateEnum.PREINVOCATION,
- InvocationStateEnum.FAILUREHANDLING
+ InvocationStateEnum.POSTINVOCATION
};
- interceptor = new EveExceptionService( root );
+ interceptor = new OperationalAttributeService( root );
provider.addInterceptor( interceptor, state );
}
Modified:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/ibs/OperationalAttributeService.java
==============================================================================
---
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/ibs/OperationalAttributeService.java
(original)
+++
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/ibs/OperationalAttributeService.java
Tue Oct 26 05:40:46 2004
@@ -20,14 +20,14 @@
import javax.naming.Name;
import javax.naming.NamingException;
import javax.naming.Context;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.*;
-import org.apache.eve.jndi.BaseInterceptor;
+import org.apache.eve.RootNexus;
import org.apache.eve.jndi.Invocation;
+import org.apache.eve.jndi.BaseInterceptor;
import org.apache.eve.jndi.InvocationStateEnum;
import org.apache.eve.schema.AttributeTypeRegistry;
-import org.apache.ldap.common.schema.AttributeType;
+
import org.apache.ldap.common.util.DateUtils;
@@ -42,31 +42,18 @@
{
/** the default user principal or DN */
private final String DEFAULT_PRINCIPAL = "cn=admin,ou=system";
- /** the global attributeType registry of the schema subsystem */
- private final AttributeTypeRegistry registry;
+ /** the root nexus of the system */
+ private final RootNexus nexus;
-// /** the root nexus of the system */
-// private final RootNexus nexus;
-//
-//
-// /**
-// * Creates the operational attribute management service interceptor.
-// *
-// * @param nexus the root nexus of the system
-// */
-// public OperationalAttributeService( RootNexus nexus )
-// {
-// this.nexus = nexus;
-// }
/**
* Creates the operational attribute management service interceptor.
*
- * @param registry the attributeType registry of the schema subsystem
+ * @param nexus the root nexus of the system
*/
- public OperationalAttributeService( AttributeTypeRegistry registry)
+ public OperationalAttributeService( RootNexus nexus )
{
- this.registry = registry;
+ this.nexus = nexus;
}
@@ -81,20 +68,142 @@
protected void add( String upName, Name normName, Attributes entry )
throws NamingException
{
Invocation invocation = getInvocation();
- Context ctx = ( ( Context ) invocation.getContextStack().peek() );
- String principal = ( String ) ctx.getEnvironment().get(
- Context.SECURITY_PRINCIPAL );
if ( invocation.getState() == InvocationStateEnum.PREINVOCATION )
{
BasicAttribute attribute = new BasicAttribute( "creatorsName" );
- principal = principal == null ? DEFAULT_PRINCIPAL : principal;
- attribute.add( principal );
+ attribute.add( getPrincipal( invocation ) );
entry.put( attribute );
attribute = new BasicAttribute( "createTimestamp" );
attribute.add( DateUtils.getGeneralizedTime(
System.currentTimeMillis() ) );
entry.put( attribute );
}
+ }
+
+
+ protected void modify( Name dn, int modOp, Attributes mods ) throws
NamingException
+ {
+ Invocation invocation = getInvocation();
+
+ // add operational attributes after call in case the operation fails
+ if ( invocation.getState() == InvocationStateEnum.POSTINVOCATION )
+ {
+ Attributes attributes = new BasicAttributes();
+ BasicAttribute attribute = new BasicAttribute( "modifiersName" );
+ attribute.add( getPrincipal( invocation ) );
+ attributes.put( attribute );
+
+ attribute = new BasicAttribute( "modifyTimestamp" );
+ attribute.add( DateUtils.getGeneralizedTime(
System.currentTimeMillis() ) );
+ attributes.put( attribute );
+
+ nexus.modify( dn, DirContext.REPLACE_ATTRIBUTE, attributes );
+ }
+ }
+
+
+ protected void modify( Name dn, ModificationItem[] mods ) throws
NamingException
+ {
+ super.modify( dn, mods );
+
+ Invocation invocation = getInvocation();
+
+ // add operational attributes after call in case the operation fails
+ if ( invocation.getState() == InvocationStateEnum.POSTINVOCATION )
+ {
+ Attributes attributes = new BasicAttributes();
+ BasicAttribute attribute = new BasicAttribute( "modifiersName" );
+ attribute.add( getPrincipal( invocation ) );
+ attributes.put( attribute );
+
+ attribute = new BasicAttribute( "modifyTimestamp" );
+ attribute.add( DateUtils.getGeneralizedTime(
System.currentTimeMillis() ) );
+ attributes.put( attribute );
+
+ nexus.modify( dn, DirContext.REPLACE_ATTRIBUTE, attributes );
+ }
+ }
+
+
+ protected void modifyRdn( Name dn, String newRdn, boolean deleteOldRdn )
throws NamingException
+ {
+ Invocation invocation = getInvocation();
+
+ // add operational attributes after call in case the operation fails
+ if ( invocation.getState() == InvocationStateEnum.POSTINVOCATION )
+ {
+ Attributes attributes = new BasicAttributes();
+ BasicAttribute attribute = new BasicAttribute( "modifiersName" );
+ attribute.add( getPrincipal( invocation ) );
+ attributes.put( attribute );
+
+ attribute = new BasicAttribute( "modifyTimestamp" );
+ attribute.add( DateUtils.getGeneralizedTime(
System.currentTimeMillis() ) );
+ attributes.put( attribute );
+
+ Name newDn = ( Name ) dn.clone();
+ newDn.remove( newDn.size() - 1 );
+ newDn.add( newRdn );
+ nexus.modify( newDn, DirContext.REPLACE_ATTRIBUTE, attributes );
+ }
+ }
+
+
+ protected void move( Name oriChildName, Name newParentName ) throws
NamingException
+ {
+ Invocation invocation = getInvocation();
+
+ // add operational attributes after call in case the operation fails
+ if ( invocation.getState() == InvocationStateEnum.POSTINVOCATION )
+ {
+ Attributes attributes = new BasicAttributes();
+ BasicAttribute attribute = new BasicAttribute( "modifiersName" );
+ attribute.add( getPrincipal( invocation ) );
+ attributes.put( attribute );
+
+ attribute = new BasicAttribute( "modifyTimestamp" );
+ attribute.add( DateUtils.getGeneralizedTime(
System.currentTimeMillis() ) );
+ attributes.put( attribute );
+
+ nexus.modify( newParentName, DirContext.REPLACE_ATTRIBUTE,
attributes );
+ }
+ }
+
+
+ protected void move( Name oriChildName, Name newParentName, String newRdn,
boolean deleteOldRdn ) throws NamingException
+ {
+ Invocation invocation = getInvocation();
+
+ // add operational attributes after call in case the operation fails
+ if ( invocation.getState() == InvocationStateEnum.POSTINVOCATION )
+ {
+ Attributes attributes = new BasicAttributes();
+ BasicAttribute attribute = new BasicAttribute( "modifiersName" );
+ attribute.add( getPrincipal( invocation ) );
+ attributes.put( attribute );
+
+ attribute = new BasicAttribute( "modifyTimestamp" );
+ attribute.add( DateUtils.getGeneralizedTime(
System.currentTimeMillis() ) );
+ attributes.put( attribute );
+
+ nexus.modify( newParentName, DirContext.REPLACE_ATTRIBUTE,
attributes );
+ }
+ }
+
+
+ /**
+ * Gets the DN of the principal associated with this operation.
+ *
+ * @param invocation the invocation to get the principal for
+ * @return the principal as a String
+ * @throws NamingException if there are problems
+ */
+ private String getPrincipal( Invocation invocation ) throws NamingException
+ {
+ String principal;
+ Context ctx = ( ( Context ) invocation.getContextStack().peek() );
+ principal = ( String ) ctx.getEnvironment().get(
Context.SECURITY_PRINCIPAL );
+ return principal == null ? DEFAULT_PRINCIPAL : principal;
}
}
Added:
incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ModifyContextTest.java
==============================================================================
--- (empty file)
+++
incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ModifyContextTest.java
Tue Oct 26 05:40:46 2004
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.eve.jndi;
+
+
+import javax.naming.directory.DirContext;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.Attribute;
+import javax.naming.NamingException;
+
+
+/**
+ * Tests the methods on JNDI contexts that are analogous to entry modify
+ * operations in LDAP.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ModifyContextTest extends AbstractJndiTest
+{
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ CreateContextTest createContextTest = new CreateContextTest();
+ createContextTest.setUp();
+ createContextTest.testCreateContexts();
+ }
+
+
+ public void testModifyOperation() throws NamingException
+ {
+ Attributes attributes = new BasicAttributes();
+ attributes.put( "ou", "testCases" );
+ sysRoot.modifyAttributes( "ou=testing00", DirContext.ADD_ATTRIBUTE,
attributes );
+ attributes = null;
+
+ DirContext ctx = ( DirContext ) sysRoot.lookup( "ou=testing00" );
+ attributes = ctx.getAttributes( "" );
+ assertTrue( attributes.get( "ou" ).contains( "testCases" ) );
+
+ Attribute attribute;
+
+ attribute = attributes.get( "creatorsName" );
+ assertNotNull( attribute );
+
+ attribute = attributes.get( "createTimestamp" );
+ assertNotNull( attribute );
+
+ attribute = attributes.get( "modifiersName" );
+ assertNotNull( attribute );
+
+ attributes.get( "modifyTimestamp" );
+ assertNotNull( attribute );
+ }
+}