Merge pull request #55 from vrockai/KEYCLOAK-83
KEYCLOAK-83 add error page
This commit is contained in:
commit
07ce446e96
9 changed files with 30 additions and 77 deletions
|
@ -65,12 +65,12 @@ public class FormServiceImpl implements FormService {
|
||||||
commandMap.put(Pages.LOGIN_RESET_PASSWORD, new CommandPassword());
|
commandMap.put(Pages.LOGIN_RESET_PASSWORD, new CommandPassword());
|
||||||
commandMap.put(Pages.LOGIN_UPDATE_PASSWORD, new CommandPassword());
|
commandMap.put(Pages.LOGIN_UPDATE_PASSWORD, new CommandPassword());
|
||||||
commandMap.put(Pages.ACCESS, new CommandAccess());
|
commandMap.put(Pages.ACCESS, new CommandAccess());
|
||||||
commandMap.put(Pages.SECURITY_FAILURE, new CommandSecurityFailure());
|
|
||||||
commandMap.put(Pages.SOCIAL, new CommandSocial());
|
commandMap.put(Pages.SOCIAL, new CommandSocial());
|
||||||
commandMap.put(Pages.TOTP, new CommandTotp());
|
commandMap.put(Pages.TOTP, new CommandTotp());
|
||||||
commandMap.put(Pages.LOGIN_CONFIG_TOTP, new CommandTotp());
|
commandMap.put(Pages.LOGIN_CONFIG_TOTP, new CommandTotp());
|
||||||
commandMap.put(Pages.LOGIN_TOTP, new CommandLoginTotp());
|
commandMap.put(Pages.LOGIN_TOTP, new CommandLoginTotp());
|
||||||
commandMap.put(Pages.LOGIN_VERIFY_EMAIL, new CommandLoginTotp());
|
commandMap.put(Pages.LOGIN_VERIFY_EMAIL, new CommandLoginTotp());
|
||||||
|
commandMap.put(Pages.ERROR, new CommandError());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId(){
|
public String getId(){
|
||||||
|
@ -143,11 +143,6 @@ public class FormServiceImpl implements FormService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CommandSecurityFailure implements Command {
|
|
||||||
public void exec(Map<String, Object> attributes, FormServiceDataBean dataBean) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CommandPassword implements Command {
|
private class CommandPassword implements Command {
|
||||||
public void exec(Map<String, Object> attributes, FormServiceDataBean dataBean) {
|
public void exec(Map<String, Object> attributes, FormServiceDataBean dataBean) {
|
||||||
if (dataBean.getError() != null){
|
if (dataBean.getError() != null){
|
||||||
|
@ -253,6 +248,14 @@ public class FormServiceImpl implements FormService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class CommandError implements Command {
|
||||||
|
public void exec(Map<String, Object> attributes, FormServiceDataBean dataBean) {
|
||||||
|
if (dataBean.getError() != null){
|
||||||
|
attributes.put("error", new ErrorBean(dataBean.getError()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private interface Command {
|
private interface Command {
|
||||||
public void exec(Map<String, Object> attributes, FormServiceDataBean dataBean);
|
public void exec(Map<String, Object> attributes, FormServiceDataBean dataBean);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<#-- TODO: Only a placeholder, implementation needed -->
|
<#-- TODO: Only a placeholder, implementation needed -->
|
||||||
<#import "template-login-action.ftl" as layout>
|
<#import "template-login-action.ftl" as layout>
|
||||||
<@layout.registrationLayout bodyClass="reset"; section>
|
<@layout.registrationLayout bodyClass="reset" isErrorPage=true; section>
|
||||||
<#if section = "title">
|
<#if section = "title">
|
||||||
|
|
||||||
We're sorry...
|
We're sorry...
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
<#elseif section = "form">
|
<#elseif section = "form">
|
||||||
|
|
||||||
<p class="instruction">Something happened and we could not process your request.</p>
|
<p class="instruction">Something happened and we could not process your request.</p>
|
||||||
<p class="instruction second">Please make sure the URL you entered is correct.</p>
|
<p class="instruction second">${error.summary}</p>
|
||||||
<a href="saas-login.html" class="link-right">Go to the homepage »</a>
|
<a href="saas-login.html" class="link-right">Go to the homepage »</a>
|
||||||
|
|
||||||
<#elseif section = "info" >
|
<#elseif section = "info" >
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<#macro registrationLayout bodyClass>
|
<#macro registrationLayout bodyClass isErrorPage=false>
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
<#nested "form">
|
<#nested "form">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<#if error?has_content>
|
<#if !isErrorPage && error?has_content>
|
||||||
<div class="feedback error bottom-left show">
|
<div class="feedback error bottom-left show">
|
||||||
<p>
|
<p>
|
||||||
<strong id="loginError">${rb.getString(error.summary)}</strong>
|
<strong id="loginError">${rb.getString(error.summary)}</strong>
|
||||||
|
|
|
@ -57,7 +57,6 @@ import org.keycloak.services.managers.RealmManager;
|
||||||
import org.keycloak.services.managers.TokenManager;
|
import org.keycloak.services.managers.TokenManager;
|
||||||
import org.keycloak.services.resources.flows.Flows;
|
import org.keycloak.services.resources.flows.Flows;
|
||||||
import org.keycloak.services.resources.flows.OAuthFlows;
|
import org.keycloak.services.resources.flows.OAuthFlows;
|
||||||
import org.keycloak.services.resources.flows.PageFlows;
|
|
||||||
import org.keycloak.services.resources.flows.Urls;
|
import org.keycloak.services.resources.flows.Urls;
|
||||||
import org.keycloak.social.AuthCallback;
|
import org.keycloak.social.AuthCallback;
|
||||||
import org.keycloak.social.AuthRequest;
|
import org.keycloak.social.AuthRequest;
|
||||||
|
@ -221,9 +220,12 @@ public class SocialResource {
|
||||||
@QueryParam("provider_id") final String providerId, @QueryParam("client_id") final String clientId,
|
@QueryParam("provider_id") final String providerId, @QueryParam("client_id") final String clientId,
|
||||||
@QueryParam("scope") final String scope, @QueryParam("state") final String state,
|
@QueryParam("scope") final String scope, @QueryParam("state") final String state,
|
||||||
@QueryParam("redirect_uri") final String redirectUri) {
|
@QueryParam("redirect_uri") final String redirectUri) {
|
||||||
|
RealmManager realmManager = new RealmManager(session);
|
||||||
|
RealmModel realm = realmManager.getRealm(realmId);
|
||||||
|
|
||||||
SocialProvider provider = getProvider(providerId);
|
SocialProvider provider = getProvider(providerId);
|
||||||
if (provider == null) {
|
if (provider == null) {
|
||||||
return Flows.pages(request).forwardToSecurityFailure("Social provider not found");
|
return Flows.forms(realm, request, uriInfo).setError("Social provider not found").forwardToErrorPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
String key = System.getProperty("keycloak.social." + providerId + ".key");
|
String key = System.getProperty("keycloak.social." + providerId + ".key");
|
||||||
|
@ -244,7 +246,7 @@ public class SocialResource {
|
||||||
|
|
||||||
return Response.status(Status.FOUND).location(authRequest.getAuthUri()).build();
|
return Response.status(Status.FOUND).location(authRequest.getAuthUri()).build();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
return Flows.pages(request).forwardToSecurityFailure("Failed to redirect to social auth");
|
return Flows.forms(realm, request, uriInfo).setError("Failed to redirect to social auth").forwardToErrorPage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,24 +255,24 @@ public class SocialResource {
|
||||||
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
||||||
public Response socialRegistration(@PathParam("realm") final String realmId,
|
public Response socialRegistration(@PathParam("realm") final String realmId,
|
||||||
final MultivaluedMap<String, String> formData) {
|
final MultivaluedMap<String, String> formData) {
|
||||||
PageFlows pageFlows = Flows.pages(request);
|
RealmManager realmManager = new RealmManager(session);
|
||||||
|
RealmModel realm = realmManager.getRealm(realmId);
|
||||||
|
|
||||||
Cookie cookie = headers.getCookies().get(SocialConstants.SOCIAL_REGISTRATION_COOKIE);
|
Cookie cookie = headers.getCookies().get(SocialConstants.SOCIAL_REGISTRATION_COOKIE);
|
||||||
if (cookie == null) {
|
if (cookie == null) {
|
||||||
return pageFlows.forwardToSecurityFailure("Social registration cookie not found");
|
return Flows.forms(realm, request, uriInfo).setError("Social registration cookie not found").forwardToErrorPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
String requestId = cookie.getValue();
|
String requestId = cookie.getValue();
|
||||||
if (!socialRequestManager.isRequestId(requestId)) {
|
if (!socialRequestManager.isRequestId(requestId)) {
|
||||||
logger.error("Unknown requestId found in cookie. Maybe it's expired. requestId=" + requestId);
|
logger.error("Unknown requestId found in cookie. Maybe it's expired. requestId=" + requestId);
|
||||||
return pageFlows.forwardToSecurityFailure("Unknown requestId found in cookie. Maybe it's expired.");
|
return Flows.forms(realm, request, uriInfo).setError("Unknown requestId found in cookie. Maybe it's expired.").forwardToErrorPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
RequestDetails requestData = socialRequestManager.getData(requestId);
|
RequestDetails requestData = socialRequestManager.getData(requestId);
|
||||||
|
|
||||||
RealmManager realmManager = new RealmManager(session);
|
|
||||||
RealmModel realm = realmManager.getRealm(realmId);
|
|
||||||
if (realm == null || !realm.isEnabled()) {
|
if (realm == null || !realm.isEnabled()) {
|
||||||
return pageFlows.forwardToSecurityFailure("Realm doesn't exists or is not enabled.");
|
return Flows.forms(realm, request, uriInfo).setError("Realm doesn't exists or is not enabled.").forwardToErrorPage();
|
||||||
}
|
}
|
||||||
TokenService tokenService = new TokenService(realm, tokenManager);
|
TokenService tokenService = new TokenService(realm, tokenManager);
|
||||||
resourceContext.initResource(tokenService);
|
resourceContext.initResource(tokenService);
|
||||||
|
|
|
@ -36,10 +36,6 @@ public class Flows {
|
||||||
private Flows() {
|
private Flows() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PageFlows pages(HttpRequest request) {
|
|
||||||
return new PageFlows(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static FormFlows forms(RealmModel realm, HttpRequest request, UriInfo uriInfo) {
|
public static FormFlows forms(RealmModel realm, HttpRequest request, UriInfo uriInfo) {
|
||||||
return new FormFlows(realm, request, uriInfo);
|
return new FormFlows(realm, request, uriInfo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,6 +168,10 @@ public class FormFlows {
|
||||||
return forwardToForm(Pages.TOTP);
|
return forwardToForm(Pages.TOTP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Response forwardToErrorPage() {
|
||||||
|
return forwardToForm(Pages.ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
public FormFlows setAccessCode(AccessCodeEntry accessCode) {
|
public FormFlows setAccessCode(AccessCodeEntry accessCode) {
|
||||||
this.accessCode = accessCode;
|
this.accessCode = accessCode;
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -126,7 +126,7 @@ public class OAuthFlows {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response forwardToSecurityFailure(String message) {
|
public Response forwardToSecurityFailure(String message) {
|
||||||
return Flows.pages(request).forwardToSecurityFailure(message);
|
return Flows.forms(realm, request, uriInfo).setError(message).forwardToErrorPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
/*
|
|
||||||
* JBoss, Home of Professional Open Source.
|
|
||||||
* Copyright 2012, Red Hat, Inc., and individual contributors
|
|
||||||
* as indicated by the @author tags. See the copyright.txt file in the
|
|
||||||
* distribution for a full listing of individual contributors.
|
|
||||||
*
|
|
||||||
* This is free software; you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU Lesser General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2.1 of
|
|
||||||
* the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This software is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this software; if not, write to the Free
|
|
||||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
||||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
|
||||||
*/
|
|
||||||
package org.keycloak.services.resources.flows;
|
|
||||||
|
|
||||||
import org.jboss.resteasy.logging.Logger;
|
|
||||||
import org.jboss.resteasy.spi.HttpRequest;
|
|
||||||
import org.keycloak.services.JspRequestParameters;
|
|
||||||
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
|
||||||
*/
|
|
||||||
public class PageFlows {
|
|
||||||
|
|
||||||
private static final Logger log = Logger.getLogger(PageFlows.class);
|
|
||||||
|
|
||||||
private HttpRequest request;
|
|
||||||
|
|
||||||
PageFlows(HttpRequest request) {
|
|
||||||
this.request = request;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response forwardToSecurityFailure(String message) {
|
|
||||||
log.error(message);
|
|
||||||
|
|
||||||
request.setAttribute(JspRequestParameters.KEYCLOAK_SECURITY_FAILURE_MESSAGE, message);
|
|
||||||
|
|
||||||
request.forward(Pages.SECURITY_FAILURE);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -48,7 +48,7 @@ public class Pages {
|
||||||
|
|
||||||
public final static String REGISTER = "/forms/register.ftl";
|
public final static String REGISTER = "/forms/register.ftl";
|
||||||
|
|
||||||
public final static String SECURITY_FAILURE = "/saas/securityFailure.jsp";
|
public final static String ERROR = "/forms/error.ftl";
|
||||||
|
|
||||||
public final static String SOCIAL = "/forms/social.ftl";
|
public final static String SOCIAL = "/forms/social.ftl";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue