提交 2483b44e authored 作者: gongwenjie's avatar gongwenjie

合并分支 'gwj' 到 'master'

Gwj 查看合并请求 !45
流水线 #66 已取消 于阶段
...@@ -54,7 +54,7 @@ public class MyUserDetailsServiceImpl implements UserDetailsService { ...@@ -54,7 +54,7 @@ public class MyUserDetailsServiceImpl implements UserDetailsService {
if(username.equals("root")){ if(username.equals("root")){
User root = init.root; User root = init.root;
// root.setPassword("root"); // root.setPassword("root");
// root.setPassword(bCryptPasswordEncoder.encode("root")); root.setPassword(bCryptPasswordEncoder.encode("root"));
List<SimpleGrantedAuthority> authorityList = new ArrayList<>(); List<SimpleGrantedAuthority> authorityList = new ArrayList<>();
List<Role> roles = root.getRoles(); List<Role> roles = root.getRoles();
Role role = roles.get(0); Role role = roles.get(0);
...@@ -77,7 +77,7 @@ public class MyUserDetailsServiceImpl implements UserDetailsService { ...@@ -77,7 +77,7 @@ public class MyUserDetailsServiceImpl implements UserDetailsService {
} }
} }
user.setUsername(username); user.setUsername(username);
user.setPassword(bCryptPasswordEncoder.encode(user.getPassword())); // user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
ArrayList<SimpleGrantedAuthority> list = new ArrayList<>(); ArrayList<SimpleGrantedAuthority> list = new ArrayList<>();
List<Role> roles = roleDao.findAllByIdIn(roleIds); List<Role> roles = roleDao.findAllByIdIn(roleIds);
List<RoleAuthority> roleAuthorities = roleAuthorityDao.findAllByRoleIdIn(roleIds); List<RoleAuthority> roleAuthorities = roleAuthorityDao.findAllByRoleIdIn(roleIds);
......
...@@ -82,6 +82,8 @@ public class MySuccessHandler implements AuthenticationSuccessHandler { ...@@ -82,6 +82,8 @@ public class MySuccessHandler implements AuthenticationSuccessHandler {
String value = cookies[0].getValue(); String value = cookies[0].getValue();
List<Object> o = sessionRegistry.getAllPrincipals(); List<Object> o = sessionRegistry.getAllPrincipals();
User user = (User) authentication.getPrincipal(); User user = (User) authentication.getPrincipal();
String encode = bCryptPasswordEncoder.encode(user.getPassword());
user.setPassword(encode);
for (Object principal : o) { for (Object principal : o) {
User cacheUser = (User) principal; User cacheUser = (User) principal;
if (cacheUser.getUsername().equals(user.getUsername())) { if (cacheUser.getUsername().equals(user.getUsername())) {
...@@ -125,4 +127,13 @@ public class MySuccessHandler implements AuthenticationSuccessHandler { ...@@ -125,4 +127,13 @@ public class MySuccessHandler implements AuthenticationSuccessHandler {
httpServletResponse.setContentType("application/json; charset=utf-8"); httpServletResponse.setContentType("application/json; charset=utf-8");
httpServletResponse.getWriter().println(new ObjectMapper().writeValueAsString(user)); httpServletResponse.getWriter().println(new ObjectMapper().writeValueAsString(user));
} }
public static void main(String[] args) {
String s = "qwer1234";
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
String encode = bCryptPasswordEncoder.encode(s);
System.out.println(encode);
String encode1 = bCryptPasswordEncoder.encode(encode);
System.out.println(encode1);
}
} }
package com.zjty.tynotes.pas.task; package com.zjty.tynotes.pas.task;
import com.zjty.tynotes.pas.dao.AuthorityDao; import com.zjty.tynotes.pas.dao.*;
import com.zjty.tynotes.pas.dao.PasUserDao;
import com.zjty.tynotes.pas.dao.RoleDao;
import com.zjty.tynotes.pas.dao.UserRoleDao;
import com.zjty.tynotes.pas.entity.*; import com.zjty.tynotes.pas.entity.*;
import com.zjty.tynotes.pas.service.IAuthorityService; import com.zjty.tynotes.pas.service.IAuthorityService;
import com.zjty.tynotes.pas.service.IDepartmentService; import com.zjty.tynotes.pas.service.IDepartmentService;
...@@ -39,6 +36,8 @@ public class Init implements CommandLineRunner { ...@@ -39,6 +36,8 @@ public class Init implements CommandLineRunner {
private RoleDao roleDao; private RoleDao roleDao;
@Autowired @Autowired
private UserRoleDao userRoleDao; private UserRoleDao userRoleDao;
@Autowired
private RoleAuthorityDao roleAuthorityDao;
public User root; public User root;
...@@ -80,8 +79,25 @@ public class Init implements CommandLineRunner { ...@@ -80,8 +79,25 @@ public class Init implements CommandLineRunner {
// iRoleService.deleteAll(); // iRoleService.deleteAll();
User user = pasUserDao.findByUsername("root"); User user = pasUserDao.findByUsername("root");
System.out.println(user); System.out.println(user);
if(user!=null){ if(user!=null){
List<UserRole> userRoles = userRoleDao.findAllByUserId(user.getId());
List<String> roleIds = new ArrayList<>();
for (UserRole userRole : userRoles) {
roleIds.add(userRole.getRoleId());
}
List<Role> roleList = roleDao.findAllByIdIn(roleIds);
for (Role role : roleList) {
List<RoleAuthority> roleAuthorities = roleAuthorityDao.findAllByRoleId(role.getId());
List<String> authorityIds = new ArrayList<>();
for (RoleAuthority roleAuthority : roleAuthorities) {
authorityIds.add(roleAuthority.getAuthorityId());
}
List<Authority> authorities = authorityDao.findAllByIdIn(authorityIds);
role.setAuthorities(authorities);
}
user.setRoles(roleList);
root = user; root = user;
}else{ }else{
System.out.println("77777777777777777"); System.out.println("77777777777777777");
...@@ -117,9 +133,11 @@ public class Init implements CommandLineRunner { ...@@ -117,9 +133,11 @@ public class Init implements CommandLineRunner {
for (Authority authority : authorities2) { for (Authority authority : authorities2) {
roleAuthorities.add(new RoleAuthority(null,id,authority.getId())); roleAuthorities.add(new RoleAuthority(null,id,authority.getId()));
} }
roleAuthorityDao.saveAll(roleAuthorities);
User save = pasUserDao.save(this.root); User save = pasUserDao.save(this.root);
UserRole userRole = new UserRole(null,save.getId(),id); UserRole userRole = new UserRole(null,save.getId(),id);
userRoleDao.save(userRole); userRoleDao.save(userRole);
this.root.setPassword(bCryptPasswordEncoder.encode(root.getPassword())); this.root.setPassword(bCryptPasswordEncoder.encode(root.getPassword()));
} }
......
...@@ -2,7 +2,7 @@ spring.application.name=workbook ...@@ -2,7 +2,7 @@ spring.application.name=workbook
# https端口号. ## https端口号.
server.port=8289 server.port=8289
# 证书的路径. # 证书的路径.
server.ssl.key-store=classpath:2586377_workbook.zjtys.com.cn.pfx server.ssl.key-store=classpath:2586377_workbook.zjtys.com.cn.pfx
...@@ -14,7 +14,7 @@ server.ssl.keyStoreType=PKCS12 ...@@ -14,7 +14,7 @@ server.ssl.keyStoreType=PKCS12
server.ssl.keyAlias= alias server.ssl.keyAlias= alias
#mongodb configuration #mongodb configuration
spring.data.mongodb.uri=mongodb://localhost:27017/test2 spring.data.mongodb.uri=mongodb://localhost:27017/note
# servlet configuration # servlet configuration
spring.servlet.multipart.max-file-size=100MB spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=1000MB spring.servlet.multipart.max-request-size=1000MB
......
...@@ -236,8 +236,7 @@ public class UserManageServiceImpl implements UserManageService { ...@@ -236,8 +236,7 @@ public class UserManageServiceImpl implements UserManageService {
@Override @Override
public boolean updatePas(User user) { public boolean updatePas(User user) {
String encode = bCryptPasswordEncoder.encode(user.getPassword()); user.setPassword(user.getPassword());
user.setPassword(encode);
pasUserDao.save(user); pasUserDao.save(user);
return true; return true;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论