@Before public void init() { audienceManagerService = mock(AudienceManagerService.class); authenticationManager = mock(AuthenticationManager.class); UserDetailsService userDetailsService = mock(UserDetailsService.class); TokenBasedRememberMeServices rememberMeServices = spy(new TokenBasedRememberMeServices("key", userDetailsService)); provider = new AudienceManagerSecurityProvider(audienceManagerService, authenticationManager, rememberMeServices); token.setDetails("id"); doThrow(new BadCredentialsException("Test")).when(authenticationManager).authenticate(any(Authentication.class)); doReturn(token).when(authenticationManager).authenticate(argThat(new BaseMatcher<Authentication>() { @Override public boolean matches(Object item) { return ((Authentication) item).getPrincipal().equals("user"); } @Override public void describeTo(Description description) { description.appendText("Username is user"); } })); }
@Bean TokenBasedRememberMeServices rememberMeServices() { BackendTokenBasedRememberMeServices tokenBasedRememberMeServices = new BackendTokenBasedRememberMeServices(REMEMBER_ME_KEY, userDetailsService); tokenBasedRememberMeServices.setCookieName(REMEMBER_ME_TOKEN); tokenBasedRememberMeServices.setParameter(REMEMBER_ME_TOKEN); tokenBasedRememberMeServices.setTokenValiditySeconds(3600); tokenBasedRememberMeServices.setAlwaysRemember(true); // tokenBasedRememberMeServices.set; return tokenBasedRememberMeServices; }
/** * try to restore remember me authentication and create valid session of it */ private static void restoreRememberMeAuth(HttpServletRequest request,HttpServletResponse response) { TokenBasedRememberMeServices tokenBasedRememberMeServices = ContextHelper.get().beanForType( TokenBasedRememberMeServices.class); Authentication authentication = tokenBasedRememberMeServices.autoLogin(request, response); if (authentication != null) { boolean sessionCreated = SessionUtils.setAuthentication(request, authentication, true); if (sessionCreated) { bindAuthentication(authentication); } } }
@Bean public RememberMeServices rememberMeServices() { // TODO Is there some way of exposing the RememberMeServices instance that the remember me configurer creates by default? TokenBasedRememberMeServices services = new TokenBasedRememberMeServices("myAppKey", userDetailsService()); services.setAlwaysRemember(true); return services; }
Object onActivate() { // Clear session Session session = request.getSession(false); if (session != null) { session.invalidate(); } // Remove RememberMe cookie cookies.removeCookieValue(TokenBasedRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY); return Home.class; }
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Get the entity manager factory if we don't have it if (this.entityManagerFactory == null) { this.entityManagerFactory = RuntimeBeanLoader.getBean(EntityManagerFactory.class); } // Create a new entity manager and set it in thread local if (this.entityManagerFactory != null) { LazyHibernateEntityManagerProvider.setCurrentEntityManager(this.entityManagerFactory.createEntityManager()); } // Process the request normally now super.service(request, response); // Remove the used entity manager since it's finished with LazyHibernateEntityManagerProvider.setCurrentEntityManager(null); // We've just authorised the user in the service method so set the Remember Me cookie. // Ordinarily this would be done by Spring's UsernamePasswordAuthenticationFilter. Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth != null && auth.isAuthenticated()) { if (rememberMeServices == null) { rememberMeServices = RuntimeBeanLoader.getBean(TokenBasedRememberMeServices.class); } rememberMeServices.onLoginSuccess(request, response, auth); } }
/** * The {@link RememberMeServices} must be available as a Spring bean for * Vaadin4Spring. */ @Bean public RememberMeServices rememberMeServices() { return new TokenBasedRememberMeServices(REMEMBERME_KEY, userDetailsService()); }
@Bean public RememberMeServices rememberMeServices() throws Exception { TokenBasedRememberMeServices result = new TokenBasedRememberMeServices("hell0w0r1d", service); result.setTokenValiditySeconds(2419200); return result; }
@Bean public TokenBasedRememberMeServices rememberMeServices() { return new TokenBasedRememberMeServices("remember-me-key", userService()); }
@Bean public TokenBasedRememberMeServices rememberMeServices() { return new TokenBasedRememberMeServices(REMEBER_ME_KEY, userService()); }
/** * The {@link RememberMeServices} must be available as a Spring bean for Vaadin4Spring. */ @Bean public RememberMeServices rememberMeServices() { return new TokenBasedRememberMeServices("myAppKey", userDetailsService()); }
private void removeRememberMeCookie() { ((WebResponse)getResponse()).clearCookie( new Cookie(TokenBasedRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY, null)); }
@Bean public RememberMeServices rememberMeServices() { return new TokenBasedRememberMeServices(env.getProperty("appKey"), userDetailsService); }
@Bean public TokenBasedRememberMeServices rememberMeServices() { return new TokenBasedRememberMeServices("remember-me-key", accountService); }
/** * Remember me services. * * @return the token based remember me services */ @Bean public TokenBasedRememberMeServices rememberMeServices() { return new TokenBasedRememberMeServices("remember-me-key", userService()); }