Beispiel #1
0
        public AuthenticationResponce TokenAuthenticate(EntrustRequest _param)
        {
            try
            {
                logger.Debug("Entrust validation started");
                string Url          = ConfigurationManager.AppSettings["Token_ENDPOINT"].ToString();
                bool   Token_Islive = Convert.ToBoolean(ConfigurationManager.AppSettings["Token_Islive"]);
                string sb           = TokenRequest.TokenRequestPayload; // File.ReadAllText(HttpContext.Current.Server.MapPath("~/XML/TokenAuthRequest.xml"));
                sb = string.Format(sb, _param.response, _param.userGroup, _param.username, _param.requesterId, _param.requesterIp);

                string authentication         = ConfigurationManager.AppSettings["upm_Authentication"].ToString();
                AuthenticationResponce result = XmlHelpers.XmlProcessor(Url, sb, Token_Islive, authentication);
                logger.Debug("AuthenticationService::TokenAuthenticate::Responce:: " + result.isSuccessful);
                //using (StringReader stringreader = new StringReader(XmlHelpers.XmlGetPayload(result)))
                //{
                //    var serializer = new XmlSerializer(typeof(AuthenticationResponce));
                //    var s = (AuthenticationResponce)serializer.Deserialize(stringreader);
                //    return s;
                //}

                return(result);
            }
            catch (Exception ex)
            {
                logger.Error(ex.StackTrace.ToString());
                throw new Exception(ex.Message + "\n" + ex.StackTrace);
            }
        }
Beispiel #2
0
        private static AuthenticationResponce InValidResponce()
        {
            AuthenticationResponce authresponce = new AuthenticationResponce();

            authresponce.isSuccessful = "false";
            authresponce.response     = "Please provide basic authentication";
            return(authresponce);
        }
Beispiel #3
0
        private static AuthenticationResponce ValidResponce()
        {
            AuthenticationResponce authresponce = new AuthenticationResponce();

            authresponce.isSuccessful = "true";
            authresponce.response     = "Successful";
            return(authresponce);
        }
Beispiel #4
0
        private static AuthenticationResponce DecodeResponse(HttpWebResponse response)
        {
            AuthenticationResponce ar = new AuthenticationResponce();

            try
            {
                using (XmlTextReader xtReader = new XmlTextReader(response.GetResponseStream()))
                {
                    while (xtReader.Read())
                    {
                        if (xtReader.IsStartElement())
                        {
                            switch (xtReader.Name)
                            {
                            case "response":
                                ar.response = xtReader.ReadString();
                                break;

                            case "isSuccessful":
                                ar.isSuccessful = xtReader.ReadString();
                                break;

                            case "errorResponseCode":
                                ar.errorResponseCode = xtReader.ReadString();
                                break;

                            case "errorResponseMessage":
                                ar.errorResponseMessage = xtReader.ReadString();
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            return(ar);
        }
Beispiel #5
0
        public static AuthenticationResponce XmlProcessor(string Uri, string xml, bool Token_Islive, string authentication)
        {
            try
            {
                //don't check the value of Token_Islive. Always use token for all validation.
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Uri);
                byte[]         bytes;
                bytes = System.Text.Encoding.ASCII.GetBytes(xml);
                request.ContentType   = "text/xml; encoding='utf-8'";
                request.ContentLength = bytes.Length;
                request.Method        = "POST";

                request.UseDefaultCredentials = false;
                request.Proxy = new WebProxy();
                //string auth = "Basic R1VQQVk6d2F0ZXJmYWxs";
                //logger.Debug("Auth:" + auth);
                //  request.Headers.Add("Authorization", ConfigurationManager.AppSettings["Token_Authorization"].ToString());
                request.Headers.Add("Authorization", authentication);

                //Token_Islive = false; //For Testing only
                Token_Islive = true;
                if (!Token_Islive)
                {
                    //On Test
                    return(ValidResponce());
                }
                else //on Production
                {
                    Stream requestStream = request.GetRequestStream();
                    requestStream.Write(bytes, 0, bytes.Length);
                    requestStream.Close();
                    HttpWebResponse response;
                    response = (HttpWebResponse)request.GetResponse();
                    //Stream responseStream = null;
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        //try
                        //{
                        //    responseStream = response.GetResponseStream();
                        //    var esb_result = new StreamReader(responseStream).ReadToEnd();
                        //    logger.Debug("Entrust Response1:: " + esb_result);
                        //    return esb_result;
                        //}
                        //catch(Exception ex)
                        //{
                        //    logger.Error("Error reading stream result");
                        //}
                        //finally
                        //{
                        //    if (responseStream != null)
                        //    {
                        //        responseStream.Close();
                        //        responseStream = null;
                        //    }
                        //}
                        AuthenticationResponce authenticationResponce = DecodeResponse(response);
                        return(authenticationResponce);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Debug("xmlProcessor:: ex: " + ex.Message + " StackTrace" + ex.StackTrace);
                return(InValidResponce());
            }
            return(null);
        }