Search in sources :

Example 1 with IPortalUrlBuilder

use of org.apereo.portal.url.IPortalUrlBuilder in project uPortal by Jasig.

the class PortletAdministrationHelper method getFragmentAdminURL.

/**
     * Get the link to the fragment admin portlet.
     *
     * @param request the current http request.
     * @return the portlet link
     */
public String getFragmentAdminURL(HttpServletRequest request) {
    IPortalUrlBuilder builder = urlProvider.getPortalUrlBuilderByPortletFName(request, PORTLET_FNAME_FRAGMENT_ADMIN_PORTLET, UrlType.RENDER);
    IPortletUrlBuilder portletUrlBuilder = builder.getTargetedPortletUrlBuilder();
    portletUrlBuilder.setPortletMode(PortletMode.VIEW);
    portletUrlBuilder.setWindowState(WindowState.MAXIMIZED);
    return builder.getUrlString();
}
Also used : IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder)

Example 2 with IPortalUrlBuilder

use of org.apereo.portal.url.IPortalUrlBuilder in project uPortal by Jasig.

the class LoginController method service.

/**
     * Process the incoming HttpServletRequest. Note that this processing occurs after
     * PortalPreAuthenticatedProcessingFilter has run and performed pre-processing.
     *
     * @param request
     * @param response
     * @exception ServletException
     * @exception IOException
     */
@RequestMapping
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
    // create the redirect URL, adding fname and args parameters if necessary
    String redirectTarget = null;
    final String refUrl = request.getParameter(REFERER_URL_PARAM);
    final URL redirectLocation = parseLocalRefUrl(request, refUrl);
    if (redirectLocation != null) {
        redirectTarget = redirectLocation.toString();
    }
    if (redirectTarget == null) {
        /* Grab the target functional name, if any, off the login request.
             * Also any arguments for the target. We will pass them  along after authentication.
             */
        String targetFname = request.getParameter("uP_fname");
        if (targetFname == null) {
            final IPortalUrlBuilder defaultUrl = this.portalUrlProvider.getDefaultUrl(request);
            redirectTarget = defaultUrl.getUrlString();
        } else {
            try {
                final IPortalUrlBuilder urlBuilder = this.portalUrlProvider.getPortalUrlBuilderByPortletFName(request, targetFname, UrlType.RENDER);
                Enumeration<String> e = request.getParameterNames();
                while (e.hasMoreElements()) {
                    String paramName = e.nextElement();
                    if (!paramName.equals("uP_fname")) {
                        urlBuilder.addParameter(paramName, request.getParameterValues(paramName));
                    }
                }
                redirectTarget = urlBuilder.getUrlString();
            } catch (IllegalArgumentException e) {
                final IPortalUrlBuilder defaultUrl = this.portalUrlProvider.getDefaultUrl(request);
                redirectTarget = defaultUrl.getUrlString();
            }
        }
    }
    IPerson person = null;
    final Object authError = request.getSession(false).getAttribute(LoginController.AUTH_ERROR_KEY);
    if (authError == null || !((Boolean) authError)) {
        person = this.personManager.getPerson(request);
    }
    if (person == null || !person.getSecurityContext().isAuthenticated()) {
        if (request.getMethod().equals("POST"))
            request.getSession(false).setAttribute(AUTH_ATTEMPTED_KEY, "true");
        // Preserve the attempted username so it can be redisplayed to the user
        String attemptedUserName = request.getParameter("userName");
        if (attemptedUserName != null)
            request.getSession(false).setAttribute(ATTEMPTED_USERNAME_KEY, request.getParameter("userName"));
    }
    final String encodedRedirectURL = response.encodeRedirectURL(redirectTarget);
    if (log.isDebugEnabled()) {
        log.debug("Redirecting to " + redirectTarget);
    }
    response.sendRedirect(encodedRedirectURL);
}
Also used : IPerson(org.apereo.portal.security.IPerson) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) URL(java.net.URL) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with IPortalUrlBuilder

use of org.apereo.portal.url.IPortalUrlBuilder in project uPortal by Jasig.

the class PortletUtils method getStringFromPortletUrl.

/**
     * A static EL function that is defined in portletUrl.tld Takes a portletUrl object and coverts
     * it into an actual Url Example is in search, returns a marketplace entry Url
     *
     * @param portletUrl
     * @param request
     * @return the Url represented by portletUrl
     */
public static String getStringFromPortletUrl(PortletUrl portletUrl, HttpServletRequest request) {
    if (portletUrl == null) {
        return null;
    }
    //Default urlType
    UrlType urlType = UrlType.RENDER;
    final PortletUrlType type = portletUrl.getType();
    switch(type) {
        case ACTION:
            urlType = UrlType.ACTION;
            break;
        case RESOURCE:
            urlType = UrlType.RESOURCE;
            break;
        default:
            urlType = UrlType.RENDER;
            break;
    }
    IPortletWindow marketplaceWindow = portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(request, MarketplacePortletDefinition.MARKETPLACE_FNAME);
    IPortalUrlBuilder portalUrlBuilder = portalUrlProvider.getPortalUrlBuilderByPortletWindow(request, marketplaceWindow.getPortletWindowId(), urlType);
    IPortletUrlBuilder portletUrlBuilder = portalUrlBuilder.getTargetedPortletUrlBuilder();
    final String portletMode = portletUrl.getPortletMode();
    if (portletMode != null) {
        portletUrlBuilder.setPortletMode(PortletUtils.getPortletMode(portletMode));
    }
    final String windowState = portletUrl.getWindowState();
    if (windowState != null) {
        portletUrlBuilder.setWindowState(PortletUtils.getWindowState(windowState));
    }
    for (final PortletUrlParameter param : portletUrl.getParam()) {
        final String name = param.getName();
        final List<String> values = param.getValue();
        portletUrlBuilder.addParameter(name, values.toArray(new String[values.size()]));
    }
    return portalUrlBuilder.getUrlString();
}
Also used : IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) PortletUrlParameter(org.apereo.portal.search.PortletUrlParameter) PortletUrlType(org.apereo.portal.search.PortletUrlType) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) PortletUrlType(org.apereo.portal.search.PortletUrlType) UrlType(org.apereo.portal.url.UrlType) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow)

Example 4 with IPortalUrlBuilder

use of org.apereo.portal.url.IPortalUrlBuilder in project uPortal by Jasig.

the class PortletRedirectionController method getUrlString.

protected String getUrlString(IRedirectionUrl url, HttpServletRequest request, List<String> extraPath) {
    if (url instanceof ExternalRedirectionUrl) {
        ExternalRedirectionUrl externalUrl = (ExternalRedirectionUrl) url;
        StringBuffer urlStr = new StringBuffer();
        urlStr.append(externalUrl.getUrl());
        try {
            // add any additional parameters
            String separator = "?";
            for (Map.Entry<String, String[]> param : externalUrl.getAdditionalParameters().entrySet()) {
                for (String value : param.getValue()) {
                    urlStr.append(separator);
                    urlStr.append(param.getKey());
                    urlStr.append("=");
                    urlStr.append(URLEncoder.encode(value, "UTF-8"));
                    separator = "&";
                }
            }
            // add any dynamic parameters
            for (Map.Entry<String, String> param : externalUrl.getDynamicParameters().entrySet()) {
                String[] values = request.getParameterValues(param.getKey());
                if (values != null) {
                    for (String value : values) {
                        urlStr.append(separator);
                        urlStr.append(param.getValue());
                        urlStr.append("=");
                        urlStr.append(URLEncoder.encode(value, "UTF-8"));
                        separator = "&";
                    }
                }
            }
            if (!extraPath.isEmpty()) {
                List<String> paramNames = externalUrl.getPathParameters();
                ListIterator<String> itt = paramNames.listIterator();
                while (itt.hasNext() && !extraPath.isEmpty()) {
                    String param = itt.next();
                    String value;
                    if (itt.hasNext()) {
                        value = extraPath.remove(0);
                    } else {
                        value = StringUtils.join(extraPath, "/");
                    }
                    urlStr.append(separator);
                    urlStr.append(param);
                    urlStr.append("=");
                    urlStr.append(URLEncoder.encode(value, "UTF-8"));
                    separator = "&";
                }
            }
            return urlStr.toString();
        } catch (UnsupportedEncodingException ex) {
            log.error("Unable to encode URL parameter for external service redirect", ex);
            return null;
        }
    } else {
        PortletRedirectionUrl portletUrl = (PortletRedirectionUrl) url;
        // create the base URL for the portlet
        final IPortletWindow portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(request, portletUrl.getFname());
        final IPortalUrlBuilder portalUrlBuilder = this.portalUrlProvider.getPortalUrlBuilderByPortletWindow(request, portletWindow.getPortletWindowId(), portletUrl.getType());
        final IPortletUrlBuilder portletUrlBuilder = portalUrlBuilder.getTargetedPortletUrlBuilder();
        portletUrlBuilder.setPortletMode(portletUrl.getMode());
        portletUrlBuilder.setWindowState(WindowState.MAXIMIZED);
        // parameter to the portlet URL
        for (Map.Entry<String, String[]> param : portletUrl.getAdditionalParameters().entrySet()) {
            portletUrlBuilder.addParameter(param.getKey(), param.getValue());
        }
        // the value submitted to this service was non-null
        for (Map.Entry<String, String> param : portletUrl.getDynamicParameters().entrySet()) {
            String[] values = request.getParameterValues(param.getKey());
            if (values != null) {
                portletUrlBuilder.addParameter(param.getValue(), values);
            }
        }
        if (!extraPath.isEmpty()) {
            List<String> paramNames = portletUrl.getPathParameters();
            ListIterator<String> itt = paramNames.listIterator();
            while (itt.hasNext() && !extraPath.isEmpty()) {
                String param = itt.next();
                String value;
                if (itt.hasNext()) {
                    value = extraPath.remove(0);
                } else {
                    value = StringUtils.join(extraPath, "/");
                }
                if (StringUtils.isEmpty(value)) {
                    break;
                } else
                    portletUrlBuilder.addParameter(param, value);
            }
        }
        return portalUrlBuilder.getUrlString();
    }
}
Also used : IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) Map(java.util.Map)

Example 5 with IPortalUrlBuilder

use of org.apereo.portal.url.IPortalUrlBuilder in project uPortal by Jasig.

the class RenderingPipelineIntegrationTest method testRenderingPipeline.

@Test
public void testRenderingPipeline() throws Exception {
    final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    final DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
    final Document doc = builder.newDocument();
    final DocumentFragment headFragment = doc.createDocumentFragment();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final IPortalUrlBuilder portalUrlBuilder = mock(IPortalUrlBuilder.class);
    final IPortletUrlBuilder portletUrlBuilder = mock(IPortletUrlBuilder.class);
    when(portalUrlBuilder.getUrlString()).thenReturn("URL_PLACEHOLDER");
    when(portletUrlBuilder.getPortalUrlBuilder()).thenReturn(portalUrlBuilder);
    when(portalUrlBuilder.getTargetedPortletUrlBuilder()).thenReturn(portletUrlBuilder);
    when(portalUrlBuilder.getPortletUrlBuilder(any(IPortletWindowId.class))).thenReturn(portletUrlBuilder);
    when(this.resourcesElementsProvider.getResourcesXmlFragment(any(HttpServletRequest.class), eq("/media/skins/respondr/defaultSkin/skin.xml"))).thenReturn(headFragment.getChildNodes());
    when(this.portalUrlProvider.getDefaultUrl(any(HttpServletRequest.class))).thenReturn(portalUrlBuilder);
    when(this.portalUrlProvider.getPortalUrlBuilderByLayoutNode(any(HttpServletRequest.class), any(String.class), any(UrlType.class))).thenReturn(portalUrlBuilder);
    when(this.portalUrlProvider.getPortalUrlBuilderByPortletFName(any(HttpServletRequest.class), any(String.class), any(UrlType.class))).thenReturn(portalUrlBuilder);
    final IPortletWindow portletWindow = mock(IPortletWindow.class);
    when(portletWindowRegistry.getPortletWindow(any(HttpServletRequest.class), any(StartElement.class))).thenReturn(new Tuple<IPortletWindow, StartElement>(portletWindow, null));
    when(portletWindowRegistry.getOrCreateDefaultPortletWindowByLayoutNodeId(any(HttpServletRequest.class), any(String.class))).thenReturn(portletWindow);
    when(portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(any(HttpServletRequest.class), anyString())).thenReturn(portletWindow);
    when(portletWindow.getPortletWindowId()).thenReturn(new MockPortletWindowId("1"));
    final PipelineEventReader<?, ?> eventReader = this.component.getEventReader(request, response);
    for (final Object event : eventReader) {
        logger.debug(toString(event));
    }
    final String mediaType = eventReader.getOutputProperty(OutputKeys.MEDIA_TYPE);
    assertEquals("text/html", mediaType);
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) Matchers.anyString(org.mockito.Matchers.anyString) Document(org.w3c.dom.Document) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) StartElement(javax.xml.stream.events.StartElement) DocumentBuilder(javax.xml.parsers.DocumentBuilder) UrlType(org.apereo.portal.url.UrlType) DocumentFragment(org.w3c.dom.DocumentFragment) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) Test(org.junit.Test)

Aggregations

IPortalUrlBuilder (org.apereo.portal.url.IPortalUrlBuilder)17 IPortletUrlBuilder (org.apereo.portal.url.IPortletUrlBuilder)11 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)6 UrlType (org.apereo.portal.url.UrlType)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)4 PortletUrlParameter (org.apereo.portal.search.PortletUrlParameter)3 URL (java.net.URL)2 PortletUrl (org.apereo.portal.search.PortletUrl)2 PortletUrlType (org.apereo.portal.search.PortletUrlType)2 SearchResult (org.apereo.portal.search.SearchResult)2 SearchResults (org.apereo.portal.search.SearchResults)2 IPerson (org.apereo.portal.security.IPerson)2 IUserInstance (org.apereo.portal.user.IUserInstance)2 Document (org.w3c.dom.Document)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1