Пример #1
0
        internal static void ProcessWebException_Security(string msg)
        {

            FunctionalException te = new FunctionalException(msg);
            HttpContext.Current.Session["Error"] = te;
            HttpContext.Current.Response.Redirect("~/ErrorMessageViewer.aspx");
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Fwk.Exceptions.FunctionalException fw = new Fwk.Exceptions.FunctionalException("localFile", null, "RecordSetsNull", "ValidationExceptionMessage", new string[] { "parametro 1", "parametro 2" });

            Fwk.Exceptions.FunctionalException fw2 = new Fwk.Exceptions.FunctionalException(null, "RecordSetsNull", "ValidationExceptionMessage", String.Empty, string.Empty);


            MessageBox.Show(fw.Message);
        }
Пример #3
0
        private void button1_Click(object sender, EventArgs e)
        {



            Fwk.Exceptions.FunctionalException fw = new Fwk.Exceptions.FunctionalException("localFile",null, "RecordSetsNull", "ValidationExceptionMessage", new string[] { "parametro 1", "parametro 2" });

            Fwk.Exceptions.FunctionalException fw2 = new Fwk.Exceptions.FunctionalException(null, "RecordSetsNull", "ValidationExceptionMessage",String.Empty,string.Empty);
            

            MessageBox.Show(fw.Message);
        }
Пример #4
0
        /// <summary>
        /// Realiza el mapeo de una Exception a un ServiceError
        /// </summary>
        /// <param name="ex">Exception</param>
        /// <returns><see cref="ServiceError"/></returns>
        public static ServiceError GetServiceError(Exception ex)
        {
            ServiceError wServiceError = new ServiceError();

            wServiceError.Message = ex.Message;
            wServiceError.InnerMessageException = Fwk.Exceptions.ExceptionHelper.GetAllMessageException(ex);
            wServiceError.Source     = ex.Source;
            wServiceError.StackTrace = ex.StackTrace;

            FwkExceptionTypes t = Fwk.Exceptions.ExceptionHelper.GetFwkExceptionTypes(ex);

            wServiceError.Type = Enum.GetName(typeof(FwkExceptionTypes), t);

            switch (t)
            {
            case FwkExceptionTypes.TechnicalException:
            {
                TechnicalException tex = (TechnicalException)ex;
                wServiceError.ErrorId     = tex.ErrorId;
                wServiceError.Machine     = tex.Machine;
                wServiceError.UserName    = tex.UserName;
                wServiceError.Namespace   = tex.Namespace;
                wServiceError.Class       = tex.Class;
                wServiceError.Assembly    = tex.Assembly;
                wServiceError.ServiceName = tex.ServiceName;
                break;
            }

            case FwkExceptionTypes.FunctionalException:
            {
                FunctionalException fex = (FunctionalException)ex;
                wServiceError.ErrorId     = fex.ErrorId;
                wServiceError.Type        = ex.GetType().Name;
                wServiceError.ServiceName = fex.ServiceName;
                break;
            }

            case FwkExceptionTypes.OtherException:
            {
                wServiceError.Type = ex.GetType().Name;
                break;
            }
            }
            return(wServiceError);
        }
Пример #5
0
 /// <summary>
 /// <para>Transforma una excepción funcional en una SoapException,
 /// para poder serializarla a través de Soap.</para>
 /// </summary>
 /// <param name="pfex"></param>
 /// <param name="pabosoluteURI"></param>
 /// <returns></returns>
 public static SoapException ToSoapException(FunctionalException pfex, string pabosoluteURI)
 {
     return(GetSoapException(pfex, pabosoluteURI));
 }
Пример #6
0
        /// <summary>
        /// Procesa la excepcion original y la retorna.
        /// </summary>
        /// <param name="err"><see cref="ServiceError"/></param>
        /// <returns></returns>
        public static Exception ProcessException(ServiceError err)
        {
            Exception ex;
            Exception inner = null;

            if (!String.IsNullOrEmpty(err.InnerMessageException))
            {
                inner = new Exception(err.InnerMessageException);
            }
            switch (err.Type)
            {
            case "FunctionalException":
            case "Fwk.Exceptions.FunctionalException":
            {
                if (inner != null)
                {
                    if (!String.IsNullOrEmpty(err.ErrorId))
                    {
                        ex = new FunctionalException(Convert.ToInt32(err.ErrorId), inner, err.Message);
                    }
                    else
                    {
                        ex = new FunctionalException(null, inner, err.Message);
                    }

                    ((FunctionalException)ex).ServiceName = err.ServiceName;
                }
                else
                {
                    if (!String.IsNullOrEmpty(err.ErrorId))
                    {
                        ex = new FunctionalException(Convert.ToInt32(err.ErrorId), err.Message);
                    }
                    else
                    {
                        ex = new FunctionalException(err.Message);
                    }
                    ((FunctionalException)ex).ServiceName = err.ServiceName;
                }

                ex.Source = err.Source;
                ((FunctionalException)ex).ErrorId = err.ErrorId;
                //((FunctionalException)ex).StackTrace = err.StackTrace;
                break;
            }

            case "TechnicalException":
            case "Fwk.Exceptions.TechnicalException":
            {
                ex        = new TechnicalException(err.Message, inner);
                ex.Source = err.Source;
                ((TechnicalException)ex).ErrorId     = err.ErrorId;
                ((TechnicalException)ex).Machine     = err.Machine;
                ((TechnicalException)ex).UserName    = err.UserName;
                ((TechnicalException)ex).Namespace   = err.Namespace;
                ((TechnicalException)ex).Class       = err.Class;
                ((TechnicalException)ex).Assembly    = err.Assembly;
                ((TechnicalException)ex).ServiceName = err.ServiceName;
                //((TechnicalException)ex).StackTrace = err.StackTrace;
                break;
            }

            default:
            {
                ex = new Exception(err.Message, inner);
                break;
            }
            }



            return(ex);
        }
Пример #7
0
        static AuthenticationTicket Unprotect(string protectedText)
        {
            Microsoft.IdentityModel.Tokens.SecurityToken validatedToken;
            if (string.IsNullOrWhiteSpace(protectedText))
            {
                throw new ArgumentNullException("Este servicio requiere autenticacion JWT (protectedText requerido)");
            }
            //Fwk.Security.Identity.jwtSecurityProvider sec_provider = null;

            var tokenHandler = new JwtSecurityTokenHandler();
            //var jwtSecurityToken = tokenHandler.ReadJwtToken(protectedText);

            var secretKey          = ConfigurationManager.AppSettings["JWT_SECRET_KEY"];
            var audienceId         = ConfigurationManager.AppSettings["JWT_AUDIENCE_TOKEN"];
            var issuerToken        = ConfigurationManager.AppSettings["JWT_ISSUER_TOKEN"];
            var securityKey        = new SymmetricSecurityKey(System.Text.Encoding.Default.GetBytes(secretKey));
            var signingCredentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256Signature);

            //string audienceId = sec_provider.audienceId;
            //string symmetricKeyAsBase64 = sec_provider.audienceSecret;
            //var keyByteArray = TextEncodings.Base64Url.Decode(symmetricKeyAsBase64);

            //var securityKey = new SymmetricSecurityKey(keyByteArray);



            //TODO : CustomJwtFormat Esta lista de issuers debe ser flexible
            ///Establezco los issuers validos
            var issuers = new List <string>()
            {
                issuerToken,
                "https://10.200.1.239:50009",
                "http://10.200.1.239:50009",
                "http://localhost:54900"
            };

            var validationParams = new TokenValidationParameters()
            {
                ValidAudience            = audienceId,
                ValidIssuers             = issuers,
                ValidateLifetime         = true,
                ValidateAudience         = true,
                ValidateIssuer           = true,
                RequireSignedTokens      = true,
                RequireExpirationTime    = true,
                ValidateIssuerSigningKey = true,
                ClockSkew = TimeSpan.Zero,
                //IssuerSigningKeys = DefaultX509Key_Public_2048
                IssuerSigningKey = signingCredentials.Key
            };

            try
            {
                var principal = tokenHandler.ValidateToken(protectedText, validationParams, out validatedToken);


                var identity = principal.Identities.First();

                // Fill out the authenticationProperties issued and expires times if the equivalent claims are in the JWT
                var authenticationProperties = new AuthenticationProperties();

                //issued
                if (validatedToken.ValidFrom != DateTime.MinValue)
                {
                    authenticationProperties.IssuedUtc = validatedToken.ValidFrom.ToUniversalTime();
                }
                //expires
                if (validatedToken.ValidTo != DateTime.MinValue)
                {
                    authenticationProperties.ExpiresUtc = validatedToken.ValidTo.ToUniversalTime();
                }

                return(new AuthenticationTicket(identity, authenticationProperties));
            }
            catch (Exception ex)
            {
                //return Task<HttpResponseMessage>.Factory.StartNew(() => new HttpResponseMessage(statusCode) { });
                //throw new UnauthorizedAccessException(ex.Message);
                var ec = new Fwk.Exceptions.FunctionalException((int)HttpStatusCode.Unauthorized, " No autorizado " + ex.Message);
                throw ec;
            }
        }