We can now use our PGT to create a PT to authenticate it to a service. The code to do this is quite trivially demonstrated in the EchoController class that we have included with this chapter. You can see the relevant portions of it in the following code snippet. For additional details, refer to the sample's source code:
//src/main/java/com/packtpub/springsecurity/web/controllers/
EchoController.java
@ResponseBody
@RequestMapping("/echo")
public String echo() throws UnsupportedEncodingException {
final CasAuthenticationToken token = (CasAuthenticationToken)
SecurityContextHolder.getContext().getAuthentication();
final String proxyTicket = token.getAssertion().getPrincipal()
.getProxyTicketFor(targetUrl);
return restClient.getForObject(targetUrl+"?ticket={pt}",
String.class, proxyTicket);
}
This...