FELIX-2647 : Implement Coordinator Service - start permission checking

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1553110 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinationImpl.java b/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinationImpl.java
index 26b6afc..e539c28 100644
--- a/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinationImpl.java
+++ b/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinationImpl.java
@@ -69,7 +69,7 @@
 
     private final ArrayList<Participant> participants;
 
-    private final HashMap<Class<?>, Object> variables;
+    private final Map<Class<?>, Object> variables;
 
     private TimerTask timeoutTask;
 
@@ -214,6 +214,8 @@
                 this.waitLock.notifyAll();
             }
 
+            this.associatedThread = null;
+
             if ( this.failReason != null )
             {
                 throw new CoordinationException("Nested coordination failed", this,
diff --git a/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinatorImpl.java b/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinatorImpl.java
index 1eb9c6e..04d0524 100644
--- a/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinatorImpl.java
+++ b/coordinator/src/main/java/org/apache/felix/coordinator/impl/CoordinatorImpl.java
@@ -18,12 +18,14 @@
  */
 package org.apache.felix.coordinator.impl;
 
+import java.security.Permission;
 import java.util.Collection;
 import java.util.TimerTask;
 
 import org.osgi.framework.Bundle;
 import org.osgi.service.coordinator.Coordination;
 import org.osgi.service.coordinator.CoordinationException;
+import org.osgi.service.coordinator.CoordinationPermission;
 import org.osgi.service.coordinator.Coordinator;
 import org.osgi.service.coordinator.Participant;
 
@@ -123,12 +125,22 @@
         }
     }
 
+    private void checkPermission(final String coordinationName, final String actions )
+    {
+        final SecurityManager securityManager = System.getSecurityManager();
+        if (securityManager != null)
+        {
+            final Permission permission = new CoordinationPermission(coordinationName, this.owner, actions);
+            securityManager.checkPermission(permission);
+        }
+    }
+
     /**
      * @see org.osgi.service.coordinator.Coordinator#create(java.lang.String, long)
      */
     public Coordination create(final String name, final long timeout)
     {
-        // TODO: check permission
+        this.checkPermission(name, CoordinationPermission.INITIATE);
 
     	// check arguments
     	checkName(name);