public IEnumerable <AuthorizationResult> Authorize(DeleteUtenteCommand command) { var username = currentUser.Identity.Name; var userOperatore = _findUserByUsername.FindUserByUs(username); var CFuser = command.CodFiscale; var utenteDelete = _findUserByCF.Get(CFuser); if (currentUser.Identity.IsAuthenticated) { if (userOperatore == null) { yield return(new AuthorizationResult(Costanti.UtenteNonAutorizzato)); } else { foreach (var ruolo in userOperatore.Ruoli) { if (!_getAutorizzazioni.GetAutorizzazioniUtente(userOperatore.Ruoli, utenteDelete.Sede.Codice, Costanti.Amministratore)) { yield return(new AuthorizationResult(Costanti.UtenteNonAutorizzato)); } } } } else { yield return(new AuthorizationResult(Costanti.UtenteNonAutorizzato)); } }
public async Task Notify(AddRuoliUtenteCommand command) { var utente = _getUtenteByCF.Get(command.CodFiscale); await _notificationHubContext.Clients.Group(utente.Sede.Codice).SendAsync("NotifyRefreshUtenti", true).ConfigureAwait(false); await _notificationHubContext.Clients.Group(utente.Sede.Codice).SendAsync("NotifyModificatoRuoloUtente", utente).ConfigureAwait(false); }
public async Task Notify(AddUtenteCommand command) { var utente = _getUtenteByCF.Get(command.CodFiscale); await _notificationHubContext.Clients.Group(command.CodiceSede).SendAsync("NotifyRefreshUtenti", true); await _notificationHubContext.Clients.Group(utente.Sede.Codice).SendAsync("NotifyRefreshUtenti", true); }
public void Delete(string codiceFiscale, Role ruolo) { var utente = _getUtenteByCF.Get(codiceFiscale); ///Se un utente ha solamente un ruolo associato, cancello direttamente l'utente dalla base dati if (utente.Ruoli.Count > 1) { var filter = Builders <Utente> .Filter.Eq(x => x.CodiceFiscale, codiceFiscale); _dbcontext.UtenteCollection.UpdateOne(filter, Builders <Utente> .Update.Pull(x => x.Ruoli, ruolo)); } else { _dbcontext.UtenteCollection.DeleteOne(x => x.CodiceFiscale.Equals(codiceFiscale)); } }
/// <summary> /// metodo della classe /// </summary> /// <param name="command">il command con i parametri di ingresso</param> public void Handle(AddUtenteCommand command) { var utenteSO = _getUtenteByCF.Get(command.CodFiscale); var personale = _personaleByCF.Get(command.CodFiscale).Result; var listaPin = new List <PinNodo>(); var sediAlberate = _getAlberaturaUnitaOperative.ListaSediAlberata(); var distaccamento = _getDistaccamentoByCodiceSede.Get(personale.CodSede).Result; foreach (var ruolo in command.Ruoli) { listaPin.Add(new PinNodo(ruolo.CodSede, ruolo.Ricorsivo)); foreach (var figli in sediAlberate.GetSottoAlbero(listaPin)) { if (figli.Codice.Equals(ruolo.CodSede)) { ruolo.DescSede = figli.Nome; } } } if (_checkOmonimia.FindUserByUs(personale.Nominativo.Replace(" ", "").ToLower()) != null) { personale.Nominativo = personale.Nominativo.Replace(" ", "").ToLower() + "1"; } //Test di refresh chain var utenteVVF = new Utente(command.CodFiscale, personale.Nominativo.Split(".")[0], personale.Nominativo.Split(".")[1]) { Ruoli = command.Ruoli, Username = personale.Nominativo.Replace(" ", "").ToLower(), Password = "******", Sede = new Sede($"{distaccamento.CodSede}", distaccamento.DescDistaccamento, distaccamento.Indirizzo, distaccamento.Coordinate, "", "", "", "", "") }; if (utenteSO != null) { _addRuoli.Add(command.CodFiscale, command.Ruoli); } else { _addUtente.Add(utenteVVF); } }
public bool Check(List <Role> ruoliDaAggiungere, string codiceFiscaleUtenteDaControllare) { var utente = _getUtenteByCF.Get(codiceFiscaleUtenteDaControllare); if (utente != null) { var listaSediAlberate = _getListaUO.ListaSediAlberata(); List <Role> listaRuoliEsplosaPerRicorsivita = new List <Role>(); foreach (var ruolo in utente.Ruoli) { var listaPin = new List <PinNodo>(); PinNodo pin = new PinNodo(ruolo.CodSede, ruolo.Ricorsivo); listaPin.Add(pin); foreach (var unita in listaSediAlberate.GetSottoAlbero(listaPin)) { Role ruoloEsploso = new Role(ruolo.Descrizione, unita.Codice); listaRuoliEsplosaPerRicorsivita.Add(ruoloEsploso); } } var risultato = listaRuoliEsplosaPerRicorsivita.Where(o => ruoliDaAggiungere.Any(s => o.CodSede.Equals(s.CodSede) && o.Descrizione.Equals(s.Descrizione))).ToList(); if (risultato.Count > 0) { return(false); } else { return(true); } } else { return(true); } }
/// <summary> /// Query che estrae i valori dei Box presenti in Home Page /// </summary> /// <param name="query">Filtri utilizzati per l'estrazione</param> /// <returns>Elenco dei mezzi disponibili</returns> public CasLoginResult Handle(CasLoginQuery query) { var Cas = CheckCasTicket(query).Result; if (Cas.serviceResponse.AuthenticationFailure != null) { Log.Information($"Autenticazione Fallita = {Cas.serviceResponse.AuthenticationFailure.Description}"); return(new CasLoginResult() { User = null, ErrorMessage = Cas.serviceResponse.AuthenticationFailure.Description }); } if (Cas.serviceResponse.AuthenticationSuccess != null) { Log.Information($"sAMAccountName = {Cas.serviceResponse.AuthenticationSuccess.Attributes.sAMAccountName}"); string CodFiscale; if (Cas.serviceResponse.AuthenticationSuccess.Attributes.sAMAccountName != null) { CodFiscale = Cas.serviceResponse.AuthenticationSuccess.Attributes.sAMAccountName[0]; } else { CodFiscale = Cas.serviceResponse.AuthenticationSuccess.User; } var utente = _getUtenteByCF.Get(CodFiscale); if (utente == null) { return new CasLoginResult() { User = null, ErrorMessage = "Utente non abilitato. Contattare l'assistenza per l'abilitazione" } } ; Log.Information($"Utente loggato = {utente.Username}"); var claim = new[] { new Claim(ClaimTypes.NameIdentifier, utente.CodiceFiscale.ToString()), new Claim(ClaimTypes.Name, utente.Username) }; var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config.GetSection("AppSettings:Token").Value)); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha512Signature); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(claim), Expires = DateTime.UtcNow.AddDays(1), SigningCredentials = creds }; var tokenHandler = new JwtSecurityTokenHandler(); var token = tokenHandler.CreateToken(tokenDescriptor); utente.Token = tokenHandler.WriteToken(token); return(new CasLoginResult() { User = utente }); } else { var utente = _getUtenteByCF.Get(Cas.serviceResponse.AuthenticationSuccess.Id); if (utente == null) { return new CasLoginResult() { User = null, ErrorMessage = "Utente non abilitato. Contattare l'assistenza per l'abilitazione" } } ; var claim = new[] { new Claim(ClaimTypes.NameIdentifier, utente.CodiceFiscale.ToString()), new Claim(ClaimTypes.Name, utente.Username) }; var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config.GetSection("AppSettings:Token").Value)); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha512Signature); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(claim), Expires = DateTime.UtcNow.AddDays(1), SigningCredentials = creds }; var tokenHandler = new JwtSecurityTokenHandler(); var token = tokenHandler.CreateToken(tokenDescriptor); utente.Token = tokenHandler.WriteToken(token); return(new CasLoginResult() { User = utente }); } }
/// <summary> /// metodo che si occupa della gestione dell'eliminazione /// </summary> /// <param name="command">i parametri di ingresso</param> public void Handle(DeleteUtenteCommand command) { command.UtenteRimosso = _getUtenteByCF.Get(command.CodFiscale); _deleteUtente.Delete(command.CodFiscale); }
public async Task Notify(AddUtenteCommand command) { var utente = _getUtenteByCF.Get(command.CodFiscale); await _notificationHubContext.Clients.All.SendAsync("NotifyAddUtente", utente.Ruoli[0].CodSede); }