清理无效代码

master
barney 2 months ago
parent 91ecd20f66
commit 786bbf8622
  1. 52
      src/main/java/cc/bnblogs/springinit/DemoApplicationConfiguration.java
  2. 33
      src/main/java/cc/bnblogs/springinit/config/SecurityConfig.java
  3. 2
      src/main/java/cc/bnblogs/springinit/service/UserService.java

@ -1,52 +0,0 @@
package cc.bnblogs.springinit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
//@Configuration
public class DemoApplicationConfiguration {
private Logger logger = LoggerFactory.getLogger(DemoApplicationConfiguration.class);
// @Bean
public UserDetailsService myUserDetailsService() {
InMemoryUserDetailsManager inMemoryUserDetailsManager = new InMemoryUserDetailsManager();
String[][] usersGroupsAndRoles = {
{ "zhangsan", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam" },
{ "lisi", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam" },
{ "wangwu", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam" },
{ "other", "password", "ROLE_ACTIVITI_USER", "GROUP_otherTeam" },
{ "admin", "password", "ROLE_ACTIVITI_ADMIN" },
};
for (String[] user : usersGroupsAndRoles) {
List<String> authoritiesStrings = Arrays.asList(Arrays.copyOfRange(user, 2, user.length));
logger.info("> Registering new user: " + user[0] + " with the following Authorities[" + authoritiesStrings + "]");
inMemoryUserDetailsManager.createUser(new User(user[0], passwordEncoder().encode(user[1]),
authoritiesStrings.stream().map(s -> new SimpleGrantedAuthority(s)).collect(Collectors.toList())));
}
return inMemoryUserDetailsManager;
}
// @Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}

@ -1,41 +1,10 @@
package cc.bnblogs.springinit.config; package cc.bnblogs.springinit.config;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.security.crypto.password.PasswordEncoder;
//
//
//@Configuration
//public class SecurityConfig extends WebSecurityConfigurerAdapter {
//
// @Override
// protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
// auth.inMemoryAuthentication().
// withUser("lucy").
// password(passwordEncoder.encode("123")).roles("admin").
// and().
// withUser("tom")
// .password(passwordEncoder.encode("123")).roles("admin");
// }
//
// @Bean
// PasswordEncoder password() {
// return new BCryptPasswordEncoder();
// }
//}
import cc.bnblogs.springinit.service.CustomUserDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
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.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;

@ -3,6 +3,8 @@ package cc.bnblogs.springinit.service;
import cc.bnblogs.springinit.mapper.UserMapper; import cc.bnblogs.springinit.mapper.UserMapper;
import cc.bnblogs.springinit.pojo.MyUser; import cc.bnblogs.springinit.pojo.MyUser;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;

Loading…
Cancel
Save