Ejemplo n.º 1
0
        /// <summary>
        /// Adds mapping
        /// </summary>
        /// <param name="application">Affiliate application</param>
        /// <param name="user">Windows user</param>
        /// <param name="XU">External user</param>
        /// <param name="XP">External password</param>
        /// <returns>True if successful, otherwise false</returns>
        public static bool AddMapping(string application, string user, string XU, string XP)
        {
            try
            {
                // Set mapping
                ISSOMapper  mapper  = new ISSOMapper();
                ISSOMapping mapping = new ISSOMapping();

                string username   = user.Substring(user.IndexOf('\\') + 1);
                string userdomain = user.Substring(0, user.IndexOf('\\'));

                mapping.WindowsDomainName = userdomain;
                mapping.WindowsUserName   = username;
                mapping.ApplicationName   = application;
                mapping.ExternalUserName  = XU;

                mapping.Create(0);

                // Set credentials
                string[] credentials = new string[] { XP };
                mapper.SetExternalCredentials(application, XU, ref credentials);

                mapping.Enable(0);
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Adds an account mapping to an affiliate application.
 /// </summary>
 /// <param name="application">The affiliate application to which the account mapping will be added.</param>
 /// <param name="accounts">The account(s) that will use the mapping.</param>
 /// <param name="externalUserid">The external user id to map the accounts to.</param>
 /// <param name="externalPassword">The external password to map the accounts to.</param>
 public void Map(string application, string accounts, string externalUserid, string externalPassword)
 {
     try
     {
         string[] accountList = accounts.Split(';');
         foreach (string account in accountList)
         {
             string accountDomain = account.Substring(0, account.IndexOf('\\'));
             string accountName   = account.Substring(account.IndexOf('\\') + 1);
             try
             {
                 // Create mapping.
                 ISSOMapping mapping = new ISSOMapping();
                 mapping.ApplicationName   = application;
                 mapping.WindowsDomainName = accountDomain;
                 mapping.WindowsUserName   = accountName;
                 mapping.ExternalUserName  = externalUserid;
                 mapping.Create(SSOFlag.SSO_FLAG_ENABLED);
                 // Set credentials.
                 ISSOMapper mapper      = new ISSOMapper();
                 string[]   credentials = new string[] { externalPassword };
                 mapper.SetExternalCredentials(application, externalUserid, ref credentials);
             }
             catch (Exception e)
             {
                 throw new Exception("Failed to map account " + accountDomain + "\\" + accountName + " to external user " + externalUserid + " for application " + application + ". " + e.Message);
             }
         }
     }
     catch (Exception e)
     {
         throw new Exception("Failed to map account(s) " + accounts + " to application " + application + ". " + e.Message);
     }
 }