Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * changes the session user including the full login process. any settings made to this session are kept except that
- * the session cart is assigned to the new session user. if specified the session language and session currency is
- * changed to the values belonging to the new user ( see {@link User#getSessionLanguage()} and
- * {@link User#getSessionCurrency()} ). Set the Boolean activateUserLanguageAndCurrency to <code>true</code> if you
- * want the new user to use his / her default language and currency. If set to <code>false</code>, the new user will
- * have the language and currency used by the former user.
- *
- * @param props
- * logging properties ( see {@link LoginProperties} )
- * @param activateUserLanguageAndCurrency
- * if true the session language and session currency are set to the values set at the new user
- * @throws JaloSecurityException
- * in case login process failed
- * @throws JaloInvalidParameterException
- * in case some provided parameter had an unexpected value
- */
- public void transfer(final Map props, final boolean activateUserLanguageAndCurrency) throws JaloSecurityException,
- JaloInvalidParameterException
- {
- final User newUser;
- if (props != null && props.get(LoginProperties.LOGIN) == null && props.get(LoginProperties.USER_PK) == null
- && props.get(LoginProperties.LOGIN_TOKEN) != null)
- {
- final LoginToken token = (LoginToken) props.get(LoginProperties.LOGIN_TOKEN);
- newUser = performLogin(token, props);
- }
- else
- {
- newUser = performLogin(props != null ? (String) props.get(LoginProperties.LOGIN) : null, props != null ? (String) props
- .get(LoginProperties.PASSWORD) : null, props);
- }
- setUser(newUser);
- if (activateUserLanguageAndCurrency)
- {
- final Currency userCurr = newUser.getSessionCurrency();
- final Language userLang = newUser.getSessionLanguage();
- if (userCurr != null)
- {
- getSessionContext().setCurrency(userCurr);
- }
- if (userLang != null)
- {
- getSessionContext().setLanguage(userLang);
- }
- }
- // make sure user has a valid language set
- final Language currentLanguage = getSessionContext().getLanguage();
- final Collection activeLanguages = getC2LManager().getActiveLanguages();
- if (activeLanguages.isEmpty())
- {
- throw new JaloSystemException(null, "No active language found for new session of user " + newUser.getLogin()
- + ". Check restrictions.", 0);
- }
- if (!currentLanguage.isAlive() || !activeLanguages.contains(currentLanguage))
- {
- final Language newLanguage = (Language) activeLanguages.iterator().next();
- log.info("transfering session to user " + newUser.getLogin() + ": forced to switch langanguage to "
- + newLanguage.getIsoCode());
- getSessionContext().setLanguage(newLanguage);
- }
- // make sure user has a valid currency set
- final Currency currentCurrency = getSessionContext().getCurrency();
- final Collection activeCurrencies = getC2LManager().getActiveCurrencies();
- if (activeCurrencies.isEmpty())
- {
- throw new JaloSystemException(null, "No active currency found for new session of user " + newUser.getLogin()
- + ". Check restrictions.", 0);
- }
- if (!currentCurrency.isAlive() || !activeCurrencies.contains(currentCurrency))
- {
- final Currency newCurr = (Currency) activeCurrencies.iterator().next();
- log.info("transfering session to user " + newUser.getLogin() + ": forced to switch currency to " + newCurr.getIsoCode());
- getSessionContext().setCurrency(newCurr);
- }
- setLoginProperties(props);
- }
Add Comment
Please, Sign In to add comment