org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices Java Examples

The following examples show how to use org.springframework.security.web.authentication.rememberme.AbstractRememberMeServices. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SignInPresenter.java    From Vaadin4Spring-MVP-Sample-SpringSecurity with Apache License 2.0 5 votes vote down vote up
@Override
public void doSignIn(String username, String password, boolean rememberMe) {
	try {			
		
		/*
		 * security.login(username, password);
		 * 
		 */			
		final SecurityContext securityContext = SecurityContextHolder.getContext();
		UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);

		final Authentication authentication = authenticationManager.authenticate(token);	  
        securityContext.setAuthentication(authentication);
        	                	        
        if (rememberMe) {
        	HttpServletRequest request = httpRequestResponseService.getCurrentRequest();
	        HttpServletResponse response = httpRequestResponseService.getCurrentResponse();		        
	        request.setAttribute(AbstractRememberMeServices.DEFAULT_PARAMETER, rememberMe);
	        rememberMeServices.loginSuccess(request, response, authentication);	        	
        } 
		
        
        
		getEventBus().publish(EventScope.UI, this, new UserSignedInEvent());
		
		//Redirect to UserHome or Admin Home
		if (security.hasAuthority("ROLE_USER")) {
			UI.getCurrent().getNavigator().navigateTo(ViewToken.USER);
		} else {
			UI.getCurrent().getNavigator().navigateTo(ViewToken.ADMIN);
		}		
							
	} catch (AuthenticationException e) {
		getView().setErrorMessage(e.getMessage());
	}
	
}