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

             $sprevisionid = $data['sprevision'];
         }
 
+        $isSpAllowed = self::_checkSPMetadataIsConnectionAllowed($data, $sprevisionid);
+
+        // Check the IdP metadata whether the SP-IdP connection is allowed.
+        $idprevisionid = null;
+
+        if(isset($data['idprevision']) && ctype_digit($data['idprevision'])) {
+            $idprevisionid = $data['idprevision'];
+        }
+
+        $isIdpAllowed = self::_checkIdpMetadataIsConnectionAllowed($data, $idprevisionid);
+
+        return ($isSpAllowed && $isIdpAllowed) ? array(true) : array(false);
+    }
+
+    protected static function _checkSPMetadataIsConnectionAllowed(array $data, $revisionId=NULL)
+    {
         $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") {
-            
+
             $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)) {
-                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'));

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