Skip to content

Commit f086ae6

Browse files
tulinkryVladimir Kotal
authored andcommitted
let the user to customize the 403 error page (#1581)
fixes #1575
1 parent eb1d0b8 commit f086ae6

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

README.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,9 @@ web.xml of source.war file and change them (see note1) appropriately.
433433
- The file 'body_include' can be created under DATA_ROOT.
434434
The contents of this file will be inserted above the footer of the web
435435
application's "Home" page.
436+
- The file 'error_forbidden_include' can be created under DATA_ROOT.
437+
The contents of this file will be displayed as the error page when
438+
the user is forbidden to see a particular project with HTTP 403 code.
436439

437440

438441
5.4.3 - Path Descriptions (optional)

src/org/opensolaris/opengrok/configuration/Configuration.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,30 @@ public String getBodyIncludeFileContent() {
10141014
return body;
10151015
}
10161016

1017+
/**
1018+
* The name of the file relative to the <var>DATA_ROOT</var>, which should
1019+
* be included into the error page handling access forbidden errors - HTTP
1020+
* code 403 Forbidden.
1021+
*/
1022+
public static final String E_FORBIDDEN_INCLUDE_FILE = "error_forbidden_include";
1023+
1024+
private transient String eforbidden_content = null;
1025+
1026+
/**
1027+
* Get the contents of the page for forbidden error page (403 Forbidden)
1028+
* include file.
1029+
*
1030+
* @return an empty string if it could not be read successfully, the
1031+
* contents of the file otherwise.
1032+
* @see Configuration#E_FORBIDDEN_INCLUDE_FILE
1033+
*/
1034+
public String getForbiddenIncludeFileContent() {
1035+
if (eforbidden_content == null) {
1036+
eforbidden_content = getFileContent(new File(getDataRoot(), E_FORBIDDEN_INCLUDE_FILE));
1037+
}
1038+
return eforbidden_content;
1039+
}
1040+
10171041
/**
10181042
* Get the eftar file, which contains definition tags.
10191043
*

web/WEB-INF/web.xml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@
127127
<param-name>keepgenerated</param-name><param-value>true</param-value>
128128
</init-param>
129129
</servlet>
130+
<servlet>
131+
<display-name>Forbidden error handler</display-name>
132+
<servlet-name>eforbidden</servlet-name>
133+
<jsp-file>/eforbidden.jsp</jsp-file>
134+
<init-param>
135+
<param-name>keepgenerated</param-name>
136+
<param-value>true</param-value>
137+
</init-param>
138+
</servlet>
130139
<servlet-mapping>
131140
<servlet-name>search</servlet-name>
132141
<url-pattern>/search</url-pattern> <!-- SEARCH_P -->
@@ -179,6 +188,10 @@
179188
<servlet-name>enoent</servlet-name>
180189
<url-pattern>/enoent</url-pattern> <!-- NOT_FOUND -->
181190
</servlet-mapping>
191+
<servlet-mapping>
192+
<servlet-name>eforbidden</servlet-name>
193+
<url-pattern>/eforbidden</url-pattern> <!-- FORBIDDEN -->
194+
</servlet-mapping>
182195
<error-page>
183196
<error-code>404</error-code>
184197
<location>/enoent</location>
@@ -187,8 +200,12 @@
187200
<error-code>500</error-code>
188201
<location>/error</location>
189202
</error-page>
203+
<error-page>
204+
<error-code>403</error-code>
205+
<location>/eforbidden</location>
206+
</error-page>
190207
<jsp-config>
191-
<jsp-property-group>
208+
<jsp-property-group>
192209
<url-pattern>*.jsp</url-pattern>
193210
<trim-directive-whitespaces>true</trim-directive-whitespaces>
194211
</jsp-property-group>

web/eforbidden.jsp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<%--
2+
CDDL HEADER START
3+
4+
The contents of this file are subject to the terms of the
5+
Common Development and Distribution License (the "License").
6+
You may not use this file except in compliance with the License.
7+
8+
See LICENSE.txt included in this distribution for the specific
9+
language governing permissions and limitations under the License.
10+
11+
When distributing Covered Code, include this CDDL HEADER in each
12+
file and include the License file at LICENSE.txt.
13+
If applicable, add the following below this CDDL HEADER, with the
14+
fields enclosed by brackets "[]" replaced with your own identifying
15+
information: Portions Copyright [yyyy] [name of copyright owner]
16+
17+
CDDL HEADER END
18+
19+
Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
20+
--%><%@page session="false" isErrorPage="true" import="
21+
org.opensolaris.opengrok.web.PageConfig"
22+
%><%
23+
/* ---------------------- eforbidden.jspf start --------------------- */
24+
{
25+
%>
26+
<%= PageConfig.get(request).getEnv().getConfiguration().getForbiddenIncludeFileContent()%>
27+
<%
28+
}
29+
/* ---------------------- eforbidden.jspf end --------------------- */
30+
%>

0 commit comments

Comments
 (0)