This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cfid-298] HTML content for access-denied error, instead of the defau…
…lt XML Fixes [#39186207] Change-Id: I61bb21a9a1b2e00676b7d69ae833d26c3898f5c8
- Loading branch information
Showing
7 changed files
with
148 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...oard/src/main/java/com/cloudfoundry/dashboard/authentication/ForwardingLogoutHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.cloudfoundry.dashboard.authentication; | ||
|
||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; | ||
|
||
import javax.servlet.RequestDispatcher; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
public class ForwardingLogoutHandler implements LogoutSuccessHandler { | ||
|
||
private String onLogoutPage = "logout.jsp"; | ||
|
||
private Map<String, String> logoutPageAttributes = Collections.emptyMap(); | ||
|
||
public void setOnLogoutPage(String onLogoutPage) { | ||
this.onLogoutPage = onLogoutPage; | ||
} | ||
|
||
public void setLogoutPageAttributes(Map<String, String> logoutPageAttributes) { | ||
this.logoutPageAttributes = logoutPageAttributes; | ||
} | ||
|
||
@Override | ||
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { | ||
for (String attr : logoutPageAttributes.keySet()) { | ||
request.setAttribute(attr, logoutPageAttributes.get(attr)); | ||
} | ||
// forward to configured page | ||
RequestDispatcher dispatcher = request.getRequestDispatcher(onLogoutPage); | ||
dispatcher.forward(request, response); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
.../src/main/java/com/cloudfoundry/dashboard/authentication/RedirectAccessDeniedHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.cloudfoundry.dashboard.authentication; | ||
|
||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.security.access.AccessDeniedException; | ||
import org.springframework.security.web.WebAttributes; | ||
import org.springframework.security.web.access.AccessDeniedHandler; | ||
import org.springframework.security.web.access.AccessDeniedHandlerImpl; | ||
import org.springframework.util.Assert; | ||
import org.springframework.util.StringUtils; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
public class RedirectAccessDeniedHandler implements AccessDeniedHandler, InitializingBean { | ||
|
||
private String redirectUrl; | ||
|
||
public void setRedirectUrl(String redirectUrl) { | ||
this.redirectUrl = redirectUrl; | ||
} | ||
|
||
@Override | ||
public void afterPropertiesSet() throws Exception { | ||
Assert.notNull(redirectUrl, "Please supply a redirect-url"); | ||
} | ||
|
||
@Override | ||
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { | ||
response.sendRedirect(response.encodeRedirectURL(redirectUrl)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,30 @@ | ||
<%@ page import="org.springframework.security.web.WebAttributes" %> | ||
<%@ page import="org.springframework.security.access.AccessDeniedException" %> | ||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> | ||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> | ||
|
||
<html> | ||
<head><title>Access Denied</title></head> | ||
<body> | ||
|
||
<h1>Sample Error Page</h1> | ||
|
||
<p> | ||
There was a problem logging you in. Don't panic. | ||
</p> | ||
<% | ||
if (request.getAttribute(WebAttributes.ACCESS_DENIED_403) != null) { | ||
%> | ||
<div class="error"> | ||
<h3> | ||
<p> | ||
<%= ((AccessDeniedException)request.getAttribute(WebAttributes.ACCESS_DENIED_403)).getMessage() %> | ||
</p> | ||
</h3> | ||
<p> | ||
<%= request.getAttribute(WebAttributes.ACCESS_DENIED_403) %> | ||
Oops! It looks like you don't have the necessary authorizations to access this resource. Click <a href="logout">here</a> to logout of Dashboard. | ||
<br /> | ||
<b>Please contact your system administrator for access permissions before trying again!</b> <br /> | ||
</p> | ||
</div> | ||
<% | ||
} | ||
%> | ||
|
||
</body> | ||
</html> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<%@ page import="org.springframework.security.web.WebAttributes" %> | ||
<%@ page import="org.springframework.security.access.AccessDeniedException" %> | ||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> | ||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> | ||
|
||
<html> | ||
<head><title>Dashboard Logout</title></head> | ||
<body> | ||
|
||
<% | ||
if (request.getParameter("access_denied") != null && "true".equals(request.getParameter("access_denied").toLowerCase())) { | ||
%> | ||
<div class="error"> | ||
<h3> | ||
<p> | ||
Access is denied | ||
</p> | ||
</h3> | ||
<p> | ||
Oops! It looks like you don't have the necessary authorizations to access this resource. | ||
<br /> | ||
<b>Please contact your system administrator for access permissions before trying again!</b> <br /> | ||
</p> | ||
</div> | ||
<% | ||
} | ||
%> | ||
|
||
<div class="logout"> | ||
<p> | ||
You have been logged out of Dashboard. | ||
<% | ||
if (request.getParameter("slo") == null || "false".equals(request.getParameter("slo").toLowerCase())) { | ||
String callbackUrl = request.getRequestURL().append("?slo=true").toString(); | ||
String sloUrl = request.getAttribute("uaaUrl") != null ? request.getAttribute("uaaUrl") + "/logout.do?redirect=" + response.encodeRedirectURL(callbackUrl) : "logout?slo=true"; | ||
%> | ||
<br /> | ||
Click <a href="<%= sloUrl %>">here</a> to logout of CloudFoundry too. | ||
<% | ||
} | ||
%> | ||
</p> | ||
</div> | ||
|
||
</body> | ||
</html> |