SEC-2915: Updated Java Code Formatting
This commit is contained in:
@@ -29,51 +29,61 @@ import org.springframework.security.cas.authentication.CasAuthenticationToken;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* {@link ProxyTicketSampleServlet} demonstrates how to obtain a proxy ticket
|
||||
* and then use it to make a remote call. To learn how proxy tickets work, see
|
||||
* the <a href="https://wiki.jasig.org/display/CAS/Proxy+CAS+Walkthrough">Proxy
|
||||
* CAS Walkthrough</a>
|
||||
* {@link ProxyTicketSampleServlet} demonstrates how to obtain a proxy ticket and then use
|
||||
* it to make a remote call. To learn how proxy tickets work, see the <a
|
||||
* href="https://wiki.jasig.org/display/CAS/Proxy+CAS+Walkthrough">Proxy CAS
|
||||
* Walkthrough</a>
|
||||
* </p>
|
||||
*
|
||||
* @author Rob Winch
|
||||
*/
|
||||
public final class ProxyTicketSampleServlet extends HttpServlet {
|
||||
/**
|
||||
* This is the URL that will be called and authenticate a proxy ticket.
|
||||
*/
|
||||
private String targetUrl;
|
||||
/**
|
||||
* This is the URL that will be called and authenticate a proxy ticket.
|
||||
*/
|
||||
private String targetUrl;
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
// NOTE: The CasAuthenticationToken can also be obtained using SecurityContextHolder.getContext().getAuthentication()
|
||||
final CasAuthenticationToken token = (CasAuthenticationToken) request.getUserPrincipal();
|
||||
// proxyTicket could be reused to make calls to to the CAS service even if the target url differs
|
||||
final String proxyTicket = token.getAssertion().getPrincipal().getProxyTicketFor(targetUrl);
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
// NOTE: The CasAuthenticationToken can also be obtained using
|
||||
// SecurityContextHolder.getContext().getAuthentication()
|
||||
final CasAuthenticationToken token = (CasAuthenticationToken) request
|
||||
.getUserPrincipal();
|
||||
// proxyTicket could be reused to make calls to to the CAS service even if the
|
||||
// target url differs
|
||||
final String proxyTicket = token.getAssertion().getPrincipal()
|
||||
.getProxyTicketFor(targetUrl);
|
||||
|
||||
// Make a remote call to ourself. This is a bit silly, but it works well to demonstrate how to use proxy tickets.
|
||||
final String serviceUrl = targetUrl+"?ticket="+URLEncoder.encode(proxyTicket, "UTF-8");
|
||||
String proxyResponse = CommonUtils.getResponseFromServer(serviceUrl, "UTF-8");
|
||||
// Make a remote call to ourself. This is a bit silly, but it works well to
|
||||
// demonstrate how to use proxy tickets.
|
||||
final String serviceUrl = targetUrl + "?ticket="
|
||||
+ URLEncoder.encode(proxyTicket, "UTF-8");
|
||||
String proxyResponse = CommonUtils.getResponseFromServer(serviceUrl, "UTF-8");
|
||||
|
||||
// modify the response and write it out to inform the user that it was obtained using a proxy ticket.
|
||||
proxyResponse = proxyResponse.replaceFirst("Secure Page", "Secure Page using a Proxy Ticket");
|
||||
proxyResponse = proxyResponse.replaceFirst("<p>",
|
||||
"<p>This page is rendered by "+getClass().getSimpleName()+" by making a remote call to the Secure Page using a proxy ticket ("+proxyTicket+") and inserts this message. ");
|
||||
final PrintWriter writer = response.getWriter();
|
||||
writer.write(proxyResponse);
|
||||
}
|
||||
// modify the response and write it out to inform the user that it was obtained
|
||||
// using a proxy ticket.
|
||||
proxyResponse = proxyResponse.replaceFirst("Secure Page",
|
||||
"Secure Page using a Proxy Ticket");
|
||||
proxyResponse = proxyResponse.replaceFirst("<p>", "<p>This page is rendered by "
|
||||
+ getClass().getSimpleName()
|
||||
+ " by making a remote call to the Secure Page using a proxy ticket ("
|
||||
+ proxyTicket + ") and inserts this message. ");
|
||||
final PrintWriter writer = response.getWriter();
|
||||
writer.write(proxyResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the target URL. It allows for the host to change based upon
|
||||
* the "cas.service.host" system property. If the property is not set, the
|
||||
* default is "localhost:8443".
|
||||
*/
|
||||
@Override
|
||||
public void init() throws ServletException {
|
||||
super.init();
|
||||
String casServiceHost = System.getProperty("cas.service.host", "localhost:8443");
|
||||
targetUrl = "https://"+casServiceHost+"/cas-sample/secure/";
|
||||
}
|
||||
/**
|
||||
* Initialize the target URL. It allows for the host to change based upon the
|
||||
* "cas.service.host" system property. If the property is not set, the default is
|
||||
* "localhost:8443".
|
||||
*/
|
||||
@Override
|
||||
public void init() throws ServletException {
|
||||
super.init();
|
||||
String casServiceHost = System.getProperty("cas.service.host", "localhost:8443");
|
||||
targetUrl = "https://" + casServiceHost + "/cas-sample/secure/";
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = -7720161771819727775L;
|
||||
private static final long serialVersionUID = -7720161771819727775L;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user