Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parametrize CallbackLogic in CallbackController #243

Closed
unkarjedy opened this issue Sep 7, 2018 · 4 comments
Closed

parametrize CallbackLogic in CallbackController #243

unkarjedy opened this issue Sep 7, 2018 · 4 comments

Comments

@unkarjedy
Copy link
Contributor

For some reason org.pac4j.play.CallbackController has a hardcoded CallbackLogic:

private CallbackLogic<Result, PlayWebContext> callbackLogic = new DefaultCallbackLogic<>();

Callback logic can be set in org.pac4j.core.config.Config:

public void setCallbackLogic(final CallbackLogic callbackLogic)

but it is not used.

It would be great to be able to parametrize the callbackLogic, parhaps to read it from config after it is injected.

@unkarjedy
Copy link
Contributor Author

unkarjedy commented Sep 7, 2018

probably related to #242 because config is injected

@leleuj
Copy link
Member

leleuj commented Sep 11, 2018

Generally, you only have one CallbackController and thus one CallbackLogic. This is a bit strange to be able to set the CallbackLogic at the Config logic, I honestly don't remember the reason behind this design.
Do you really have a use case for that?

@unkarjedy
Copy link
Contributor Author

@leleuj The only reason we have only one CallbackController is just that it delegates the real work to CallbackLogic. There is no need for extra abstraction interface CallbackLogic while we do not allow user to change it. The main purpose of Strategy Pattern is to be able to change the logic at a runtime.

In my current prod project, I've created a custom MyCallbackLogic extends DefaultCallbackLogic[Result, PlayWebContext] that a bit modifies redirectToOriginallyRequestedUrl (to support redirection to SinglePageApplications that are deployed on a separate domain). And just because CallbackController has a hardcoded logic I had to create my custom MyCallbackController. So I create 2 classes instead of 1. More of that I have to extend Java-based play.mvc.Controller in my Scala code just because PlayWebContext requires Java-based play.mvc.Context

Actually the same logic for LogoutController and DefaultLogoutLogic

If you agree that we should be able to change the default logic I could prepare a pull-request.

@leleuj
Copy link
Member

leleuj commented Sep 12, 2018

Yes, sure, we should be able to plug in a new CallbackLogic without creating a new CallbackController class.
Please submit a PR, this must be backward compatible as it will target the version 6.1.0.

unkarjedy pushed a commit to unkarjedy/play-pac4j that referenced this issue Sep 13, 2018
leleuj added a commit that referenced this issue Sep 13, 2018
#243 Parametrize CallbackLogic and LogoutLogic for CallbackController and LogoutController respectively
@leleuj leleuj closed this as completed Sep 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants