public string Translate(Identity id, Exception ex, string originalMessage)
        {
            string text = null;
            PropertyValidationException ex2 = ex as PropertyValidationException;

            if (ex2 != null)
            {
                StringBuilder stringBuilder = new StringBuilder(128);
                foreach (PropertyValidationError propertyValidationError in ex2.PropertyValidationErrors)
                {
                    stringBuilder.Append(propertyValidationError.Description);
                    stringBuilder.Append(" ");
                }
                text = stringBuilder.ToString();
            }
            if (this.IsLogging)
            {
                EcpEventLogConstants.Tuple_PowershellExceptionTranslated.LogEvent(new object[]
                {
                    EcpEventLogExtensions.GetUserNameToLog(),
                    ex.GetType(),
                    text,
                    originalMessage
                });
            }
            return(text);
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddInfrastructure(Configuration);

            // Identity
            services.AddIdentity <ApplicationUser, IdentityRole>(options =>
            {
                options.User.RequireUniqueEmail        = true;
                options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                options.ClaimsIdentity.UserIdClaimType = ClaimTypes.NameIdentifier;
            })
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultScheme             = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(options =>
            {
                options.SaveToken                 = true;
                options.RequireHttpsMetadata      = false;
                options.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuer   = false,
                    ValidateAudience = false,
                    ValidAudience    = Configuration["JWT:ValidAudience"],
                    ValidIssuer      = Configuration["JWT:ValidIssuer"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JWT:Secret"]))
                };
            });
            // End Identity

            // Add domain and application services
            services.AddDomain(Configuration);
            services.AddApplication(Configuration);

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "ProjectManagement.API", Version = "v1"
                });

                c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
                {
                    Name         = "Authorization",
                    Type         = SecuritySchemeType.ApiKey,
                    Scheme       = "Bearer",
                    BearerFormat = "JWT",
                    In           = ParameterLocation.Header,
                    Description  = "Enter 'Bearer [token]'"
                });

                c.AddSecurityRequirement(new OpenApiSecurityRequirement
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference
                            {
                                Type = ReferenceType.SecurityScheme,
                                Id   = "Bearer"
                            }
                        },
                        Array.Empty <string>()
                    }
                });
            });

            services.AddProblemDetails(setup =>
            {
                setup.IncludeExceptionDetails = (context, exception) => false;

                setup.OnBeforeWriteDetails = (context, details) =>
                {
                    details.Instance = context.Request.Path;
                };

                EntityAlreadyExistsException.Map(setup);
                PropertyValidationException.Map(setup);
            });
        }