Ejemplo n.º 1
0
        private string[] GetCredentialsFromSSS()
        {
            string[] Credentials = new String[2];

            //Get the provider info
            string ssoProvider = this.LobSystemInstance.GetProperties()["SsoProviderImplementation"] as string;

            if (ssoProvider == null)
            {
                throw new LobBusinessErrorException("The SSO provider information is missing to retrieve the credentials");
            }

            Type providerType             = Type.GetType(ssoProvider);
            ISecureStoreProvider provider = (ISecureStoreProvider)Activator.CreateInstance(providerType);

            //Get the credentials
            string appTargetName = this.LobSystemInstance.GetProperties()["SecondarySsoApplicationId"] as string;

            SecureStoreCredentialCollection credentials = provider.GetCredentials(appTargetName);

            foreach (ISecureStoreCredential cred in credentials)
            {
                if (cred.CredentialType == SecureStoreCredentialType.UserName)
                {
                    Credentials[0] = GetString(cred.Credential);
                }
                else if (cred.CredentialType == SecureStoreCredentialType.Password)
                {
                    Credentials[1] = GetString(cred.Credential);
                }
            }

            return(Credentials);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get credentials from Secure Store Service
        /// </summary>
        /// <param name="targetAppId">Target Application ID for the Secure Store</param>
        /// <param name="site"></param>
        /// <returns>Object of NetworkCredential class. This class provides credentials for password-based authentication schemes such as basic, digest, NTLM, and Kerberos authentication.</returns>
        public static SecureStoreCredentials GetCredentials(string targetAppId, SPSite site)
        {
            // Get the default Secure Store Service provider.
            ISecureStoreProvider provider = SecureStoreProviderFactory.Create();

            if (provider == null)
            {
                throw new Exception("Unable to get an ISecureStoreProvider.");
            }

            ISecureStoreServiceContext providerContext = provider as ISecureStoreServiceContext;

            if (providerContext != null)
            {
                providerContext.Context = SPServiceContext.GetContext(site);
            }

            var credentials = new SecureStoreCredentials();

            using (SecureStoreCredentialCollection credentialCollection = provider.GetCredentials(targetAppId))
            {
                foreach (ISecureStoreCredential credential in credentialCollection)
                {
                    switch (credential.CredentialType)
                    {
                    case SecureStoreCredentialType.UserName:
                        credentials.UserName = GetStringFromSecureString(credential.Credential);
                        break;

                    case SecureStoreCredentialType.Password:
                        credentials.Password = credential.Credential;
                        break;

                    case SecureStoreCredentialType.WindowsUserName:
                        credentials.WindowsUserName = GetStringFromSecureString(credential.Credential);
                        break;

                    case SecureStoreCredentialType.WindowsPassword:
                        credentials.WindowsPassword = credential.Credential;
                        break;

                    case SecureStoreCredentialType.Certificate:
                        credentials.Certificate = GetStringFromSecureString(credential.Credential);
                        break;

                    case SecureStoreCredentialType.CertificatePassword:
                        credentials.CertificatePassword = credential.Credential;
                        break;
                    }
                }
            }
            return(credentials);
        }