src/Sulu/Component/Security/Authorization/AccessControl/SecuredEntityRepositoryTrait.php
protected function addAccessControl(
        QueryBuilder $queryBuilder,
        UserInterface $user,
        $permission,
        $entityClass,
        $entityAlias
    ) {
        $queryBuilder->leftJoin(
            AccessControl::class,
            'accessControl',
            'WITH',
            'accessControl.entityClass = :entityClass AND accessControl.entityId = ' . $entityAlias . '.id'
        );
        $queryBuilder->leftJoin('accessControl.role', 'role');
        $queryBuilder->andWhere(
            'BIT_AND(accessControl.permissions, :permission) = :permission OR accessControl.permissions IS NULL'
        );

        $roleIds = [];
        foreach ($user->getRoleObjects() as $role) {
            $roleIds[] = $role->getId();
        }

        $queryBuilder->andWhere('role.id IN(:roleIds) OR role.id IS NULL');
        $queryBuilder->setParameter('roleIds', $roleIds);
        $queryBuilder->setParameter('entityClass', $entityClass);
        $queryBuilder->setParameter('permission', $permission);
    }
protected function addAccessControl(
        QueryBuilder $queryBuilder,
        UserInterface $user,
        $permission,
        $entityClass,
        $entityAlias
    ) {
        $queryBuilder->leftJoin(
            AccessControl::class,
            'accessControl',
            'WITH',
            'accessControl.entityClass = :entityClass AND accessControl.entityId = ' . $entityAlias . '.id'
        );
        $queryBuilder->leftJoin('accessControl.role', 'role');
        $queryBuilder->andWhere(
            'BIT_AND(accessControl.permissions, :permission) = :permission OR accessControl.permissions IS NULL'
        );

        $roleIds = [];
        foreach ($user->getRoleObjects() as $role) {
            $roleIds[] = $role->getId();
        }

        $queryBuilder->andWhere('role.id IN(:roleIds) OR role.id IS NULL');
        $queryBuilder->setParameter('roleIds', $roleIds);
        $queryBuilder->setParameter('entityClass', $entityClass);
        $queryBuilder->setParameter('permission', $permission);
    }
protected function addAccessControl ( QueryBuilder $ queryBuilder , UserInterface $ user , $ permission , $ entityClass , $ entityAlias ) { $ queryBuilder -> leftJoin ( AccessControl :: class , 'accessControl' , 'WITH' , 'accessControl.entityClass = :entityClass AND accessControl.entityId = ' . $ entityAlias . '.id' ) ; $ queryBuilder -> leftJoin ( 'accessControl.role' , 'role' ) ; $ queryBuilder -> andWhere ( 'BIT_AND(accessControl.permissions, :permission) = :permission OR accessControl.permissions IS NULL' ) ; $ roleIds = [ ] ; foreach ( $ user -> getRoleObjects ( ) as $ role ) { $ roleIds [ ] = $ role -> getId ( ) ; } $ queryBuilder -> andWhere ( 'role.id IN(:roleIds) OR role.id IS NULL' ) ; $ queryBuilder -> setParameter ( 'roleIds' , $ roleIds ) ; $ queryBuilder -> setParameter ( 'entityClass' , $ entityClass ) ; $ queryBuilder -> setParameter ( 'permission' , $ permission ) ; }
Adds joins and conditions to the QueryBuilder in order to only return entities the given user is allowed to see.

@param QueryBuilder $queryBuilder The instance of the QueryBuilder to adjust
@param UserInterface $user The user for which the access control is checked
@param int $permission The permission mask for which is checked
@param string $entityClass The class of the entity of which the access control is checked
@param string $entityAlias The alias of the entity used in the query builder
Adds joins and conditions to the QueryBuilder in order to only return entities the given user is allowed to see .