Problem on configuring Vaadin managed Spring Security with Vaadin4Spring ex

I am not really sure, if this is right place to post my question about Vaadin4Spring.

I set up a project based on the sample https://github.com/peholmst/vaadin4spring/tree/master/samples/security-sample-managed. I try to replace the inMemoryAuthentication by an userDetailsService, but then i am getting the following exceptions.
I can’t figure out the problem. The inMemoryAuthentication configuartion is working.
Many Thanks for your advices and hint.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'eu.cm.CmApplication$AuthenticationConfiguration': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [eu.cm.CmApplication$AuthenticationConfiguration$$EnhancerBySpringCGLIB$$a5edc68d]
: No default constructor found; nested exception is java.lang.NoSuchMethodException: eu.cm.CmApplication$AuthenticationConfiguration$$EnhancerBySpringCGLIB$$a5edc68d.<init>()
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1101)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1046)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:687)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:967)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:956)
    at eu.cm.CmApplication.main(CmApplication.java:30)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [eu.cm.CmApplication$AuthenticationConfiguration$$EnhancerBySpringCGLIB$$a5edc68d]
: No default constructor found; nested exception is java.lang.NoSuchMethodException: eu.cm.CmApplication$AuthenticationConfiguration$$EnhancerBySpringCGLIB$$a5edc68d.<init>()
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:85)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1094)
    ... 16 common frames omitted
Caused by: java.lang.NoSuchMethodException: eu.cm.CmApplication$AuthenticationConfiguration$$EnhancerBySpringCGLIB$$a5edc68d.<init>()
    at java.lang.Class.getConstructor0(Class.java:3074)
    at java.lang.Class.getDeclaredConstructor(Class.java:2170)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:80)
    ... 17 common frames omitted

Here are some snippets of my codes:

CmApplication
============
@SpringBootApplication(exclude = org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration.class)
@EnableVaadinManagedSecurity
public class CmApplication {
    
    @Autowired
    private UserService userService;
    
    @Autowired
    private CmPasswordEncoder passwordEncoder;

    public static void main(String[] args) {
        SpringApplication.run(CmApplication.class, args);
    } 
    
    /**
     * Provide custom system messages to make sure the application is reloaded when the session expires.
     */
    @Bean
    SystemMessagesProvider systemMessagesProvider() {
        return new SystemMessagesProvider() {
              @Override
            public SystemMessages getSystemMessages(SystemMessagesInfo systemMessagesInfo) {
                CustomizedSystemMessages systemMessages = new CustomizedSystemMessages();
                systemMessages.setSessionExpiredNotificationEnabled(false);
                return systemMessages;
            }
        };
    }

    /**
     * Configure the authentication manager.
     */
    @Configuration  
    class AuthenticationConfiguration implements AuthenticationManagerConfigurer {   
        @Override
        public void configure(AuthenticationManagerBuilder auth) throws Exception {            
           auth.userDetailsService(userService).passwordEncoder(passwordEncoder);
        }       
   
    }
}


UserDetails
===========

@Component("userService")
@Scope(value = BeanDefinition.SCOPE_PROTOTYPE)
public class UserService implements UserDetailsService {

    @Autowired
    private BackendUserService backendUserService;
    
    /**
     * @param backendUserService the backendUserService to set
     */
    public void setBackendUserService(BackendUserService backendUserService) {
        this.backendUserService = backendUserService;
    }

    /* (non-Javadoc)
     * @see org.springframework.security.core.userdetails.UserDetailsService#loadUserByUsername(java.lang.String)
     */
    @Override
    public UserDetails loadUserByUsername(String username)
            throws UsernameNotFoundException {
        return this.backendUserService.loadUserByUsername(username);
    }

}

PasswordEncoder
=================
@Component("passwordEncoder")
@Scope(value = BeanDefinition.SCOPE_PROTOTYPE)
public class CmPasswordEncoder implements PasswordEncoder {    

    @Autowired
    private Crypt encrypter;

    public void setEncrypter(Crypt encrypter) {
        this.encrypter = encrypter;
    }

    @Override
    public String encode(CharSequence rawPassword) {
        return this.encrypter.encrypt(rawPassword.toString());
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        return this.encrypter.decrypt(encodedPassword).equals(rawPassword);
    }

}

Hi,

You could try moving your autowiring of the userService & passwordEncoder into the configuration:

[code]

/**
* Configure the authentication manager.
*/
@Configuration
class AuthenticationConfiguration implements AuthenticationManagerConfigurer {

    @Autowired
    private UserService userService;

    @Autowired
    private CmPasswordEncoder passwordEncoder;

    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {            
       auth.userDetailsService(userService).passwordEncoder(passwordEncoder);
    }  

[/code]I made a similar proof of concept based on the vaadin4spring security-sample-managed, UserDetailService and Spring Data JPA. It is really working fine.

Cheers,
Koenraad

Hey Koenraad,

Many thanks. That is the solution. Have a nice day.

Cheers,
Founaboui