예제 #1
0
        public static ProvisionResponse GrantMOETAccess(string env, string user)
        {
            ProvisionResponse result = new ProvisionResponse();

            try
            {
                //if (string.IsNullOrWhiteSpace(user)) user = Thread.CurrentPrincipal.Identity.Name;
                //else
                //{
                //    string emailAddress = ActiveDirectoryHelper.GetValue("mail", user);
                //}

                ActiveDirectoryHelper.ValidateUser(user);

                string response = SqlDataHelper.Provision(AppName.MOET, env, user, string.Empty, Properties.Resources.Query_MOETAccess);

                if (response == "1")
                {
                    result.Status = "Success";
                    result.Reason = "Access Granted";
                }
                else
                {
                    result.Status = "Error";
                    result.Reason = "Unable to grant MOET Access.";
                }
            }
            catch (Exception ex)
            {
                result.Status = "Error";
                result.Reason = ex.Message;
            }
            return(result);
        }
예제 #2
0
        public static ProvisionResponse GrantMsQuoteAccess(string env, string user, string mq1 = "D", string mq2 = "D", string mq3 = "D", string mq4 = "D", string qsu = "D", string mqf = "D", string qv = "D")
        {
            ProvisionResponse result = new ProvisionResponse();

            try
            {
                //if (string.IsNullOrWhiteSpace(user)) user = Thread.CurrentPrincipal.Identity.Name;

                ActiveDirectoryHelper.ValidateUser(user);

                bool response = SqlDataHelper.ProvisionMsQuote(env, Properties.Resources.Query_MSQuote, user, mq1, mq2, mq3, mq4, qsu, mqf, qv);

                if (!response)
                {
                    result.Status = "Success";
                    result.Reason = "Access Revoked";
                }
                else
                {
                    result.Status = "Success";
                    result.Reason = "Access Granted";
                }
            }
            catch (Exception ex)
            {
                result.Status = "Error";
                result.Reason = ex.Message;
            }
            return(result);
        }
예제 #3
0
        public static ProvisionResponse GrantMSLAccess(string env, string user, string pcn, bool needPQRole)
        {
            ProvisionResponse result = new ProvisionResponse();

            try
            {
                //if (string.IsNullOrWhiteSpace(user)) user = Thread.CurrentPrincipal.Identity.Name;

                ActiveDirectoryHelper.ValidateUser(user);

                string response = SqlDataHelper.Provision(AppName.MSL, env, user, pcn, (needPQRole ? Properties.Resources.Query_MSL_PQ : Properties.Resources.Query_MSLAccess));

                using (XmlReader reader = XmlReader.Create(new StringReader(response)))
                {
                    XElement            root             = XElement.Load(reader);
                    XmlNameTable        nameTable        = reader.NameTable;
                    XmlNamespaceManager namespaceManager = new XmlNamespaceManager(nameTable);
                    namespaceManager.AddNamespace("ns1", "http://MS.IT.Ops.MSLicense.TransactionService.DataContracts/");

                    XElement element = root.XPathSelectElement("/ns1:Accessor/ns1:AccessorStatus/ns1:StatusID", namespaceManager);

                    if (element == null || element.Value != "1")
                    {
                        result.Status = "Error";
                    }
                    else
                    {
                        result.Status = "Success";
                        result.Reason = "Access Granted";
                    }
                }
            }
            catch (Exception ex)
            {
                result.Status = "Error";
                result.Reason = ex.Message;
            }
            return(result);
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="env"></param>
        /// <param name="query"></param>
        /// <param name="alias"></param>
        /// <param name="mq1"></param>
        /// <param name="mq2"></param>
        /// <param name="mq3"></param>
        /// <param name="mq4"></param>
        /// <param name="qsu"></param>
        /// <param name="mqf"></param>
        /// <param name="qv"></param>
        /// <returns></returns>
        public static bool ProvisionMsQuote(string env, string query, string alias, string mq1 = "D", string mq2 = "D", string mq3 = "D", string mq4 = "D", string qsu = "D", string mqf = "D", string qv = "D")
        {
            bool result;

            if (ConfigurationManager.ConnectionStrings[env] == null)
            {
                throw new Exception("Invalid environment.");
            }

            using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings[env].ConnectionString))
            {
                connection.Open();

                var email = ActiveDirectoryHelper.GetValue(alias, "mail");
                var fname = ActiveDirectoryHelper.GetValue(alias, "givenName");
                var lname = ActiveDirectoryHelper.GetValue(alias, "sn");

                try
                {
                    var cmd = connection.CreateCommand();
                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue("alias", alias);
                    cmd.Parameters.AddWithValue("email", email);
                    cmd.Parameters.AddWithValue("fname", fname);
                    cmd.Parameters.AddWithValue("lname", lname);

                    cmd.Parameters.AddWithValue("MQ1", mq1);
                    cmd.Parameters.AddWithValue("MQ2", mq2);
                    cmd.Parameters.AddWithValue("MQ3", mq3);
                    cmd.Parameters.AddWithValue("MQ4", mq4);
                    cmd.Parameters.AddWithValue("QSU", qsu);
                    cmd.Parameters.AddWithValue("MQF", mqf);
                    cmd.Parameters.AddWithValue("QV", qv);

                    var adapter = new SqlDataAdapter(cmd);
                    var ds      = new DataSet();

                    adapter.Fill(ds);

                    if (ds.Tables[1].Rows.Count == 0)
                    {
                        throw new Exception("User is not provisioned.");
                    }

                    result  = (mq1 == "I" && (ds.Tables[1].Rows.OfType <DataRow>().Where(item => item["ClaimType"].ToString() == "OperationalRole" && item["ClaimValue"].ToString() == "MQ1").FirstOrDefault() != null));
                    result |= (mq2 == "I" && (ds.Tables[1].Rows.OfType <DataRow>().Where(item => item["ClaimType"].ToString() == "OperationalRole" && item["ClaimValue"].ToString() == "MQ2").FirstOrDefault() != null));
                    result |= (mq3 == "I" && (ds.Tables[1].Rows.OfType <DataRow>().Where(item => item["ClaimType"].ToString() == "OperationalRole" && item["ClaimValue"].ToString() == "MQ3").FirstOrDefault() != null));
                    result |= (mq4 == "I" && (ds.Tables[1].Rows.OfType <DataRow>().Where(item => item["ClaimType"].ToString() == "OperationalRole" && item["ClaimValue"].ToString() == "MQ4").FirstOrDefault() != null));

                    result |= (qsu == "I" && (ds.Tables[1].Rows.OfType <DataRow>().Where(item => item["ClaimType"].ToString() == "OperationalRole" && item["ClaimValue"].ToString() == "QSU").FirstOrDefault() != null));
                    result |= (mqf == "I" && (ds.Tables[1].Rows.OfType <DataRow>().Where(item => item["ClaimType"].ToString() == "OperationalRole" && item["ClaimValue"].ToString() == "MQF").FirstOrDefault() != null));
                    result |= (qv == "I" && (ds.Tables[1].Rows.OfType <DataRow>().Where(item => item["ClaimType"].ToString() == "OperationalRole" && item["ClaimValue"].ToString() == "QV").FirstOrDefault() != null));
                }
                finally
                {
                    connection.Close();
                }
            }

            return(result);
        }