      public static function method_isConnectionAllowed($data, &$status)
      {
          if (!isset($data["spentityid"]) || !isset($data["idpentityid"])) {
-@@ -140,32 +140,26 @@
+@@ -140,31 +140,25 @@
              return '';
          }
  

-            $spbloked = $specontroller->getBlockedEntities();
-            if(count($spbloked) && !array_key_exists($data['idpentityid'], $spbloked)) {
-                return array(true);
+        if(isset($data['idprevision']) && ctype_digit($data['idprevision'])) {
+            $idprevisionid = $data['idprevision'];
-            }         
+        }
-            $spallowed = $specontroller->getAllowedEntities();
-            if (count($spallowed) && array_key_exists($data['idpentityid'], $spallowed)) {
-                return array(true);
-            }
-    
+
-            return array(false);
+        $isIdpAllowed = self::_checkIdpMetadataIsConnectionAllowed($data, $idprevisionid);
-    
+
+        return ($isSpAllowed && $isIdpAllowed) ? array(true) : array(false);
-        }
+    }
-        return array(true);
-    }
 
     public static function method_findIdentifiersByMetadata($data, &$status)
     {
@@ -175,80 +169,80 @@
         }
 
         $ucontroller = new sspmod_janus_UserController(SimpleSAML_Configuration::getConfig('module_janus.php'));
-    
+
         $ucontroller->setUser($data['userid']);
 
         $entities = $ucontroller->searchEntitiesByMetadata($data['key'], $data['value']);
 
         $result = array();
-        
+
         foreach($entities AS $entity) {
             $result[] = $entity->getentityid();
         }
 
         return $result;
     }
-    
+
 /**
      * Unfinished implementation, awaits blacklist/whitelist implementation in janus.
      * For now, uses in efficient query that retrieves all eids (regardless of blacklist)
      * @param array $request The request parameters (typically from $_REQUEST)
      *        The entries in $request for this method are:
-     * 
-     *        keys (optional) - one or more comma separated keys of metadata 
+     *
+     *        keys (optional) - one or more comma separated keys of metadata
      *                          to retrieve.
-     *                          Note that keys that don't exist are silently 
-     *                          discarded and won't be present in the output.  
-     *        spentityid (optional) - List only those idps which are 
+     *                          Note that keys that don't exist are silently
+     *                          discarded and won't be present in the output.
+     *        spentityid (optional) - List only those idps which are
      *                                whitelisted against the SP identified by
      *                                this parameter
-     *                      
+     *
      */
     public static function method_getIdpList($data, &$status)
     {
         $filter = array();
-        
+
         // here we have access to $this->_entityController->getBlockedEntities() 
         // but we need a whitelist approach.
         if (isset($data["keys"]) && $data["keys"]!="") {
-            $filter = explode(",", $data["keys"]);            
+            $filter = explode(",", $data["keys"]);
         }
-        
+
         $spEntityId = NULL;
-        if (isset($data["spentityid"]) && $data["spentityid"]!="") { 
+        if (isset($data["spentityid"]) && $data["spentityid"]!="") {
             $spEntityId = $data["spentityid"];
         }
-        
+
         return self::_getEntities("saml20-idp", $filter, $spEntityId);
     }
-    
+
     /**
-     * Retrieves a list of all Service Providers. 
+     * Retrieves a list of all Service Providers.
      * @todo Use blacklist/whitelist
-     * 
+     *
      *        The entries in $data for this method are:
-     * 
-     *        keys (optional) - one or more comma separated keys of metadata 
+     *
+     *        keys (optional) - one or more comma separated keys of metadata
      *                          to retrieve.
-     *                          Note that keys that don't exist are silently 
+     *                          Note that keys that don't exist are silently
      *                          discarded and won't be present in the output.
      */
     public static function method_getSpList($data, &$status)
     {
         $filter = array();
-        
+
         if (isset($data["keys"]) && $data["keys"]!="") {
             $filter = explode(",", $data["keys"]);
-            
+
             // We also need the identifier
             if (!in_array("entityID", $filter)) {
                 $filter[] = "entityID";
             }
         }
-        
+
         return self::_getEntities("saml20-sp", $filter);
     }
-    
+
     protected static function _getMetadataForEntity($entity, $revisionid = NULL, $keys=array())
     {
         $econtroller = new sspmod_janus_EntityController(SimpleSAML_Configuration::getConfig('module_janus.php'));
@@ -264,35 +258,35 @@
                 $result[$meta->getKey()] = $meta->getValue();
             }
         }
-        
+
         return $result;
-        
+
     }
-    
- /** 
+
+ /**
      * Retrieve all entity metadata for all entities of a certain type.
      * @param String $type Supported types: "saml20-idp" or "saml20-sp"
      * @param Array $keys optional list of metadata keys to retrieve. Retrieves all if blank
-     * @param String $allowedEntityId if passed, returns only those entities that are 
+     * @param String $allowedEntityId if passed, returns only those entities that are
      *                         whitelisted against the given entity
      * @return Array Associative array of all metadata. The key of the array is the identifier
      */
     protected static function _getEntities($type, $keys=array(), $allowedEntityId=NULL)
     {
         $econtroller = new sspmod_janus_EntityController(SimpleSAML_Configuration::getConfig('module_janus.php'));
-        
-        $ucontroller = new sspmod_janus_UserController(SimpleSAML_Configuration::getConfig('module_janus.php'));   
-        
+
+        $ucontroller = new sspmod_janus_UserController(SimpleSAML_Configuration::getConfig('module_janus.php'));
+
         $entities = array();
-        
+
         if (isset($allowedEntityId)) {
             $econtroller->setEntity($allowedEntityId);
             $econtroller->loadEntity();
-            
+
             if ($econtroller->getEntity()->getAllowedAll()=="yes") {
-                
+
                 $entities = $ucontroller->searchEntitiesByType($type);
-                                
+
             } else {
                 $allowedEntities = $econtroller->getAllowedEntities();
 
@@ -309,7 +303,7 @@
                         foreach ($blockedEntities as $entityid=>$data) {
                             $blockedEntityIds[] = $data["remoteentityid"];
                         }
-                  
+
                         $all = $ucontroller->searchEntitiesByType($type);
                         $list = array();
                         foreach($all as $entity) {
@@ -318,17 +312,17 @@
                         // Return all entities that are not in the blacklist
                         $entities = array_diff($list, $blockedEntityIds);
                     }
-                    
+
                 }
             }
-            
+
         } else {
-            $entities = $ucontroller->searchEntitiesByType($type);    
+            $entities = $ucontroller->searchEntitiesByType($type);
         }
-        
+
         $result = array();
-        
-        
+
+
         foreach($entities as $entity) {
            $data = self::_getMetadataForEntity($entity, NULL, $keys);
            if (is_object($entity)) {
@@ -336,9 +330,51 @@
            } else {
                $entityId = $entity;
            }
-           $result[$entityId] = $data;          
-      
+           $result[$entityId] = $data;
+
         }
         return $result;
     }

+        }
+        return true;
+    }
 }