Example usage for com.liferay.portal.util PropsValues PORTAL_JAAS_ENABLE

List of usage examples for com.liferay.portal.util PropsValues PORTAL_JAAS_ENABLE

Introduction

In this page you can find the example usage for com.liferay.portal.util PropsValues PORTAL_JAAS_ENABLE.

Prototype

boolean PORTAL_JAAS_ENABLE

To view the source code for com.liferay.portal.util PropsValues PORTAL_JAAS_ENABLE.

Click Source Link

Usage

From source file:com.labimo.Oauth2Filter.java

License:Open Source License

protected String getLoginRemoteUser(HttpServletRequest request, HttpServletResponse response,
        HttpSession session, String[] credentials) throws Exception {

    if ((credentials == null) || (credentials.length != 3)) {
        return null;
    }//from w w w .  j a va 2  s  .  co m

    String jUsername = credentials[0];
    String jPassword = credentials[1];
    boolean encPassword = GetterUtil.getBoolean(credentials[2]);

    if (Validator.isNull(jUsername) || Validator.isNull(jPassword)) {
        return null;
    }

    long userId = GetterUtil.getLong(jUsername);

    if (userId <= 0) {
        return null;
    }

    User user = UserLocalServiceUtil.fetchUserById(userId);

    if ((user == null) || user.isLockout()) {
        return null;
    }

    if (PropsValues.SESSION_ENABLE_PHISHING_PROTECTION) {
        session = LoginUtil.renewSession(request, session);
    }

    session.setAttribute("j_username", jUsername);

    // Not having access to the unencrypted password will not allow you to
    // connect to external resources that require it (mail server)

    if (encPassword) {
        session.setAttribute("j_password", jPassword);
    } else {
        session.setAttribute("j_password", PasswordEncryptorUtil.encrypt(jPassword));

        if (PropsValues.SESSION_STORE_PASSWORD) {
            session.setAttribute(WebKeys.USER_PASSWORD, jPassword);
        }
    }

    session.setAttribute("j_remoteuser", jUsername);

    if (PropsValues.PORTAL_JAAS_ENABLE) {
        String redirect = PortalUtil.getPathMain().concat("/portal/protected");

        if (PropsValues.AUTH_FORWARD_BY_LAST_PATH) {
            String autoLoginRedirect = (String) request
                    .getAttribute(AutoLogin.AUTO_LOGIN_REDIRECT_AND_CONTINUE);

            redirect = redirect.concat("?redirect=");

            if (Validator.isNotNull(autoLoginRedirect)) {
                redirect = redirect.concat(autoLoginRedirect);
            } else {
                redirect = redirect.concat(PortalUtil.getCurrentCompleteURL(request));
            }
        }

        response.sendRedirect(redirect);
    }

    return jUsername;
}

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 www .j  av  a 2 s . c  om*/

    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.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   w  w  w . j av a2  s . com*/
        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);
    }/*  w  ww. ja  v  a  2  s  .  c  om*/

    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.test.CharterLogin.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);

    LoginUtil.login(request, response, login, password, rememberMe, authType);

    if (PropsValues.PORTAL_JAAS_ENABLE) {
        actionResponse.sendRedirect(themeDisplay.getPathMain() + "/portal/protected");
    } else {/*from   www .  ja va  2 s.c  om*/
        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:org.openinfinity.sso.springsecurity.liferay.PreAuthenticationAwareAutologinFilter.java

License:Apache License

protected String getLoginRemoteUser(HttpServletRequest request, HttpServletResponse response,
        HttpSession session, String[] credentials) throws Exception {

    if ((credentials != null) && (credentials.length == 3)) {
        String jUsername = credentials[0];
        String jPassword = credentials[1];
        boolean encPassword = GetterUtil.getBoolean(credentials[2]);

        if (Validator.isNotNull(jUsername) && Validator.isNotNull(jPassword)) {

            try {
                long userId = GetterUtil.getLong(jUsername);

                if (userId > 0) {
                    User user = UserLocalServiceUtil.getUserById(userId);

                    if (user.isLockout()) {
                        return null;
                    }//  ww w .  j av a2 s. c o m
                } else {
                    return null;
                }
            } catch (NoSuchUserException nsue) {
                return null;
            }

            session.setAttribute("j_username", jUsername);

            // Not having access to the unencrypted password
            // will not allow you to connect to external
            // resources that require it (mail server)

            if (encPassword) {
                session.setAttribute("j_password", jPassword);
            } else {
                session.setAttribute("j_password", PwdEncryptor.encrypt(jPassword));

                if (PropsValues.SESSION_STORE_PASSWORD) {
                    session.setAttribute(com.liferay.portal.util.WebKeys.USER_PASSWORD, jPassword);
                }
            }

            if (PropsValues.PORTAL_JAAS_ENABLE) {
                response.sendRedirect(PortalUtil.getPathMain() + "/portal/touch_protected");
            }

            return jUsername;
        }
    }

    return null;
}

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);
    }/* w w w. j  av  a  2  s. c o  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);
}