Java Code Examples for org.keycloak.forms.login.LoginFormsProvider#setError()
The following examples show how to use
org.keycloak.forms.login.LoginFormsProvider#setError() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectUserAuthenticatorForm.java From keycloak-extension-playground with Apache License 2.0 | 6 votes |
private LoginFormsProvider createSelectUserForm(AuthenticationFlowContext context, String error) { MultivaluedMap<String, String> formData = createLoginFormData(context); LoginFormsProvider form = context.form(); if (formData.size() > 0) { form.setFormData(formData); } form.setAttribute("login", new LoginBean(formData)); if (error != null) { form.setError(error); } return form; }
Example 2
Source File: IdpUsernamePasswordForm.java From keycloak with Apache License 2.0 | 6 votes |
protected LoginFormsProvider setupForm(AuthenticationFlowContext context, MultivaluedMap<String, String> formData, Optional<UserModel> existingUser) { SerializedBrokeredIdentityContext serializedCtx = SerializedBrokeredIdentityContext.readFromAuthenticationSession(context.getAuthenticationSession(), AbstractIdpAuthenticator.BROKERED_CONTEXT_NOTE); if (serializedCtx == null) { throw new AuthenticationFlowException("Not found serialized context in clientSession", AuthenticationFlowError.IDENTITY_PROVIDER_ERROR); } existingUser.ifPresent(u -> formData.putSingle(AuthenticationManager.FORM_USERNAME, u.getUsername())); LoginFormsProvider form = context.form() .setFormData(formData) .setAttribute(LoginFormsProvider.REGISTRATION_DISABLED, true) .setInfo(Messages.FEDERATED_IDENTITY_CONFIRM_REAUTHENTICATE_MESSAGE, serializedCtx.getIdentityProviderId()); SerializedBrokeredIdentityContext serializedCtx0 = SerializedBrokeredIdentityContext.readFromAuthenticationSession(context.getAuthenticationSession(), AbstractIdpAuthenticator.NESTED_FIRST_BROKER_CONTEXT); if (serializedCtx0 != null) { BrokeredIdentityContext ctx0 = serializedCtx0.deserialize(context.getSession(), context.getAuthenticationSession()); form.setError(Messages.NESTED_FIRST_BROKER_FLOW_MESSAGE, ctx0.getIdpConfig().getAlias(), ctx0.getUsername()); context.getAuthenticationSession().setAuthNote(AbstractIdpAuthenticator.NESTED_FIRST_BROKER_CONTEXT, null); } return form; }
Example 3
Source File: ThirdPartyMfaAuthenticator.java From keycloak-extension-playground with Apache License 2.0 | 5 votes |
private Response createChallengeFormResponse(AuthenticationFlowContext context, boolean firstTry, MfaMethod mfaMethod, MfaResponse mfaResponse) { LoginFormsProvider form = context.form() .setAttribute(MFA_METHOD, mfaMethod.name()) .setAttribute("mfa_error", mfaResponse.getErrorCode()); if (MfaMethod.PUSH.equals(mfaMethod)) { form.setAttribute("hint", firstTry ? "mfa_push_await_challenge_response" : "mfa_push_await_challenge_response"); } Locale locale = session.getContext().resolveLocale(context.getUser()); form.setAttribute("customMsg", new MessageFormatterMethod(locale, MfaMessages.getMessages())); if (mfaResponse.getErrorCode() != null) { if (MfaVerifyResponse.ERR_INVALID_CODE.equals(mfaResponse.getErrorCode())) { form.setError(Messages.INVALID_TOTP); } else { form.setError(mfaResponse.getErrorCode()); } } switch (mfaMethod) { case OTP: return form.createForm("custom-mfa-form-otp.ftl"); case PUSH: default: return form.createForm("custom-mfa-form-push.ftl"); } }
Example 4
Source File: PasswordAuthenticatorForm.java From keycloak-extension-playground with Apache License 2.0 | 5 votes |
@Override protected Response challenge(AuthenticationFlowContext context, String error) { LoginFormsProvider form = context.form(); if (error != null) { form.setError(error); } String attemptedUsername = context.getAuthenticationSession().getAuthNote(AbstractUsernameFormAuthenticator.ATTEMPTED_USERNAME); form.setAttribute(AuthenticationManager.FORM_USERNAME, attemptedUsername); Response response = form.createForm("validate-password-form.ftl"); return response; }
Example 5
Source File: AbstractUsernameFormAuthenticator.java From keycloak with Apache License 2.0 | 4 votes |
protected Response challenge(AuthenticationFlowContext context, String error) { LoginFormsProvider form = context.form() .setExecution(context.getExecution().getId()); if (error != null) form.setError(error); return createLoginForm(form); }