Search in sources :

Example 6 with FormMessage

use of org.keycloak.models.utils.FormMessage in project keycloak by keycloak.

the class IdentityBrokerService method redirectToAccountErrorPage.

private Response redirectToAccountErrorPage(AuthenticationSessionModel authSession, String message, Object... parameters) {
    fireErrorEvent(message);
    FormMessage errorMessage = new FormMessage(message, parameters);
    try {
        String serializedError = JsonSerialization.writeValueAsString(errorMessage);
        authSession.setAuthNote(AccountFormService.ACCOUNT_MGMT_FORWARDED_ERROR_NOTE, serializedError);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
    URI accountServiceUri = UriBuilder.fromUri(authSession.getRedirectUri()).queryParam(Constants.TAB_ID, authSession.getTabId()).build();
    return Response.status(302).location(accountServiceUri).build();
}
Also used : IOException(java.io.IOException) FormMessage(org.keycloak.models.utils.FormMessage) URI(java.net.URI)

Example 7 with FormMessage

use of org.keycloak.models.utils.FormMessage in project keycloak by keycloak.

the class IdentityBrokerService method browserAuthentication.

protected Response browserAuthentication(AuthenticationSessionModel authSession, String errorMessage) {
    this.event.event(EventType.LOGIN);
    AuthenticationFlowModel flow = AuthenticationFlowResolver.resolveBrowserFlow(authSession);
    String flowId = flow.getId();
    AuthenticationProcessor processor = new AuthenticationProcessor();
    processor.setAuthenticationSession(authSession).setFlowPath(LoginActionsService.AUTHENTICATE_PATH).setFlowId(flowId).setBrowserFlow(true).setConnection(clientConnection).setEventBuilder(event).setRealm(realmModel).setSession(session).setUriInfo(session.getContext().getUri()).setRequest(request);
    if (errorMessage != null)
        processor.setForwardedErrorMessage(new FormMessage(null, errorMessage));
    try {
        CacheControlUtil.noBackButtonCacheControlHeader();
        return processor.authenticate();
    } catch (Exception e) {
        return processor.handleBrowserException(e);
    }
}
Also used : AuthenticationFlowModel(org.keycloak.models.AuthenticationFlowModel) AuthenticationProcessor(org.keycloak.authentication.AuthenticationProcessor) FormMessage(org.keycloak.models.utils.FormMessage) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) IdentityBrokerException(org.keycloak.broker.provider.IdentityBrokerException) OAuthErrorException(org.keycloak.OAuthErrorException) NotFoundException(javax.ws.rs.NotFoundException) ErrorPageException(org.keycloak.services.ErrorPageException)

Example 8 with FormMessage

use of org.keycloak.models.utils.FormMessage in project keycloak by keycloak.

the class FreeMarkerLoginFormsProvider method setMessage.

protected void setMessage(MessageType type, String message, Object... parameters) {
    messageType = type;
    messages = new ArrayList<>();
    messages.add(new FormMessage(null, message, parameters));
}
Also used : FormMessage(org.keycloak.models.utils.FormMessage)

Example 9 with FormMessage

use of org.keycloak.models.utils.FormMessage in project keycloak by keycloak.

the class FreeMarkerLoginFormsProvider method handleMessages.

/**
 * Handle messages to be shown on the page - set them to template attributes
 *
 * @param locale to be used for message text loading
 * @param messagesBundle to be used for message text loading
 * @see #messageType
 * @see #messages
 */
protected void handleMessages(Locale locale, Properties messagesBundle) {
    MessagesPerFieldBean messagesPerField = new MessagesPerFieldBean();
    if (messages != null) {
        MessageBean wholeMessage = new MessageBean(null, messageType);
        for (FormMessage message : this.messages) {
            String formattedMessageText = formatMessage(message, messagesBundle, locale);
            if (formattedMessageText != null) {
                wholeMessage.appendSummaryLine(formattedMessageText);
                messagesPerField.addMessage(message.getField(), formattedMessageText, messageType);
            }
        }
        attributes.put("message", wholeMessage);
    } else {
        attributes.put("message", null);
    }
    attributes.put("messagesPerField", messagesPerField);
}
Also used : MessageBean(org.keycloak.theme.beans.MessageBean) MessagesPerFieldBean(org.keycloak.theme.beans.MessagesPerFieldBean) FormMessage(org.keycloak.models.utils.FormMessage)

Example 10 with FormMessage

use of org.keycloak.models.utils.FormMessage in project keycloak by keycloak.

the class FreeMarkerAccountProvider method handleMessages.

/**
 * Handle messages to be shown on the page - set them to template attributes
 *
 * @param locale to be used for message text loading
 * @param messagesBundle to be used for message text loading
 * @param attributes template attributes to messages related info to
 * @see #messageType
 * @see #messages
 */
protected void handleMessages(Locale locale, Properties messagesBundle, Map<String, Object> attributes) {
    MessagesPerFieldBean messagesPerField = new MessagesPerFieldBean();
    if (messages != null) {
        MessageBean wholeMessage = new MessageBean(null, messageType);
        for (FormMessage message : this.messages) {
            String formattedMessageText = formatMessage(message, messagesBundle, locale);
            if (formattedMessageText != null) {
                wholeMessage.appendSummaryLine(formattedMessageText);
                messagesPerField.addMessage(message.getField(), formattedMessageText, messageType);
            }
        }
        attributes.put("message", wholeMessage);
    }
    attributes.put("messagesPerField", messagesPerField);
}
Also used : MessageBean(org.keycloak.theme.beans.MessageBean) MessagesPerFieldBean(org.keycloak.theme.beans.MessagesPerFieldBean) FormMessage(org.keycloak.models.utils.FormMessage)

Aggregations

FormMessage (org.keycloak.models.utils.FormMessage)20 Response (javax.ws.rs.core.Response)5 IOException (java.io.IOException)4 EventBuilder (org.keycloak.events.EventBuilder)4 LoginFormsProvider (org.keycloak.forms.login.LoginFormsProvider)3 UserModel (org.keycloak.models.UserModel)3 AuthenticationSessionModel (org.keycloak.sessions.AuthenticationSessionModel)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 AuthenticatorConfigModel (org.keycloak.models.AuthenticatorConfigModel)2 RealmModel (org.keycloak.models.RealmModel)2 MessageBean (org.keycloak.theme.beans.MessageBean)2 MessagesPerFieldBean (org.keycloak.theme.beans.MessagesPerFieldBean)2 URI (java.net.URI)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Locale (java.util.Locale)1 Map (java.util.Map)1