Example usage for com.liferay.portal.util PortalInstances isAutoLoginIgnoreHost

List of usage examples for com.liferay.portal.util PortalInstances isAutoLoginIgnoreHost

Introduction

In this page you can find the example usage for com.liferay.portal.util PortalInstances isAutoLoginIgnoreHost.

Prototype

public static boolean isAutoLoginIgnoreHost(String host) 

Source Link

Usage

From source file:org.openinfinity.sso.springsecurity.liferay.PreAuthenticationAwareAutologinFilter.java

License:Apache License

protected void processFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
        throws Exception {

    HttpSession session = request.getSession();

    String userID = (String) session.getAttribute(LIFERAY_USER_ID_SESSION_ATTRIBUTE_KEY);
    if (userID != null) {
        request = new LiferayRequestWrapper(request, userID);
    }/*from   ww w  .j  a va  2s  .  co  m*/

    String host = PortalUtil.getHost(request);

    if (PortalInstances.isAutoLoginIgnoreHost(host)) {
        if (_log.isDebugEnabled()) {
            _log.debug("Ignore host " + host);
        }

        processFilter(PreAuthenticationAwareAutologinFilter.class, request, response, filterChain);

        return;
    }

    String contextPath = PortalUtil.getPathContext();

    String path = request.getRequestURI().toLowerCase();

    if ((!contextPath.equals(StringPool.SLASH)) && (path.indexOf(contextPath) != -1)) {

        path = path.substring(contextPath.length(), path.length());
    }

    if (PortalInstances.isAutoLoginIgnorePath(path)) {
        if (_log.isDebugEnabled()) {
            _log.debug("Ignore path " + path);
        }

        processFilter(PreAuthenticationAwareAutologinFilter.class, request, response, filterChain);

        return;
    }

    String remoteUser = request.getRemoteUser();
    String jUserName = (String) session.getAttribute("j_username");

    if (((remoteUser == null) && (jUserName == null))
            || autoLoginNeedingValveAuthenticationIn(request, session)) {
        setValveAuthenticationAttributeToFalseIfNeededIn(request);
        for (AutoLogin autoLogin : _autoLogins) {
            try {
                String[] credentials = autoLogin.login(request, response);

                session.setAttribute(LIFERAY_USER_ID_SESSION_ATTRIBUTE_KEY, credentials[0]);

                String redirect = (String) request.getAttribute(AutoLogin.AUTO_LOGIN_REDIRECT);

                if (Validator.isNotNull(redirect)) {
                    response.sendRedirect(redirect);

                    return;
                }

                String loginRemoteUser = getLoginRemoteUser(request, response, session, credentials);

                if (loginRemoteUser != null) {
                    request = new ProtectedServletRequest(request, loginRemoteUser);

                    if (PropsValues.PORTAL_JAAS_ENABLE) {
                        return;
                    }

                    redirect = (String) request.getAttribute(AutoLogin.AUTO_LOGIN_REDIRECT_AND_CONTINUE);

                    if (Validator.isNotNull(redirect)) {
                        response.sendRedirect(redirect);

                        break;
                    }
                }
            } catch (Exception e) {
                if (_log.isWarnEnabled()) {
                    _log.warn(e, e);
                }

                String currentURL = PortalUtil.getCurrentURL(request);

                if (currentURL.endsWith(_PATH_CHAT_LATEST)) {
                    if (_log.isWarnEnabled()) {
                        _log.warn("Current URL " + currentURL + " generates exception: " + e.getMessage());
                    }
                } else {
                    _log.error("Current URL " + currentURL + " generates exception: " + e.getMessage());
                }
            }
        }
    }

    processFilter(PreAuthenticationAwareAutologinFilter.class, request, response, filterChain);
}