Search in sources :

Example 1 with CasProxyTicketAcquisitionException

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) MalformedURLException(java.net.MalformedURLException) ISecurityContext(org.apereo.portal.security.ISecurityContext) URL(java.net.URL) CasProxyTicketAcquisitionException(org.apereo.portal.security.provider.cas.CasProxyTicketAcquisitionException)

Aggregations

MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 IPerson (org.apereo.portal.security.IPerson)1 ISecurityContext (org.apereo.portal.security.ISecurityContext)1 CasProxyTicketAcquisitionException (org.apereo.portal.security.provider.cas.CasProxyTicketAcquisitionException)1 IUserInstance (org.apereo.portal.user.IUserInstance)1