Exemplo n.º 1
0
		private PrincipalWithDatabaseAccess UpdateUserPrincipal(IHttpContext ctx, List<DatabaseAccess> databaseAccessLists)
		{
			var access = ctx.User as PrincipalWithDatabaseAccess;
			if (access != null)
				return access;

			var user = new PrincipalWithDatabaseAccess((WindowsPrincipal)ctx.User);

			foreach (var databaseAccess in databaseAccessLists)
			{
				if (databaseAccess.Admin)
					user.AdminDatabases.Add(databaseAccess.TenantId);
				else if (databaseAccess.ReadOnly)
					user.ReadOnlyDatabases.Add(databaseAccess.TenantId);
				else
					user.ReadWriteDatabases.Add(databaseAccess.TenantId);
			}

			ctx.User = user;
			return user;
		}
Exemplo n.º 2
0
        private PrincipalWithDatabaseAccess UpdateUserPrincipal(RavenBaseApiController controller, List<ResourceAccess> databaseAccessLists)
        {
            var access = controller.User as PrincipalWithDatabaseAccess;
            if (access != null)
                return access;

            var user = new PrincipalWithDatabaseAccess((WindowsPrincipal)controller.User);

            foreach (var databaseAccess in databaseAccessLists)
            {
                if (databaseAccess.Admin)
                    user.AdminDatabases.Add(databaseAccess.TenantId);
                else if (databaseAccess.ReadOnly)
                    user.ReadOnlyDatabases.Add(databaseAccess.TenantId);
                else
                    user.ReadWriteDatabases.Add(databaseAccess.TenantId);
            }

            controller.User = user;
            Thread.CurrentPrincipal = user;

            return user;
        }
		private PrincipalWithDatabaseAccess UpdateUserPrincipal(IHttpContext ctx, Dictionary<string, List<DatabaseAccess>> databaseAccessLists)
		{
			if (ctx.User is PrincipalWithDatabaseAccess)
				return (PrincipalWithDatabaseAccess) ctx.User;

			var user = new PrincipalWithDatabaseAccess((WindowsPrincipal) ctx.User);
			
			List<DatabaseAccess> list;
			if (databaseAccessLists.TryGetValue(ctx.User.Identity.Name, out list) == false)
			{
				ctx.User = user;
				user.ExplicitlyConfigured = false;
				return user;
			}
			user.ExplicitlyConfigured = true;

			foreach (var databaseAccess in list) 
			{
				if (databaseAccess.Admin)
					user.AdminDatabases.Add(databaseAccess.TenantId);
				else if (databaseAccess.ReadOnly)
					user.ReadOnlyDatabases.Add(databaseAccess.TenantId);
				else
					user.ReadWriteDatabases.Add(databaseAccess.TenantId);
			}

			ctx.User = user;
			return user;
		}