// Path: src/main/java/org/vaadin/spring/sample/security/account/JdbcUserDetailsService.java
// @Service
// public class JdbcUserDetailsService implements UserDetailsService {
// 	
// 	private final Logger LOG = LoggerFactory.getLogger(getClass());
// 
// 	@Autowired
// 	AccountRepository repository;
// 	
// 	@Override
// 	public UserDetails loadUserByUsername(String username)
// 			throws UsernameNotFoundException {
// 		
// 		try {
// 			Account account = repository.findAccountByUsername(username);
// 			User user = new User(account.getUsername(), account.getPassword(), AuthorityUtils.createAuthorityList(account.getRole()));
// 			return user;
// 		} catch (DataAccessException e) {
// 			LOG.debug("Account not found", e);
// 			throw new UsernameNotFoundException("Username not found.");
// 		}
// 		
// 	}
// 
// }
// 
// Path: src/main/java/org/vaadin/spring/sample/security/ui/security/PreAuthorizeSpringViewProviderAccessDelegate.java
// public class PreAuthorizeSpringViewProviderAccessDelegate implements ViewProviderAccessDelegate {
// 
// 	private final Security security;
//     private final ApplicationContext applicationContext;
// 
//     @Autowired
//     public PreAuthorizeSpringViewProviderAccessDelegate(Security security, ApplicationContext applicationContext) {
//         this.security = security;
//         this.applicationContext = applicationContext;
//     }
// 	
// 	@Override
// 	public boolean isAccessGranted(String beanName, UI ui) {
// 		
// 		final PreAuthorize viewSecured = applicationContext.findAnnotationOnBean(beanName, PreAuthorize.class);
// 					
// 		if (viewSecured != null) {
// 
// 			final Class<?> targetClass = AopUtils.getTargetClass(applicationContext.getBean(beanName));
// 			final Method method = ClassUtils.getMethod(AopUtils.getTargetClass(applicationContext.getBean(beanName)), "enter", com.vaadin.navigator.ViewChangeListener.ViewChangeEvent.class);								
// 			final MethodInvocation methodInvocation = MethodInvocationUtils.createFromClass(targetClass, method.getName());
// 									
// 			final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
// 			final AccessDecisionManager accessDecisionManager = applicationContext.getBean(AccessDecisionManager.class);			        	        	        	       	        	       
// 	        final ExpressionBasedAnnotationAttributeFactory attributeFactory = new ExpressionBasedAnnotationAttributeFactory(new DefaultMethodSecurityExpressionHandler());
// 	        
// 			Collection<ConfigAttribute> atributi = new ArrayList<ConfigAttribute>();
// 			atributi.add(attributeFactory.createPreInvocationAttribute(null, null, viewSecured.value()));
// 			
// 	        try {
// 	            accessDecisionManager.decide(authentication, methodInvocation, atributi);
// 	            return true;
// 	        } catch (AccessDeniedException | InsufficientAuthenticationException ex) {
// 	            return false;
// 	        }
// 			
// 		} else {
// 			return true;
// 		}
// 		
// 	}
// 
// }
// 
// Path: src/main/java/org/vaadin/spring/sample/security/ui/security/VaadinPersistentTokenBasedRememberMeServices.java
// public class VaadinPersistentTokenBasedRememberMeServices extends
// 		PersistentTokenBasedRememberMeServices {
// 
// 	public VaadinPersistentTokenBasedRememberMeServices(String key,
// 			UserDetailsService userDetailsService,
// 			PersistentTokenRepository tokenRepository) {		
// 		super(key, userDetailsService, tokenRepository);
// 	}
// 
// 	@Override
// 	protected boolean rememberMeRequested(HttpServletRequest request,
// 			String parameter) {
// 
// 		if (request.getAttribute(DEFAULT_PARAMETER) != null && (boolean)request.getAttribute(DEFAULT_PARAMETER)) {
// 			request.removeAttribute(DEFAULT_PARAMETER);
// 			return true;
// 		}
// 		return super.rememberMeRequested(request, parameter);		
// 	}
// 
// }


import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.AccessDecisionManager;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
import org.springframework.security.crypto.encrypt.Encryptors;
import org.springframework.security.crypto.encrypt.TextEncryptor;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
import org.springframework.security.web.authentication.RememberMeServices;
import org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl;
import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository;
import org.vaadin.spring.sample.security.account.JdbcUserDetailsService;
import org.vaadin.spring.sample.security.ui.security.PreAuthorizeSpringViewProviderAccessDelegate;
import org.vaadin.spring.sample.security.ui.security.VaadinPersistentTokenBasedRememberMeServices;
import org.vaadin.spring.security.Security;
package org.vaadin.spring.sample.security;




@Configuration
@ComponentScan
public class SecurityConfig   {
			
	
	@Autowired
	private ApplicationContext context;
	
	@Autowired
	private Security security;
	
	@Bean
// Path: src/main/java/org/vaadin/spring/sample/security/account/JdbcUserDetailsService.java
// @Service
// public class JdbcUserDetailsService implements UserDetailsService {
// 	
// 	private final Logger LOG = LoggerFactory.getLogger(getClass());
// 
// 	@Autowired
// 	AccountRepository repository;
// 	
// 	@Override
// 	public UserDetails loadUserByUsername(String username)
// 			throws UsernameNotFoundException {
// 		
// 		try {
// 			Account account = repository.findAccountByUsername(username);
// 			User user = new User(account.getUsername(), account.getPassword(), AuthorityUtils.createAuthorityList(account.getRole()));
// 			return user;
// 		} catch (DataAccessException e) {
// 			LOG.debug("Account not found", e);
// 			throw new UsernameNotFoundException("Username not found.");
// 		}
// 		
// 	}
// 
// }
// 
// Path: src/main/java/org/vaadin/spring/sample/security/ui/security/PreAuthorizeSpringViewProviderAccessDelegate.java
// public class PreAuthorizeSpringViewProviderAccessDelegate implements ViewProviderAccessDelegate {
// 
// 	private final Security security;
//     private final ApplicationContext applicationContext;
// 
//     @Autowired
//     public PreAuthorizeSpringViewProviderAccessDelegate(Security security, ApplicationContext applicationContext) {
//         this.security = security;
//         this.applicationContext = applicationContext;
//     }
// 	
// 	@Override
// 	public boolean isAccessGranted(String beanName, UI ui) {
// 		
// 		final PreAuthorize viewSecured = applicationContext.findAnnotationOnBean(beanName, PreAuthorize.class);
// 					
// 		if (viewSecured != null) {
// 
// 			final Class<?> targetClass = AopUtils.getTargetClass(applicationContext.getBean(beanName));
// 			final Method method = ClassUtils.getMethod(AopUtils.getTargetClass(applicationContext.getBean(beanName)), "enter", com.vaadin.navigator.ViewChangeListener.ViewChangeEvent.class);								
// 			final MethodInvocation methodInvocation = MethodInvocationUtils.createFromClass(targetClass, method.getName());
// 									
// 			final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
// 			final AccessDecisionManager accessDecisionManager = applicationContext.getBean(AccessDecisionManager.class);			        	        	        	       	        	       
// 	        final ExpressionBasedAnnotationAttributeFactory attributeFactory = new ExpressionBasedAnnotationAttributeFactory(new DefaultMethodSecurityExpressionHandler());
// 	        
// 			Collection<ConfigAttribute> atributi = new ArrayList<ConfigAttribute>();
// 			atributi.add(attributeFactory.createPreInvocationAttribute(null, null, viewSecured.value()));
// 			
// 	        try {
// 	            accessDecisionManager.decide(authentication, methodInvocation, atributi);
// 	            return true;
// 	        } catch (AccessDeniedException | InsufficientAuthenticationException ex) {
// 	            return false;
// 	        }
// 			
// 		} else {
// 			return true;
// 		}
// 		
// 	}
// 
// }
// 
// Path: src/main/java/org/vaadin/spring/sample/security/ui/security/VaadinPersistentTokenBasedRememberMeServices.java
// public class VaadinPersistentTokenBasedRememberMeServices extends
// 		PersistentTokenBasedRememberMeServices {
// 
// 	public VaadinPersistentTokenBasedRememberMeServices(String key,
// 			UserDetailsService userDetailsService,
// 			PersistentTokenRepository tokenRepository) {		
// 		super(key, userDetailsService, tokenRepository);
// 	}
// 
// 	@Override
// 	protected boolean rememberMeRequested(HttpServletRequest request,
// 			String parameter) {
// 
// 		if (request.getAttribute(DEFAULT_PARAMETER) != null && (boolean)request.getAttribute(DEFAULT_PARAMETER)) {
// 			request.removeAttribute(DEFAULT_PARAMETER);
// 			return true;
// 		}
// 		return super.rememberMeRequested(request, parameter);		
// 	}
// 
// }


// Path: src/main/java/org/vaadin/spring/sample/security/SecurityConfig.java
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.AccessDecisionManager;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
import org.springframework.security.crypto.encrypt.Encryptors;
import org.springframework.security.crypto.encrypt.TextEncryptor;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
import org.springframework.security.web.authentication.RememberMeServices;
import org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl;
import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository;
import org.vaadin.spring.sample.security.account.JdbcUserDetailsService;
import org.vaadin.spring.sample.security.ui.security.PreAuthorizeSpringViewProviderAccessDelegate;
import org.vaadin.spring.sample.security.ui.security.VaadinPersistentTokenBasedRememberMeServices;
import org.vaadin.spring.security.Security;

package org.vaadin.spring.sample.security;




@Configuration
@ComponentScan
public class SecurityConfig   {
			
	
	@Autowired
	private ApplicationContext context;
	
	@Autowired
	private Security security;
	
	@Bean
	public PreAuthorizeSpringViewProviderAccessDelegate preAuthorizeSpringViewProviderAccessDelegate() {