diff options
Diffstat (limited to 'eaaf_core/src/main/java')
2 files changed, 42 insertions, 21 deletions
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/api/idp/auth/services/IProtocolAuthenticationService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/api/idp/auth/services/IProtocolAuthenticationService.java index f6f8e576..de5eb036 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/api/idp/auth/services/IProtocolAuthenticationService.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/api/idp/auth/services/IProtocolAuthenticationService.java @@ -33,6 +33,12 @@ import at.gv.egiz.eaaf.core.exceptions.EAAFException; public interface IProtocolAuthenticationService { + public String PARAM_GUI_ERROMSG = "errorMsg"; + public String PARAM_GUI_ERRORCODE = "errorCode"; + public String PARAM_GUI_ERRORCODEPARAMS = "errorParams"; + public String PARAM_GUI_ERRORSTACKTRACE = "stacktrace"; + + /** * Initialize an authentication process for this protocol request * diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java index 7d3ca2f8..5d3028bc 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java @@ -25,17 +25,21 @@ package at.gv.egiz.eaaf.core.impl.idp.auth.services; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; +import java.util.Arrays; import javax.naming.ConfigurationException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.text.StringEscapeUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; +import org.springframework.lang.NonNull; +import org.springframework.lang.Nullable; import org.springframework.stereotype.Service; import at.gv.egiz.components.eventlog.api.EventConstants; @@ -247,7 +251,7 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer else { //write generic message for general exceptions final String msg = statusMessager.getMessage(IStatusMessenger.CODES_INTERNAL_ERROR_GENERIC, null); - writeHTMLErrorResponse(req, resp, msg, "9199", (Exception) throwable); + writeHTMLErrorResponse(req, resp, msg, "9199", null, (Exception) throwable); } @@ -372,24 +376,31 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer } - private void writeHTMLErrorResponse(final HttpServletRequest httpReq, final HttpServletResponse httpResp, final String msg, final String errorCode, final Exception error) throws IOException, EAAFException { + private void writeHTMLErrorResponse(@NonNull final HttpServletRequest httpReq, @NonNull final HttpServletResponse httpResp, + @NonNull final String msg, @NonNull final String errorCode, @Nullable final Object[] params, @NonNull final Exception error) throws IOException, EAAFException { try { final IGUIBuilderConfiguration config = guiConfigFactory.getDefaultErrorGUI(HTTPUtils.extractAuthURLFromRequest(httpReq)); -// HTTPUtils.extractAuthURLFromRequest(req), -// DefaultGUIFormBuilderConfiguration.VIEW_ERRORMESSAGE, -// null); - + + String[] errorCodeParams = null; + if (params == null) + errorCodeParams = new String[] {}; + else + errorCodeParams = Arrays.copyOf(params, params.length, String[].class); + + + //add errorcode and errormessage if (config instanceof ModifyableGuiBuilderConfiguration) { - ((ModifyableGuiBuilderConfiguration)config).putCustomParameter("errorMsg", msg); - ((ModifyableGuiBuilderConfiguration)config).putCustomParameter("errorCode", errorCode); + ((ModifyableGuiBuilderConfiguration)config).putCustomParameter(PARAM_GUI_ERROMSG, msg); + ((ModifyableGuiBuilderConfiguration)config).putCustomParameter(PARAM_GUI_ERRORCODE, errorCode); + ((ModifyableGuiBuilderConfiguration)config).putCustomParameterWithOutEscaption(PARAM_GUI_ERRORCODEPARAMS, ArrayUtils.toString(errorCodeParams)); //add stacktrace if debug is enabled if (log.isTraceEnabled()) { - ((ModifyableGuiBuilderConfiguration)config).putCustomParameter("stacktrace", getStacktraceFromException(error)); + ((ModifyableGuiBuilderConfiguration)config).putCustomParameter(PARAM_GUI_ERRORSTACKTRACE, getStacktraceFromException(error)); } @@ -408,15 +419,7 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer } } - - private void writeHTMLErrorResponse(final HttpServletRequest req, final HttpServletResponse httpResp, final Exception error) throws IOException, EAAFException { - writeHTMLErrorResponse(req, httpResp, - error.getMessage(), - statusMessager.getResponseErrorCode(error), - error); - } - - + private String getStacktraceFromException(final Exception ex) { final StringWriter errors = new StringWriter(); ex.printStackTrace(new PrintWriter(errors)); @@ -446,15 +449,27 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer } else if (e instanceof ConfigurationException) { //send HTML formated error message - writeHTMLErrorResponse(req, resp, e); + writeHTMLErrorResponse(req, resp, + e.getMessage(), + statusMessager.getResponseErrorCode(e), + null, + e); } else if (e instanceof EAAFException) { //send HTML formated error message - writeHTMLErrorResponse(req, resp, e); + writeHTMLErrorResponse(req, resp, + e.getMessage(), + statusMessager.getResponseErrorCode(e), + ((EAAFException) e).getParams(), + e); } else if (e instanceof ProcessExecutionException) { //send HTML formated error message - writeHTMLErrorResponse(req, resp, e); + writeHTMLErrorResponse(req, resp, + e.getMessage(), + statusMessager.getResponseErrorCode(e), + null, + e); } |