internal bool IsAuthorized(Oid userId, Oid entityId, EAuthorizations authorizations) { var isAuthorized = Context.Authorizations.Values.Any(a => ((a.UserId == userId) && (a.EntityId == entityId) && ((a.Authorizations & authorizations) == authorizations))); return(isAuthorized); }
//---------------------------------------------------------------------------------------------- internal Authorization AddAuthorization(Oid userId, Oid entityId, EAuthorizations authorizations) { var authorization = new Authorization(userId, entityId, authorizations); Context.Authorizations.Add(authorization.UserId, authorization); return(authorization); }
//---------------------------------------------------------------------------------------------- public bool AssertIsUserAuthorized(string username, Oid entityId, EAuthorizations authorizations) { var user = GetUserByUsername(username); if (!(user.IsAdmin || IsAuthorized(user.Id, entityId, authorizations))) { throw new AuthorizationException($"User '{user.Username}' is not authorized for this operation."); } return(true); }
public Authorization(Oid userId, Oid entityId, EAuthorizations authorizations) { UserId = userId; EntityId = entityId; Authorizations = authorizations; }