ecphp / cas-bundle

CAS Bundle, a standard Symfony bundle for authentication using CAS protocol.
https://ecphp-cas-bundle.readthedocs.io
BSD 3-Clause "New" or "Revised" License
43 stars 9 forks source link

How to load custom / existing User entities instead of CasUser ? #56

Closed luminouw closed 2 years ago

luminouw commented 3 years ago

Hello,

I am adding the bundle to an existing project (Symfony 5.3) with existing users based on the default Symfony user entities.

So far I am able to protect the pages I want with a CAS auth, being redirected to the CAS server and then back to my app with the security token validated. In the Symfony profiler toolbar I can see the user I used on the CAS server as authenticated with the role "ROLE_CAS_AUTHENTICATED".

However my app then fails because I'm using methods to get user preferences ($this->getUser()->getPrefs();) which obviously aren't implemented in the CasUser class (Attempted to call an undefined method named "getTexts" of class "EcPhp\CasBundle\Security\Core\User\CasUser"). The current provider loads my users via their email attribute (and the CAS server I'll use will only return the email when auth is successful).

Is there any way to specify which User entity to load when authentication is ok ? And can it be done with some configuration options or do I need to write a couple of specific files (providers etc ...)

Thank you and thanks for your work : )

drupol commented 2 years ago

Hi,

Sorry for the delay in my response, I just see this message right now. For some reason I most probably skipped it by error.

I understand your "issue" which is not a real one. We enforce this pattern in the design of the bundle. If you wish to customize the user which is returned by the bundle, then you must create your own UserProvider and decorate the original one.

I just replied to someone else here: https://github.com/ecphp/eu-login-api-authentication-bundle/issues/14 and this is basically the same issue.

Let me know if this is helping and if the issue can now be closed.

Thanks and good luck.

luminouw commented 2 years ago

Hello,

We finally ended up rewriting a very basic authenticator with the help of your cas-lib but without the use of Guard as we moved the projet to Symfony 5.4 and this has been marked as deprecated for future Symfony releases.

Should have closed this earlier, my bad as well : )

drupol commented 2 years ago

Ok ! Sorry again for the delay and glad you found out a solution in the end.

I'm currently working on an updated version of cas-bundle for symfony >= 5.4 as well.