diff --git a/forms/src/main/java/org/keycloak/forms/FormsBean.java b/forms/src/main/java/org/keycloak/forms/FormsBean.java index 7c7e25be4c..7b38b0cb7a 100755 --- a/forms/src/main/java/org/keycloak/forms/FormsBean.java +++ b/forms/src/main/java/org/keycloak/forms/FormsBean.java @@ -1,4 +1,4 @@ -package org.keycloak.sdk; +package org.keycloak.forms; import java.net.URI; import java.util.HashMap; @@ -14,9 +14,12 @@ import javax.faces.context.FacesContext; import javax.imageio.spi.ServiceRegistry; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.UriBuilder; import org.keycloak.services.models.RealmModel; import org.keycloak.services.models.RequiredCredentialModel; +import org.keycloak.services.resources.flows.FormFlows; +import org.keycloak.services.resources.flows.Urls; @ManagedBean(name = "forms") @RequestScoped @@ -30,7 +33,7 @@ public class FormsBean { private String loginAction; - private String socialLoginUrl; + private UriBuilder socialLoginUrlBuilder; private String registrationUrl; @@ -38,8 +41,6 @@ public class FormsBean { private List requiredCredentials; - private List hiddenProperties; - private List providers; private String theme; @@ -62,9 +63,11 @@ public class FormsBean { HttpServletRequest request = (HttpServletRequest) ctx.getExternalContext().getRequest(); - realm = (RealmModel) request.getAttribute(RealmModel.class.getName()); + realm = (RealmModel) request.getAttribute(FormFlows.REALM); - if (RealmModel.DEFAULT_REALM.equals(realm.getName())) { + boolean saas = RealmModel.DEFAULT_REALM.equals(realm.getName()); + + if (saas) { name = "Keycloak"; } else { name = realm.getName(); @@ -72,18 +75,29 @@ public class FormsBean { view = ctx.getViewRoot().getViewId(); view = view.substring(view.lastIndexOf('/') + 1, view.lastIndexOf('.')); + + UriBuilder b = UriBuilder.fromUri(request.getRequestURI()).replaceQuery(request.getQueryString()) + .replacePath(request.getContextPath()).path("rest"); + URI baseURI = b.build(); - loginUrl = ((URI) request.getAttribute("KEYCLOAK_LOGIN_PAGE")).toString(); - loginAction = ((URI) request.getAttribute("KEYCLOAK_LOGIN_ACTION")).toString(); + if (saas) { + loginUrl = Urls.saasLoginPage(baseURI).toString(); + loginAction = Urls.saasLoginAction(baseURI).toString(); - registrationUrl = ((URI) request.getAttribute("KEYCLOAK_REGISTRATION_PAGE")).toString(); - registrationAction = ((URI) request.getAttribute("KEYCLOAK_REGISTRATION_ACTION")).toString(); + registrationUrl = Urls.saasRegisterPage(baseURI).toString(); + registrationAction = Urls.saasRegisterAction(baseURI).toString(); + } else { + loginUrl = Urls.realmLoginPage(baseURI, realm.getId()).toString(); + loginAction = Urls.realmLoginAction(baseURI, realm.getId()).toString(); - socialLoginUrl = ((URI) request.getAttribute("KEYCLOAK_SOCIAL_LOGIN")).toString(); + registrationUrl = Urls.realmRegisterPage(baseURI, realm.getId()).toString(); + registrationAction = Urls.realmRegisterAction(baseURI, realm.getId()).toString(); + } + + socialLoginUrlBuilder = UriBuilder.fromUri(Urls.socialRedirectToProviderAuth(baseURI, realm.getId())); addRequiredCredentials(); addFormData(request); - addHiddenProperties(request, "client_id", "scope", "state", "redirect_uri"); addSocialProviders(); addErrors(request); @@ -132,10 +146,6 @@ public class FormsBean { return formData; } - public List getHiddenProperties() { - return hiddenProperties; - } - public List getRequiredCredentials() { return requiredCredentials; } @@ -173,7 +183,7 @@ public class FormsBean { formData = new HashMap(); @SuppressWarnings("unchecked") - MultivaluedMap t = (MultivaluedMap) request.getAttribute("KEYCLOAK_FORM_DATA"); + MultivaluedMap t = (MultivaluedMap) request.getAttribute(FormFlows.DATA); if (t != null) { for (String k : t.keySet()) { formData.put(k, t.getFirst(k)); @@ -181,16 +191,6 @@ public class FormsBean { } } - private void addHiddenProperties(HttpServletRequest request, String... names) { - hiddenProperties = new LinkedList(); - for (String name : names) { - Object v = request.getAttribute(name); - if (v != null) { - hiddenProperties.add(new Property(name, (String) v)); - } - } - } - private void addRequiredCredentials() { requiredCredentials = new LinkedList(); for (RequiredCredentialModel m : realm.getRequiredCredentials()) { @@ -211,7 +211,7 @@ public class FormsBean { } private void addErrors(HttpServletRequest request) { - error = (String) request.getAttribute("KEYCLOAK_LOGIN_ERROR_MESSAGE"); + error = (String) request.getAttribute(FormFlows.ERROR_MESSAGE); if (error != null) { if (view.equals("login")) { @@ -288,13 +288,7 @@ public class FormsBean { } public String getLoginUrl() { - StringBuilder sb = new StringBuilder(); - sb.append(socialLoginUrl); - sb.append("?provider_id=" + id); - for (Property p : hiddenProperties) { - sb.append("&" + p.getName() + "=" + p.getValue()); - } - return sb.toString(); + return socialLoginUrlBuilder.replaceQueryParam("provider_id", id).build().toString(); } } diff --git a/forms/src/main/resources/META-INF/faces-config.xml b/forms/src/main/resources/META-INF/faces-config.xml index 82f93dadb2..42cc657718 100644 --- a/forms/src/main/resources/META-INF/faces-config.xml +++ b/forms/src/main/resources/META-INF/faces-config.xml @@ -3,6 +3,11 @@ xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd "> + + + org.keycloak.forms.messages + messages + + - diff --git a/forms/src/main/resources/META-INF/resources/sdk/theme/default/login.xhtml b/forms/src/main/resources/META-INF/resources/sdk/theme/default/login.xhtml index 7362f0731b..07a9f2432c 100755 --- a/forms/src/main/resources/META-INF/resources/sdk/theme/default/login.xhtml +++ b/forms/src/main/resources/META-INF/resources/sdk/theme/default/login.xhtml @@ -7,20 +7,16 @@
- +
- +
- - - -
@@ -32,7 +28,7 @@ -

No account? Register.

+

#{messages.noAccount} #{messages.register}.

\ No newline at end of file diff --git a/forms/src/main/resources/META-INF/resources/sdk/theme/default/register.xhtml b/forms/src/main/resources/META-INF/resources/sdk/theme/default/register.xhtml index d8a0f42392..12ae4884ef 100755 --- a/forms/src/main/resources/META-INF/resources/sdk/theme/default/register.xhtml +++ b/forms/src/main/resources/META-INF/resources/sdk/theme/default/register.xhtml @@ -4,36 +4,32 @@ - Register with #{forms.name} + #{messages.registerWith} #{forms.name} -

All fields are required

+

#{messages.allRequired}

- +
- +
- +
- +
- +
- - - -

By registering you agree to the Terms of Service and the Privacy Policy.

@@ -43,6 +39,6 @@
-

Already have an account? Log in.

+

#{messages.alreadyHaveAccount} #{messages.logIn}.

\ No newline at end of file diff --git a/forms/src/main/resources/META-INF/resources/sdk/theme/default/template.xhtml b/forms/src/main/resources/META-INF/resources/sdk/theme/default/template.xhtml index 7f8415f173..fdbf1a418f 100644 --- a/forms/src/main/resources/META-INF/resources/sdk/theme/default/template.xhtml +++ b/forms/src/main/resources/META-INF/resources/sdk/theme/default/template.xhtml @@ -3,7 +3,7 @@ - Log in to #{forms.name} + #{messages.logInTo} #{forms.name}