This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » eZ Publish 5 Platform » access_control and siteaccess
expandshrink

access_control and siteaccess

access_control and siteaccess

Monday 06 January 2014 10:07:51 am - 6 replies

Hi,

I would like to secure one of my siteAccess by redirect to user/login if user is not logged.
I've tried differents things but without success.
Thanks in advance.

Monday 06 January 2014 11:07:55 am

You could use the pre content view listener and redirect the user to that url if he is not authenticated.

http://partialcontent.com/code/working-with-ez-publish-5-listeners

 

Or even the event on kernel request, like I used to set the locale:

http://share.ez.no/blogs/thiago-campos-viana/ez-publish-5-symfony-2-siteaccess-locale-support

Modified on Monday 06 January 2014 12:08:36 pm by Thiago Campos Viana

Wednesday 08 January 2014 10:10:40 am

Hi,

When i used kernelRequest event, i have this error :

The value '' that you were trying to assign to parameter 'dbParams' is invalid. Allowed values are: string or array.

500 Internal Server Error - ezcBaseValueExceptionI don't understand why ?Can you help me ?Thanks in advance.

Wednesday 08 January 2014 10:26:06 am

Quote from David Le Riche :

Hi,

When i used kernelRequest event, i have this error :

The value '' that you were trying to assign to parameter 'dbParams' is invalid. Allowed values are: string or array.

500 Internal Server Error - ezcBaseValueExceptionI don't understand why ?Can you help me ?Thanks in advance.

Hi,

Last time i've got this error i was trying to access @ezpublish.api.repository? Do you use it on your kernelRequest event ?

Wednesday 08 January 2014 11:56:58 am

Yes,

I use it, i need it to get the currentUser.

Wednesday 08 January 2014 12:28:33 pm

Ok so in fact when you call @ezpublish.api.repository, the siteaccess is not instantiate (and the database params too).

You have to you use @ezpublish.api.repository.lazy, so the repository will be called later in the code ans the siteacces params will be available.

Here the way i manage it :

 
 
 In my service :
arguments: [@ezpublish.api.repository.lazy]
 
    public function __construct( \Closure $lazyRepository )
    {
        $this->lazyRepository = $lazyRepository;
    }
 
    protected function getRepository()
    {
        $lazyRepository = $this->lazyRepository;
        return $lazyRepository();
    }

So when you call $this->getRepository()->getCurrentUser()->id it should work

Wednesday 08 January 2014 3:50:46 pm

it works.
Thanks a lot

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from