              $sprevisionid = $data['sprevision'];
          }
  
--        $specontroller = new sspmod_janus_EntityController(SimpleSAML_Configuration::getConfig('module_janus.php'));
 +        $isSpAllowed = self::_checkSPMetadataIsConnectionAllowed($data, $sprevisionid);
- 
--        $specontroller->setEntity($data['spentityid'], $sprevisionid);
++
 +        // Check the IdP metadata whether the SP-IdP connection is allowed.
 +        $idprevisionid = null;
- 
--        if ($specontroller->getAllowedAll()!="yes") {
--            
--            $spbloked = $specontroller->getBlockedEntities();
--            if(count($spbloked) && !array_key_exists($data['idpentityid'], $spbloked)) {
--                return array(true);
--            }         
--            $spallowed = $specontroller->getAllowedEntities();
--            if (count($spallowed) && array_key_exists($data['idpentityid'], $spallowed)) {
--                return array(true);
--            }
--    
--            return array(false);
--    
++
 +        if(isset($data['idprevision']) && ctype_digit($data['idprevision'])) {
 +            $idprevisionid = $data['idprevision'];
-         }
--        return array(true);
++        }
 +
 +        $isIdpAllowed = self::_checkIdpMetadataIsConnectionAllowed($data, $idprevisionid);
 +
 +        return ($isSpAllowed && $isIdpAllowed) ? array(true) : array(false);
-     }
- 
-     public static function method_findIdentifiersByMetadata($data, &$status)
-@@ -341,4 +335,46 @@
-         }
-         return $result;
-     }
++    }
 +
 +    protected static function _checkSPMetadataIsConnectionAllowed(array $data, $revisionId=NULL)
 +    {
-+        $specontroller = new sspmod_janus_EntityController(SimpleSAML_Configuration::getConfig('module_janus.php'));
+         $specontroller = new sspmod_janus_EntityController(SimpleSAML_Configuration::getConfig('module_janus.php'));
+ 
+-        $specontroller->setEntity($data['spentityid'], $sprevisionid);
++        $specontroller->setEntity($data['spentityid'], $revisionId);
+ 
+         if ($specontroller->getAllowedAll()!="yes") {
+-            
 +
-+        $specontroller->setEntity($data['spentityid'], $revisionId);
-+
-+        if ($specontroller->getAllowedAll()!="yes") {
-+
-+            $spbloked = $specontroller->getBlockedEntities();
-+            if(count($spbloked) && !array_key_exists($data['idpentityid'], $spbloked)) {
+             $spbloked = $specontroller->getBlockedEntities();
+             if(count($spbloked) && !array_key_exists($data['idpentityid'], $spbloked)) {
+-                return array(true);
+-            }         
 +               return true;
 +            }
-+            $spallowed = $specontroller->getAllowedEntities();
-+            if (count($spallowed) && array_key_exists($data['idpentityid'], $spallowed)) {
+             $spallowed = $specontroller->getAllowedEntities();
+             if (count($spallowed) && array_key_exists($data['idpentityid'], $spallowed)) {
+-                return array(true);
 +                return true;
-+            }
+             }
+-    
+-            return array(false);
+-    
 +            return false;
-+        }
+         }
+-        return array(true);
 +        return true;
-+    }
-+
+     }
+ 
 +    protected static function _checkIdPMetadataIsConnectionAllowed(array $data, $revisionId=NULL)
 +    {
 +        $idpcontroller = new sspmod_janus_EntityController(SimpleSAML_Configuration::getConfig('module_janus.php'));

+        }
+        return true;
+    }
 }
Index: modules/janus/lib/REST/Methods.php
===================================================================
--- modules/janus/lib/REST/Methods.php	(revision 746)
+++ modules/janus/lib/REST/Methods.php	(working copy)
@@ -132,7 +132,7 @@
         return $result;
     }
