jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1095338 [1/2] - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/ jackrabbit-...
Date Wed, 20 Apr 2011 09:29:04 GMT
Author: angela
Date: Wed Apr 20 09:29:02 2011
New Revision: 1095338

URL: http://svn.apache.org/viewvc?rev=1095338&view=rev
Log:
JCR-2887 : Split PrivilegeRegistry in a per-session manager instance and a repository level registry [work in progress]

- clustering support
- move definition & def-reader/writer to spi-commons

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeEventChannel.java   (with props)
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeEventListener.java   (with props)
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeRecord.java   (with props)
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/
      - copied from r1092629, jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/ParseException.java
      - copied, changed from r1095335, jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/ParseException.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeDefinition.java
      - copied, changed from r1095335, jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/PrivilegeDefinition.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeDefinitionReader.java
      - copied, changed from r1095335, jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/PrivilegeDefinitionReader.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeDefinitionWriter.java
      - copied, changed from r1095335, jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/PrivilegeDefinitionWriter.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeHandler.java
      - copied, changed from r1095335, jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/PrivilegeHandler.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeXmlHandler.java
      - copied, changed from r1095335, jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/PrivilegeXmlHandler.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/privilege/
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/privilege/PrivilegeHandlerTest.java
      - copied, changed from r1092629, jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/privilege/PrivilegeHandlerTest.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/privilege/TestAll.java   (with props)
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/resources/org/apache/jackrabbit/spi/commons/privilege/
      - copied from r1092629, jackrabbit/trunk/jackrabbit-jcr-commons/src/test/resources/org/apache/jackrabbit/commons/privilege/
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/resources/org/apache/jackrabbit/spi/commons/privilege/readtest.xml
      - copied unchanged from r1095335, jackrabbit/trunk/jackrabbit-jcr-commons/src/test/resources/org/apache/jackrabbit/commons/privilege/readtest.xml
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/resources/org/apache/jackrabbit/spi/commons/privilege/writetest.xml
      - copied unchanged from r1095335, jackrabbit/trunk/jackrabbit-jcr-commons/src/test/resources/org/apache/jackrabbit/commons/privilege/writetest.xml
Removed:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/privilege/
    jackrabbit/trunk/jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/privilege/
    jackrabbit/trunk/jackrabbit-jcr-commons/src/test/resources/org/apache/jackrabbit/commons/privilege/
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterRecordDeserializer.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterRecordProcessor.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractRecord.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/Record.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventJournalImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/PrivilegeManagerImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/PrivilegeRegistry.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/ClusterRecordTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/SimpleEventListener.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/CustomPrivilegeTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/PrivilegeRegistryTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?rev=1095338&r1=1095337&r2=1095338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java Wed Apr 20 09:29:02 2011
@@ -326,15 +326,15 @@ public class RepositoryImpl extends Abst
                 wspInfos.put(config.getName(), info);
             }
 
-            // initialize optional clustering
-            // put here before setting up any other external event source that a cluster node
-            // will be interested in
+            // initialize optional clustering before setting up any other
+            // external event source that a cluster node will be interested in
             ClusterNode clusterNode = null;
             if (repConfig.getClusterConfig() != null) {
                 clusterNode = createClusterNode();
                 context.setClusterNode(clusterNode);
                 context.getNamespaceRegistry().setEventChannel(clusterNode);
                 context.getNodeTypeRegistry().setEventChannel(clusterNode);
+                context.getPrivilegeRegistry().setEventChannel(clusterNode);
 
                 createWorkspaceEventChannel = clusterNode;
                 clusterNode.setListener(this);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java?rev=1095338&r1=1095337&r2=1095338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java Wed Apr 20 09:29:02 2011
@@ -40,6 +40,7 @@ import org.apache.jackrabbit.core.state.
 import org.apache.jackrabbit.core.version.InternalVersionManagerImpl;
 import org.apache.jackrabbit.core.xml.ClonedInputSource;
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+import org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -51,7 +52,7 @@ import EDU.oswego.cs.dl.util.concurrent.
  */
 public class ClusterNode implements Runnable,
         NamespaceEventChannel, NodeTypeEventChannel, RecordConsumer,
-        ClusterRecordProcessor, WorkspaceEventChannel  {
+        ClusterRecordProcessor, WorkspaceEventChannel, PrivilegeEventChannel  {
 
     /**
      * System property specifying a node id to use.
@@ -168,6 +169,11 @@ public class ClusterNode implements Runn
     private NodeTypeEventListener nodeTypeListener;
 
     /**
+     * Privilege listener.
+     */
+    private PrivilegeEventListener privilegeListener;
+
+    /**
      * Instance revision manager.
      */
     private InstanceRevision instanceRevision;
@@ -505,6 +511,43 @@ public class ClusterNode implements Runn
         nodeTypeListener = listener;
     }
 
+    //----------------------------------------------< PrivilegeEventChannel >---
+    /**
+     * {@inheritDoc}
+     * @see PrivilegeEventChannel#registeredPrivileges(java.util.Collection)
+     */
+    public void registeredPrivileges(Collection<PrivilegeDefinition> definitions) {
+        if (status != STARTED) {
+            log.info("not started: nodetype operation ignored.");
+            return;
+        }
+        ClusterRecord record = null;
+        boolean succeeded = false;
+
+        try {
+            record = new PrivilegeRecord(definitions, producer.append());
+            record.write();
+            record.update();
+            setRevision(record.getRevision());
+            succeeded = true;
+        } catch (JournalException e) {
+            String msg = "Unable to create log entry: " + e.getMessage();
+            log.error(msg);
+        } catch (Throwable e) {
+            String msg = "Unexpected error while creating log entry.";
+            log.error(msg, e);
+        } finally {
+            if (!succeeded && record != null) {
+                record.cancelUpdate();
+            }
+        }
+    }
+
+    public void setListener(PrivilegeEventListener listener) {
+        privilegeListener = listener;
+    }
+
+    //--------------------------------------------------------------------------
     /**
      * Workspace update channel.
      */
@@ -909,6 +952,20 @@ public class ClusterNode implements Runn
         }
     }
 
+    public void process(PrivilegeRecord record) {
+        if (privilegeListener == null) {
+            String msg = "Privilege listener unavailable.";
+            log.error(msg);
+            return;
+        }
+        try {
+            privilegeListener.externalRegisteredPrivileges(record.getDefinitions());
+        } catch (RepositoryException e) {
+            String msg = "Unable to deliver privilege registration operation: " + e.getMessage();
+            log.error(msg);
+        }
+    }
+
     public void process(WorkspaceRecord record) {
         if (createWorkspaceListener == null) {
             String msg = "Create Workspace listener unavailable.";

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterRecordDeserializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterRecordDeserializer.java?rev=1095338&r1=1095337&r2=1095338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterRecordDeserializer.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterRecordDeserializer.java Wed Apr 20 09:29:02 2011
@@ -60,15 +60,22 @@ public class ClusterRecordDeserializer {
             clusterRecord = new WorkspaceRecord(record);
             clusterRecord.read();
             break;
+        case PrivilegeRecord.IDENTIFIER:
+            clusterRecord = new PrivilegeRecord(record);
+            clusterRecord.read();
+            break;
         case ClusterRecord.END_MARKER:
             // JCR-1813: Invalid journal records during XATransactions
             // Some journal records may be empty due to JCR-1813 and other
             // issues. We handle such cases with this dummy sentinel record.
             clusterRecord = new ClusterRecord(record) {
+                @Override
                 protected void doRead() {
                 }
+                @Override
                 protected void doWrite() {
                 }
+                @Override
                 public void process(ClusterRecordProcessor processor) {
                 }
             };

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterRecordProcessor.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterRecordProcessor.java?rev=1095338&r1=1095337&r2=1095338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterRecordProcessor.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterRecordProcessor.java Wed Apr 20 09:29:02 2011
@@ -54,6 +54,13 @@ public interface ClusterRecordProcessor 
     void process(NodeTypeRecord record);
 
     /**
+     * Process a privilege record
+     *
+     * @param record privilege record
+     */
+    void process(PrivilegeRecord record);
+
+    /**
      * Process a workspace record
      * @param record workspace record
      */

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeEventChannel.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeEventChannel.java?rev=1095338&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeEventChannel.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeEventChannel.java Wed Apr 20 09:29:02 2011
@@ -0,0 +1,31 @@
+/*
+ * 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.jackrabbit.core.cluster;
+
+import org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinition;
+
+import java.util.Collection;
+
+/**
+ * <code>PrivilegeEventChannel</code>...
+ */
+public interface PrivilegeEventChannel {
+
+    void registeredPrivileges(Collection<PrivilegeDefinition> definitions);
+
+    void setListener(PrivilegeEventListener listener);
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeEventChannel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeEventChannel.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeEventListener.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeEventListener.java?rev=1095338&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeEventListener.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeEventListener.java Wed Apr 20 09:29:02 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.jackrabbit.core.cluster;
+
+import org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinition;
+
+import javax.jcr.RepositoryException;
+import java.util.Collection;
+
+/**
+ * <code>PrivilegeEventListener</code>...
+ */
+public interface PrivilegeEventListener {
+
+    /**
+     * Called when one or more privilege definitions have been externally registered.
+     *
+     * @param definitions privilege definitions
+     * @throws RepositoryException if an error occurs
+     */
+    void externalRegisteredPrivileges(Collection<PrivilegeDefinition> definitions) throws RepositoryException;
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeEventListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeEventListener.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeRecord.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeRecord.java?rev=1095338&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeRecord.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeRecord.java Wed Apr 20 09:29:02 2011
@@ -0,0 +1,91 @@
+/*
+ * 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.jackrabbit.core.cluster;
+
+import org.apache.jackrabbit.core.journal.JournalException;
+import org.apache.jackrabbit.core.journal.Record;
+import org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+
+/**
+ * <code>PrivilegeRecord</code>...
+ */
+public class PrivilegeRecord extends ClusterRecord {
+
+    /**
+     * logger instance
+     */
+    private static final Logger log = LoggerFactory.getLogger(PrivilegeRecord.class);
+
+    /**
+     * Identifier: PRIVILEGES.
+     */
+    static final char IDENTIFIER = 'A';
+
+    /**
+     * Collection of privilege definitions.
+     */
+    private Collection<PrivilegeDefinition> definitions;
+
+    protected PrivilegeRecord(Record record) {
+        super(record);
+    }
+
+    protected PrivilegeRecord(Collection<PrivilegeDefinition> definitions, Record record) {
+        super(record);
+
+        this.definitions = definitions;
+    }
+
+    @Override
+    protected void doRead() throws JournalException {
+        int size = record.readInt();
+        definitions = new HashSet();
+        for (int i = 0; i < size; i++) {
+            definitions.add(record.readPrivilegeDef());
+        }
+    }
+
+    @Override
+    protected void doWrite() throws JournalException {
+        record.writeChar(IDENTIFIER);
+        record.writeInt(definitions.size());
+
+        for (PrivilegeDefinition def : definitions) {
+            record.writePrivilegeDef(def);
+        }
+    }
+
+    @Override
+    public void process(ClusterRecordProcessor processor) {
+        processor.process(this);
+    }
+
+    /**
+     * Return the collection of privilege definitions.
+     *
+     * @return unmodifiable collection
+     */
+    public Collection<PrivilegeDefinition> getDefinitions() {
+        return Collections.unmodifiableCollection(definitions);
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeRecord.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/PrivilegeRecord.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractRecord.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractRecord.java?rev=1095338&r1=1095337&r2=1095338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractRecord.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/AbstractRecord.java Wed Apr 20 09:29:02 2011
@@ -16,10 +16,19 @@
  */
 package org.apache.jackrabbit.core.journal;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
 
 import javax.jcr.NamespaceException;
 
@@ -40,6 +49,10 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
 import org.apache.jackrabbit.spi.commons.nodetype.QDefinitionBuilderFactory;
 import org.apache.jackrabbit.spi.commons.nodetype.compact.CompactNodeTypeDefWriter;
+import org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinition;
+import org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionReader;
+import org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionWriter;
+import org.apache.jackrabbit.spi.commons.privilege.PrivilegeHandler;
 
 /**
  * Base implementation for a record.
@@ -160,6 +173,34 @@ public abstract class AbstractRecord imp
     /**
      * {@inheritDoc}
      */
+    public void writePrivilegeDef(PrivilegeDefinition privilegeDefinition) throws JournalException {
+        try {
+            Map<String, String> nsMapping = new HashMap<String, String>();
+            String uri = privilegeDefinition.getName().getNamespaceURI();
+            nsMapping.put(nsResolver.getPrefix(uri), uri);
+            for (Name n : privilegeDefinition.getDeclaredAggregateNames()) {
+                nsMapping.put(nsResolver.getPrefix(n.getNamespaceURI()), n.getNamespaceURI());
+            }
+
+            StringWriter sw = new StringWriter();
+            PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter("text/xml");
+            writer.writeDefinitions(sw, new PrivilegeDefinition[] {privilegeDefinition}, nsMapping);
+            sw.close();
+
+            writeString(sw.toString());
+
+        } catch (IOException e) {
+            String msg = "I/O error while writing privilege definition.";
+            throw new JournalException(msg, e);
+        } catch (NamespaceException e) {
+            String msg = "NamespaceException error while writing privilege definition.";
+            throw new JournalException(msg, e);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public Name readQName() throws JournalException {
         try {
             return resolver.getQName(readString());
@@ -266,6 +307,26 @@ public abstract class AbstractRecord imp
     }
 
     /**
+     * {@inheritDoc}
+     */
+    public PrivilegeDefinition readPrivilegeDef() throws JournalException {
+        try {
+            StringReader sr = new StringReader(readString());
+            PrivilegeDefinitionReader reader = new PrivilegeDefinitionReader(sr, "text/xml");
+            PrivilegeDefinition[] defs = reader.getPrivilegeDefinitions();
+
+            if (defs.length != 1) {
+                throw new JournalException("Expected one privilege definition: got " + defs.length);
+            }
+            return defs[0];
+
+        } catch (org.apache.jackrabbit.spi.commons.privilege.ParseException e) {
+            String msg = "Parse error while reading privilege definition.";
+            throw new JournalException(msg, e);
+        }
+    }
+
+    /**
      * Get a <code>NodeId</code>'s existing cache index, creating a new entry
      * if necessary.
      *

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/Record.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/Record.java?rev=1095338&r1=1095337&r2=1095338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/Record.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/Record.java Wed Apr 20 09:29:02 2011
@@ -21,6 +21,7 @@ import org.apache.jackrabbit.core.id.Pro
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+import org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinition;
 
 /**
  * Record interface.
@@ -153,6 +154,14 @@ public interface Record {
     QNodeTypeDefinition readNodeTypeDef() throws JournalException;
 
     /**
+     * Read a <code>PrivilegeDefinition</code> from the underlying stream.
+     *
+     * @return privilege definition
+     * @throws JournalException if an error occurs
+     */
+    PrivilegeDefinition readPrivilegeDef() throws JournalException;
+
+    /**
      * Write a byte to the underlying stream.
      *
      * @param n byte
@@ -257,6 +266,14 @@ public interface Record {
     void writeNodeTypeDef(QNodeTypeDefinition ntd) throws JournalException;
 
     /**
+     * Write a <code>PrivilegeDefinition</code> to the underlying stream.
+     *
+     * @param privilegeDefinition privilege definition
+     * @throws JournalException if an error occurs
+     */
+    void writePrivilegeDef(PrivilegeDefinition privilegeDefinition) throws JournalException;
+
+    /**
      * Update the changes made to an appended record. This will also update
      * this record's revision.
      *

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventJournalImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventJournalImpl.java?rev=1095338&r1=1095337&r2=1095338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventJournalImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventJournalImpl.java Wed Apr 20 09:29:02 2011
@@ -33,6 +33,7 @@ import javax.jcr.observation.EventIterat
 import javax.jcr.observation.EventJournal;
 
 import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.cluster.PrivilegeRecord;
 import org.apache.jackrabbit.core.journal.Journal;
 import org.apache.jackrabbit.core.journal.RecordIterator;
 import org.apache.jackrabbit.core.journal.JournalException;
@@ -295,6 +296,10 @@ public class EventJournalImpl implements
             // ignore
         }
 
+        public void process(PrivilegeRecord record) {
+            // ignore
+        }
+
         public void process(WorkspaceRecord record) {
             // ignore
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/PrivilegeManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/PrivilegeManagerImpl.java?rev=1095338&r1=1095337&r2=1095338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/PrivilegeManagerImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/PrivilegeManagerImpl.java Wed Apr 20 09:29:02 2011
@@ -21,6 +21,7 @@ import org.apache.jackrabbit.core.Sessio
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -81,10 +82,10 @@ public final class PrivilegeManagerImpl 
      * @see PrivilegeManager#getRegisteredPrivileges()
      */
     public Privilege[] getRegisteredPrivileges() throws RepositoryException {
-        PrivilegeRegistry.Definition[] allDefs = registry.getAll();
+        PrivilegeDefinition[] allDefs = registry.getAll();
         if (allDefs.length != cache.size()) {
             synchronized (cache) {
-                for (PrivilegeRegistry.Definition def : allDefs) {
+                for (PrivilegeDefinition def : allDefs) {
                     if (!cache.containsKey(def.getName())) {
                         cache.put(def.getName(), new PrivilegeImpl(def));
                     }
@@ -172,16 +173,18 @@ public final class PrivilegeManagerImpl 
         if (privileges == null || privileges.length == 0) {
             throw new AccessControlException("Privilege array is empty or null.");
         }
-        PrivilegeBits bits = PrivilegeBits.getInstance();
-        for (Privilege priv : privileges) {
-            if (priv instanceof PrivilegeImpl) {
-                bits.add(((PrivilegeImpl) priv).definition.getBits());
+
+        PrivilegeDefinition[] defs = new PrivilegeDefinition[privileges.length];
+        for (int i = 0; i < privileges.length; i++) {
+            Privilege p = privileges[i];
+            if (p instanceof PrivilegeImpl) {
+                defs[i] = ((PrivilegeImpl) p).definition;
             } else {
-                String name = (priv == null) ? "null" : priv.getName();
+                String name = (p == null) ? "null" : p.getName();
                 throw new AccessControlException("Unknown privilege '" + name + "'.");
             }
         }
-        return bits;
+        return registry.getBits(defs);
     }
 
     /**
@@ -228,7 +231,7 @@ public final class PrivilegeManagerImpl 
             if (cache.containsKey(name)) {
                 privilege = cache.get(name);
             } else {
-                PrivilegeRegistry.Definition def = registry.get(name);
+                PrivilegeDefinition def = registry.get(name);
                 if (def != null) {
                     privilege = new PrivilegeImpl(def);
                     cache.put(name, privilege);
@@ -242,9 +245,10 @@ public final class PrivilegeManagerImpl 
 
     //-----------------------------------------< PrivilegeRegistry.Listener >---
     /**
-     * @see PrivilegeRegistry.Listener#privilegeRegistered(org.apache.jackrabbit.spi.Name)
+     * @see PrivilegeRegistry.Listener#privilegesRegistered(java.util.Set
+     * @param privilegeNames
      */
-    public void privilegeRegistered(Name privilegeName) {
+    public void privilegesRegistered(Set<Name> privilegeNames) {
         // force recalculation of jcr:all privilege
         synchronized (cache) {
             cache.remove(NameConstants.JCR_ALL);
@@ -258,15 +262,16 @@ public final class PrivilegeManagerImpl 
      */
     private class PrivilegeImpl implements Privilege {
 
-        private final PrivilegeRegistry.Definition definition;
+        private final PrivilegeDefinition definition;
 
         private final Privilege[] declaredAggregates;
         private final Privilege[] aggregates;
 
-        private PrivilegeImpl(PrivilegeRegistry.Definition definition) throws RepositoryException {
+        private PrivilegeImpl(PrivilegeDefinition definition) throws RepositoryException {
             this.definition = definition;
 
-            Name[] declAggrNames = definition.getDeclaredAggregateNames();
+            Set<Name> set = definition.getDeclaredAggregateNames();
+            Name[] declAggrNames = set.toArray(new Name[set.size()]);
             if (declAggrNames.length == 0) {
                 declaredAggregates = EMPTY_ARRAY;
                 aggregates = EMPTY_ARRAY;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/PrivilegeRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/PrivilegeRegistry.java?rev=1095338&r1=1095337&r2=1095338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/PrivilegeRegistry.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/authorization/PrivilegeRegistry.java Wed Apr 20 09:29:02 2011
@@ -17,10 +17,12 @@
 package org.apache.jackrabbit.core.security.authorization;
 
 import org.apache.commons.collections.map.ReferenceMap;
-import org.apache.jackrabbit.commons.privilege.ParseException;
-import org.apache.jackrabbit.commons.privilege.PrivilegeDefinition;
-import org.apache.jackrabbit.commons.privilege.PrivilegeDefinitionReader;
-import org.apache.jackrabbit.commons.privilege.PrivilegeDefinitionWriter;
+import org.apache.jackrabbit.core.cluster.PrivilegeEventChannel;
+import org.apache.jackrabbit.core.cluster.PrivilegeEventListener;
+import org.apache.jackrabbit.spi.commons.privilege.ParseException;
+import org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinition;
+import org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionReader;
+import org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionWriter;
 import org.apache.jackrabbit.core.NamespaceRegistryImpl;
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.fs.FileSystemException;
@@ -44,6 +46,7 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -57,7 +60,7 @@ import java.util.Set;
  * The <code>PrivilegeRegistry</code> defines the set of <code>Privilege</code>s
  * known to the repository.
  */
-public final class PrivilegeRegistry {
+public final class PrivilegeRegistry implements PrivilegeEventListener {
 
     private static final Logger log = LoggerFactory.getLogger(PrivilegeRegistry.class);
 
@@ -124,17 +127,29 @@ public final class PrivilegeRegistry {
 
     private PrivilegeBits nextBits = PrivilegeBits.getInstance(RETENTION_MNGMT).nextBits();
 
+    /**
+     * Privilege event channel for clustering support.
+     */
+    private PrivilegeEventChannel eventChannel;
+
+    /**
+     * Create a new <code>PrivilegeRegistry</code> instance.
+     *
+     * @param namespaceRegistry
+     * @param fs
+     * @throws RepositoryException
+     */
     public PrivilegeRegistry(NamespaceRegistry namespaceRegistry, FileSystem fs)
             throws RepositoryException {
 
         this.namespaceRegistry = namespaceRegistry;
         this.customPrivilegesStore = new CustomPrivilegeStore(new FileSystemResource(fs, CUSTOM_PRIVILEGES_RESOURCE_NAME));
-        registerDefinitions(createBuiltInPrivilegeDefinitions());
+        cacheDefinitions(createBuiltInPrivilegeDefinitions());
 
         try {
-            Map<Name, DefinitionStub> customDefs = customPrivilegesStore.load();
+            Map<Name, PrivilegeDefinition> customDefs = customPrivilegesStore.load();
             Map<Name, Definition> definitions = createCustomDefinitions(customDefs);
-            registerDefinitions(definitions);
+            cacheDefinitions(definitions);
         } catch (IOException e) {
             throw new RepositoryException("Failed to load custom privileges", e);
         } catch (FileSystemException e) {
@@ -155,7 +170,7 @@ public final class PrivilegeRegistry {
      * @see org.apache.jackrabbit.api.JackrabbitWorkspace#getPrivilegeManager()
      */
     public PrivilegeRegistry(NameResolver resolver) {
-        registerDefinitions(createBuiltInPrivilegeDefinitions());
+        cacheDefinitions(createBuiltInPrivilegeDefinitions());
 
         namespaceRegistry = null;
         customPrivilegesStore = null;
@@ -163,6 +178,33 @@ public final class PrivilegeRegistry {
         this.resolver = resolver;
     }
 
+
+    //---------------------------------------------< PrivilegeEventListener >---
+    /**
+     * @inheritDoc
+     * @see PrivilegeEventListener#externalRegisteredPrivileges(java.util.Collection)
+     */
+    public void externalRegisteredPrivileges(Collection<PrivilegeDefinition> definitions) throws RepositoryException {
+        Map<Name, PrivilegeDefinition> defs = new HashMap<Name, PrivilegeDefinition>(definitions.size());
+        for (PrivilegeDefinition d : definitions) {
+            defs.put(d.getName(), d);
+        }
+        registerCustomDefinitions(defs);
+    }
+
+    //----------------------------------------< public methods : clustering >---
+
+    /**
+     * Set a clustering event channel to inform about changes.
+     *
+     * @param eventChannel event channel
+     */
+    public void setEventChannel(PrivilegeEventChannel eventChannel) {
+        this.eventChannel = eventChannel;
+        eventChannel.setListener(this);
+    }
+
+    //--------------------------------< public methods : privilege registry >---
     /**
      * Throws <code>UnsupportedOperationException</code>.
      *
@@ -394,30 +436,12 @@ public final class PrivilegeRegistry {
      * to constraint violations or if persisting the custom privilege fails.
      */
     void registerDefinition(Name privilegeName, boolean isAbstract, Set<Name> declaredAggregateNames) throws RepositoryException {
-        if (customPrivilegesStore == null) {
-            throw new UnsupportedOperationException("No privilege store defined.");
-        }
-        synchronized (registeredPrivileges) {
-            Map<Name, DefinitionStub> stubs = Collections.singletonMap(privilegeName, new DefinitionStub(privilegeName, isAbstract, declaredAggregateNames));
-            Map<Name, Definition> definitions = createCustomDefinitions(stubs);
-            try {
-                // write the new custom privilege to the store and upon successful
-                // update of the file system resource add finally it to the map of
-                // registered privileges.
-                customPrivilegesStore.append(definitions);
-                registerDefinitions(definitions);
-
-            } catch (IOException e) {
-                throw new RepositoryException("Failed to register custom privilege " + privilegeName.toString(), e);
-            } catch (FileSystemException e) {
-                throw new RepositoryException("Failed to register custom privilege " + privilegeName.toString(), e);
-            } catch (ParseException e) {
-                throw new RepositoryException("Failed to register custom privilege " + privilegeName.toString(), e);
-            }
-        }
+        Map<Name, PrivilegeDefinition> stubs = Collections.singletonMap(privilegeName, new PrivilegeDefinition(privilegeName, isAbstract, declaredAggregateNames));
+        registerCustomDefinitions(stubs);
 
-        for (Listener l : listeners.keySet()) {
-            l.privilegeRegistered(privilegeName);
+        // inform clustering about the new privilege.
+        if (eventChannel != null) {
+            eventChannel.registeredPrivileges(stubs.values());
         }
     }
     
@@ -426,7 +450,7 @@ public final class PrivilegeRegistry {
      *
      * @return all registered internal privileges
      */
-    Definition[] getAll() {
+    PrivilegeDefinition[] getAll() {
         return registeredPrivileges.values().toArray(new Definition[registeredPrivileges.size()]);
     }
 
@@ -436,7 +460,7 @@ public final class PrivilegeRegistry {
      * @param name Name of the internal privilege.
      * @return the internal privilege with the specified name or <code>null</code>
      */
-    Definition get(Name name) {
+    PrivilegeDefinition get(Name name) {
         return registeredPrivileges.get(name);
     }
 
@@ -509,15 +533,15 @@ public final class PrivilegeRegistry {
             Set<Definition> aggr = new HashSet<Definition>();
             for (Definition def : registeredPrivileges.values()) {
                 if (def.isCustom && privilegeBits.includes(def.bits)) {
-                    customNames.add(def.name);
-                    if (!def.declaredAggregateNames.isEmpty()) {
+                    customNames.add(def.getName());
+                    if (!def.getDeclaredAggregateNames().isEmpty()) {
                         aggr.add(def);
                     }
                 }
             }
             // avoid redundant entries in case of aggregate privileges.
             for (Definition aggregate : aggr) {
-                customNames.removeAll(aggregate.declaredAggregateNames);
+                customNames.removeAll(aggregate.getDeclaredAggregateNames());
             }
             names.addAll(customNames);
 
@@ -529,21 +553,75 @@ public final class PrivilegeRegistry {
         }
     }
 
+    /**
+     * Return the privilege bits for the specified privilege definitions.
+     *
+     * @param definitions
+     * @return privilege bits.
+     */
+    PrivilegeBits getBits(PrivilegeDefinition... definitions) {
+        PrivilegeBits bts = PrivilegeBits.getInstance();
+        for (PrivilegeDefinition d : definitions) {
+            if (d instanceof Definition) {
+                bts.add(((Definition) d).bits);
+            }
+        }
+        return bts;
+    }
+
+    /**
+     * Add a privilege registration listener.
+     * 
+     * @param listener
+     */
     void addListener(Listener listener) {
         listeners.put(listener,listener);
     }
 
     //---------------------------------------------< privilege registration >---
     /**
+     * Register the specified custom privilege definitions.
+     * 
+     * @param stubs
+     * @throws RepositoryException If an error occurs.
+     */
+    private void registerCustomDefinitions(Map<Name, PrivilegeDefinition> stubs) throws RepositoryException {
+        if (customPrivilegesStore == null) {
+            throw new UnsupportedOperationException("No privilege store defined.");
+        }
+        synchronized (registeredPrivileges) {
+            Map<Name, Definition> definitions = createCustomDefinitions(stubs);
+            try {
+                // write the new custom privilege to the store and upon successful
+                // update of the file system resource add finally it to the map of
+                // registered privileges.
+                customPrivilegesStore.append(definitions);
+                cacheDefinitions(definitions);
+
+            } catch (IOException e) {
+                throw new RepositoryException("Failed to register custom privilegess.", e);
+            } catch (FileSystemException e) {
+                throw new RepositoryException("Failed to register custom privileges.", e);
+            } catch (ParseException e) {
+                throw new RepositoryException("Failed to register custom privileges.", e);
+            }
+        }
+
+        for (Listener l : listeners.keySet()) {
+            l.privilegesRegistered(stubs.keySet());
+        }
+    }
+
+    /**
      * Adds the specified privilege definitions to the internal map(s) and
      * recalculates the jcr:all privilege definition.
      * 
      * @param definitions
      */
-    private void registerDefinitions(Map<Name, Definition> definitions) {
+    private void cacheDefinitions(Map<Name, Definition> definitions) {
         registeredPrivileges.putAll(definitions);
         for (Definition def : definitions.values()) {
-            bitsToNames.put(def.bits, Collections.singleton(def.name));
+            bitsToNames.put(def.bits, Collections.singleton(def.getName()));
         }
 
         if (!definitions.containsKey(NameConstants.JCR_ALL)) {
@@ -551,7 +629,7 @@ public final class PrivilegeRegistry {
             Definition all = registeredPrivileges.get(NameConstants.JCR_ALL);
             bitsToNames.remove(all.bits);
             
-            Set<Name> allAggrNames = all.declaredAggregateNames;
+            Set<Name> allAggrNames = new HashSet<Name>(all.getDeclaredAggregateNames());
             allAggrNames.addAll(definitions.keySet());
 
             PrivilegeBits allbits = PrivilegeBits.getInstance(all.bits);
@@ -584,11 +662,11 @@ public final class PrivilegeRegistry {
 
         // jcr:write
         Definition jcrWrite = createJcrWriteDefinition();
-        defs.put(jcrWrite.name, jcrWrite);
+        defs.put(jcrWrite.getName(), jcrWrite);
 
         // rep:write
         Definition repWrite = createRepWriteDefinition(jcrWrite);
-        defs.put(repWrite.name, repWrite);
+        defs.put(repWrite.getName(), repWrite);
 
         // jcr:all
         Set<Name> jcrAllAggregates = new HashSet<Name>(10);
@@ -604,7 +682,7 @@ public final class PrivilegeRegistry {
         jcrAllAggregates.add(REP_WRITE_NAME);
 
         Definition jcrAll = new Definition(NameConstants.JCR_ALL, false, jcrAllAggregates, jcrAllBits);
-        defs.put(jcrAll.name, jcrAll);
+        defs.put(jcrAll.getName(), jcrAll);
 
         return defs;
     }
@@ -619,12 +697,12 @@ public final class PrivilegeRegistry {
      * @return new privilege definitions.
      * @throws RepositoryException If any of the specified stubs is invalid.
      */
-    private Map<Name, Definition> createCustomDefinitions(Map<Name, DefinitionStub> toRegister) throws RepositoryException {
+    private Map<Name, Definition> createCustomDefinitions(Map<Name, PrivilegeDefinition> toRegister) throws RepositoryException {
         Map<Name, Definition> definitions = new HashMap<Name, Definition>(toRegister.size());
-        Set<DefinitionStub> aggregates = new HashSet<DefinitionStub>();
+        Set<PrivilegeDefinition> aggregates = new HashSet<PrivilegeDefinition>();
 
-        for (DefinitionStub stub : toRegister.values()) {
-            Name name = stub.name;
+        for (PrivilegeDefinition stub : toRegister.values()) {
+            Name name = stub.getName();
             if (name == null) {
                 throw new RepositoryException("Name of custom privilege may not be null.");
             }
@@ -634,18 +712,19 @@ public final class PrivilegeRegistry {
 
             // namespace validation:
             // - make sure the specified name defines a registered namespace
-            namespaceRegistry.getPrefix(stub.name.getNamespaceURI());
+            namespaceRegistry.getPrefix(name.getNamespaceURI());
             // - and isn't one of the reserved namespaces
             if (((NamespaceRegistryImpl) namespaceRegistry).isReservedURI(name.getNamespaceURI())) {
                 throw new RepositoryException("Failed to register custom privilege: Reserved namespace URI: " + name.getNamespaceURI());
             }
 
             // validate aggregates
-            if (stub.declaredAggregateNames.isEmpty()) {
+            Set<Name> dagn = stub.getDeclaredAggregateNames();
+            if (dagn.isEmpty()) {
                 // not an aggregate priv definition.
                 definitions.put(name, new Definition(stub, nextBits()));
             } else {
-                for (Name declaredAggregateName : stub.declaredAggregateNames) {
+                for (Name declaredAggregateName : dagn) {
                     if (name.equals(declaredAggregateName)) {
                         throw new RepositoryException("Declared aggregate name '"+ declaredAggregateName.toString() +"'refers to the same custom privilege.");
                     }
@@ -672,27 +751,27 @@ public final class PrivilegeRegistry {
             int cnt = aggregates.size();
 
             // look for those definitions whose declared aggregates have all been processed.
-            for (Iterator<DefinitionStub> itr = aggregates.iterator(); itr.hasNext();) {
-                DefinitionStub stub = itr.next();
-                PrivilegeBits bts = getAggregateBits(stub.declaredAggregateNames, definitions);
+            for (Iterator<PrivilegeDefinition> itr = aggregates.iterator(); itr.hasNext();) {
+                PrivilegeDefinition stub = itr.next();
+                PrivilegeBits bts = getAggregateBits(stub.getDeclaredAggregateNames(), definitions);
                 if (!bts.isEmpty()) {
                     // make sure the same aggregation is not yet covered by an
                     // already registered privilege
                     if (bitsToNames.containsKey(bts) && bitsToNames.get(bts).size() == 1) {
                         Name existingName = bitsToNames.get(bts).iterator().next();
-                        throw new RepositoryException("Custom aggregate privilege '" + stub.name + "' is already covered by '" + existingName.toString() + "'");
+                        throw new RepositoryException("Custom aggregate privilege '" + stub.getName() + "' is already covered by '" + existingName.toString() + "'");
                     }
                     // ... nor is present within the set of definitions that have
                     // been created before for registration.
                     for (Definition d : definitions.values()) {
                         if (bts.equals(d.bits)) {
-                            throw new RepositoryException("Custom aggregate privilege '" + stub.name + "' is already defined by '"+ d.name+"'");
+                            throw new RepositoryException("Custom aggregate privilege '" + stub.getName() + "' is already defined by '"+ d.getName()+"'");
                         }
                     }
 
                     // now its save to create the new definition
                     Definition def = new Definition(stub, bts);
-                    definitions.put(def.name, def);
+                    definitions.put(def.getName(), def);
                     itr.remove();
                 } // unresolvable bts -> postpone to next iterator.
             }
@@ -745,14 +824,14 @@ public final class PrivilegeRegistry {
      * @param toRegister
      * @return
      */
-    private boolean isCircularAggregation(DefinitionStub def, Name declaredAggregateName, Map<Name, DefinitionStub> toRegister) {
-        DefinitionStub d = toRegister.get(declaredAggregateName);
-        if (d.declaredAggregateNames.isEmpty()) {
+    private boolean isCircularAggregation(PrivilegeDefinition def, Name declaredAggregateName, Map<Name, PrivilegeDefinition> toRegister) {
+        PrivilegeDefinition d = toRegister.get(declaredAggregateName);
+        if (d.getDeclaredAggregateNames().isEmpty()) {
             return false;
         } else {
             boolean isCircular = false;
-            for (Name n : d.declaredAggregateNames) {
-                if (def.name.equals(n)) {
+            for (Name n : d.getDeclaredAggregateNames()) {
+                if (def.getName().equals(n)) {
                     return true;
                 }
                 if (toRegister.containsKey(n)) {
@@ -795,78 +874,25 @@ public final class PrivilegeRegistry {
      */
     interface Listener {
         /**
-         * @param privilegeName The name of the new privilege
+         * @param privilegeNames
          */
-        void privilegeRegistered(Name privilegeName);
-    }
-
-
-    /**
-     * Raw, non-validated stub of a PrivilegeDefinition
-     */
-    private static class DefinitionStub {
-        
-        protected final Name name;
-        protected final boolean isAbstract;
-        protected final Set<Name> declaredAggregateNames;
-
-        private int hashCode;
-
-        private DefinitionStub(Name name, boolean isAbstract, Set<Name> declaredAggregateNames) {
-            this.name = name;
-            this.isAbstract = isAbstract;
-            this.declaredAggregateNames = (declaredAggregateNames == null) ? Collections.<Name>emptySet() : declaredAggregateNames;
-        }
-
-        //---------------------------------------------------------< Object >---
-        @Override
-        public String toString() {
-            return name.toString();
-        }
-
-        @Override
-        public int hashCode() {
-            if (hashCode == 0) {
-                int h = 17;
-                h = 37 * h + name.hashCode();
-                h = 37 * h + Boolean.valueOf(isAbstract).hashCode();
-                /* NOTE: evaluation of decl-aggr-names is sufficient as
-                   uniqueness is asserted upon registration */
-                h = 37 * h + declaredAggregateNames.hashCode();
-                hashCode = h;
-            }
-            return hashCode;
-        }
-
-        @Override
-        public boolean equals(Object obj) {
-            if (obj == this) {
-                return true;
-            }
-            if (obj instanceof DefinitionStub) {
-                DefinitionStub other = (DefinitionStub) obj;
-                return name.equals(other.name)
-                        && isAbstract==other.isAbstract
-                        /* NOTE: comparison of decl-aggr-names is sufficient as
-                           uniqueness is asserted upon registration */
-                        && declaredAggregateNames.equals(other.declaredAggregateNames);
-            }
-            return false;
-        }
+        void privilegesRegistered(Set<Name> privilegeNames);
     }
 
     /**
-     * Internal definition of a jcr level privilege.
+     * Internal definition of a JCR privilege extending from the general
+     * privilege definition. It defines addition information that ease
+     * the evaluation of privileges.
      */
-    static class Definition extends DefinitionStub {
+    private static class Definition extends PrivilegeDefinition {
 
         private final PrivilegeBits bits;
         private final boolean isCustom;
 
         private int hashCode;
 
-        private Definition(DefinitionStub stub, PrivilegeBits bits) {
-            this(stub.name, stub.isAbstract, stub.declaredAggregateNames, bits, true);
+        private Definition(PrivilegeDefinition stub, PrivilegeBits bits) {
+            this(stub.getName(), stub.isAbstract(), stub.getDeclaredAggregateNames(), bits, true);
         }
 
         private Definition(Name name, boolean isAbstract, long bits) {
@@ -887,33 +913,11 @@ public final class PrivilegeRegistry {
             this.isCustom = isCustom;
         }
 
-        Name getName() {
-            return name;
-        }
-
-        PrivilegeBits getBits() {
-            return bits;
-        }
-
-        boolean isAbstract() {
-            return isAbstract;
-        }
-
-        Name[] getDeclaredAggregateNames() {
-            if (declaredAggregateNames.isEmpty()) {
-                return Name.EMPTY_ARRAY;
-            } else {
-                return declaredAggregateNames.toArray(new Name[declaredAggregateNames.size()]);
-            }
-        }
-
         //---------------------------------------------------------< Object >---
         @Override
         public int hashCode() {
             if (hashCode == 0) {
-                int h = 17;
-                h = 37 * h + name.hashCode();
-                h = 37 * h + Boolean.valueOf(isAbstract).hashCode();
+                int h = super.hashCode();
                 h = 37 * h + bits.hashCode();
                 hashCode = h;
             }
@@ -927,9 +931,7 @@ public final class PrivilegeRegistry {
             }
             if (obj instanceof Definition) {
                 Definition other = (Definition) obj;
-                return name.equals(other.name)
-                        && isAbstract==other.isAbstract
-                        && bits.equals(other.bits);
+                return bits.equals(other.bits) && super.equals(other);
             }
             return false;
         }
@@ -961,26 +963,19 @@ public final class PrivilegeRegistry {
             }
         }
 
-        private Map<Name, DefinitionStub> load() throws FileSystemException, RepositoryException, ParseException, IOException {
-            Map<Name, DefinitionStub> stubs = new LinkedHashMap<Name, DefinitionStub>();
+        private Map<Name, PrivilegeDefinition> load() throws FileSystemException, RepositoryException, ParseException, IOException {
+            Map<Name, PrivilegeDefinition> stubs = new LinkedHashMap<Name, PrivilegeDefinition>();
 
             if (customPrivilegesResource.exists()) {
                 InputStream in = customPrivilegesResource.getInputStream();
                 try {
                     PrivilegeDefinitionReader pr = new PrivilegeDefinitionReader(in, "text/xml");
                     for (PrivilegeDefinition def : pr.getPrivilegeDefinitions()) {
-
-                        Name privName = getName(def.getName());
-                        boolean isAbstract = def.isAbstract();
-                        Set<Name> declaredAggrNames = new HashSet<Name>();
-                        for (String dan : def.getDeclaredAggregateNames()) {
-                            declaredAggrNames.add(getName(dan));
-                        }
-
+                        Name privName = def.getName();
                         if (stubs.containsKey(privName)) {
                             throw new RepositoryException("Duplicate entry for custom privilege with name " + privName.toString());
                         }
-                        stubs.put(privName, new DefinitionStub(privName, isAbstract, declaredAggrNames));
+                        stubs.put(privName, def);
                     }
                 } finally {
                     in.close();
@@ -989,11 +984,6 @@ public final class PrivilegeRegistry {
             return stubs;
         }
 
-        private Name getName(String jcrName) throws RepositoryException {
-            String uri = namespaceRegistry.getURI(Text.getNamespacePrefix(jcrName));
-            return NAME_FACTORY.create(uri, Text.getLocalName(jcrName));
-        }
-
         private void append(Map<Name, Definition> newPrivilegeDefinitions) throws IOException, FileSystemException, RepositoryException, ParseException {
             List<PrivilegeDefinition> jcrDefs;
             Map<String, String> nsMapping;
@@ -1013,19 +1003,14 @@ public final class PrivilegeRegistry {
             }
 
             for (Definition d : newPrivilegeDefinitions.values()) {
-                String name = resolver.getJCRName(d.name);
-                String uri = d.name.getNamespaceURI();
+                String uri = d.getName().getNamespaceURI();
                 nsMapping.put(namespaceRegistry.getPrefix(uri), uri);
 
-                String[] aggrNames = new String[d.declaredAggregateNames.size()];
-                int i = 0;
-                for (Name dan : d.declaredAggregateNames) {
-                    aggrNames[i++] = resolver.getJCRName(dan);
-                    uri = d.name.getNamespaceURI();
+                for (Name dan : d.getDeclaredAggregateNames()) {
+                    uri = dan.getNamespaceURI();
                     nsMapping.put(namespaceRegistry.getPrefix(uri), uri);
                 }
-                PrivilegeDefinition pd = new PrivilegeDefinition(name, d.isAbstract, aggrNames);
-                jcrDefs.add(pd);
+                jcrDefs.add(d);
             }
 
             OutputStream out = customPrivilegesResource.getOutputStream();

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/ClusterRecordTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/ClusterRecordTest.java?rev=1095338&r1=1095337&r2=1095338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/ClusterRecordTest.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/ClusterRecordTest.java Wed Apr 20 09:29:02 2011
@@ -17,12 +17,14 @@
 package org.apache.jackrabbit.core.cluster;
 
 import java.util.ArrayList;
+import java.util.Collections;
 
 import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.core.cluster.SimpleEventListener.LockEvent;
 import org.apache.jackrabbit.core.cluster.SimpleEventListener.NamespaceEvent;
 import org.apache.jackrabbit.core.cluster.SimpleEventListener.NodeTypeEvent;
+import org.apache.jackrabbit.core.cluster.SimpleEventListener.PrivilegeEvent;
 import org.apache.jackrabbit.core.cluster.SimpleEventListener.UnlockEvent;
 import org.apache.jackrabbit.core.cluster.SimpleEventListener.UpdateEvent;
 import org.apache.jackrabbit.core.config.ClusterConfig;
@@ -37,6 +39,7 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
 import org.apache.jackrabbit.spi.commons.nodetype.QNodeTypeDefinitionBuilder;
+import org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinition;
 import org.apache.jackrabbit.test.JUnitTest;
 
 /**
@@ -78,6 +81,7 @@ public class ClusterRecordTest extends J
     /**
      * {@inheritDoc}
      */
+    @Override
     protected void setUp() throws Exception {
         master = createClusterNode("master", records);
         master.start();
@@ -90,6 +94,7 @@ public class ClusterRecordTest extends J
     /**
      * {@inheritDoc}
      */
+    @Override
     protected void tearDown() throws Exception {
         if (master != null) {
             master.stop();
@@ -276,6 +281,24 @@ public class ClusterRecordTest extends J
     }
 
     /**
+     * Test producing and consuming a privilege registration.
+     * @throws Exception
+     */
+    public void testPrivilegeRegistration() throws Exception {
+        PrivilegeDefinition pdf = new PrivilegeDefinition(NameFactoryImpl.getInstance().create("", "test"), false, null);
+
+        PrivilegeEvent event = new PrivilegeEvent(Collections.singletonList(pdf));
+        master.registeredPrivileges(event.getDefinitions());
+
+        SimpleEventListener listener = new SimpleEventListener();
+        slave.setListener((PrivilegeEventListener) listener);
+        slave.sync();
+
+        assertEquals(1, listener.getClusterEvents().size());
+        assertEquals(listener.getClusterEvents().get(0), event);
+    }
+
+    /**
      * Create a cluster node, with a memory journal referencing a list of records.
      *
      * @param id cluster node id

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/SimpleEventListener.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/SimpleEventListener.java?rev=1095338&r1=1095337&r2=1095338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/SimpleEventListener.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/SimpleEventListener.java Wed Apr 20 09:29:02 2011
@@ -32,13 +32,14 @@ import org.apache.jackrabbit.core.nodety
 import org.apache.jackrabbit.core.state.ChangeLog;
 import org.apache.jackrabbit.core.state.ItemState;
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
+import org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinition;
 
 /**
  * Simple event listener that can be registered for all cluster event listener
  * types and records external events in an array list.
  */
 public class SimpleEventListener implements LockEventListener,
-        NodeTypeEventListener, NamespaceEventListener, UpdateEventListener {
+        NodeTypeEventListener, NamespaceEventListener, PrivilegeEventListener, UpdateEventListener {
 
     /**
      * List of cluster events received.
@@ -407,6 +408,61 @@ public class SimpleEventListener impleme
         }
     }
 
+    //---------------------------------------------< PrivilegeEventListener >---
+    /**
+     * {@inheritDoc}
+     */
+    public void externalRegisteredPrivileges(Collection<PrivilegeDefinition> definitions) throws RepositoryException {
+        clusterEvents.add(new PrivilegeEvent(definitions));
+    }
+
+    /**
+     * privilege event auxiliary class.
+     */
+    public static class PrivilegeEvent {
+
+        /**
+         * Collection of node type definitions or node type names.
+         */
+        private Collection<PrivilegeDefinition> definitions;
+
+        /**
+         * Create a new instance of this class.
+         *
+         * @param definitions
+         */
+        public PrivilegeEvent(Collection<PrivilegeDefinition> definitions) {
+            this.definitions = definitions;
+        }
+
+        /**
+         * Return the definitions.
+         *
+         * @return definitions
+         */
+        public Collection<PrivilegeDefinition> getDefinitions() {
+            return definitions;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public int hashCode() {
+            return definitions.hashCode();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        public boolean equals(Object obj) {
+            if (obj instanceof PrivilegeEvent) {
+                PrivilegeEvent other = (PrivilegeEvent) obj;
+                return SimpleEventListener.equals(definitions, other.definitions);
+            }
+            return false;
+        }
+    }
+
     //------------------------------------------------------ UpdateEventListener
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/CustomPrivilegeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/CustomPrivilegeTest.java?rev=1095338&r1=1095337&r2=1095338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/CustomPrivilegeTest.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/CustomPrivilegeTest.java Wed Apr 20 09:29:02 2011
@@ -16,8 +16,10 @@
  */
 package org.apache.jackrabbit.core.security.authorization;
 
-import org.apache.jackrabbit.commons.privilege.PrivilegeDefinition;
-import org.apache.jackrabbit.commons.privilege.PrivilegeDefinitionWriter;
+import org.apache.jackrabbit.spi.NameFactory;
+import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+import org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinition;
+import org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionWriter;
 import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.fs.FileSystem;
@@ -81,16 +83,16 @@ public class CustomPrivilegeTest extends
         }
     }
 
-    private static void assertPrivilege(PrivilegeRegistry registry, NameResolver resolver, PrivilegeRegistry.Definition def) throws RepositoryException {
+    private static void assertPrivilege(PrivilegeRegistry registry, NameResolver resolver, PrivilegeDefinition def) throws RepositoryException {
         PrivilegeManagerImpl pmgr = new PrivilegeManagerImpl(registry, resolver);
         Privilege p = pmgr.getPrivilege(resolver.getJCRName(def.getName()));
 
         assertNotNull(p);
 
         assertEquals(def.isAbstract(), p.isAbstract());
-        Name[] danames = def.getDeclaredAggregateNames();
-        assertEquals(danames.length > 0, p.isAggregate());
-        assertEquals(danames.length, p.getDeclaredAggregatePrivileges().length);
+        Set<Name> danames = def.getDeclaredAggregateNames();
+        assertEquals(danames.size() > 0, p.isAggregate());
+        assertEquals(danames.size(), p.getDeclaredAggregatePrivileges().length);
     }
 
     private static Set<Name> createNameSet(Name... names) {
@@ -132,14 +134,21 @@ public class CustomPrivilegeTest extends
             resource.makeParentDirs();
         }
 
+        NameFactory nf = NameFactoryImpl.getInstance();
+        Name test = nf.create(Name.NS_DEFAULT_URI, "test");
+        Name test2 = nf.create(Name.NS_DEFAULT_URI, "test2");
+        Name test3 = nf.create(Name.NS_DEFAULT_URI, "test3");
+        Name test4 = nf.create(Name.NS_DEFAULT_URI, "test4");
+        Name test5 = nf.create(Name.NS_DEFAULT_URI, "test5");
+
         OutputStream out = resource.getOutputStream();
         try {
             List<PrivilegeDefinition> defs = new ArrayList<PrivilegeDefinition>();
-            defs.add(new PrivilegeDefinition("test", false, new String[] {"test2"}));
-            defs.add(new PrivilegeDefinition("test4", true, new String[] {"test5"}));
-            defs.add(new PrivilegeDefinition("test5", false, new String[] {"test3"}));
-            defs.add(new PrivilegeDefinition("test3", false, new String[] {"test"}));
-            defs.add(new PrivilegeDefinition("test2", false, new String[] {"test4"}));
+            defs.add(new PrivilegeDefinition(test, false, Collections.singleton(test2)));
+            defs.add(new PrivilegeDefinition(test4, true, Collections.singleton(test5)));
+            defs.add(new PrivilegeDefinition(test5, false, Collections.singleton(test3)));
+            defs.add(new PrivilegeDefinition(test3, false, Collections.singleton(test)));
+            defs.add(new PrivilegeDefinition(test2, false, Collections.singleton(test4)));
             PrivilegeDefinitionWriter pdw = new PrivilegeDefinitionWriter("text/xml");
             pdw.writeDefinitions(out, defs.toArray(new PrivilegeDefinition[defs.size()]), Collections.<String, String>emptyMap());
 
@@ -161,17 +170,25 @@ public class CustomPrivilegeTest extends
             resource.makeParentDirs();
         }
 
+        NameFactory nf = NameFactoryImpl.getInstance();
+        Name test = nf.create(Name.NS_DEFAULT_URI, "test");
+        Name test2 = nf.create(Name.NS_DEFAULT_URI, "test2");
+        Name test3 = nf.create(Name.NS_DEFAULT_URI, "test3");
+        Name test4 = nf.create(Name.NS_DEFAULT_URI, "test4");
+        Name test5 = nf.create(Name.NS_DEFAULT_URI, "test5");
+        Name test6 = nf.create(Name.NS_DEFAULT_URI, "test6");
+
         OutputStream out = resource.getOutputStream();
         try {
             List<PrivilegeDefinition> defs = new ArrayList<PrivilegeDefinition>();
-            defs.add(new PrivilegeDefinition("test", false, new String[] {"test2","test3"}));
-            defs.add(new PrivilegeDefinition("test2", true, new String[] {"test4"}));
-            defs.add(new PrivilegeDefinition("test3", true, new String[] {"test5"}));
-            defs.add(new PrivilegeDefinition("test4", true, new String[0]));
-            defs.add(new PrivilegeDefinition("test5", true, new String[0]));
+            defs.add(new PrivilegeDefinition(test, false, createNameSet(test2, test3)));
+            defs.add(new PrivilegeDefinition(test2, true, Collections.singleton(test4)));
+            defs.add(new PrivilegeDefinition(test3, true, Collections.singleton(test5)));
+            defs.add(new PrivilegeDefinition(test4, true, Collections.<Name>emptySet()));
+            defs.add(new PrivilegeDefinition(test5, true, Collections.<Name>emptySet()));
 
             // the equivalent definition to 'test'
-            defs.add(new PrivilegeDefinition("test6", false, new String[] {"test2","test5"}));
+            defs.add(new PrivilegeDefinition(test6, false, createNameSet(test2, test5)));
 
             PrivilegeDefinitionWriter pdw = new PrivilegeDefinitionWriter("text/xml");
             pdw.writeDefinitions(out, defs.toArray(new PrivilegeDefinition[defs.size()]), Collections.<String, String>emptyMap());
@@ -273,26 +290,26 @@ public class CustomPrivilegeTest extends
             privilegeRegistry.registerDefinition(name, isAbstract, aggrNames);
 
             // validate definition
-            PrivilegeRegistry.Definition definition = privilegeRegistry.get(name);
+            PrivilegeDefinition definition = privilegeRegistry.get(name);
             assertNotNull(definition);
             assertEquals(name, definition.getName());
             assertTrue(definition.isAbstract());
-            assertTrue(definition.declaredAggregateNames.isEmpty());
-            assertEquals(aggrNames.size(), definition.declaredAggregateNames.size());
+            assertTrue(definition.getDeclaredAggregateNames().isEmpty());
+            assertEquals(aggrNames.size(), definition.getDeclaredAggregateNames().size());
             for (Name n : aggrNames) {
-                assertTrue(definition.declaredAggregateNames.contains(n));
+                assertTrue(definition.getDeclaredAggregateNames().contains(n));
             }
 
-            List<Name> allAgg = Arrays.asList(privilegeRegistry.get(NameConstants.JCR_ALL).getDeclaredAggregateNames());
+            Set<Name> allAgg = privilegeRegistry.get(NameConstants.JCR_ALL).getDeclaredAggregateNames();
             assertTrue(allAgg.contains(name));
 
             // re-read the filesystem resource and check if definition is correct
             PrivilegeRegistry registry = new PrivilegeRegistry(superuser.getWorkspace().getNamespaceRegistry(), fs);
-            PrivilegeRegistry.Definition def = registry.get(name);
-            assertEquals(isAbstract, def.isAbstract);
-            assertEquals(aggrNames.size(), def.declaredAggregateNames.size());
+            PrivilegeDefinition def = registry.get(name);
+            assertEquals(isAbstract, def.isAbstract());
+            assertEquals(aggrNames.size(), def.getDeclaredAggregateNames().size());
             for (Name n : aggrNames) {
-                assertTrue(def.declaredAggregateNames.contains(n));
+                assertTrue(def.getDeclaredAggregateNames().contains(n));
             }
 
             assertPrivilege(privilegeRegistry, (SessionImpl) superuser, definition);
@@ -310,28 +327,28 @@ public class CustomPrivilegeTest extends
             boolean isAbstract = false;
             Set<Name> aggrNames = newAggregates.get(name);
             privilegeRegistry.registerDefinition(name, isAbstract, aggrNames);
-            PrivilegeRegistry.Definition definition = privilegeRegistry.get(name);
+            PrivilegeDefinition definition = privilegeRegistry.get(name);
 
             assertNotNull(definition);
             assertEquals(name, definition.getName());
             assertFalse(definition.isAbstract());
-            assertFalse(definition.declaredAggregateNames.isEmpty());
-            assertEquals(aggrNames.size(), definition.declaredAggregateNames.size());
+            assertFalse(definition.getDeclaredAggregateNames().isEmpty());
+            assertEquals(aggrNames.size(), definition.getDeclaredAggregateNames().size());
             for (Name n : aggrNames) {
-                assertTrue(definition.declaredAggregateNames.contains(n));
+                assertTrue(definition.getDeclaredAggregateNames().contains(n));
             }
 
-            List<Name> allAgg = Arrays.asList(privilegeRegistry.get(NameConstants.JCR_ALL).getDeclaredAggregateNames());
+            Set<Name> allAgg = privilegeRegistry.get(NameConstants.JCR_ALL).getDeclaredAggregateNames();
             assertTrue(allAgg.contains(name));
 
             // re-read the filesystem resource and check if definition is correct
             PrivilegeRegistry registry = new PrivilegeRegistry(superuser.getWorkspace().getNamespaceRegistry(), fs);
-            PrivilegeRegistry.Definition def = registry.get(name);
-            assertEquals(isAbstract, def.isAbstract);
-            assertEquals(isAbstract, def.isAbstract);
-            assertEquals(aggrNames.size(), def.declaredAggregateNames.size());
+            PrivilegeDefinition def = registry.get(name);
+            assertEquals(isAbstract, def.isAbstract());
+            assertEquals(isAbstract, def.isAbstract());
+            assertEquals(aggrNames.size(), def.getDeclaredAggregateNames().size());
             for (Name n : aggrNames) {
-                assertTrue(def.declaredAggregateNames.contains(n));
+                assertTrue(def.getDeclaredAggregateNames().contains(n));
             }
 
             assertPrivilege(registry, (SessionImpl) superuser, def);
@@ -357,26 +374,26 @@ public class CustomPrivilegeTest extends
     }
 
     public void testRegister100CustomPrivileges() throws RepositoryException, FileSystemException {
-        PrivilegeBits previous = privilegeRegistry.get(NameConstants.JCR_RETENTION_MANAGEMENT).getBits();
+        PrivilegeBits previous = privilegeRegistry.getBits(privilegeRegistry.get(NameConstants.JCR_RETENTION_MANAGEMENT)).unmodifiable();
         for (int i = 0; i < 100; i++) {
             boolean isAbstract = true;
             Name name = ((SessionImpl) superuser).getQName("test"+i);
             privilegeRegistry.registerDefinition(name, isAbstract, Collections.<Name>emptySet());
-            PrivilegeRegistry.Definition definition = privilegeRegistry.get(name);
+            PrivilegeDefinition definition = privilegeRegistry.get(name);
 
             assertNotNull(definition);
             assertEquals(name, definition.getName());
 
-            PrivilegeBits bits = definition.getBits();
+            PrivilegeBits bits = privilegeRegistry.getBits(definition).unmodifiable();
             assertNotNull(bits);
             assertFalse(bits.isEmpty());
 
             assertFalse(previous.equals(bits));
             assertEquals(previous.nextBits(), bits);
 
-            PrivilegeRegistry.Definition all = privilegeRegistry.get(NameConstants.JCR_ALL);
-            assertTrue(Arrays.asList(all.getDeclaredAggregateNames()).contains(name));
-            assertTrue(all.getBits().includes(bits));
+            PrivilegeDefinition all = privilegeRegistry.get(NameConstants.JCR_ALL);
+            assertTrue(all.getDeclaredAggregateNames().contains(name));
+            assertTrue(privilegeRegistry.getBits(all).includes(bits));
 
             previous = bits;
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/PrivilegeRegistryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/PrivilegeRegistryTest.java?rev=1095338&r1=1095337&r2=1095338&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/PrivilegeRegistryTest.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/authorization/PrivilegeRegistryTest.java Wed Apr 20 09:29:02 2011
@@ -20,6 +20,7 @@ import org.apache.jackrabbit.core.Sessio
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinition;
 import org.apache.jackrabbit.test.AbstractJCRTest;
 
 import javax.jcr.RepositoryException;
@@ -48,9 +49,9 @@ public class PrivilegeRegistryTest exten
 
     public void testGetAll() throws RepositoryException {
 
-        PrivilegeRegistry.Definition[] defs = privilegeRegistry.getAll();
+        PrivilegeDefinition[] defs = privilegeRegistry.getAll();
 
-        List<PrivilegeRegistry.Definition> l = new ArrayList<PrivilegeRegistry.Definition>(Arrays.asList(defs));
+        List<PrivilegeDefinition> l = new ArrayList<PrivilegeDefinition>(Arrays.asList(defs));
         assertTrue(l.remove(privilegeRegistry.get(NameConstants.JCR_READ)));
         assertTrue(l.remove(privilegeRegistry.get(NameConstants.JCR_ADD_CHILD_NODES)));
         assertTrue(l.remove(privilegeRegistry.get(NameConstants.JCR_REMOVE_CHILD_NODES)));
@@ -73,71 +74,60 @@ public class PrivilegeRegistryTest exten
 
     public void testGet() throws RepositoryException {
 
-        for (PrivilegeRegistry.Definition def : privilegeRegistry.getAll()) {
+        for (PrivilegeDefinition def : privilegeRegistry.getAll()) {
 
-            PrivilegeRegistry.Definition d = privilegeRegistry.get(def.name);
+            PrivilegeDefinition d = privilegeRegistry.get(def.getName());
             assertEquals(def, d);
 
-            assertNotNull(d.name);
-            assertEquals(d.name, d.getName());
+            assertNotNull(d.getName());
+            assertEquals(def.getName(), d.getName());
 
-            assertFalse(d.isAbstract);
-            assertEquals(d.isAbstract, d.isAbstract());
+            assertFalse(d.isAbstract());
+            assertEquals(def.isAbstract(), d.isAbstract());
 
-            assertNotNull(d.declaredAggregateNames);
-            List<Name> l = Arrays.asList(d.getDeclaredAggregateNames());
-            assertTrue(d.declaredAggregateNames.containsAll(l));
-            assertTrue(l.containsAll(d.declaredAggregateNames));
+            assertNotNull(d.getDeclaredAggregateNames());
+            assertTrue(def.getDeclaredAggregateNames().containsAll(d.getDeclaredAggregateNames()));
+            assertTrue(d.getDeclaredAggregateNames().containsAll(def.getDeclaredAggregateNames()));
 
-            assertFalse(d.getBits().isEmpty());
+            assertFalse(privilegeRegistry.getBits(d).isEmpty());
         }
     }
 
     public void testAggregates() throws RepositoryException {
 
-        for (PrivilegeRegistry.Definition def : privilegeRegistry.getAll()) {
-            if (def.declaredAggregateNames.isEmpty()) {
+        for (PrivilegeDefinition def : privilegeRegistry.getAll()) {
+            if (def.getDeclaredAggregateNames().isEmpty()) {
                 continue; // ignore non aggregate
             }
 
-            List<Name> l = Arrays.asList(def.getDeclaredAggregateNames());
-            for (Name n : l) {
-                PrivilegeRegistry.Definition d = privilegeRegistry.get(n);
+            for (Name n : def.getDeclaredAggregateNames()) {
+                PrivilegeDefinition d = privilegeRegistry.get(n);
                 assertNotNull(d);
-                Name[] names = privilegeRegistry.getNames(d.getBits());
+                Name[] names = privilegeRegistry.getNames(privilegeRegistry.getBits(d));
                 assertNotNull(names);
                 assertEquals(1, names.length);
-                assertEquals(d.name, names[0]);
+                assertEquals(d.getName(), names[0]);
             }
         }
     }
 
     public void testPrivilegeDefinition() throws RepositoryException {
 
-        for (PrivilegeRegistry.Definition def : privilegeRegistry.getAll()) {
-
-            assertNotNull(def.name);
-            assertEquals(def.name, def.getName());
-
-            assertFalse(def.isAbstract);
-            assertEquals(def.isAbstract, def.isAbstract());
-
-            assertNotNull(def.declaredAggregateNames);
-            List<Name> l = Arrays.asList(def.getDeclaredAggregateNames());
-            assertTrue(def.declaredAggregateNames.containsAll(l));
-            assertTrue(l.containsAll(def.declaredAggregateNames));
-
-            assertFalse(def.getBits().isEmpty());
+        for (PrivilegeDefinition def : privilegeRegistry.getAll()) {
+            assertNotNull(def.getName());
+            assertFalse(def.isAbstract());
+            assertNotNull(def.getDeclaredAggregateNames());
+            assertFalse(privilegeRegistry.getBits(def).isEmpty());
         }
     }
 
     public void testJcrAll() throws RepositoryException {
-        PrivilegeRegistry.Definition p = privilegeRegistry.get(NameConstants.JCR_ALL);
+        PrivilegeDefinition p = privilegeRegistry.get(NameConstants.JCR_ALL);
         assertEquals(p.getName(), NameConstants.JCR_ALL);
-        assertFalse(p.declaredAggregateNames.isEmpty());
+        assertFalse(p.getDeclaredAggregateNames().isEmpty());
         assertFalse(p.isAbstract());
 
-        Set<Name> l = new HashSet<Name>(p.declaredAggregateNames);
+        Set<Name> l = new HashSet<Name>(p.getDeclaredAggregateNames());
         assertTrue(l.remove(NameConstants.JCR_READ));
         assertTrue(l.remove(NameConstants.JCR_WRITE));
         assertTrue(l.remove(resolver.getQName(PrivilegeRegistry.REP_WRITE)));
@@ -153,25 +143,25 @@ public class PrivilegeRegistryTest exten
 
     public void testJcrWrite() throws RepositoryException {
         Name rw = resolver.getQName(PrivilegeRegistry.REP_WRITE);
-        PrivilegeRegistry.Definition p = privilegeRegistry.get(rw);
+        PrivilegeDefinition p = privilegeRegistry.get(rw);
 
         assertEquals(p.getName(), rw);
-        assertFalse(p.declaredAggregateNames.isEmpty());
+        assertFalse(p.getDeclaredAggregateNames().isEmpty());
         assertFalse(p.isAbstract());
 
-        Set<Name> l = new HashSet<Name>(p.declaredAggregateNames);
+        Set<Name> l = new HashSet<Name>(p.getDeclaredAggregateNames());
         assertTrue(l.remove(NameConstants.JCR_WRITE));
         assertTrue(l.remove(NameConstants.JCR_NODE_TYPE_MANAGEMENT));
         assertTrue(l.isEmpty());
     }
 
     public void testRepWrite() throws RepositoryException {
-        PrivilegeRegistry.Definition p = privilegeRegistry.get(NameConstants.JCR_WRITE);
+        PrivilegeDefinition p = privilegeRegistry.get(NameConstants.JCR_WRITE);
         assertEquals(p.getName(), NameConstants.JCR_WRITE);
-        assertFalse(p.declaredAggregateNames.isEmpty());
+        assertFalse(p.getDeclaredAggregateNames().isEmpty());
         assertFalse(p.isAbstract());
 
-        Set<Name> l = new HashSet<Name>(p.declaredAggregateNames);
+        Set<Name> l = new HashSet<Name>(p.getDeclaredAggregateNames());
         assertTrue(l.remove(NameConstants.JCR_MODIFY_PROPERTIES));
         assertTrue(l.remove(NameConstants.JCR_ADD_CHILD_NODES));
         assertTrue(l.remove(NameConstants.JCR_REMOVE_CHILD_NODES));



Mime
View raw message