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

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

Introduction

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

Prototype

boolean SESSION_STORE_PASSWORD

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

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;
    }//w w  w.  java2s  .c o  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.iframe.web.internal.util.IFrameUtil.java

License:Open Source License

public static boolean isPasswordTokenEnabled(PortletRequest portletRequest) throws PortalException {

    if (!PropsValues.SESSION_STORE_PASSWORD) {
        return false;
    }//  ww  w . ja  va 2  s . co  m

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    String roleName = PropsValues.IFRAME_PASSWORD_PASSWORD_TOKEN_ROLE;

    if (layout.isPrivateLayout() && layout.getGroup().isUser()
            && (themeDisplay.getRealUserId() == layout.getGroup().getClassPK())) {

        return true;
    }

    if (Validator.isNull(roleName)) {
        return false;
    }

    try {
        Role role = RoleLocalServiceUtil.getRole(themeDisplay.getCompanyId(), roleName);

        if (UserLocalServiceUtil.hasRoleUser(role.getRoleId(), themeDisplay.getUserId())) {

            return true;
        }
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn("Error getting role " + roleName + ". The password token " + "will be disabled.");
        }
    }

    return false;
}

From source file:com.liferay.iframe.web.internal.util.IFrameUtil.java

License:Open Source License

public static boolean isPasswordTokenResolutionEnabled(PortletRequest portletRequest) throws PortalException {

    if (!PropsValues.SESSION_STORE_PASSWORD) {
        return false;
    }/*from  w ww.  j  av  a 2s .  c  o m*/

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    if (layout.isPrivateLayout() && layout.getGroup().isUser()
            && (themeDisplay.getRealUserId() != layout.getGroup().getClassPK())) {

        return false;
    }

    return true;
}

From source file:com.liferay.portlet.login.util.LoginUtil.java

License:Open Source License

public static void login(HttpServletRequest request, HttpServletResponse response, String login,
        String password, boolean rememberMe, String authType) throws Exception {

    CookieKeys.validateSupportCookie(request);

    HttpSession session = request.getSession();

    Company company = PortalUtil.getCompany(request);

    long userId = getAuthenticatedUserId(request, login, password, authType);

    if (!PropsValues.AUTH_SIMULTANEOUS_LOGINS) {
        Map<String, UserTracker> sessionUsers = LiveUsers.getSessionUsers(company.getCompanyId());

        List<UserTracker> userTrackers = new ArrayList<UserTracker>(sessionUsers.values());

        for (UserTracker userTracker : userTrackers) {
            if (userId != userTracker.getUserId()) {
                continue;
            }//from  w w  w.  j  a v a 2s .  co  m

            JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

            ClusterNode clusterNode = ClusterExecutorUtil.getLocalClusterNode();

            if (clusterNode != null) {
                jsonObject.put("clusterNodeId", clusterNode.getClusterNodeId());
            }

            jsonObject.put("command", "signOut");

            long companyId = CompanyLocalServiceUtil.getCompanyIdByUserId(userId);

            jsonObject.put("companyId", companyId);
            jsonObject.put("sessionId", userTracker.getSessionId());
            jsonObject.put("userId", userId);

            MessageBusUtil.sendMessage(DestinationNames.LIVE_USERS, jsonObject.toString());
        }
    }

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

    // Set cookies

    String domain = CookieKeys.getDomain(request);

    User user = UserLocalServiceUtil.getUserById(userId);

    String userIdString = String.valueOf(userId);

    session.setAttribute("j_username", userIdString);

    if (PropsValues.PORTAL_JAAS_PLAIN_PASSWORD) {
        session.setAttribute("j_password", password);
    } else {
        session.setAttribute("j_password", user.getPassword());
    }

    session.setAttribute("j_remoteuser", userIdString);

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

    Cookie companyIdCookie = new Cookie(CookieKeys.COMPANY_ID, String.valueOf(company.getCompanyId()));

    if (Validator.isNotNull(domain)) {
        companyIdCookie.setDomain(domain);
    }

    companyIdCookie.setPath(StringPool.SLASH);

    Cookie idCookie = new Cookie(CookieKeys.ID, Encryptor.encrypt(company.getKeyObj(), userIdString));

    if (Validator.isNotNull(domain)) {
        idCookie.setDomain(domain);
    }

    idCookie.setPath(StringPool.SLASH);

    Cookie passwordCookie = new Cookie(CookieKeys.PASSWORD, Encryptor.encrypt(company.getKeyObj(), password));

    if (Validator.isNotNull(domain)) {
        passwordCookie.setDomain(domain);
    }

    passwordCookie.setPath(StringPool.SLASH);

    Cookie rememberMeCookie = new Cookie(CookieKeys.REMEMBER_ME, Boolean.TRUE.toString());

    if (Validator.isNotNull(domain)) {
        rememberMeCookie.setDomain(domain);
    }

    rememberMeCookie.setPath(StringPool.SLASH);

    int loginMaxAge = PropsValues.COMPANY_SECURITY_AUTO_LOGIN_MAX_AGE;

    String userUUID = userIdString.concat(StringPool.PERIOD).concat(String.valueOf(System.nanoTime()));

    Cookie userUUIDCookie = new Cookie(CookieKeys.USER_UUID, Encryptor.encrypt(company.getKeyObj(), userUUID));

    userUUIDCookie.setPath(StringPool.SLASH);

    session.setAttribute(WebKeys.USER_UUID, userUUID);

    if (PropsValues.SESSION_DISABLED) {
        rememberMe = true;
    }

    if (rememberMe) {
        companyIdCookie.setMaxAge(loginMaxAge);
        idCookie.setMaxAge(loginMaxAge);
        passwordCookie.setMaxAge(loginMaxAge);
        rememberMeCookie.setMaxAge(loginMaxAge);
        userUUIDCookie.setMaxAge(loginMaxAge);
    } else {

        // This was explicitly changed from 0 to -1 so that the cookie lasts
        // as long as the browser. This allows an external servlet wrapped
        // in AutoLoginFilter to work throughout the client connection. The
        // cookies ARE removed on an actual logout, so there is no security
        // issue. See LEP-4678 and LEP-5177.

        companyIdCookie.setMaxAge(-1);
        idCookie.setMaxAge(-1);
        passwordCookie.setMaxAge(-1);
        rememberMeCookie.setMaxAge(0);
        userUUIDCookie.setMaxAge(-1);
    }

    Cookie loginCookie = new Cookie(CookieKeys.LOGIN, login);

    if (Validator.isNotNull(domain)) {
        loginCookie.setDomain(domain);
    }

    loginCookie.setMaxAge(loginMaxAge);
    loginCookie.setPath(StringPool.SLASH);

    Cookie screenNameCookie = new Cookie(CookieKeys.SCREEN_NAME,
            Encryptor.encrypt(company.getKeyObj(), user.getScreenName()));

    if (Validator.isNotNull(domain)) {
        screenNameCookie.setDomain(domain);
    }

    screenNameCookie.setMaxAge(loginMaxAge);
    screenNameCookie.setPath(StringPool.SLASH);

    boolean secure = request.isSecure();

    if (secure && !PropsValues.COMPANY_SECURITY_AUTH_REQUIRES_HTTPS
            && !StringUtil.equalsIgnoreCase(Http.HTTPS, PropsValues.WEB_SERVER_PROTOCOL)) {

        Boolean httpsInitial = (Boolean) session.getAttribute(WebKeys.HTTPS_INITIAL);

        if ((httpsInitial == null) || !httpsInitial.booleanValue()) {
            secure = false;
        }
    }

    CookieKeys.addCookie(request, response, companyIdCookie, secure);
    CookieKeys.addCookie(request, response, idCookie, secure);
    CookieKeys.addCookie(request, response, userUUIDCookie, secure);

    if (rememberMe) {
        CookieKeys.addCookie(request, response, loginCookie, secure);
        CookieKeys.addCookie(request, response, passwordCookie, secure);
        CookieKeys.addCookie(request, response, rememberMeCookie, secure);
        CookieKeys.addCookie(request, response, screenNameCookie, secure);
    }

    AuthenticatedUserUUIDStoreUtil.register(userUUID);
}

From source file:com.liferay.portlet.usersadmin.action.EditUserAction.java

License:Open Source License

protected Object[] updateUser(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    User user = PortalUtil.getSelectedUser(actionRequest);

    boolean deleteLogo = ParamUtil.getBoolean(actionRequest, "deleteLogo");

    if (deleteLogo) {
        UserServiceUtil.deletePortrait(user.getUserId());
    }//from   w  w w.  java  2 s. com

    Contact contact = user.getContact();

    String oldPassword = AdminUtil.getUpdateUserPassword(actionRequest, user.getUserId());
    String newPassword1 = actionRequest.getParameter("password1");
    String newPassword2 = actionRequest.getParameter("password2");
    boolean passwordReset = ParamUtil.getBoolean(actionRequest, "passwordReset");

    String reminderQueryQuestion = BeanParamUtil.getString(user, actionRequest, "reminderQueryQuestion");

    if (reminderQueryQuestion.equals(UsersAdminUtil.CUSTOM_QUESTION)) {
        reminderQueryQuestion = BeanParamUtil.getString(user, actionRequest, "reminderQueryCustomQuestion");
    }

    String reminderQueryAnswer = BeanParamUtil.getString(user, actionRequest, "reminderQueryAnswer");
    String oldScreenName = user.getScreenName();
    String screenName = BeanParamUtil.getString(user, actionRequest, "screenName");
    String oldEmailAddress = user.getEmailAddress();
    String emailAddress = BeanParamUtil.getString(user, actionRequest, "emailAddress");
    long facebookId = user.getFacebookId();
    String openId = BeanParamUtil.getString(user, actionRequest, "openId");
    String oldLanguageId = user.getLanguageId();
    String languageId = BeanParamUtil.getString(user, actionRequest, "languageId");
    String timeZoneId = BeanParamUtil.getString(user, actionRequest, "timeZoneId");
    String greeting = BeanParamUtil.getString(user, actionRequest, "greeting");
    String firstName = BeanParamUtil.getString(user, actionRequest, "firstName");
    String middleName = BeanParamUtil.getString(user, actionRequest, "middleName");
    String lastName = BeanParamUtil.getString(user, actionRequest, "lastName");
    int prefixId = BeanParamUtil.getInteger(contact, actionRequest, "prefixId");
    int suffixId = BeanParamUtil.getInteger(contact, actionRequest, "suffixId");
    boolean male = BeanParamUtil.getBoolean(user, actionRequest, "male", true);

    Calendar birthdayCal = CalendarFactoryUtil.getCalendar();

    birthdayCal.setTime(contact.getBirthday());

    int birthdayMonth = ParamUtil.getInteger(actionRequest, "birthdayMonth", birthdayCal.get(Calendar.MONTH));
    int birthdayDay = ParamUtil.getInteger(actionRequest, "birthdayDay", birthdayCal.get(Calendar.DATE));
    int birthdayYear = ParamUtil.getInteger(actionRequest, "birthdayYear", birthdayCal.get(Calendar.YEAR));
    String comments = BeanParamUtil.getString(user, actionRequest, "comments");
    String smsSn = BeanParamUtil.getString(contact, actionRequest, "smsSn");
    String aimSn = BeanParamUtil.getString(contact, actionRequest, "aimSn");
    String facebookSn = BeanParamUtil.getString(contact, actionRequest, "facebookSn");
    String icqSn = BeanParamUtil.getString(contact, actionRequest, "icqSn");
    String jabberSn = BeanParamUtil.getString(contact, actionRequest, "jabberSn");
    String msnSn = BeanParamUtil.getString(contact, actionRequest, "msnSn");
    String mySpaceSn = BeanParamUtil.getString(contact, actionRequest, "mySpaceSn");
    String skypeSn = BeanParamUtil.getString(contact, actionRequest, "skypeSn");
    String twitterSn = BeanParamUtil.getString(contact, actionRequest, "twitterSn");
    String ymSn = BeanParamUtil.getString(contact, actionRequest, "ymSn");
    String jobTitle = BeanParamUtil.getString(user, actionRequest, "jobTitle");
    long[] groupIds = getLongArray(actionRequest, "groupsSearchContainerPrimaryKeys");
    long[] organizationIds = getLongArray(actionRequest, "organizationsSearchContainerPrimaryKeys");
    long[] roleIds = getLongArray(actionRequest, "rolesSearchContainerPrimaryKeys");

    List<UserGroupRole> userGroupRoles = null;

    if ((actionRequest.getParameter("groupRolesGroupIds") != null)
            || (actionRequest.getParameter("groupRolesRoleIds") != null)) {

        userGroupRoles = UsersAdminUtil.getUserGroupRoles(actionRequest);
    }

    long[] userGroupIds = getLongArray(actionRequest, "userGroupsSearchContainerPrimaryKeys");
    List<Address> addresses = UsersAdminUtil.getAddresses(actionRequest);
    List<EmailAddress> emailAddresses = UsersAdminUtil.getEmailAddresses(actionRequest);
    List<Phone> phones = UsersAdminUtil.getPhones(actionRequest);
    List<Website> websites = UsersAdminUtil.getWebsites(actionRequest);
    List<AnnouncementsDelivery> announcementsDeliveries = getAnnouncementsDeliveries(actionRequest);

    ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest);

    user = UserServiceUtil.updateUser(user.getUserId(), oldPassword, newPassword1, newPassword2, passwordReset,
            reminderQueryQuestion, reminderQueryAnswer, screenName, emailAddress, facebookId, openId,
            languageId, timeZoneId, greeting, comments, firstName, middleName, lastName, prefixId, suffixId,
            male, birthdayMonth, birthdayDay, birthdayYear, smsSn, aimSn, facebookSn, icqSn, jabberSn, msnSn,
            mySpaceSn, skypeSn, twitterSn, ymSn, jobTitle, groupIds, organizationIds, roleIds, userGroupRoles,
            userGroupIds, addresses, emailAddresses, phones, websites, announcementsDeliveries, serviceContext);

    if (oldScreenName.equals(user.getScreenName())) {
        oldScreenName = StringPool.BLANK;
    }

    if (user.getUserId() == themeDisplay.getUserId()) {

        // Reset the locale

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

        session.removeAttribute(Globals.LOCALE_KEY);

        Locale locale = LocaleUtil.fromLanguageId(languageId);

        LanguageUtil.updateCookie(request, response, locale);

        // Clear cached portlet responses

        PortletSession portletSession = actionRequest.getPortletSession();

        InvokerPortletImpl.clearResponses(portletSession);

        // Password

        if (PropsValues.SESSION_STORE_PASSWORD && Validator.isNotNull(newPassword1)) {

            portletSession.setAttribute(WebKeys.USER_PASSWORD, newPassword1, PortletSession.APPLICATION_SCOPE);
        }
    }

    long publicLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "publicLayoutSetPrototypeId");
    long privateLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "privateLayoutSetPrototypeId");

    SitesUtil.applyLayoutSetPrototypes(user.getGroup(), publicLayoutSetPrototypeId, privateLayoutSetPrototypeId,
            serviceContext);

    Company company = PortalUtil.getCompany(actionRequest);

    if (company.isStrangersVerify() && !oldEmailAddress.equalsIgnoreCase(emailAddress)) {

        SessionMessages.add(actionRequest, "verificationEmailSent");
    }

    return new Object[] { user, oldScreenName, oldLanguageId };
}

From source file:com.liferay.users.admin.web.internal.portlet.action.UpdatePasswordMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    try {/* w w  w  .ja  v  a2 s  . c  o  m*/
        User user = _portal.getSelectedUser(actionRequest);

        String newPassword1 = actionRequest.getParameter("password1");
        String newPassword2 = actionRequest.getParameter("password2");

        boolean passwordReset = ParamUtil.getBoolean(actionRequest, "passwordReset");

        PasswordPolicy passwordPolicy = user.getPasswordPolicy();

        if ((user.getLastLoginDate() == null) && ((passwordPolicy == null)
                || (passwordPolicy.isChangeable() && passwordPolicy.isChangeRequired()))) {

            passwordReset = true;
        }

        String reminderQueryQuestion = BeanParamUtil.getString(user, actionRequest, "reminderQueryQuestion");

        if (reminderQueryQuestion.equals(UsersAdmin.CUSTOM_QUESTION)) {
            reminderQueryQuestion = BeanParamUtil.getStringSilent(user, actionRequest,
                    "reminderQueryCustomQuestion");
        }

        String reminderQueryAnswer = BeanParamUtil.getString(user, actionRequest, "reminderQueryAnswer");

        if (Validator.isNotNull(newPassword1) || Validator.isNotNull(newPassword2)) {

            _userLocalService.updatePassword(user.getUserId(), newPassword1, newPassword2, passwordReset);
        }

        _userLocalService.updatePasswordReset(user.getUserId(), passwordReset);

        if (Validator.isNotNull(reminderQueryQuestion) && Validator.isNotNull(reminderQueryAnswer)) {

            _userLocalService.updateReminderQuery(user.getUserId(), reminderQueryQuestion, reminderQueryAnswer);
        }

        ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

        if ((user.getUserId() == themeDisplay.getUserId()) && PropsValues.SESSION_STORE_PASSWORD
                && Validator.isNotNull(newPassword1)) {

            PortletSession portletSession = actionRequest.getPortletSession();

            portletSession.setAttribute(WebKeys.USER_PASSWORD, newPassword1, PortletSession.APPLICATION_SCOPE);
        }
    } catch (Exception e) {
        if (e instanceof NoSuchUserException || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass());

            actionResponse.setRenderParameter("mvcPath", "/error.jsp");
        } else if (e instanceof UserPasswordException) {
            SessionErrors.add(actionRequest, e.getClass(), e);

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

            if (Validator.isNotNull(redirect)) {
                sendRedirect(actionRequest, actionResponse, redirect);
            }
        } else {
            throw e;
        }
    }
}

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;
                    }/*from  w ww.  jav 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;
}