/// <summary> /// Metodo extraer un equipaje de la tabla retornada por las consultas a la base de datos ejecutadas por el PgConnection /// </summary> /// <param name="row">fila a extraer</param> private Claim ExtractClaimFromRow(DataRow row) { var id = Convert.ToInt32(row[0]); var title = row[1].ToString(); var description = row[2].ToString(); var status = row[3].ToString(); var baggageId = Convert.ToInt32(row[4]); // TODO: Pila con esta condicion que tenian antes // Claim claim; // if (table.Columns.Count == 4) // { // claim = new Claim(id, titulo, descripcion, status); // } // else // { // var idEquipaje = Convert.ToInt32(table.Rows[i][4].ToString()); // claim = new Claim(id, titulo, descripcion, status, idEquipaje); // } return(ClaimBuilder.Create() .WithId(id) .WithTitle(title) .WithStatus(status) .WithDescription(description) .WithBagagge(baggageId) .Build()); }
protected internal virtual bool TryGetSpecialSourceClaim(ClaimsPrincipal principal, string source, out IClaimBuilder claim) { if(principal == null) throw new ArgumentNullException(nameof(principal)); claim = null; // ReSharper disable InvertIf if(!string.IsNullOrWhiteSpace(source) && source.StartsWith(this.PrincipalIdentitySourcePrefix, StringComparison.OrdinalIgnoreCase)) { if(source.Equals(this.PrincipalIdentityAuthenticationTypeSource, StringComparison.OrdinalIgnoreCase)) { claim = new ClaimBuilder { Type = source, Value = principal.Identity.AuthenticationType }; var firstPrincipalClaim = principal.Claims?.FirstOrDefault(); claim.Issuer = firstPrincipalClaim?.Issuer; claim.OriginalIssuer = firstPrincipalClaim?.OriginalIssuer; } else { this.Logger.LogDebugIfEnabled($"Could not get special source-claim for source {this.ValueAsFormatArgument(source)}."); } return true; } // ReSharper restore InvertIf return false; }
public override async Task DecorateAsync(AuthenticateResult authenticateResult, string authenticationScheme, IClaimBuilderCollection claims, AuthenticationProperties properties) { if(authenticateResult == null) throw new ArgumentNullException(nameof(authenticateResult)); if(authenticateResult.Principal == null) throw new ArgumentException("The principal-property of the authenticate-result can not be null.", nameof(authenticateResult)); if(claims == null) throw new ArgumentNullException(nameof(claims)); foreach(var mapping in this.ClaimInclusionsMap.Values) { if(!this.TryGetSpecialSourceClaim(authenticateResult.Principal, mapping.Source, out var claim)) { var sourceClaim = this.GetSourceClaim(authenticateResult.Principal, mapping.Source); if(sourceClaim != null) claim = new ClaimBuilder(sourceClaim); } if(claim == null) continue; if(mapping.Destination != null) claim.Type = mapping.Destination; claims.Add(claim); } await base.DecorateAsync(authenticateResult, authenticationScheme, claims, properties).ConfigureAwait(false); }
public Claim CreateEntity(ClaimDto dto) { return(ClaimBuilder.Create() .WithTitle(dto.Title) .WithDescription(dto.Description) .WithBagagge(dto.BaggageId) .WithStatus(dto.Status) .WithId(dto.Id) .Build()); }
public virtual async Task DecorateAsync(AuthenticateResult authenticateResult, string authenticationScheme, IClaimBuilderCollection claims, AuthenticationProperties properties) { try { if (authenticateResult == null) { throw new ArgumentNullException(nameof(authenticateResult)); } if (claims == null) { throw new ArgumentNullException(nameof(claims)); } if (!this.IsActiveLoginAuthenticationScheme(authenticationScheme)) { return; } var identityProviderClaim = claims.FindFirstIdentityProviderClaim(); if (identityProviderClaim == null) { identityProviderClaim = new ClaimBuilder { Type = ExtendedClaimTypes.IdentityProvider, }; claims.Add(identityProviderClaim); } identityProviderClaim.Issuer = identityProviderClaim.OriginalIssuer = null; identityProviderClaim.Value = this.IdentityProvider; var originalIdentityProviderClaim = authenticateResult.Principal.Claims.FindFirstIdentityProviderClaim(); if (originalIdentityProviderClaim != null) { claims.Add(new ClaimBuilder(originalIdentityProviderClaim) { Type = this.OriginalIdentityProviderClaimType }); } await Task.CompletedTask.ConfigureAwait(false); } catch (Exception exception) { const string message = "Could not decorate active-login-callback."; this.Logger.LogErrorIfEnabled(exception, message); throw new InvalidOperationException(message, exception); } }
public void SetUp() { _claim = _claim = ClaimBuilder.Create() .WithStatus("ABIERTO") .WithDescription("Bolso negro extraviado en el areopuerto de maiquetia") .WithTitle("Bolso extraviado") .WithBagagge(6) .Build(); _user = new User(0, 26350800, "Angel", "Rivero", "*****@*****.**", "assadasad"); _addedClaimList = new List <int>(); _claimDao = (PostgresClaimDao)DAOFactory.GetFactory(DAOFactory.Type.Postgres).GetClaimDao(); }
public static void SetClaims(this BaseController controller, Action <ClaimBuilder> action) { var builder = new ClaimBuilder(); action(builder); controller.ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() { User = new ClaimsPrincipal(new ClaimsIdentity(builder.GetClaims())) } }; }
public void Setup() { _postgresClaimDao = new PostgresClaimDao(); _claimController = new ClaimController(null); _insertedClaims = new List <int>(); var claim = ClaimBuilder.Create() .WithStatus("ABIERTO") .WithDescription("Bolso negro extraviado en el areopuerto de maiquetia") .WithTitle("Bolso extraviado") .WithBagagge(6) .Build(); _claimMapper = MapperFactory.CreateClaimMapper(); _claimDto = _claimMapper.CreateDTO(claim); }
public void UpdateClaimTest() { var id = _claimDao.Add(_claim); _addedClaimList.Add(id); var toUpdateClaim = ClaimBuilder.Create() .WithStatus("CERRADO") .WithDescription("Bolso actualizado descripcion") .WithTitle("Bolso actualizado") .WithBagagge(6) .Build(); _claimDao.Update(id, toUpdateClaim); var updatedClaim = _claimDao.GetById(id); Assert.AreEqual(toUpdateClaim.Title, updatedClaim.Title); }
public void Test() { var claimBuilder = new ClaimBuilder { Type = "type", Value = "value" }; claimBuilder.Properties.Add("First", "First value"); claimBuilder.Properties.Add("Second", "Second value"); claimBuilder.Properties.Add("Third", "Third value"); var claim = claimBuilder.Build(); Assert.IsNotNull(claim); Assert.AreEqual(ClaimsIdentity.DefaultIssuer, claim.Issuer); Assert.AreEqual(ClaimsIdentity.DefaultIssuer, claim.OriginalIssuer); Assert.AreEqual("type", claim.Type); Assert.AreEqual("value", claim.Value); Assert.AreEqual(ClaimValueTypes.String, claim.ValueType); Assert.AreEqual(3, claim.Properties.Count); }
protected internal override bool TryGetSpecialSourceClaim(ClaimsPrincipal principal, string source, out IClaimBuilder claim) { if (principal == null) { throw new ArgumentNullException(nameof(principal)); } if (base.TryGetSpecialSourceClaim(principal, source, out claim)) { return(true); } // ReSharper disable InvertIf if (!string.IsNullOrWhiteSpace(source) && source.StartsWith(this.ActiveDirectorySourcePrefix, StringComparison.OrdinalIgnoreCase)) { var attributes = new List <string>(); if (!this.ActiveDirectoryIntegration) { this.Logger.LogWarningIfEnabled($"Could not get special source-claim for source {this.ValueAsFormatArgument(source)}. Active-Directory integration is not enabled."); } else if (source.Equals(this.ActiveDirectoryEmailSource, StringComparison.OrdinalIgnoreCase)) { attributes.Add(this.ActiveDirectoryEmailAttributeName); } else if (source.Equals(this.ActiveDirectoryUserPrincipalNameSource, StringComparison.OrdinalIgnoreCase)) { attributes.Add(this.ActiveDirectoryUserPrincipalNameAttributeName); } else { this.Logger.LogDebugIfEnabled($"Could not get special source-claim for source {this.ValueAsFormatArgument(source)}."); } if (attributes.Any()) { try { var result = this.ActiveDirectory.GetAttributesAsync(attributes, this.IdentifierKind, principal).Result; if (result.Any()) { claim = new ClaimBuilder { Type = source, Value = result.First().Value }; claim.Issuer = claim.OriginalIssuer = this.ActiveDirectoryClaimIssuer; } else { this.Logger.LogWarningIfEnabled($"Could not get special source-claim for source {this.ValueAsFormatArgument(source)}. No items were returned for attributes \"{string.Join(", ", attributes)}\"."); } } catch (Exception exception) { this.Logger.LogErrorIfEnabled(exception, $"Could not get special source-claim for source {this.ValueAsFormatArgument(source)}."); } } return(true); } // ReSharper restore InvertIf return(false); }