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

+        }
+        return true;
+    }
 }
             $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'));
