NgrinderUsernamePasswordAuthenticationFilter extends UsernamePasswordAuthenticationFilter { @Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) { Authentication auth = getAuthentication(request, response); String timezone = request.getParameter("user_timezone"); String language = request.getParameter("native_language"); SecuredUser securedUser = (SecuredUser) auth.getPrincipal(); User user = securedUser.getUser(); User existingUser = userRepository.findOneByUserId(user.getUserId()); if (existingUser != null) { user = existingUser; } user.setTimeZone(timezone); user.setUserLanguage(language); securedUser.setUser(userRepository.saveAndFlush(user)); return auth; } NgrinderUsernamePasswordAuthenticationFilter();  NgrinderUsernamePasswordAuthenticationFilter(UserRepository userRepository); @Override Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response);  }
@Test public void testFilter() { filter.setUserRepository(userRepository); HttpServletRequest req = mock(HttpServletRequest.class); when(req.getParameter("user_timezone")).thenReturn("Korean"); when(req.getParameter("native_language")).thenReturn("KoreanLang"); HttpServletResponse res = mock(HttpServletResponse.class); filter.attemptAuthentication(req, res); Optional<User> findOne = userRepository.findOne(idEqual(getTestUser().getId())); if (!findOne.isPresent()) { fail(); } User user = findOne.get(); assertThat(user.getUserLanguage(), is("KoreanLang")); assertThat(user.getTimeZone(), is("Korean")); }