Exemplo n.º 1
0
        public async Task <User> GetOrAddUserWithBedrockUser(IBedrockUser bedrockUser)
        {
            if (bedrockUser.GlobalKey == Guid.Empty)
            {
                return(default(User));
            }

            var returnValue = await Context
                              .Users
                              .AsNoTracking()
                              .FirstOrDefaultAsync(u => u.GlobalKey == bedrockUser.GlobalKey);

            if (returnValue == null)
            {
                returnValue = new User
                {
                    Username  = bedrockUser.Emails?.FirstOrDefault(),
                    GlobalKey = bedrockUser.GlobalKey
                };

                Context.Users.Add(returnValue);
            }

            return(returnValue);
        }
Exemplo n.º 2
0
        public static void SetRowAuditDataEntityDeletable(EntityEntry entry, IBedrockUser user, DateTime currentDateTime)
        {
            var deletableEntity = entry.Entity as IBedrockDeletableEntity;

            if (deletableEntity != null && deletableEntity.IsDeleted)
            {
                deletableEntity.DeletedBy   = user.UserId;
                deletableEntity.DeletedDate = currentDateTime;
            }
        }
        protected virtual async Task PostAuthenticate(HttpContext context)
        {
            var claimsPrincipal = context.User.Transform(_options.ClaimType);

            BedrockUser = SecurityModel.BedrockUser.CreateFromPrincipal(claimsPrincipal, _options.ClaimType);

            var bedrockIdentity  = new BedrockIdentity(BedrockUser, (ClaimsIdentity)context.User.Identity);
            var bedrockPrincipal = new BedrockPrincipal(BedrockUser, bedrockIdentity);

            bedrockPrincipal.AddIdentity(bedrockIdentity);

            context.User            = bedrockPrincipal;
            Thread.CurrentPrincipal = bedrockPrincipal;
        }
        public override Task TokenValidated(TokenValidatedContext context)
        {
            ClaimsPrincipal = context.Principal.Transform(ClaimType);
            BedrockUser     = SecurityModel.BedrockUser.CreateFromPrincipal(ClaimsPrincipal, ClaimType);

            var bedrockIdentity  = new BedrockIdentity(BedrockUser);
            var bedrockPrincipal = new BedrockPrincipal(BedrockUser, bedrockIdentity);

            bedrockIdentity.AddClaims(ClaimsPrincipal.Claims);
            bedrockPrincipal.AddIdentity(bedrockIdentity);

            context.Principal       = bedrockPrincipal;
            Thread.CurrentPrincipal = bedrockPrincipal;
            ClaimsPrincipal         = bedrockPrincipal;

            return(base.TokenValidated(context));
        }
Exemplo n.º 5
0
        public static void SetRowAuditDataEntity(EntityEntry entry, IBedrockUser user, DateTime currentDateTime)
        {
            var auditableEntity = entry.Entity as IBedrockAuditEntity;

            if (auditableEntity != null)
            {
                if (entry.State == EntityState.Added)
                {
                    auditableEntity.CreatedBy   = user.UserId;
                    auditableEntity.CreatedDate = currentDateTime;

                    auditableEntity.UpdatedBy   = user.UserId;
                    auditableEntity.UpdatedDate = currentDateTime;
                }
                else if (entry.State == EntityState.Modified)
                {
                    auditableEntity.UpdatedBy   = user.UserId;
                    auditableEntity.UpdatedDate = currentDateTime;
                }
            }
        }
Exemplo n.º 6
0
 public BedrockIdentity(IBedrockUser user, ClaimsIdentity claimsIdentity) : this(user.DisplayName, claimsIdentity)
 {
 }
Exemplo n.º 7
0
 public BedrockIdentity(IBedrockUser user) : this(user.DisplayName)
 {
 }
Exemplo n.º 8
0
        protected void SetRowAuditDataEntitiesDeletable(IEnumerable <EntityEntry> changedEntries, IBedrockUser user, DateTime currentDateTime)
        {
            if (!BedrockConfiguration.Data.AutoSaveAuditFields)
            {
                return;
            }

            changedEntries.Each(e => EntityHelper.SetRowAuditDataEntityDeletable(e, user, currentDateTime));
        }
Exemplo n.º 9
0
 public void SetUser(IBedrockUser user, ClaimsPrincipal principal)
 {
     User      = user ?? throw new ArgumentNullException(nameof(user));
     Principal = principal;
 }
Exemplo n.º 10
0
 public void SetUser(IBedrockUser user)
 {
     User      = user ?? throw new ArgumentNullException(nameof(user));
     Principal = new BedrockPrincipal(User, new BedrockIdentity(User));
 }
Exemplo n.º 11
0
 public BedrockPrincipal(IBedrockUser bedrockUser, BedrockIdentity identity)
 {
     BedrockUser = bedrockUser;
     _identity   = identity;
 }