Example usage for com.liferay.portal.kernel.util Http HTTP

List of usage examples for com.liferay.portal.kernel.util Http HTTP

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util Http HTTP.

Prototype

String HTTP

To view the source code for com.liferay.portal.kernel.util Http HTTP.

Click Source Link

Usage

From source file:com.cd.learning.hook.MBUtil.java

License:Open Source License

private static String[] _findThreadPriority(double value, ThemeDisplay themeDisplay, String[] priorities) {

    for (int i = 0; i < priorities.length; i++) {
        String[] priority = StringUtil.split(priorities[i]);

        try {/*  ww w  .  ja  va 2  s .  com*/
            String priorityName = priority[0];
            String priorityImage = priority[1];
            double priorityValue = GetterUtil.getDouble(priority[2]);

            if (value == priorityValue) {
                if (!priorityImage.startsWith(Http.HTTP)) {
                    priorityImage = themeDisplay.getPathThemeImages() + priorityImage;
                }

                return new String[] { priorityName, priorityImage };
            }
        } catch (Exception e) {
            _log.error("Unable to determine thread priority", e);
        }
    }

    return null;
}

From source file:com.liferay.content.targeting.analytics.hook.filter.YoutubeVideoHtmlFilter.java

License:Open Source License

private String sanitizeURL(String url, boolean secure) {
    if (url.startsWith(StringPool.DOUBLE_SLASH)) {
        url = url.replace(StringPool.DOUBLE_SLASH, StringPool.BLANK);
    }/*from ww w.ja v a 2  s. co  m*/

    if (!url.startsWith(Http.HTTP)) {
        url = Http.HTTP_WITH_SLASH + url;
    }

    return HttpUtil.protocolize(url, secure);
}

From source file:com.liferay.faces.demos.bean.LoginBackingBean.java

License:Open Source License

public void authenticate() {

    LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
    ActionRequest actionRequest = (ActionRequest) liferayFacesContext.getPortletRequest();
    ActionResponse actionResponse = (ActionResponse) liferayFacesContext.getPortletResponse();
    ThemeDisplay themeDisplay = liferayFacesContext.getThemeDisplay();
    HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(actionRequest);

    // If the request object is a wrapper that handles special namespacing considerations for portlet session
    // attributes, then get the inner-most wrapped request. This will ensure that the following call to
    // LoginUtil.login(...) will be able to work with a session that has an attribute map shared by the portal.
    if (httpServletRequest.getClass().getName().equals(NAMESPACE_SERVLET_REQUEST_FQCN)) {

        while (httpServletRequest instanceof HttpServletRequestWrapper) {
            HttpServletRequestWrapper httpServletRequestWrapper = (HttpServletRequestWrapper) httpServletRequest;
            httpServletRequest = (HttpServletRequest) httpServletRequestWrapper.getRequest();
        }/*  w ww .j  a  va  2s  .  co  m*/
    }

    HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(actionResponse);

    String handle = loginModelBean.getHandle();
    String password = loginModelBean.getPassword();
    boolean rememberMe = loginModelBean.isRememberMe();

    boolean authenticated = false;
    String feedbackMessageId = null;

    try {

        LoginUtilCompat.invokeLogin(httpServletRequest, httpServletResponse, handle, password, rememberMe,
                authType);

        authenticated = true;
    } catch (AuthException e) {
        feedbackMessageId = "authentication-failed";
    } catch (CompanyMaxUsersException e) {
        feedbackMessageId = "unable-to-login-because-the-maximum-number-of-users-has-been-reached";
    } catch (CookieNotSupportedException e) {
        feedbackMessageId = "authentication-failed-please-enable-browser-cookies";
    } catch (NoSuchUserException e) {
        feedbackMessageId = "authentication-failed";
    } catch (PasswordExpiredException e) {
        feedbackMessageId = "your-password-has-expired";
    } catch (UserEmailAddressException e) {
        feedbackMessageId = "authentication-failed";
    } catch (UserLockoutException e) {
        feedbackMessageId = "this-account-has-been-locked";
    } catch (UserPasswordException e) {
        feedbackMessageId = "authentication-failed";
    } catch (UserScreenNameException e) {
        feedbackMessageId = "authentication-failed";
    } catch (Exception e) {
        logger.error(e);
    }

    if (authenticated) {

        try {
            ExternalContext externalContext = liferayFacesContext.getExternalContext();

            if (PropsValuesCompat.PORTAL_JAAS_ENABLE) {
                externalContext.redirect(themeDisplay.getPathMain() + "/portal/protected");
            } else {
                String redirect = ParamUtil.getString(actionRequest, "redirect");

                if (Validator.isNotNull(redirect)) {
                    redirect = PortalUtilCompat.escapeRedirect(redirect);

                    if (!redirect.startsWith(Http.HTTP)) {
                        redirect = getCompleteRedirectURL(httpServletRequest, redirect);
                    }

                    externalContext.redirect(redirect);
                } else {
                    boolean doActionAfterLogin = ParamUtil.getBoolean(actionRequest, "doActionAfterLogin");

                    if (doActionAfterLogin) {
                        return;
                    } else {

                        redirect = getCompleteRedirectURL(httpServletRequest, themeDisplay.getPathMain());
                        externalContext.redirect(redirect);
                    }
                }
            }
        } catch (IOException e) {
            logger.error(e);
            liferayFacesContext.addGlobalUnexpectedErrorMessage();
        }
    } else {

        if (feedbackMessageId != null) {
            liferayFacesContext.addGlobalErrorMessage(feedbackMessageId);
        }
    }
}

From source file:com.liferay.login.web.internal.portlet.action.LoginMVCActionCommand.java

License:Open Source License

protected void login(ThemeDisplay themeDisplay, ActionRequest actionRequest, ActionResponse actionResponse)
        throws Exception {

    HttpServletRequest request = _portal
            .getOriginalServletRequest(_portal.getHttpServletRequest(actionRequest));
    HttpServletResponse response = _portal.getHttpServletResponse(actionResponse);

    String login = ParamUtil.getString(actionRequest, "login");
    String password = actionRequest.getParameter("password");
    boolean rememberMe = ParamUtil.getBoolean(actionRequest, "rememberMe");

    if (!themeDisplay.isSignedIn()) {
        String portletId = _portal.getPortletId(actionRequest);

        PortletPreferences portletPreferences = PortletPreferencesFactoryUtil
                .getStrictPortletSetup(themeDisplay.getLayout(), portletId);

        String authType = portletPreferences.getValue("authType", null);

        _authenticatedSessionManager.login(request, response, login, password, rememberMe, authType);
    }/*from w  w w.  ja  va 2s.  c  o m*/

    String redirect = ParamUtil.getString(actionRequest, "redirect");

    if (Validator.isNotNull(redirect)) {
        redirect = _portal.escapeRedirect(redirect);

        if (Validator.isNotNull(redirect) && !redirect.startsWith(Http.HTTP)) {

            redirect = getCompleteRedirectURL(request, redirect);
        }
    }

    String mainPath = themeDisplay.getPathMain();

    if (PropsValues.PORTAL_JAAS_ENABLE) {
        if (Validator.isNotNull(redirect)) {
            redirect = mainPath.concat("/portal/protected?redirect=").concat(URLCodec.encodeURL(redirect));
        } else {
            redirect = mainPath.concat("/portal/protected");
        }

        actionResponse.sendRedirect(redirect);
    } else {
        if (Validator.isNotNull(redirect)) {
            actionResponse.sendRedirect(redirect);
        } else {
            boolean doActionAfterLogin = ParamUtil.getBoolean(actionRequest, "doActionAfterLogin");

            if (doActionAfterLogin) {
                return;
            } else {
                actionResponse.sendRedirect(mainPath);
            }
        }
    }
}

From source file:com.liferay.portlet.layoutsadmin.util.SitemapImpl.java

License:Open Source License

protected void visitLayout(Element element, Layout layout, ThemeDisplay themeDisplay)
        throws PortalException, SystemException {

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    if (layout.isHidden() || !PortalUtil.isLayoutSitemapable(layout)
            || !GetterUtil.getBoolean(typeSettingsProperties.getProperty("sitemap-include"), true)) {

        return;//ww  w  .jav a 2s  . c om
    }
    //Modification start
    boolean useCdnAsHost = false;
    SiteConfiguration configuration = SiteConfigurationServiceUtil
            .getSiteConfiguration(themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId());
    if (configuration != null && configuration.getHttp404Configuration() != null) {
        useCdnAsHost = configuration.getHttp404Configuration().isRedirectToCdn();
    }

    String virtualHost;

    if (useCdnAsHost) {
        virtualHost = themeDisplay.getCDNHost();
        if (!virtualHost.startsWith(Http.HTTP))
            if (virtualHost.startsWith(StringPool.DOUBLE_SLASH)) {
                virtualHost = Http.HTTP + StringPool.COLON + virtualHost;
            } else
                virtualHost = Http.HTTP_WITH_SLASH + virtualHost;
    } else
        virtualHost = PortalUtil.getPortalURL(layout, themeDisplay);

    String layoutURL = virtualHost;

    if (!layout.isFirstParent())
        layoutURL += layout.getFriendlyURL();

    addURLElement(element, layoutURL, typeSettingsProperties, layout.getModifiedDate());

    String[] als = CommonConfigurationServiceUtil.getService().getAllowedLocales(themeDisplay.getCompanyId(),
            themeDisplay.getScopeGroupId());

    if (als != null) {
        Locale[] availableLocales = LocaleUtil.fromLanguageIds(als);

        if (availableLocales.length > 1) {
            Locale defaultLocale = LocaleUtil.getDefault();

            for (Locale availableLocale : availableLocales) {
                if (availableLocale.equals(defaultLocale)) {
                    continue;
                }
                String alternateURL = virtualHost + buildI18NPath(availableLocale);

                if (!layout.isFirstParent())
                    alternateURL += layout.getFriendlyURL();

                addURLElement(element, alternateURL, typeSettingsProperties, layout.getModifiedDate());
            }
        }
    }

    visitArticles(element, layout, themeDisplay);
    visitLayouts(element, layout.getChildren(), themeDisplay);
}

From source file:com.liferay.portlet.login.action.LoginAction.java

License:Open Source License

protected void login(ThemeDisplay themeDisplay, ActionRequest actionRequest, ActionResponse actionResponse,
        PortletPreferences preferences) throws Exception {

    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
    HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);

    String login = ParamUtil.getString(actionRequest, "login");
    String password = actionRequest.getParameter("password");
    boolean rememberMe = ParamUtil.getBoolean(actionRequest, "rememberMe");

    String authType = preferences.getValue("authType", null);

    //cusotm code =============
    try {//from   ww w.j  ava 2  s .c o  m
        User tmp = null;
        UserEntry userEntryTmp = null;
        if (Validator.isEmailAddress(login)) {
            tmp = UserLocalServiceUtil.getUserByEmailAddress(PortalUtil.getCompanyId(request), login);
            login = String.valueOf(tmp.getUserId());
            System.out.println("email:" + login);
        } else if (Validator.isNumber(login)) {
            // is mobile number
            //            UserEntryLocalServiceUtil.get
            userEntryTmp = UserEntryLocalServiceUtil.findByMobilePhone(login);
            login = String.valueOf(userEntryTmp.getUserId());
            System.out.println("mobile number:" + login);
        } else {
            //userEntryTmp = UserEntryLocalServiceUtil.findByUserName(login);
            tmp = UserLocalServiceUtil.getUserByScreenName(PortalUtil.getCompanyId(request), login);
            login = String.valueOf(tmp.getUserId());
            System.out.println("userName:" + login);
        }
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
        //_log.error(e, e);
    }

    //authType = CompanyConstants.AUTH_TYPE_ID;
    //end cusotm code =============      
    LoginUtil.login(request, response, login, password, rememberMe, authType);

    if (PropsValues.PORTAL_JAAS_ENABLE) {
        actionResponse.sendRedirect(themeDisplay.getPathMain() + "/portal/protected");
    } else {
        String redirect = ParamUtil.getString(actionRequest, "redirect");

        if (Validator.isNotNull(redirect)) {
            redirect = PortalUtil.escapeRedirect(redirect);

            if (!redirect.startsWith(Http.HTTP)) {
                redirect = getCompleteRedirectURL(request, redirect);
            }

            actionResponse.sendRedirect(redirect);
        } else {
            boolean doActionAfterLogin = ParamUtil.getBoolean(actionRequest, "doActionAfterLogin");

            if (doActionAfterLogin) {
                return;
            } else {
                actionResponse.sendRedirect(themeDisplay.getPathMain());
            }
        }
    }
}

From source file:com.liferay.portlet.login.action.SampleLoginAction.java

License:Open Source License

protected void login(ThemeDisplay themeDisplay, ActionRequest actionRequest, ActionResponse actionResponse)
        throws Exception {

    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
    HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);

    String login = ParamUtil.getString(actionRequest, "login");
    System.out.println("login======>>" + login);
    String password = actionRequest.getParameter("password");
    System.out.println("password======>>" + password);
    boolean rememberMe = ParamUtil.getBoolean(actionRequest, "rememberMe");
    System.out.println("rememberMe======>>" + rememberMe);

    if (!themeDisplay.isSignedIn()) {
        PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest);

        String authType = portletPreferences.getValue("authType", null);

        LoginUtil.login(request, response, login, password, rememberMe, authType);
    }/*from  ww  w.  j a  va  2s.com*/

    String redirect = ParamUtil.getString(actionRequest, "redirect");

    if (Validator.isNotNull(redirect)) {
        redirect = PortalUtil.escapeRedirect(redirect);

        if (!redirect.startsWith(Http.HTTP)) {
            redirect = getCompleteRedirectURL(request, redirect);
        }
    }

    String mainPath = themeDisplay.getPathMain();

    if (PropsValues.PORTAL_JAAS_ENABLE) {
        if (Validator.isNotNull(redirect)) {
            redirect = mainPath.concat("/portal/protected?redirect=").concat(redirect);
        } else {
            redirect = mainPath.concat("/portal/protected");
        }

        actionResponse.sendRedirect(redirect);
    } else {
        if (Validator.isNotNull(redirect)) {
            actionResponse.sendRedirect(redirect);
        } else {
            boolean doActionAfterLogin = ParamUtil.getBoolean(actionRequest, "doActionAfterLogin");

            if (doActionAfterLogin) {
                return;
            } else {
                actionResponse.sendRedirect(mainPath);
            }
        }
    }
}

From source file:com.liferay.portlet.social.util.FacebookUtil.java

License:Open Source License

public static boolean isFacebook(String currentURL) {
    String path = currentURL;/*from ww  w.j a  v  a2 s  .c  o m*/

    if (currentURL.startsWith(Http.HTTP)) {
        int pos = currentURL.indexOf(CharPool.SLASH, Http.HTTPS_WITH_SLASH.length());

        path = currentURL.substring(pos);
    }

    if (path.startsWith(FACEBOOK_SERVLET_PATH)) {
        return true;
    } else {
        return false;
    }
}

From source file:com.liferay.wiki.navigation.web.internal.util.MenuItem.java

License:Open Source License

private static List<MenuItem> _fromWikiPage(WikiPage wikiPage, PortletURL portletURL) {

    List<MenuItem> menuItems = new LinkedList<>();

    Matcher matcher = _pattern.matcher(wikiPage.getContent());

    MenuItem menuItem = null;//w  ww  .jav a 2  s  . c  o m

    while (matcher.find()) {
        String title = matcher.group(3);

        if (title != null) {
            menuItem = new MenuItem();

            menuItem.setLabel(title);

            menuItems.add(menuItem);
        }

        if (menuItem == null) {
            menuItem = new MenuItem();

            menuItem.setLabel(StringPool.BLANK);

            menuItems.add(menuItem);
        }

        String s = matcher.group(6);

        if (s != null) {
            MenuItem childMenuItem = new MenuItem();

            int index = s.indexOf(StringPool.PIPE);

            String label = null;
            String url = null;

            if (index != -1) {
                label = s.substring(index + 1);
                url = s.substring(0, index);

                if (!url.startsWith(Http.HTTP)) {
                    long nodeId = wikiPage.getNodeId();

                    portletURL.setParameter("title", url);
                    portletURL.setParameter("nodeId", String.valueOf(nodeId));

                    url = portletURL.toString();
                } else {
                    childMenuItem.setExternalURL(true);
                }
            } else {
                label = s;
                url = s;

                if (!url.startsWith(Http.HTTP)) {
                    long nodeId = wikiPage.getNodeId();

                    portletURL.setParameter("title", url);
                    portletURL.setParameter("nodeId", String.valueOf(nodeId));

                    url = portletURL.toString();
                }
            }

            childMenuItem.setLabel(label);
            childMenuItem.setURL(url);

            menuItem.addChild(childMenuItem);
        }
    }

    return menuItems;
}

From source file:com.liferay.wikinavigation.util.MenuItem.java

License:Open Source License

private static List<MenuItem> _fromWikiPage(WikiPage wikiPage, PortletURL portletURL) {

    List<MenuItem> menuItems = new LinkedList<MenuItem>();

    Matcher matcher = _pattern.matcher(wikiPage.getContent());

    MenuItem menuItem = null;// www. j av a 2s  . com

    while (matcher.find()) {
        String title = matcher.group(3);

        if (title != null) {
            menuItem = new MenuItem();

            menuItem.setLabel(title);

            menuItems.add(menuItem);
        }

        if (menuItem == null) {
            menuItem = new MenuItem();

            menuItem.setLabel(StringPool.BLANK);

            menuItems.add(menuItem);
        }

        String s = matcher.group(6);

        if (s != null) {
            MenuItem childMenuItem = new MenuItem();

            int index = s.indexOf(StringPool.PIPE);

            String label = null;
            String url = null;

            if (index != -1) {
                label = s.substring(index + 1);
                url = s.substring(0, index);

                if (!url.startsWith(Http.HTTP)) {
                    long nodeId = wikiPage.getNodeId();

                    portletURL.setParameter("title", url);
                    portletURL.setParameter("nodeId", String.valueOf(nodeId));

                    url = portletURL.toString();
                } else {
                    childMenuItem.setExternalURL(true);
                }
            } else {
                label = s;
                url = s;

                if (!url.startsWith(Http.HTTP)) {
                    long nodeId = wikiPage.getNodeId();

                    portletURL.setParameter("title", url);
                    portletURL.setParameter("nodeId", String.valueOf(nodeId));

                    url = portletURL.toString();
                }
            }

            childMenuItem.setLabel(label);
            childMenuItem.setURL(url);

            menuItem.addChild(childMenuItem);
        }
    }

    return menuItems;
}