private void foldersItem_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { TreeView tree = (TreeView)sender; TreeViewItem temp = ((TreeViewItem)tree.SelectedItem); if (temp == null) { return; } SelectedImagePath = ""; string temp2 = ""; while (true) { var temp1 = temp.Header.ToString(); if (temp1.Contains(@"\")) { temp2 = ""; } SelectedImagePath = temp1 + temp2 + SelectedImagePath; if (temp.Parent.GetType() == typeof(TreeView)) { break; } temp = ((TreeViewItem)temp.Parent); temp2 = @"\"; } Forbidden.Add(SelectedImagePath); }
public void SetUp() { var mediaType = new Mock <IMediaType>(); mediaType.SetupGet(mt => mt.Synonyms).Returns(new[] { "media-type" }); result = new Forbidden { MediaType = mediaType.Object }; }
internal bool TryAuthenticate(string apiKeyHash, out Forbidden error) { error = null; AccessRights = Authenticator.GetAccessRights(apiKeyHash); if (!RESTarConfig.RequireApiKey) { AccessRights = AccessRights.Root; } if (AccessRights == null) { error = new NotAuthorized(); return(false); } return(true); }
private Task HandleExceptionAsync(HttpContext context, Exception exception) { // Response Error errorResponse; switch (exception) { case UnauthorizedException _: // 401 var unauthorizedException = (UnauthorizedException)exception; errorResponse = new Unauthorized(nameof(ErrorMessage.Unauthorized), unauthorizedException.Message); break; case ForbiddenException _: // 403 var forbiddenException = (ForbiddenException)exception; errorResponse = new Forbidden(nameof(ErrorMessage.Forbidden), forbiddenException.Message); break; case NotFoundException _: // 404 var notFoundException = (NotFoundException)exception; errorResponse = new NotFound(nameof(ErrorMessage.NotFound), notFoundException.Message); break; case ConflictException _: // 409 var conflictException = (ConflictException)exception; errorResponse = new Conflict(nameof(ErrorMessage.Conflict), conflictException.Message); break; default: // 500 errorResponse = new InternalServerError(nameof(ErrorMessage.InternalServerError), ErrorMessage.InternalServerError); // Log error _logger.LogSplunkError(exception); break; } var response = JsonConvert.SerializeObject(errorResponse, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, ContractResolver = new CamelCasePropertyNamesContractResolver(), Converters = new List <JsonConverter> { new Newtonsoft.Json.Converters.StringEnumConverter() } }); context.Response.ContentType = "application/json"; context.Response.StatusCode = errorResponse.Status; return(context.Response.WriteAsync(response)); }
private int Query(uint alias) { if (Forbidden.Contains(alias)) { return(0); } if (Limited.Contains(alias)) { return(1); } if (SemiLimited.Contains(alias)) { return(2); } return(3); }
/// <summary> /// Returns true if and only if this client is considered authenticated. This is a necessary precondition for /// being included in a context. If false, a NotAuthorized result object is returned in the out parameter, that /// can be returned to the client. /// </summary> /// <param name="uri">The URI of the request</param> /// <param name="headers">The headers of the request</param> /// <param name="error">The error result, if not authenticated</param> /// <returns></returns> public bool TryAuthenticate(ref string uri, Headers headers, out Forbidden error) { error = null; AccessRights = Authenticator.GetAccessRights(ref uri, headers); if (!RESTarConfig.RequireApiKey) { AccessRights = AccessRights.Root; } if (AccessRights == null) { error = new NotAuthorized(); if (headers.Metadata == "full") { error.Headers.Metadata = error.Metadata; } return(false); } return(true); }
public void Add(Spell spell) { switch (spell.type) { case Spell.Type.Beam: Beam b = spell as Beam; beamSpells.Add(b); break; case Spell.Type.Enhancement: Enhancement e = spell as Enhancement; enhancementSpells.Add(e); break; case Spell.Type.Forbidden: Forbidden f = spell as Forbidden; forbiddenSpells.Add(f); break; case Spell.Type.Projectile: Projectile p = spell as Projectile; projectileSpells.Add(p); break; case Spell.Type.Ring: Ring r = spell as Ring; ringSpells.Add(r); break; case Spell.Type.Utility: Utility u = spell as Utility; utilitySpells.Add(u); break; case Spell.Type.Wall: Wall w = spell as Wall; wallSpells.Add(w); break; } CompileSpells(); }
public void Add(uint cardId, int qualification) { switch (qualification) { case 0: Forbidden.Add(cardId); break; case 1: Limited.Add(cardId); break; case 2: SemiLimited.Add(cardId); break; default: return; } uint code = cardId; Hash = Hash ^ ((code << 18) | (code >> 14)) ^ ((code << (27 + qualification)) | (code >> (5 - qualification))); }
public async Task <IActionResult> PutAsync([FromBody] ClientApi data) { if (data == null) { _loger.LogError("Bad request parameter"); var error = new BadRequest("Parameter is null", new { data }); return(error.ReturnResponse()); } var id = await _service.PutAsync(data); if (id == null) { _loger.LogError("Duplicate data for client id : " + data.ClientId); var error = new Forbidden("Duplicate data for client id : " + data.ClientId, new { data }); return(error.ReturnResponse()); } var result = new OK("Success update data", new { id }); return(result.ReturnResponse()); }
public async Task <IActionResult> PostAsync([FromBody] Tasks data) { if (data == null) { _loger.LogError("Bad request parameter"); var error = new BadRequest("Parameter is null", new { data }); return(error.ReturnResponse()); } var id = await _service.PostAsync(data); if (id == null) { _loger.LogError("Duplicate data for Name : " + data.Name); var error = new Forbidden("Duplicate data for Name : " + data.Name, new { data }); return(error.ReturnResponse()); } var result = new OK("Success add data", new { id }); return(result.ReturnResponse()); }
private void Delete(object sender, RoutedEventArgs e) { Forbidden.Remove((string)List.SelectedItem); }
public override void Configure(IApplicationBuilder app) { // Global error handler for API app.UseWhen(http => http.Request.Path.StartsWithSegments("/api"), appApi => { var routeController = new RouteController(appApi.ApplicationServices); // Native error appApi.UseExceptionHandler(appB => { appB.Run(async http => { var exf = http.Features.Get <IExceptionHandlerFeature>(); System.Exception error = (exf != null) ? exf.Error : new ErrorException(); http.Response.ContentType = "application/json"; http.Response.Headers.Add("x-api-standard", "1"); await http.Response.WriteAsync( JsonConvert.SerializeObject( routeController.WrapError(error, error.Message) ) ); // Will log on file on production and console on development }); }); // Custom error appApi.UseStatusCodePages(async context => { context.HttpContext.Response.ContentType = "application/json"; Error error; switch (context.HttpContext.Response.StatusCode) { case 401: error = new Unauthorized(); break; case 404: error = new RouteNotFound(); break; case 403: error = new Forbidden(); break; default: error = new Error(); break; } context.HttpContext.Response.Headers.Add("x-api-standard", "1"); await context.HttpContext.Response.WriteAsync( JsonConvert.SerializeObject( routeController.WrapError(error, null) ) ); }); // Use MVC appApi.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action=Index}/{id?}"); }); // At this point status code must be already set by MVC // If not, respond with 404 Not Found appApi.Use(async(context, next) => { context.Response.ContentType = "application/json"; await context.Response.WriteAsync( JsonConvert.SerializeObject( routeController.WrapError(new RouteNotFound(), null) ) ); }); }); }