directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r503640 - in /directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/collective: CollectiveAttributeService.java CollectiveAttributesSchemaChecker.java
Date Mon, 05 Feb 2007 11:24:54 GMT
Author: elecharny
Date: Mon Feb  5 03:24:53 2007
New Revision: 503640

URL: http://svn.apache.org/viewvc?view=rev&rev=503640
Log:
Added fixes for CollectiveAttributes

Added:
    directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributesSchemaChecker.java
Modified:
    directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeService.java

Modified: directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeService.java?view=diff&rev=503640&r1=503639&r2=503640
==============================================================================
--- directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeService.java
(original)
+++ directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeService.java
Mon Feb  5 03:24:53 2007
@@ -32,6 +32,7 @@
 import org.apache.directory.server.core.schema.AttributeTypeRegistry;
 import org.apache.directory.shared.ldap.filter.ExprNode;
 import org.apache.directory.shared.ldap.message.LockableAttributeImpl;
+import org.apache.directory.shared.ldap.message.ModificationItemImpl;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 
@@ -65,6 +66,7 @@
 
     private AttributeTypeRegistry attrTypeRegistry = null;
     private PartitionNexus nexus = null;
+    private CollectiveAttributesSchemaChecker collectiveAttributesSchemaChecker = null;
     //private AttributeTypeRegistry registry = null;
 
 
@@ -236,6 +238,7 @@
         super.init( factoryCfg, cfg );
         nexus = factoryCfg.getPartitionNexus();
         attrTypeRegistry = factoryCfg.getGlobalRegistries().getAttributeTypeRegistry();
+        collectiveAttributesSchemaChecker = new CollectiveAttributesSchemaChecker( nexus,
attrTypeRegistry );
     }
 
     // ------------------------------------------------------------------------
@@ -284,5 +287,29 @@
         NamingEnumeration e = nextInterceptor.search( base, env, filter, searchCtls );
         Invocation invocation = InvocationStack.getInstance().peek();
         return new SearchResultFilteringEnumeration( e, searchCtls, invocation, SEARCH_FILTER
);
+    }
+    
+    // ------------------------------------------------------------------------
+    // Partial Schema Checking
+    // ------------------------------------------------------------------------
+
+    public void add( NextInterceptor next, LdapDN normName, Attributes entry ) throws NamingException
+    {
+        collectiveAttributesSchemaChecker.checkAdd( normName, entry );
+        super.add( next, normName, entry );
+    }
+
+
+    public void modify( NextInterceptor next, LdapDN normName, int modOp, Attributes mods
) throws NamingException
+    {
+        collectiveAttributesSchemaChecker.checkModify( normName, modOp, mods );
+        super.modify( next, normName, modOp, mods );
+    }
+
+
+    public void modify( NextInterceptor next, LdapDN normName, ModificationItemImpl[] mods
) throws NamingException
+    {
+        collectiveAttributesSchemaChecker.checkModify( normName, mods );
+        super.modify( next, normName, mods );
     }
 }

Added: directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributesSchemaChecker.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributesSchemaChecker.java?view=auto&rev=503640
==============================================================================
--- directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributesSchemaChecker.java
(added)
+++ directory/apacheds/branches/1.0/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributesSchemaChecker.java
Mon Feb  5 03:24:53 2007
@@ -0,0 +1,152 @@
+/*
+ *  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.collective;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+
+import org.apache.directory.server.core.partition.PartitionNexus;
+import org.apache.directory.server.core.schema.AttributeTypeRegistry;
+import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
+import org.apache.directory.shared.ldap.message.ModificationItemImpl;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.SchemaUtils;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
+
+/**
+ * Schema checking utilities specifically for operations on collective attributes.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev:$
+ */
+public class CollectiveAttributesSchemaChecker
+{
+    private PartitionNexus nexus = null;
+    private AttributeTypeRegistry attrTypeRegistry = null;
+
+    public CollectiveAttributesSchemaChecker( PartitionNexus nexus, AttributeTypeRegistry
attrTypeRegistry )
+    {
+        this.nexus = nexus;
+        this.attrTypeRegistry = attrTypeRegistry;
+    }
+
+    public void checkAdd( LdapDN normName, Attributes entry ) throws LdapSchemaViolationException,
NamingException
+    {
+        Attribute objectClass = entry.get( "objectClass" );
+
+        if ( AttributeUtils.containsValueCaseIgnore( objectClass, "collectiveAttributeSubentry"
) )
+        {
+            return;
+        }
+
+        if ( containsAnyCollectiveAttributes( entry ) )
+        {
+            /*
+             * TODO: Replace the Exception and the ResultCodeEnum with the correct ones.
+             */
+            throw new LdapSchemaViolationException(
+                "Collective attributes cannot be stored in non-collectiveAttributeSubentries",
+                ResultCodeEnum.OTHER);
+        }
+    }
+
+    public void checkModify( LdapDN normName, int modOp, Attributes mods ) throws NamingException
+    {
+        ModificationItemImpl[] modsAsArray = new ModificationItemImpl[ mods.size() ];
+        NamingEnumeration allAttrs = mods.getAll();
+        int i = 0;
+        
+        while ( allAttrs.hasMoreElements() )
+        {
+            Attribute attr = ( Attribute ) allAttrs.nextElement();
+            modsAsArray[i] = new ModificationItemImpl( modOp, attr );
+            i++;
+        }
+
+        checkModify( normName, modsAsArray );
+    }
+
+    public void checkModify( LdapDN normName, ModificationItemImpl[] mods ) throws NamingException
+    {
+        Attributes originalEntry = nexus.lookup( normName );
+        Attributes targetEntry = SchemaUtils.getTargetEntry( mods, originalEntry );
+        Attribute targetObjectClasses = targetEntry.get( "objectClass" );
+
+        if ( AttributeUtils.containsValueCaseIgnore( targetObjectClasses, "collectiveAttributeSubentry"
) )
+        {
+            return;
+        }
+
+        if ( addsAnyCollectiveAttributes( mods ) )
+        {
+            /*
+             * TODO: Replace the Exception and the ResultCodeEnum with the correct ones.
+             */
+            throw new LdapSchemaViolationException(
+                "Cannot operate on collective attributes in non-collectiveAttributeSubentries",
+                ResultCodeEnum.OTHER);
+        }
+    }
+
+
+    private boolean addsAnyCollectiveAttributes( ModificationItemImpl[] mods ) throws NamingException
+    {
+        for ( int i = 0; i < mods.length; i++ )
+        {
+            Attribute attr = mods[i].getAttribute();
+            String attrID = attr.getID();
+            AttributeType attrType = attrTypeRegistry.lookup( attrID );
+            int modOp = mods[i].getModificationOp();
+
+            if ( ( modOp == DirContext.ADD_ATTRIBUTE || modOp == DirContext.REPLACE_ATTRIBUTE
) &&
+                attrType.isCollective() )
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+
+    private boolean containsAnyCollectiveAttributes( Attributes entry ) throws NamingException
+    {
+        NamingEnumeration allIDs = entry.getIDs();
+        
+        while ( allIDs.hasMoreElements() )
+        {
+            String attrTypeStr = ( String ) allIDs.nextElement();
+            AttributeType attrType = attrTypeRegistry.lookup( attrTypeStr );
+            
+            if ( attrType.isCollective() )
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+}



Mime
View raw message