public void SetPassword(ResetUserPasswordViewModel model, ClaimsPrincipal ctx)
        {
            AuthenticablePrincipal principal = this.GetUser(model.Id);

            authorizationLogic.IsAuthorizedThrowsException(AuthorizationScopes.ManageUsers, ctx, principal, EventCategory.UserManagementResetPassword);

            principal.PasswordHash = BCrypt.Net.BCrypt.HashPassword(model.NewPassword);

            configurationRepository.Update <AuthenticablePrincipal>(principal);
        }
        public void UpdateIdp(OidcIdentityProvider idp, ClaimsPrincipal user)
        {
            if (idp == null)
            {
                throw new Exception("Identity provider was not provided.");
            }

            authorizationLogic.IsAuthorizedThrowsException(AuthorizationScopes.ManageIdentityProviders, user, idp);

            if (!configurationRepository.Exists <OidcIdentityProvider>(idp.Id))
            {
                throw new Exception("Identity provider does not exist");
            }

            configurationRepository.Update <OidcIdentityProvider>(idp);
        }
        public AccessControlEntry AddCertificateAce(Guid certId, AddCertificateAceEntity entity, ClaimsPrincipal user)
        {
            Certificate cert = certificateRepository.Get <Certificate>(certId);

            authorizationLogic.IsAuthorizedThrowsException(AuthorizationScopes.CertificateFullControl, user, cert);

            if (cert.Acl == null)
            {
                cert.Acl = new List <AccessControlEntry>();
            }

            AccessControlEntry ace = new AccessControlEntry(entity);

            cert.Acl.Add(ace);

            certificateRepository.Update <Certificate>(cert);

            ace.IdentityDisplayName = securityPrincipalLogic.ResolveSecurityPrincipalDisplayName(ace.Identity);
            ace.Identity            = string.Empty;
            return(ace);
        }
        public SecurityRole AddRole(SecurityRole entity, ClaimsPrincipal user)
        {
            entity.Id = Guid.NewGuid();

            authorizationLogic.IsAuthorizedThrowsException(AuthorizationScopes.ManageRoles, user, entity, EventCategory.RoleManagementNew);

            configurationRepository.Insert <SecurityRole>(entity);
            return(entity);
        }