List of usage examples for org.springframework.web.servlet.i18n SessionLocaleResolver LOCALE_SESSION_ATTRIBUTE_NAME
String LOCALE_SESSION_ATTRIBUTE_NAME
To view the source code for org.springframework.web.servlet.i18n SessionLocaleResolver LOCALE_SESSION_ATTRIBUTE_NAME.
Click Source Link
From source file:com.wisemapping.filter.UserLocaleInterceptor.java
public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, Object object) throws Exception { final HttpSession session = request.getSession(false); User user = Utils.getUser(false);//from w w w . j a v a 2 s . c om if (user != null && session != null) { String userLocale = user.getLocale(); final Locale sessionLocale = (Locale) session .getAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME); if ((userLocale != null) && ((sessionLocale == null) || (!userLocale.equals(sessionLocale.toString())))) { Locale locale; if (userLocale.contains("_")) { final String[] spit = userLocale.split("_"); locale = new Locale(spit[0], spit[1]); } else { locale = new Locale(userLocale); } session.setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, locale); } } return true; }
From source file:org.jamwiki.servlets.JAMWikiLocaleInterceptor.java
/** * Ensure that the session locale value is set. *///from www . ja va2s .c o m public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException { Locale locale = (Locale) request.getSession() .getAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME); if (locale == null) { locale = this.setUserLocale(request, response); } if (locale != null) { LocaleResolver resolver = RequestContextUtils.getLocaleResolver(request); if (resolver != null) { resolver.setLocale(request, response, locale); } } return super.preHandle(request, response, handler); }
From source file:ru.mystamps.web.support.spring.security.SessionLocaleResolverAwareFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try {//from ww w . jav a2s. com HttpServletRequest req = (HttpServletRequest) request; LOG.debug("Handling request {} {}", req.getMethod(), req.getRequestURI()); Locale locale = (Locale) WebUtils.getSessionAttribute((HttpServletRequest) request, SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME); if (locale == null) { locale = Locale.ENGLISH; LOG.debug("Locale reset to 'en' (default)"); } else { LOG.debug("Locale reset to '{}' (from session)", locale); } LocaleContextHolder.setLocale(locale); } catch (RuntimeException ex) { // NOPMD: AvoidCatchingGenericException LOG.warn("Couldn't handle request: {}", ex); } finally { chain.doFilter(request, response); } }
From source file:org.jamwiki.servlets.JAMWikiLocaleInterceptor.java
/** * */// ww w .ja va 2 s.c o m private Locale setUserLocale(HttpServletRequest request, HttpServletResponse response) throws ServletException { Locale locale = this.retrieveUserLocale(request); request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, locale); return locale; }
From source file:fi.csc.shibboleth.mobileauth.impl.authn.utils.ExtractLanguageCodeFromAuthnRequestTest.java
@SuppressWarnings("unchecked") @Test/*from ww w . java 2 s. c om*/ public void testSuccessLangExtract() throws ComponentInitializationException, ParserConfigurationException { action.setHttpServletRequest(new MockHttpServletRequest()); ((MockHttpServletRequest) action.getHttpServletRequest()) .setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, Locale.ENGLISH); messageContext = new MessageContext<>(); authreq = new AuthnRequestBuilder().buildObject(); messageContext.setMessage(authreq); profileCtx.setInboundMessageContext(messageContext); action.initialize(); action.execute(profileCtx); ActionTestingSupport.assertProceedEvent(profileCtx); Assert.assertNotNull(profileCtx.getInboundMessageContext()); Assert.assertEquals(profileCtx.getInboundMessageContext().getMessage(), authreq); final AuthenticationContext authContext = profileCtx.getSubcontext(AuthenticationContext.class); mobCtx = authContext.getSubcontext(MobileContext.class, true); Assert.assertEquals(mobCtx.getLang(), DEFAULT_LANG); }
From source file:fi.csc.shibboleth.mobileauth.impl.authn.ExtractLanguageCodeFromAuthnRequest.java
/** {@inheritDoc} */ @Override/*from w w w. j a v a2s.co m*/ protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) { log.debug("Entering ExtractLanguageCodeFromAuthnRequest doExecute"); HttpServletRequest request = getHttpServletRequest(); final AuthenticationContext authContext = profileRequestContext.getSubcontext(AuthenticationContext.class); MobileContext mobCtx = authContext.getSubcontext(MobileContext.class, true); final AuthnRequest authnReq = (AuthnRequest) profileRequestContext.getInboundMessageContext().getMessage(); final Element root = authnReq.getDOM(); String lang = null; try { lang = MobileAuthenticationUtils.unMarshallLanguage(root, ns, langTag); } catch (Exception e) { log.debug("{} Can't fetch language from the request", getLogPrefix()); } if (lang != null) { log.debug("{} Adding language [{}] to the MobileContext", getLogPrefix(), lang); mobCtx.setLang(lang); try { Locale loc = new Locale(lang); request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, loc); return; } catch (Exception e) { log.debug("{} Can't set language", getLogPrefix()); } } log.debug("{} Adding default language [{}] to the MobileContext", getLogPrefix(), mobCtx.getLang()); }
From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractRegistrationController.java
/** * This method Shows Signup./* w w w. j a v a 2 s . c o m*/ * * @param registration * @param map * @param channelParam * @param request * @param accountType * @param promoCode * @param channelCode * @return String */ private String showSignup(final UserRegistration registration, final ModelMap map, String channelParam, HttpServletRequest request, AccountType accountType, String promoCode, String channelCode) { map.addAttribute("page", Page.HOME); map.addAttribute(Page.HOME.getLevel1().name(), "on"); // compatibility for channel and promotion would happen at register.post // if promotion code is passed, we select a appropriate channel to pass // but do not fail here in case we do not find such a channel. Channel channel = null; if (StringUtils.isNotBlank(promoCode) && StringUtils.isNotBlank(channelCode)) { channel = channelService.locateByChannelCode(channelCode); } else if (StringUtils.isNotBlank(promoCode)) { channel = promotionService.findAptChannel(promoCode); } else if (StringUtils.isNotBlank(channelCode) && !accountType.isTrial()) { channel = channelService.locateByChannelCode(channelCode); } if (channel != null) { channelParam = channel.getParam(); } Locale currentLocale = (Locale) WebUtils.getSessionAttribute(request, SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME); map.addAttribute("currentLocale", currentLocale); registration.getTenant().setAccountType(accountType); registration.setCurrencyValueList(channelService.listCurrencies(channelParam)); map.addAttribute("registration", registration); map.addAttribute("tenant", registration.getTenant()); map.addAttribute("supportedLocaleList", this.getLocaleDisplayName(listSupportedLocales())); map.addAttribute("defaultLocale", getDefaultLocale()); addFraudProfilingHostToSession(map); map.addAttribute("channelParam", channelParam); map.addAttribute("promoCode", promoCode); boolean trialAcountSelected = registrationService.getTrialAccountType().equals(accountType); map.addAttribute("trialAcountSelected", trialAcountSelected); map.addAttribute("isTrialSignup", trialAcountSelected); String homeUrl = config.getValue(Names.com_citrix_cpbm_portal_marketing_home_url); String cloudmktgUrl = config.getValue(Names.com_citrix_cpbm_portal_marketing_marketing_url); if (homeUrl != null) { map.addAttribute("homeUrl", homeUrl); } if (cloudmktgUrl != null) { map.addAttribute("cloudmktgUrl", cloudmktgUrl); } return "register.userinfo"; }
From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractRegistrationController.java
/** * @author amitpals: Call Flow- User Clicks on the link Emailed to him post registration * @param model/* ww w . jav a 2 s . c o m*/ * @param request * @return :- Jsp Prompting user to enter password */ // verifyUser mapping is to have upgrade compatibility for email verifyUser @RequestMapping(value = { "/verify_user", "/verifyUser" }, method = RequestMethod.GET) public String updatePasswordAndVerifyEmail(@RequestParam(value = "a", required = true) final String auth, @RequestParam(value = "i", required = true) final String userParam, final HttpServletRequest request, ModelMap model, HttpSession session) { logger.debug("###Entering in checkPassword(auth,userId,request) method @GET"); String redirect = null; redirect = "/portal/login"; User user = privilegeService.runAsPortal(new PrivilegedAction<User>() { @Override public User run() { User user = userService.get(userParam); Locale locale = user.getLocale(); if (locale != null) { WebUtils.setSessionAttribute(request, SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, locale); } return user; } }); // needed in verifyemail session.setAttribute("regAuth", auth); session.setAttribute("regParam", userParam); if (user.getPassword() == null && (!config.getBooleanValue(Configuration.Names.com_citrix_cpbm_portal_directory_service_enabled) || config.getValue(Names.com_citrix_cpbm_directory_mode).equals("push"))) { return "register.setpassword"; } if (user.isEmailVerified()) { return "redirect:" + redirect; } else { return "redirect:" + "/portal/verify_email"; } }