Exemple #1
0
 private AuthToken( ErpUser user, DateTime expirationDate)
 {
     UserId = user.Id;
     Email = user.Email;
     FirstName = user.FirstName;
     LastName = user.LastName;
     LastModified = user.ModifiedOn;
     ExpirationDate = expirationDate;
 }
        public static bool HasEntityPermission(EntityPermission permission, Entity entity, ErpUser user = null)
        {
            if (entity == null)
                throw new ArgumentNullException("entity");

            if (user == null)
                user = CurrentUser;

            if (user != null)
            {
                //system user has unlimited permissions :)
                if (user.Id == SystemIds.SystemUserId)
                    return true;

                switch (permission)
                {
                    case EntityPermission.Read:
                        return user.Roles.Any(x => entity.RecordPermissions.CanRead.Any(z => z == x.Id));
                    case EntityPermission.Create:
                        return user.Roles.Any(x => entity.RecordPermissions.CanCreate.Any(z => z == x.Id));
                    case EntityPermission.Update:
                        return user.Roles.Any(x => entity.RecordPermissions.CanUpdate.Any(z => z == x.Id));
                    case EntityPermission.Delete:
                        return user.Roles.Any(x => entity.RecordPermissions.CanDelete.Any(z => z == x.Id));
                    default:
                        throw new NotSupportedException("Entity permission type is not supported");
                }
            }
            else
            {
                switch (permission)
                {
                    case EntityPermission.Read:
                        return entity.RecordPermissions.CanRead.Any(z => z == SystemIds.GuestRoleId);
                    case EntityPermission.Create:
                        return entity.RecordPermissions.CanCreate.Any(z => z == SystemIds.GuestRoleId);
                    case EntityPermission.Update:
                        return entity.RecordPermissions.CanUpdate.Any(z => z == SystemIds.GuestRoleId);
                    case EntityPermission.Delete:
                        return entity.RecordPermissions.CanDelete.Any(z => z == SystemIds.GuestRoleId);
                    default:
                        throw new NotSupportedException("Entity permission type is not supported");
                }
            }
        }
Exemple #3
0
 public static AuthToken Create(ErpUser user, bool extendedExpiration)
 {
     return new AuthToken(user, DateTime.UtcNow.AddDays(extendedExpiration
                                                                ? WebSecurityUtil.AUTH_TOKEN_EXTENDED_EXPIRATION_DAYS
                                                                : WebSecurityUtil.AUTH_TOKEN_EXPIRATION_DAYS));
 }
        public static IDisposable OpenScope(ErpUser user)
        {
            if (current == null)
            {
                current = new AsyncLocal<SecurityContext>();
                current.Value = new SecurityContext();
            }
            if (current.Value == null)
                current.Value = new SecurityContext();

            current.Value.userStack.Push(user);
            return current.Value;
        }
 public static IDisposable OpenScope(ErpUser user)
 {
     Debug.WriteLine("SECURITY: OpenScope -> " + ( user != null ? user.Id.ToString() : "none" ) );
     GetStack().Push(user);
     return new Stopper();
 }