Guest User

Untitled

a guest
Jun 18th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. /**
  2. * changes the session user including the full login process. any settings made to this session are kept except that
  3. * the session cart is assigned to the new session user. if specified the session language and session currency is
  4. * changed to the values belonging to the new user ( see {@link User#getSessionLanguage()} and
  5. * {@link User#getSessionCurrency()} ). Set the Boolean activateUserLanguageAndCurrency to <code>true</code> if you
  6. * want the new user to use his / her default language and currency. If set to <code>false</code>, the new user will
  7. * have the language and currency used by the former user.
  8. *
  9. * @param props
  10. * logging properties ( see {@link LoginProperties} )
  11. * @param activateUserLanguageAndCurrency
  12. * if true the session language and session currency are set to the values set at the new user
  13. * @throws JaloSecurityException
  14. * in case login process failed
  15. * @throws JaloInvalidParameterException
  16. * in case some provided parameter had an unexpected value
  17. */
  18. public void transfer(final Map props, final boolean activateUserLanguageAndCurrency) throws JaloSecurityException,
  19. JaloInvalidParameterException
  20. {
  21. final User newUser;
  22.  
  23. if (props != null && props.get(LoginProperties.LOGIN) == null && props.get(LoginProperties.USER_PK) == null
  24. && props.get(LoginProperties.LOGIN_TOKEN) != null)
  25. {
  26. final LoginToken token = (LoginToken) props.get(LoginProperties.LOGIN_TOKEN);
  27. newUser = performLogin(token, props);
  28. }
  29. else
  30. {
  31. newUser = performLogin(props != null ? (String) props.get(LoginProperties.LOGIN) : null, props != null ? (String) props
  32. .get(LoginProperties.PASSWORD) : null, props);
  33. }
  34.  
  35. setUser(newUser);
  36. if (activateUserLanguageAndCurrency)
  37. {
  38. final Currency userCurr = newUser.getSessionCurrency();
  39. final Language userLang = newUser.getSessionLanguage();
  40.  
  41. if (userCurr != null)
  42. {
  43. getSessionContext().setCurrency(userCurr);
  44. }
  45. if (userLang != null)
  46. {
  47. getSessionContext().setLanguage(userLang);
  48. }
  49. }
  50. // make sure user has a valid language set
  51. final Language currentLanguage = getSessionContext().getLanguage();
  52.  
  53. final Collection activeLanguages = getC2LManager().getActiveLanguages();
  54.  
  55. if (activeLanguages.isEmpty())
  56. {
  57. throw new JaloSystemException(null, "No active language found for new session of user " + newUser.getLogin()
  58. + ". Check restrictions.", 0);
  59. }
  60.  
  61. if (!currentLanguage.isAlive() || !activeLanguages.contains(currentLanguage))
  62. {
  63. final Language newLanguage = (Language) activeLanguages.iterator().next();
  64. log.info("transfering session to user " + newUser.getLogin() + ": forced to switch langanguage to "
  65. + newLanguage.getIsoCode());
  66. getSessionContext().setLanguage(newLanguage);
  67. }
  68. // make sure user has a valid currency set
  69. final Currency currentCurrency = getSessionContext().getCurrency();
  70. final Collection activeCurrencies = getC2LManager().getActiveCurrencies();
  71. if (activeCurrencies.isEmpty())
  72. {
  73. throw new JaloSystemException(null, "No active currency found for new session of user " + newUser.getLogin()
  74. + ". Check restrictions.", 0);
  75. }
  76. if (!currentCurrency.isAlive() || !activeCurrencies.contains(currentCurrency))
  77. {
  78. final Currency newCurr = (Currency) activeCurrencies.iterator().next();
  79. log.info("transfering session to user " + newUser.getLogin() + ": forced to switch currency to " + newCurr.getIsoCode());
  80. getSessionContext().setCurrency(newCurr);
  81. }
  82. setLoginProperties(props);
  83. }
Add Comment
Please, Sign In to add comment