Repository navigation
SPI to append data to username on authentication #39217
|
Hi team, I'm trying (for 3 days already) to find a solution to my scenario:
The users need to be able to login using only the first part of the email, without needing to fill the complete address on the input. So a user with CPF = 12345678901 and email carlos@iftm.edu.br must be able to login using just 'carlos' as username. I found that I could implement an SPI to build a custom authenticator, and append the '@iftm.edu.br' part to the input value. So i built the jar, deployed on my Keycloak and set-up the flow, replacing the form with my SPI. It works when the users try to login using CPF or email (I've added log messages to check if this cases are being ignored). When the user tries to login using the first part of the email address, the SPI do append the domain to it, but it seems that it keeps using the original value, and the login fails. I don't know what else to do, so I'm asking for help. Thank you in advance =) the code: |
Replies: 1 comment
The issue in this case is that the current impl of It means you would not be able to call What you need to do instead of calling the MultivaluedMap<String, String> formData = <your-form-data>;
if (formData.containsKey("cancel")) {
context.cancelLogin();
return;
}
if (!validateForm(context, formData)) {
return;
}
context.success();I would also recommend to use this instead of putSingle() - to be completely sure: formData.put(AuthenticationManager.FORM_USERNAME, List.of(username)); |
The issue in this case is that the current impl of
context.getHttpRequest().getDecodedFormParameters()always returns a new instance ofMultivaluedMapon every call with form params obtained from RESTEasy context. It means that even though you update these items in the multivaluedMap, the map is recreated in theUsernamePasswordForm#action()as there's another call ofcontext.getHttpRequest().getDecodedFormParameters().It means you would not be able to call
super.action(context), but probably mimic the behavior of theUsernamePasswor…