use of org.apereo.portal.security.provider.cas.CasProxyTicketAcquisitionException in project uPortal by Jasig.
the class CasTicketUserInfoService method getProxyTicket.
/**
* Attempt to get a proxy ticket for the current portlet.
*
* @param request portlet request
* @return a proxy ticket, or <code>null</code> if we were unsuccessful
*/
private String getProxyTicket(PortletRequest request) {
final HttpServletRequest httpServletRequest = this.portalRequestUtils.getPortletHttpRequest(request);
// try to determine the URL for our portlet
String targetService = null;
try {
URL url = null;
// if the server port is 80 or 443, don't include it in the URL
int port = request.getServerPort();
if (port == 80 || port == 443)
url = new URL(request.getScheme(), request.getServerName(), request.getContextPath());
else
url = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), request.getContextPath());
targetService = url.toString();
} catch (MalformedURLException e) {
log.error("Failed to create a URL for the target portlet", e);
e.printStackTrace();
return null;
}
// get the CasSecurityContext
final IUserInstance userInstance = userInstanceManager.getUserInstance(httpServletRequest);
final IPerson person = userInstance.getPerson();
final ISecurityContext context = person.getSecurityContext();
if (context == null) {
log.error("no security context, no proxy ticket passed to the portlet");
return null;
}
ISecurityContext casContext = getCasContext(context);
if (casContext == null) {
log.debug("no CAS security context, no proxy ticket passed to the portlet");
return null;
}
if (!casContext.isAuthenticated()) {
log.debug("no CAS authentication, no proxy ticket passed to the portlet");
return null;
}
// get a proxy ticket for our portlet from the CasSecurityContext
String proxyTicket = null;
try {
proxyTicket = ((ICasSecurityContext) casContext).getCasServiceToken(targetService);
log.debug("Put proxy ticket in userinfo: " + proxyTicket);
} catch (CasProxyTicketAcquisitionException e) {
log.error("no proxy ticket passed to the portlet: " + e);
}
return proxyTicket;
}
Aggregations