mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Simplify UserDetailsService creation in samples
Closes gh-10385
This commit is contained in:
parent
61bbaf140c
commit
7093602753
@ -176,7 +176,7 @@
|
||||
<spring-plugin.version>1.2.0.RELEASE</spring-plugin.version>
|
||||
<spring-restdocs.version>1.2.1.RELEASE</spring-restdocs.version>
|
||||
<spring-retry.version>1.2.1.RELEASE</spring-retry.version>
|
||||
<spring-security.version>5.0.0.M4</spring-security.version>
|
||||
<spring-security.version>5.0.0.BUILD-SNAPSHOT</spring-security.version>
|
||||
<spring-session.version>2.0.0.M4</spring-session.version>
|
||||
<spring-session-data-mongodb.version>2.0.0.M3</spring-session-data-mongodb.version>
|
||||
<spring-social.version>2.0.0.M4</spring-social.version>
|
||||
|
@ -20,18 +20,14 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||
|
||||
@SpringBootApplication
|
||||
public class HelloWebSecurityApplication {
|
||||
|
||||
@Bean
|
||||
public UserDetailsService userDetailsService() throws Exception {
|
||||
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
|
||||
manager.createUser(
|
||||
User.withUsername("user").password("password").roles("USER").build());
|
||||
return manager;
|
||||
public InMemoryUserDetailsManager inMemoryUserDetailsManager() throws Exception {
|
||||
return new InMemoryUserDetailsManager(User.withUsername("user").password("password").roles("USER").build());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
@ -20,18 +20,14 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SampleActuatorLog4J2Application {
|
||||
|
||||
@Bean
|
||||
public UserDetailsService userDetailsService() throws Exception {
|
||||
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
|
||||
manager.createUser(
|
||||
User.withUsername("user").password("password").roles("USER").build());
|
||||
return manager;
|
||||
public InMemoryUserDetailsManager inMemoryUserDetailsManager() throws Exception {
|
||||
return new InMemoryUserDetailsManager(User.withUsername("user").password("password").roles("USER").build());
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
@ -23,7 +23,6 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -34,11 +33,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
public class SampleActuatorUiApplication {
|
||||
|
||||
@Bean
|
||||
public UserDetailsService userDetailsService() throws Exception {
|
||||
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
|
||||
manager.createUser(
|
||||
User.withUsername("user").password("password").roles("USER").build());
|
||||
return manager;
|
||||
public InMemoryUserDetailsManager inMemoryUserDetailsManager() throws Exception {
|
||||
return new InMemoryUserDetailsManager(User.withUsername("user").password("password").roles("USER").build());
|
||||
}
|
||||
|
||||
@GetMapping("/")
|
||||
|
@ -23,7 +23,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||
|
||||
@SpringBootApplication
|
||||
@ -35,11 +34,8 @@ public class SampleActuatorApplication {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public UserDetailsService userDetailsService() throws Exception {
|
||||
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
|
||||
manager.createUser(
|
||||
User.withUsername("user").password("password").roles("USER").build());
|
||||
return manager;
|
||||
public InMemoryUserDetailsManager inMemoryUserDetailsManager() throws Exception {
|
||||
return new InMemoryUserDetailsManager(User.withUsername("user").password("password").roles("USER").build());
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
@ -27,7 +27,6 @@ import org.springframework.security.config.annotation.method.configuration.Enabl
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@ -39,11 +38,8 @@ public class SampleSecureApplication implements CommandLineRunner {
|
||||
private SampleService service;
|
||||
|
||||
@Bean
|
||||
public UserDetailsService userDetailsService() throws Exception {
|
||||
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
|
||||
manager.createUser(
|
||||
User.withUsername("user").password("password").roles("USER").build());
|
||||
return manager;
|
||||
public InMemoryUserDetailsManager inMemoryUserDetailsManager() throws Exception {
|
||||
return new InMemoryUserDetailsManager(User.withUsername("user").password("password").roles("USER").build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,7 +31,6 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||
|
||||
@SpringBootConfiguration
|
||||
@ -39,11 +38,8 @@ import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||
public class SampleServletApplication extends SpringBootServletInitializer {
|
||||
|
||||
@Bean
|
||||
public UserDetailsService userDetailsService() throws Exception {
|
||||
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
|
||||
manager.createUser(
|
||||
User.withUsername("user").password("password").roles("USER").build());
|
||||
return manager;
|
||||
public InMemoryUserDetailsManager inMemoryUserDetailsManager() throws Exception {
|
||||
return new InMemoryUserDetailsManager(User.withUsername("user").password("password").roles("USER").build());
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
|
@ -20,7 +20,6 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||
|
||||
@SpringBootApplication
|
||||
@ -31,11 +30,8 @@ public class SampleSessionApplication {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public UserDetailsService userDetailsService() {
|
||||
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
|
||||
manager.createUser(
|
||||
User.withUsername("user").password("password").roles("USER").build());
|
||||
return manager;
|
||||
public InMemoryUserDetailsManager inMemoryUserDetailsManager() throws Exception {
|
||||
return new InMemoryUserDetailsManager(User.withUsername("user").password("password").roles("USER").build());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import org.springframework.boot.test.autoconfigure.web.servlet.MockMvcSecurityAu
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@ -35,11 +34,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
public class SecurityTestApplication {
|
||||
|
||||
@Bean
|
||||
public UserDetailsService userDetailsService() throws Exception {
|
||||
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
|
||||
manager.createUser(
|
||||
User.withUsername("user").password("secret").roles("USER").build());
|
||||
return manager;
|
||||
public InMemoryUserDetailsManager inMemoryUserDetailsManager() throws Exception {
|
||||
return new InMemoryUserDetailsManager(User.withUsername("user").password("password").roles("USER").build());
|
||||
}
|
||||
|
||||
@RestController
|
||||
|
Loading…
Reference in New Issue
Block a user