keycloak: Determine which RequiredAction was initially called in info.ftl - keycloak

I am using custom required actions in keycloak 16. Now at the end of the action processing the user sees the content of the info.ftl template. Is it possible to use different info.ftls depending on which action was performed or is there a way to find out which action(s) where executed from within the info.ftl template?

I helped myself by adding a cookie in the request an query this cookie in the info.ftl. Not very elegant, but it works for me.

Related

Why does keycloak set wrong execution of another required action?

Now we are about to use keycloak 14 (after 10.0.2).
And i found strange problem with 14 kc.
We have two custom required actions which have correct order on the page with required actions(in admin console). I add this actions to user. And after redirect to the first action i found that execution parameter in the uri was setted in wrong value(value for another required action). So links don't work correctly on the page because of it(got error page with loginTimeout message error).
Found place in kc code where execution parameter is setted
AuthenticationManager
On 1035 line in reqAction variable i have wrong required action name. I think this value have to be setted using required action priority. Is it bug? Or i do smth wrong?
On keycloak 10.0.2 i didn't find this problem.
Thank you for help.
this is probably already too late but I thought for any other people in the future its still nice to see one answer.
I had the exact same problem and I was able to solve it for me. I don't know if it will also work for you.
Apparently, there was one part in my own custom code where I add actionB and before actionA.
user.addRequiredAction("actionB"); //added first
user.addRequiredAction("actionA"); //added second
But in the rank (under Authentication > required Action in Keycloak) actionA is above actionB and therefore is shown first to the user.
However, it seems like the actions are saved in the order given by the code (makes sense) and the url the user is redirected after login does not take the rank into account and therefore the url is:
[website]/auth/realms/bpc/login-actions/required-action?execution=actionB[...]
which of course causes problems with the generated links in the form.
Once I changed the order in the code to reflect the actual ranking, everything worked perfectly.

JSON Request is not configure with zap Authentication.

I am using ZAP security testing tool.but at the point of Authentication by username and password of a JSON Request, I face problem to configure these. I checked all links and blogs too. but I can't get the proper step by step solution on it.
Request code:-
{"userName":"cwc_patna","password":"33a0d2e93e0ad396b7c9374bbbc83a58"}
Response code:-
{"userId":72,"userName":"cwc_patna","password":"33a0d2e93e0ad396b7c9374bbbc83a58","emilId":"pratyush#sdrc.co.in","userTypeId":1,"viewName":"cwc","isLive":null,"isActive":null,"isApproved":null,"sjpuAccess":null,"userUserTypeFeaturePermissionMapping":null,"area":null}
That functionality was only just added last week: https://github.com/zaproxy/zaproxy/pull/4624
If you want to use it, you'll either have to use a weekly: https://github.com/zaproxy/zaproxy/wiki/Downloads#zap-weekly
Or, wait for the next full release (likely 2.8.0).
The corresponding PR to update the help content for the new JSON Authentication functionality is here: https://github.com/zaproxy/zap-core-help/pull/188/files if you want to check it out.
You set it up the same way you would for form based authentication. Make sure you define a Logged-in or Logged-out Identifier (or both). Here's some screenshots to help you along:
Manually configure the Authentication for your Context:
Use the Site Tree Context menu(s) to set it up:
Here's an additional help link that might assist you in getting authentication setup: https://github.com/zaproxy/zaproxy/wiki/FAQformauth

Token is not getting a value when the form sent by email

I'm developing a basic recruitment-type website.
I have an "Apply" CustomForm attached with a contenttype("Job"), but I can't get access fields outside of the CustomForm widget. I'm trying to add the reference number or the url to the email within the workflow. Orchard shows {Content.Fields.Input-Reference} token, but it returns no value when used.
Should I overwrite the handler when the form is created or how can I access fields of other zones?
As far as I understand the question, you don't actually need to add a custom token to your module. Custom Forms module takes care of that for you and adds the tokens for fields itself. You just need to use them in the email module.
Just look for a tokens named like this:
Content.Fields.[FormContentTypeName].[FieldName]
Not that the tasks of adding custom tokens to the system and accessing them inside the workflow are particularly hard, mind you.

Redirecting requests form a catch-all controller in Zend Application without looping forever

There are plenty of related posts to what I'm asking, but after some lengthy searches couldn't quite find what I was looking for, my apologies if it exists somewhere.
My goal -- ALL requests to my Zend App must go through a preDispatch plugin, then pass to a custom Auth controller that will decide whether existing auth credentials are sufficient for the requested operation. 'Sufficient' depends on the logic of the app, hence why I want to do this at the controller+model level. If they suffice, they send the original request along to the specified controller+action, if not they default to a 'get lost' action.
At present I'm using an auth custom plugin set in the preDispatch to simply check for POST'ed auth credentials (if we are logging in), then in all cases the plugin stores the original request and redirects everyone (auth'd or not) to my auth controller, a-la:
$request->setModuleName('default')
->setControllerName('auth')
->setActionName('check')
->setParam('oreq',$request->getParams());
My problem/question is that within my auth->check action, how should I perform the redirect after a decision is made? If I use:
$this->_helper->redirector($or['action'], $oreq['controller']);
then I obviously get an infinite loop as these requests pass through the preDispatch plugin again. Sure I could pass something with the redirect so that the Auth plugin ignores such requests, but this is clearly a security hole. I had thought about maybe generating and storing an md5 hash, storing it to session and passing that as an escape param, but that seems a little sketchy.
Any better ideas out there? Perhaps a redirect method that does not go through the standard predispatch routine in Zend App? Thanks in advance!
This is not how it is done usually in Zend Framework. Not all requests go to a common place and gets redirected to the original requested place authentication.
For access control, use Zend_Acl. Through that, you could easily determine whether the current user has the necessary auth to access the content, else redirect to 'get lost' action.
If you are still adamant on using your technique, use _forward method instead of redirect method.
Since _forward is an internal redirect, you could pass additional arguments and check that in preDispath to avoid a loop.
$this->_forward($action, $controller, $module, $params)

How is ACL implemented

i am using Zend_Acl, PHP and is wondering how shld ACLs be implemented.
shld every page be a resource and i always query the acl to see if a user is authorized? i guess i must use this if i want to use a controller plugin (can be setup to run on every request) to check if a user is allowed?
or do i just put the query code where i need it? eg. at the top of pages i need to query the acl? then in pages publicly available, i just skip it? may get troublesome if the application gets big?
ok, i just answer this question then close it
what i did now was have a controller plugin that sets its resource based on controller name and privilege based on action name. then query the acl based on that
still under development, but what i currently have look like http://pastebin.com/9BYzms7W