how to login to a spring boot API that has spring security, from a another java application

Viewed 97

I have a spring boot App that uses spring security, I want that application to be accessible as a web application and as an API, currently I am using this simple config:

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Autowired
    public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication().withUser("admin")
                .roles("ADMIN").password("{noop}admin");;
    }
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/admin").hasRole("ADMIN")
                .and().formLogin();
    }
}

i want to able to login through another java application, maybe using webflux webclient.<>

this may not be the best way, if so tell me, I've looked everywhere and cant seem to find a way to authenticate with spring security from another application.

1 Answers

i got it,

         webClient.get()
                .uri(url)
                .headers(headers -> headers.setBasicAuth(username, password))
                .retrieve().bodyToMono(String.class);

Related