Commit f733e3c5 authored by Gradl, Tobias's avatar Gradl, Tobias
Browse files

428: Show real error page instead of Whitelabel Error Page (OPENED)

Task-Url: #428
parent b3b25d62
Pipeline #23490 passed with stage
in 53 seconds
...@@ -9,7 +9,7 @@ allprojects { ...@@ -9,7 +9,7 @@ allprojects {
apply plugin: 'eclipse' apply plugin: 'eclipse'
group = 'eu.dariah.de.minfba' group = 'eu.dariah.de.minfba'
version = '4.0-SNAPSHOT' version = '4.1-SNAPSHOT'
repositories { repositories {
mavenLocal() mavenLocal()
...@@ -22,7 +22,7 @@ allprojects { ...@@ -22,7 +22,7 @@ allprojects {
gtfVersion = "2.1.0-SNAPSHOT" gtfVersion = "2.1.0-SNAPSHOT"
processingVersion = "4.2.0-SNAPSHOT" processingVersion = "4.2.0-SNAPSHOT"
colregModelVersion = "4.3.4-RELEASE" colregModelVersion = "4.3.4-RELEASE"
dariahSpVersion = "2.1.6-RELEASE" dariahSpVersion = "2.1.7-RELEASE"
jsonAssertVersion = "1.5.0" jsonAssertVersion = "1.5.0"
jodaTimeVersion = "2.10.10" jodaTimeVersion = "2.10.10"
......
package eu.dariah.de.search.controller;
import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ErrorProperties;
import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import eu.dariah.de.dariahsp.config.SecurityConfig;
import eu.dariah.de.dariahsp.error.RequiredAttributesException;
/**
* Error controller for the sample application
*
* @author Tobias Gradl
*/
@Controller
@RequestMapping({"${server.error.path:${error.path:/error}}"})
public class ErrorController extends BasicErrorController {
@Autowired private SecurityConfig securityConfig;
/**
* Constructor with autowired ErrorAttributes
*
* @param errorAttributes
*/
@Autowired
public ErrorController(ErrorAttributes errorAttributes) {
super(errorAttributes, new ErrorProperties());
}
/**
* Error handling method dispatching all errors as messages to the default index view.
* Particular attention lies on the treatment of the {@link RequiredAttributesException}
*/
@Override
@RequestMapping(produces = {"text/html"})
public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) {
Map<String, Object> attr = getErrorAttributes(request, getErrorAttributeOptions(request, MediaType.ALL));
HttpStatus status = getStatus(request);
this.assembleMap(attr, status);
// This is an error that needs special treatment in DARIAH/CLARIAH
Object ex = request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
if (ex!=null && RequiredAttributesException.class.isAssignableFrom(ex.getClass())) {
StringBuilder errorStrBldr = new StringBuilder();
errorStrBldr.append("Your IdP did not provide all required attributes. ");
if (securityConfig.getSaml().getSp().getAttributesIncompleteRedirectUrl()!=null) {
errorStrBldr
.append("Please visit ")
.append("<a href='").append(securityConfig.getSaml().getSp().getAttributesIncompleteRedirectUrl()).append("'>")
.append(securityConfig.getSaml().getSp().getAttributesIncompleteRedirectUrl())
.append("</a> to validate your profile setup.");
}
attr.put("hint", errorStrBldr.toString());
attr.put("error", HttpStatus.FORBIDDEN.value());
attr.put("reason", HttpStatus.FORBIDDEN.getReasonPhrase());
}
return new ModelAndView("common/error", attr);
}
/* Do not do this in production as users should not see all reasons openly */
@Override
protected boolean isIncludeMessage(HttpServletRequest request, MediaType produces) {
return true;
}
private void assembleMap(Map<String, Object> map, HttpStatus status) {
map.put("error", status.value());
map.put("reason", status.getReasonPhrase());
map.put("localEnabled", securityConfig.getLocal().isEnabled());
map.put("samlEnabled", securityConfig.getSaml().isEnabled());
}
}
\ No newline at end of file
Subproject commit 7274639e8461b8c5970617dcdeb6305f7c819fb9 Subproject commit ca479bb95e8f7dac66ac4718192f1374710bb06e
...@@ -76,9 +76,14 @@ ...@@ -76,9 +76,14 @@
</definition> </definition>
<!-- Errors --> <!-- Errors -->
<definition name="*/error" extends="{1}/template_simple"> <definition name="*/common/error" extends="{1}/template_simple">
<put-attribute name="fluidLayout" cascade="true" value="false" />
<put-attribute name="content" value="/WEB-INF/view/jsp/_search-commons/common/error.jsp" /> <put-attribute name="content" value="/WEB-INF/view/jsp/_search-commons/common/error.jsp" />
</definition> </definition>
<definition name="*/error/404" extends="{1}/template_simple">
<put-attribute name="fluidLayout" cascade="true" value="false" />
<put-attribute name="content" value="/WEB-INF/view/jsp/_search-commons/common/error404.jsp" />
</definition>
<!-- User profile --> <!-- User profile -->
<definition name="*/user" extends="{1}/template_simple"> <definition name="*/user" extends="{1}/template_simple">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment