Skip to content

Commit

Permalink
- App: Custom Error pages
Browse files Browse the repository at this point in the history
  • Loading branch information
alegauss committed Oct 29, 2023
1 parent 3220434 commit a467eba
Show file tree
Hide file tree
Showing 7 changed files with 279 additions and 5 deletions.
6 changes: 3 additions & 3 deletions turing-app/src/main/java/com/viglet/turing/sn/TurSNUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static URI requestToURI(HttpServletRequest request) {


public static URI addFilterQuery(URI uri, String fq) {
List<NameValuePair> params = URLEncodedUtils.parse(uri, "UTF-8");
List<NameValuePair> params = URLEncodedUtils.parse(uri, StandardCharsets.UTF_8);
StringBuilder sbQueryString = new StringBuilder();
boolean alreadyExists = false;
for (NameValuePair nameValuePair : params) {
Expand All @@ -85,7 +85,7 @@ public static URI addFilterQuery(URI uri, String fq) {
}

public static URI removeFilterQuery(URI uri, String fq) {
List<NameValuePair> params = URLEncodedUtils.parse(uri, "UTF-8");
List<NameValuePair> params = URLEncodedUtils.parse(uri, StandardCharsets.UTF_8);
StringBuilder sbQueryString = new StringBuilder();
for (NameValuePair nameValuePair : params) {
if (!(java.net.URLDecoder.decode(nameValuePair.getValue(), StandardCharsets.UTF_8).equals(fq)
Expand All @@ -97,7 +97,7 @@ public static URI removeFilterQuery(URI uri, String fq) {
}

public static URI removeQueryField(URI uri, String field) {
List<NameValuePair> params = URLEncodedUtils.parse(uri, "UTF-8");
List<NameValuePair> params = URLEncodedUtils.parse(uri, StandardCharsets.UTF_8);
StringBuilder sbQueryString = new StringBuilder();

for (NameValuePair nameValuePair : params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ SecurityFilterChain filterChain(HttpSecurity http, MvcRequestMatcher.Builder mvc
http.csrf(csrf -> csrf
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.csrfTokenRequestHandler(new TurSpaCsrfTokenRequestHandler())
.ignoringRequestMatchers(mvc.pattern("/api/sn/**"),
.ignoringRequestMatchers(mvc.pattern("/api/sn/**"),mvc.pattern("/error/**"),
mvc.pattern("/logout"), mvc.pattern("/api/nlp/**"),
mvc.pattern("/api/v2/guest/**"), AntPathRequestMatcher.antMatcher("/h2/**")))
.addFilterAfter(new TurCsrfCookieFilter(), BasicAuthenticationFilter.class);
Expand All @@ -86,6 +86,7 @@ SecurityFilterChain filterChain(HttpSecurity http, MvcRequestMatcher.Builder mvc
http.oauth2Login(withDefaults());
http.authorizeHttpRequests(authorizeRequests -> {
authorizeRequests.requestMatchers(
mvc.pattern("/error/**"),
mvc.pattern("/api/discovery"),
mvc.pattern("/assets/**"),
mvc.pattern("/favicon.ico"),
Expand All @@ -105,6 +106,7 @@ SecurityFilterChain filterChain(HttpSecurity http, MvcRequestMatcher.Builder mvc
http.httpBasic(httpBasic -> httpBasic.authenticationEntryPoint(turAuthenticationEntryPoint))
.authorizeHttpRequests(authorizeRequests -> {
authorizeRequests.requestMatchers(
mvc.pattern("/error/**"),
mvc.pattern("/api/discovery"),
mvc.pattern("/logout"),
mvc.pattern("/index.html"),
Expand Down
10 changes: 10 additions & 0 deletions turing-app/src/main/resources/public/error/401.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0; url=/welcome">
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Not Authorized</title>
</head>
<body>
</body>
</html>
85 changes: 85 additions & 0 deletions turing-app/src/main/resources/public/error/403.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Forbidden</title>
<style type="text/css" media="screen">
body {
background-color: #f1f1f1;
margin: 0;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.container {
margin: 50px auto 40px auto;
width: 600px;
text-align: center;
}

a {
color: #4183c4;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

h1 {
width: 800px;
position: relative;
left: -100px;
letter-spacing: -1px;
line-height: 60px;
font-size: 60px;
font-weight: 100;
margin: 0px 0 50px 0;
text-shadow: 0 1px 0 #fff;
}

p {
color: rgba(0, 0, 0, 0.5);
margin: 20px 0;
line-height: 1.6;
}

ul {
list-style: none;
margin: 25px 0;
padding: 0;
}

li {
display: table-cell;
font-weight: bold;
width: 1%;
}

@media only screen and (-webkit-min-device-pixel-ratio: 2) , only screen and (
min--moz-device-pixel-ratio: 2) , only screen and (
-o-min-device-pixel-ratio: 2/1) , only screen and (
min-device-pixel-ratio: 2) , only screen and ( min-resolution: 192dpi)
, only screen and ( min-resolution: 2dppx) {
.logo-img-1x {
display: none;
}
.logo-img-2x {
display: inline-block;
}
}
</style>
</head>
<body>

<div class="container">

<h1>403</h1>
<p>
<strong>Forbidden</strong>
</p>

<p>You do not have permission to access this page.</p>

</div>
</body>
</html>
89 changes: 89 additions & 0 deletions turing-app/src/main/resources/public/error/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Security-Policy"
content="default-src 'none'; style-src 'unsafe-inline'; img-src data:; connect-src 'self'">
<title>Page not found</title>
<style type="text/css" media="screen">
body {
background-color: #f1f1f1;
margin: 0;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.container {
margin: 50px auto 40px auto;
width: 600px;
text-align: center;
}

a {
color: #4183c4;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

h1 {
width: 800px;
position: relative;
left: -100px;
letter-spacing: -1px;
line-height: 60px;
font-size: 60px;
font-weight: 100;
margin: 0px 0 50px 0;
text-shadow: 0 1px 0 #fff;
}

p {
color: rgba(0, 0, 0, 0.5);
margin: 20px 0;
line-height: 1.6;
}

ul {
list-style: none;
margin: 25px 0;
padding: 0;
}

li {
display: table-cell;
font-weight: bold;
width: 1%;
}

@media only screen and (-webkit-min-device-pixel-ratio: 2) , only screen and (
min--moz-device-pixel-ratio: 2) , only screen and (
-o-min-device-pixel-ratio: 2/1) , only screen and (
min-device-pixel-ratio: 2) , only screen and ( min-resolution: 192dpi)
, only screen and ( min-resolution: 2dppx) {
.logo-img-1x {
display: none;
}
.logo-img-2x {
display: inline-block;
}
}
</style>
</head>
<body>

<div class="container">

<h1>404</h1>
<p>
<strong>File not found</strong>
</p>

<p>Something went wrong</p>

<p>The page you are looking for has been removed, had its name
changed or temporarily unavailable.</p>
</div>
</body>
</html>
88 changes: 88 additions & 0 deletions turing-app/src/main/resources/public/error/500.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Security-Policy"
content="default-src 'none'; style-src 'unsafe-inline'; img-src data:; connect-src 'self'">
<title>That's an error</title>
<style type="text/css" media="screen">
body {
background-color: #f1f1f1;
margin: 0;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.container {
margin: 50px auto 40px auto;
width: 600px;
text-align: center;
}

a {
color: #4183c4;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

h1 {
width: 800px;
position: relative;
left: -100px;
letter-spacing: -1px;
line-height: 60px;
font-size: 60px;
font-weight: 100;
margin: 0px 0 50px 0;
text-shadow: 0 1px 0 #fff;
}

p {
color: rgba(0, 0, 0, 0.5);
margin: 20px 0;
line-height: 1.6;
}

ul {
list-style: none;
margin: 25px 0;
padding: 0;
}

li {
display: table-cell;
font-weight: bold;
width: 1%;
}

@media only screen and (-webkit-min-device-pixel-ratio: 2) , only screen and (
min--moz-device-pixel-ratio: 2) , only screen and (
-o-min-device-pixel-ratio: 2/1) , only screen and (
min-device-pixel-ratio: 2) , only screen and ( min-resolution: 192dpi)
, only screen and ( min-resolution: 2dppx) {
.logo-img-1x {
display: none;
}
.logo-img-2x {
display: inline-block;
}
}
</style>
</head>
<body>

<div class="container">

<h1>500</h1>
<p>
<strong>That's an error</strong>
</p>

<p>Something has gone seriously wrong.</p>

<p>We're experiencing an internal server problem.<br> Please try back later.</p>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private TurCommonsUtils() {

public static URI addOrReplaceParameter(URI uri, String paramName, String paramValue) {

List<NameValuePair> params = URLEncodedUtils.parse(uri, StandardCharsets.UTF_8.name());
List<NameValuePair> params = URLEncodedUtils.parse(uri, StandardCharsets.UTF_8);

StringBuilder sbQueryString = new StringBuilder();
boolean alreadyExists = false;
Expand Down

0 comments on commit a467eba

Please sign in to comment.