BAEL-4674 - Basic Authentication in JMeter (#11882)
* BAEL-4674 - Basic Authentication in JMeter Test plans & resources for article Basic Authentication in JMeter Server classes to test basic auth against local server * handled comments * updated following feedback Co-authored-by: Sebastien HARDEMAN <sebastien.hardeman@groupe-mma.fr>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package com.baeldung.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
@Configuration
|
||||
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
||||
|
||||
PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
|
||||
|
||||
auth.inMemoryAuthentication()
|
||||
.withUser("admin").password(encoder.encode("admin")).roles("USER", "ADMIN")
|
||||
.and()
|
||||
.withUser("user1").password(encoder.encode("password1")).roles("USER")
|
||||
.and()
|
||||
.withUser("user2").password(encoder.encode("password2")).roles("USER")
|
||||
.and()
|
||||
.withUser("user3").password(encoder.encode("password3")).roles("USER")
|
||||
.and()
|
||||
.withUser("user4").password(encoder.encode("password4")).roles("USER")
|
||||
.and()
|
||||
.withUser("user5").password(encoder.encode("password5")).roles("USER")
|
||||
.and()
|
||||
.withUser("user6").password(encoder.encode("password6")).roles("USER")
|
||||
.and()
|
||||
.withUser("user7").password(encoder.encode("password7")).roles("USER")
|
||||
.and()
|
||||
.withUser("user8").password(encoder.encode("password8")).roles("USER")
|
||||
.and()
|
||||
.withUser("user9").password(encoder.encode("password9")).roles("USER")
|
||||
.and()
|
||||
.withUser("user10").password(encoder.encode("password10")).roles("USER");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
|
||||
http
|
||||
.authorizeRequests()
|
||||
.antMatchers("/secured/**").authenticated()
|
||||
.anyRequest().permitAll()
|
||||
.and()
|
||||
.httpBasic();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.controller;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.baeldung.model.Response;
|
||||
|
||||
@RestController
|
||||
public class SecuredUuidController {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SecuredUuidController.class);
|
||||
|
||||
@GetMapping("/secured/uuid")
|
||||
public Response uuid() {
|
||||
|
||||
LOGGER.info("Returning response");
|
||||
|
||||
return new Response(String.format("Secured test message... %s.", UUID.randomUUID()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user