oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.26k stars 1.62k forks source link

Unable to get AuthenticationManager instance. The AuthenticationManager instance always null. #7881

Open KaeYan93 opened 10 months ago

KaeYan93 commented 10 months ago

Hi,

I have encountered the issue that the AuthenticationManager instance from Spring Boot Security is always null. Note that this issue will not happen when it is built as jar. My application is using this instance to authenticate user login.

I have a reproducer to reproduce this issue, the below examples are from reproducer. This is how the AuthenticationManager is included in the class.

@RestController
@RequestMapping("/hello")
public class HelloController {
    @Resource
    private AuthenticationManager authenticationManager;

    @Autowired
    private HelloService service;

    @GetMapping
    public String getHello() {
        boolean isNull = authenticationManager==null;
        return "Is AuthenticationManager null" + isNull;
    }
}

This is how it is being configured.

@SuppressWarnings("unused")
@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class SecurityConfig {
    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
                .inMemoryAuthentication()
                .withUser("user").password("{noop}password").roles("USER");
    }

    @Bean
    public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
        return authenticationConfiguration.getAuthenticationManager();
    }
}
KaeYan93 commented 10 months ago

The reproducer can be downloaded here. https://drive.google.com/file/d/16zOYRFkHMftVYNoaj3dQdYz8KSRx8Gku/view?usp=sharing

hamzaGhaissi commented 10 months ago

Hi can you please share your graalvm version, and OS with architecture, and steps you used to run the app ?

KaeYan93 commented 10 months ago

Graalvm JDK: v17.0.9 OS: Windows 10 Architecture: x64

brahimhaddou commented 10 months ago

@KaeYan93 can you please share the steps to reproduce the issue

KaeYan93 commented 10 months ago

The reproducer is: https://drive.google.com/file/d/16zOYRFkHMftVYNoaj3dQdYz8KSRx8Gku/view?usp=sharing

The steps is: $ cd testfeature\parent\starter $ mvnw native:compile -Pnative $ cd target $ starter.exe

Upon calling the REST API GET http://localhost:8080/hello, with Authorization header, Basic, user: user, password: password, the output will show that the instance is null.

image