end: 密码使用BCryptPasswordEncoder散列

This commit is contained in:
wangiegie@gmail.com 2017-12-04 22:35:34 +08:00
parent 781a355261
commit 8087db0c34
3 changed files with 11 additions and 4 deletions

View File

@ -13,11 +13,10 @@ import com.github.pig.common.constant.CommonConstant;
import com.github.pig.common.util.UserUtils;
import com.github.pig.common.vo.UserVo;
import com.github.pig.common.web.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
@ -29,6 +28,7 @@ import java.util.Date;
@RestController
@RequestMapping("/user")
public class UserController extends BaseController {
private static final PasswordEncoder ENCODER = new BCryptPasswordEncoder();
@Autowired
private UserService userService;
@Autowired
@ -94,6 +94,7 @@ public class UserController extends BaseController {
SysUser sysUser = new SysUser();
BeanUtils.copyProperties(userDto, sysUser);
sysUser.setDelFlag(CommonConstant.STATUS_NORMAL);
sysUser.setPassword(ENCODER.encode(userDto.getPassword()));
userService.insert(sysUser);
SysUserRole userRole = new SysUserRole();
userRole.setUserId(sysUser.getUserId());

View File

@ -4,7 +4,6 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
/**

View File

@ -7,6 +7,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.security.authentication.AuthenticationManager;
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.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
@ -53,6 +55,11 @@ public class PigAuthorizationConfig extends AuthorizationServerConfigurerAdapter
.userDetailsService(userDetailsService);
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Bean
public JwtAccessTokenConverter jwtAccessTokenConverter() {
JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();