Index: src/main/java/org/wso2/carbon/hostobjects/sso/internal/util/Util.java
===================================================================
--- src/main/java/org/wso2/carbon/hostobjects/sso/internal/util/Util.java	(revision 185110)
+++ src/main/java/org/wso2/carbon/hostobjects/sso/internal/util/Util.java	(working copy)
@@ -18,23 +18,6 @@
 
 package org.wso2.carbon.hostobjects.sso.internal.util;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.security.KeyStore;
-import java.util.Random;
-import java.util.zip.DataFormatException;
-import java.util.zip.Deflater;
-import java.util.zip.DeflaterOutputStream;
-import java.util.zip.Inflater;
-import java.util.zip.InflaterInputStream;
-
-import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.opensaml.Configuration;
@@ -58,9 +41,21 @@
 import org.w3c.dom.ls.LSSerializer;
 import org.wso2.carbon.base.MultitenantConstants;
 import org.wso2.carbon.core.util.KeyStoreManager;
+import org.wso2.carbon.registry.core.service.TenantRegistryLoader;
 import org.wso2.carbon.user.core.service.RealmService;
 import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
 
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.security.KeyStore;
+import java.util.Random;
+
 public class Util {
 
     private static boolean bootStrapped = false;
@@ -68,6 +63,7 @@
     private static Random random = new Random();
     
     private static RealmService realmService = null;
+    private static TenantRegistryLoader tenantRegistryLoader = null;
 
     private static final char[] charMapping = {
             'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
@@ -201,7 +197,16 @@
      * @return decoded AuthReq
      */
     public static String decode(String encodedStr) throws Exception {
-       return new String(Base64.decode(encodedStr));
+        try {
+            org.apache.commons.codec.binary.Base64 base64Decoder = new org.apache.commons.codec.binary.Base64();
+            byte[] xmlBytes = encodedStr.getBytes("UTF-8");
+            byte[] base64DecodedByteArray = base64Decoder.decode(xmlBytes);
+
+            return new String(base64DecodedByteArray, 0, base64DecodedByteArray.length, "UTF-8");
+
+        } catch (IOException e) {
+            throw new Exception("Error when decoding the SAML Request.", e);
+        }
     }
 
     /**
@@ -217,6 +222,10 @@
             KeyStore keyStore = null;
             java.security.cert.X509Certificate cert = null;
             if (tenantId != MultitenantConstants.SUPER_TENANT_ID) {
+
+                TenantRegistryLoader tenantRegistryLoader = Util.getTenantRegistryLoader();
+                tenantRegistryLoader.loadTenantRegistry(tenantId);
+                
                 // get an instance of the corresponding Key Store Manager instance
                 KeyStoreManager keyStoreManager = KeyStoreManager.getInstance(tenantId);
                 keyStore = keyStoreManager.getKeyStore(generateKSNameFromDomainName(tenantDomain));
@@ -241,7 +250,7 @@
             return isSigValid;
         }
     }
-    
+
     public static String getDomainName(XMLObject samlObject) {
         NodeList list = samlObject.getDOM().getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "NameID");
         String domainName = null;
@@ -271,4 +280,12 @@
         return Util.realmService;
     }
 
+    public static void setTenantRegistryLoader(TenantRegistryLoader tenantRegistryLoader) {
+        Util.tenantRegistryLoader = tenantRegistryLoader;
+    }
+
+    public static TenantRegistryLoader getTenantRegistryLoader() {
+        return Util.tenantRegistryLoader;
+    }
+
 }
Index: src/main/java/org/wso2/carbon/hostobjects/sso/internal/SSOHostObjectServiceComponent.java
===================================================================
--- src/main/java/org/wso2/carbon/hostobjects/sso/internal/SSOHostObjectServiceComponent.java	(revision 185110)
+++ src/main/java/org/wso2/carbon/hostobjects/sso/internal/SSOHostObjectServiceComponent.java	(working copy)
@@ -20,14 +20,21 @@
 import org.apache.commons.logging.LogFactory;
 import org.osgi.service.component.ComponentContext;
 import org.wso2.carbon.hostobjects.sso.internal.util.Util;
+import org.wso2.carbon.registry.core.service.TenantRegistryLoader;
 import org.wso2.carbon.user.core.service.RealmService;
 
 /**
  * @scr.component name="identity.sso.saml.component" immediate="true"
  * @scr.reference name="user.realmservice.default"
- *                interface="org.wso2.carbon.user.core.service.RealmService"
- *                cardinality="1..1" policy="dynamic" bind="setRealmService"
- *                unbind="unsetRealmService"
+ * interface="org.wso2.carbon.user.core.service.RealmService"
+ * cardinality="1..1" policy="dynamic" bind="setRealmService"
+ * unbind="unsetRealmService"
+ * @scr.reference name="registry.loader.default"
+ * interface="org.wso2.carbon.registry.core.service.TenantRegistryLoader"
+ * cardinality="1..1"
+ * policy="dynamic"
+ * bind="setRegistryLoader"
+ * unbind="unsetRegistryLoader"
  */
 public class SSOHostObjectServiceComponent {
 
@@ -59,4 +66,13 @@
         }
     }
 
+    protected void setRegistryLoader(TenantRegistryLoader tenantRegistryLoader) {
+        Util.setTenantRegistryLoader(tenantRegistryLoader);
+    }
+
+    protected void unsetRegistryLoader(TenantRegistryLoader tenantRegistryLoader) {
+        Util.setTenantRegistryLoader(null);
+    }
+
+
 }
\ No newline at end of file
