From c567d961c149033f861260ce1535099eeb43b7f0 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Sat, 15 Feb 2020 17:42:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9D=83=E9=99=90=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=AD=90=E7=B3=BB=E7=BB=9F=E7=9A=84=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=B1=82=E6=8E=A5=E5=8F=A3,=E4=BF=AE=E6=AD=A3=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=B1=82=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...onalPermissionContainersListGenerator.java | 11 +- ...FunctionalScopeRelationsListGenerator.java | 10 +- ...ionContainersCollectionsListGenerator.java | 12 +- .../ase/component/UserRolesListGenerator.java | 12 +- .../ase/component/UserTagsListGenerator.java | 1 - .../ase/configure/ComponentsConfigure.java | 34 +++++ .../ase/configure/GlobalConfigure.java | 1 + .../ase/controller/HomeController.java | 12 ++ .../ase/controller/RegisterController.java | 4 +- .../codesdream/ase/model/permission/Tag.java | 2 +- .../codesdream/ase/model/permission/User.java | 16 ++- .../ase/model/permission/UserAuth.java | 24 ++++ .../ase/model/permission/UserDetail.java | 3 + .../FunctionalPermissionRepository.java | 2 +- .../repository/ScopePermissionRepository.java | 2 +- .../ase/service/IPermissionService.java | 67 ++++++++++ .../codesdream/ase/service/IUserService.java | 18 ++- .../ase/service/PermissionService.java | 119 ++++++++++++++++++ .../codesdream/ase/service/UserService.java | 26 +++- .../com/codesdream/ase/test/UserTest.java | 1 + src/main/resources/templates/forget.html | 4 +- 21 files changed, 342 insertions(+), 39 deletions(-) create mode 100644 src/main/java/com/codesdream/ase/configure/ComponentsConfigure.java create mode 100644 src/main/java/com/codesdream/ase/controller/HomeController.java create mode 100644 src/main/java/com/codesdream/ase/model/permission/UserAuth.java diff --git a/src/main/java/com/codesdream/ase/component/UserFunctionalPermissionContainersListGenerator.java b/src/main/java/com/codesdream/ase/component/UserFunctionalPermissionContainersListGenerator.java index 49f2c20..cc6ddfd 100644 --- a/src/main/java/com/codesdream/ase/component/UserFunctionalPermissionContainersListGenerator.java +++ b/src/main/java/com/codesdream/ase/component/UserFunctionalPermissionContainersListGenerator.java @@ -1,23 +1,22 @@ package com.codesdream.ase.component; import com.codesdream.ase.model.permission.*; -import org.springframework.stereotype.Component; -import javax.annotation.Resource; import java.util.ArrayList; import java.util.Collection; /** * 生成功能性权限容器列表 */ -@Component public class UserFunctionalPermissionContainersListGenerator { private UserFunctionalScopeRelationsListGenerator functionalScopeRelationsListGenerator; - public UserFunctionalPermissionContainersListGenerator(){ - this.functionalScopeRelationsListGenerator = - new UserFunctionalScopeRelationsListGenerator(); + public UserFunctionalPermissionContainersListGenerator( + UserFunctionalScopeRelationsListGenerator userFunctionalScopeRelationsListGenerator) + { + if(userFunctionalScopeRelationsListGenerator == null) throw new NullPointerException(); + this.functionalScopeRelationsListGenerator = userFunctionalScopeRelationsListGenerator; } public Collection generateFunctionalContainers( diff --git a/src/main/java/com/codesdream/ase/component/UserFunctionalScopeRelationsListGenerator.java b/src/main/java/com/codesdream/ase/component/UserFunctionalScopeRelationsListGenerator.java index 5a6f8a8..027ecd7 100644 --- a/src/main/java/com/codesdream/ase/component/UserFunctionalScopeRelationsListGenerator.java +++ b/src/main/java/com/codesdream/ase/component/UserFunctionalScopeRelationsListGenerator.java @@ -3,23 +3,23 @@ package com.codesdream.ase.component; import com.codesdream.ase.model.permission.FunctionalScopeRelation; import com.codesdream.ase.model.permission.PermissionContainersCollection; import com.codesdream.ase.model.permission.User; -import org.springframework.stereotype.Component; -import javax.annotation.Resource; import java.util.ArrayList; import java.util.Collection; /** * 生成功能性权限容器与范围性权限容器关联对列表 */ -@Component public class UserFunctionalScopeRelationsListGenerator { private UserPermissionContainersCollectionsListGenerator userPermissionContainersCollectionsListGenerator; - public UserFunctionalScopeRelationsListGenerator(){ + public UserFunctionalScopeRelationsListGenerator( + UserPermissionContainersCollectionsListGenerator userPermissionContainersCollectionsListGenerator) + { + if(userPermissionContainersCollectionsListGenerator == null) throw new NullPointerException(); this.userPermissionContainersCollectionsListGenerator = - new UserPermissionContainersCollectionsListGenerator(); + userPermissionContainersCollectionsListGenerator; } public Collection generateFunctionalScopeRelations( diff --git a/src/main/java/com/codesdream/ase/component/UserPermissionContainersCollectionsListGenerator.java b/src/main/java/com/codesdream/ase/component/UserPermissionContainersCollectionsListGenerator.java index 3baade0..e4a87bd 100644 --- a/src/main/java/com/codesdream/ase/component/UserPermissionContainersCollectionsListGenerator.java +++ b/src/main/java/com/codesdream/ase/component/UserPermissionContainersCollectionsListGenerator.java @@ -3,25 +3,21 @@ package com.codesdream.ase.component; import com.codesdream.ase.model.permission.PermissionContainersCollection; import com.codesdream.ase.model.permission.Tag; import com.codesdream.ase.model.permission.User; -import org.springframework.stereotype.Component; -import javax.annotation.Resource; import java.util.ArrayList; import java.util.Collection; -import java.util.List; -import java.util.Optional; /** * 生成权限容器集合列表 */ -@Component public class UserPermissionContainersCollectionsListGenerator { private UserTagsListGenerator userTagsListGenerator; - public UserPermissionContainersCollectionsListGenerator(){ - this.userTagsListGenerator = - new UserTagsListGenerator(); + public UserPermissionContainersCollectionsListGenerator(UserTagsListGenerator userTagsListGenerator) + { + if(userTagsListGenerator == null) throw new NullPointerException(); + this.userTagsListGenerator = userTagsListGenerator; } public Collection generatePermissionContainerCollections( diff --git a/src/main/java/com/codesdream/ase/component/UserRolesListGenerator.java b/src/main/java/com/codesdream/ase/component/UserRolesListGenerator.java index 5c9f19b..d05c35c 100644 --- a/src/main/java/com/codesdream/ase/component/UserRolesListGenerator.java +++ b/src/main/java/com/codesdream/ase/component/UserRolesListGenerator.java @@ -2,27 +2,25 @@ package com.codesdream.ase.component; import com.codesdream.ase.model.permission.FunctionalPermissionContainer; import com.codesdream.ase.model.permission.User; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.stereotype.Component; -import javax.annotation.Resource; import java.util.ArrayList; import java.util.Collection; -import java.util.Optional; /** * 生成用户访问权限角色列表 */ -@Component + public class UserRolesListGenerator { private UserFunctionalPermissionContainersListGenerator functionalPermissionContainersListGenerator; - public UserRolesListGenerator(){ + public UserRolesListGenerator( + UserFunctionalPermissionContainersListGenerator userFunctionalPermissionContainersListGenerator) + { this.functionalPermissionContainersListGenerator = - new UserFunctionalPermissionContainersListGenerator(); + userFunctionalPermissionContainersListGenerator; } public Collection generateRoles( diff --git a/src/main/java/com/codesdream/ase/component/UserTagsListGenerator.java b/src/main/java/com/codesdream/ase/component/UserTagsListGenerator.java index b3fca13..cb0f2a8 100644 --- a/src/main/java/com/codesdream/ase/component/UserTagsListGenerator.java +++ b/src/main/java/com/codesdream/ase/component/UserTagsListGenerator.java @@ -14,7 +14,6 @@ import java.util.Optional; /** * 生成用户标签列表 */ -@Component public class UserTagsListGenerator { @Resource UserRepository userRepository; diff --git a/src/main/java/com/codesdream/ase/configure/ComponentsConfigure.java b/src/main/java/com/codesdream/ase/configure/ComponentsConfigure.java new file mode 100644 index 0000000..c0e7aaa --- /dev/null +++ b/src/main/java/com/codesdream/ase/configure/ComponentsConfigure.java @@ -0,0 +1,34 @@ +package com.codesdream.ase.configure; + +import com.codesdream.ase.component.*; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class ComponentsConfigure { + @Bean + UserTagsListGenerator userTagsListGenerator(){ + return new UserTagsListGenerator(); + } + + @Bean + UserPermissionContainersCollectionsListGenerator userPermissionContainersCollectionsListGenerator(){ + return new UserPermissionContainersCollectionsListGenerator(userTagsListGenerator()); + } + + @Bean + UserFunctionalScopeRelationsListGenerator userFunctionalScopeRelationsListGenerator(){ + return new UserFunctionalScopeRelationsListGenerator(userPermissionContainersCollectionsListGenerator()); + } + + @Bean + UserFunctionalPermissionContainersListGenerator userFunctionalPermissionContainersListGenerator(){ + return new UserFunctionalPermissionContainersListGenerator(userFunctionalScopeRelationsListGenerator()); + } + + @Bean + UserRolesListGenerator userRolesListGenerator(){ + return new UserRolesListGenerator(userFunctionalPermissionContainersListGenerator()); + } + +} diff --git a/src/main/java/com/codesdream/ase/configure/GlobalConfigure.java b/src/main/java/com/codesdream/ase/configure/GlobalConfigure.java index a6dc9ad..e39a0e2 100644 --- a/src/main/java/com/codesdream/ase/configure/GlobalConfigure.java +++ b/src/main/java/com/codesdream/ase/configure/GlobalConfigure.java @@ -16,4 +16,5 @@ import java.util.Map; public class GlobalConfigure { + } diff --git a/src/main/java/com/codesdream/ase/controller/HomeController.java b/src/main/java/com/codesdream/ase/controller/HomeController.java new file mode 100644 index 0000000..2515570 --- /dev/null +++ b/src/main/java/com/codesdream/ase/controller/HomeController.java @@ -0,0 +1,12 @@ +package com.codesdream.ase.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +public class HomeController { + @RequestMapping(value = "/home") + public String showHomeView(){ + return "home"; + } +} diff --git a/src/main/java/com/codesdream/ase/controller/RegisterController.java b/src/main/java/com/codesdream/ase/controller/RegisterController.java index c8a3aca..024a7e4 100644 --- a/src/main/java/com/codesdream/ase/controller/RegisterController.java +++ b/src/main/java/com/codesdream/ase/controller/RegisterController.java @@ -49,8 +49,8 @@ public class RegisterController { if (password.equals(retry_password)) { user.setPassword(password); userService.save(user); - - return "index"; + // 返回登录界面 + return "login"; } } diff --git a/src/main/java/com/codesdream/ase/model/permission/Tag.java b/src/main/java/com/codesdream/ase/model/permission/Tag.java index 0e79659..bffab68 100644 --- a/src/main/java/com/codesdream/ase/model/permission/Tag.java +++ b/src/main/java/com/codesdream/ase/model/permission/Tag.java @@ -26,7 +26,7 @@ public class Tag { private String description; // 标签关联用户 - @ManyToMany(mappedBy = "tags", cascade = CascadeType.MERGE, fetch = FetchType.LAZY) + @ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) private Set users; // 启用标志 diff --git a/src/main/java/com/codesdream/ase/model/permission/User.java b/src/main/java/com/codesdream/ase/model/permission/User.java index 45c446a..89c97e2 100644 --- a/src/main/java/com/codesdream/ase/model/permission/User.java +++ b/src/main/java/com/codesdream/ase/model/permission/User.java @@ -1,10 +1,13 @@ package com.codesdream.ase.model.permission; import com.codesdream.ase.component.UserRolesListGenerator; +import com.codesdream.ase.service.UserService; import lombok.Data; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; +import javax.annotation.PostConstruct; +import javax.annotation.Resource; import javax.persistence.*; import java.util.Collection; import java.util.HashSet; @@ -14,6 +17,10 @@ import java.util.Set; @Entity @Table(name = "user") public class User implements UserDetails { + + @Resource + private transient UserService userService; + @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; @@ -45,9 +52,14 @@ public class User implements UserDetails { @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) private Set tags; + // 用户详细信息 @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) private UserDetail userDetail; + // 用户认证表 + @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private UserAuth userAuth; + public User(String username, String password) { this.username = username; @@ -73,12 +85,12 @@ public class User implements UserDetails { this.enabled = true; this.tags = new HashSet<>(); this.userDetail = new UserDetail(); + this.userAuth = new UserAuth(); } @Override public Collection getAuthorities() { - UserRolesListGenerator userRolesListGenerator = new UserRolesListGenerator(); - return userRolesListGenerator.generateRoles(this); + return userService.getUserAuthorities(this); } } diff --git a/src/main/java/com/codesdream/ase/model/permission/UserAuth.java b/src/main/java/com/codesdream/ase/model/permission/UserAuth.java new file mode 100644 index 0000000..e80d7b7 --- /dev/null +++ b/src/main/java/com/codesdream/ase/model/permission/UserAuth.java @@ -0,0 +1,24 @@ +package com.codesdream.ase.model.permission; + +import lombok.Data; + +import javax.persistence.*; + +@Data +@Entity +@Table(name = "user_auth") +public class UserAuth { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + // 密保问题 + private String user_question; + + // 密保问题答案 + private String user_answer; + + // 用户邮箱 + private String mail; +} diff --git a/src/main/java/com/codesdream/ase/model/permission/UserDetail.java b/src/main/java/com/codesdream/ase/model/permission/UserDetail.java index 52f7fb8..8e4fe06 100644 --- a/src/main/java/com/codesdream/ase/model/permission/UserDetail.java +++ b/src/main/java/com/codesdream/ase/model/permission/UserDetail.java @@ -35,4 +35,7 @@ public class UserDetail { // 学生ID private String studentID; + + // 在校状态 + private boolean atSchool; } diff --git a/src/main/java/com/codesdream/ase/repository/FunctionalPermissionRepository.java b/src/main/java/com/codesdream/ase/repository/FunctionalPermissionRepository.java index 098f8d4..5776b09 100644 --- a/src/main/java/com/codesdream/ase/repository/FunctionalPermissionRepository.java +++ b/src/main/java/com/codesdream/ase/repository/FunctionalPermissionRepository.java @@ -8,5 +8,5 @@ import java.util.Optional; @Repository public interface FunctionalPermissionRepository extends CrudRepository { - Optional findByName(String name); + Optional findByName(String name); } diff --git a/src/main/java/com/codesdream/ase/repository/ScopePermissionRepository.java b/src/main/java/com/codesdream/ase/repository/ScopePermissionRepository.java index 8d0dd0d..984580a 100644 --- a/src/main/java/com/codesdream/ase/repository/ScopePermissionRepository.java +++ b/src/main/java/com/codesdream/ase/repository/ScopePermissionRepository.java @@ -6,5 +6,5 @@ import org.springframework.data.repository.CrudRepository; import java.util.Optional; public interface ScopePermissionRepository extends CrudRepository { - Optional findByName(String name); + Optional findByName(String name); } diff --git a/src/main/java/com/codesdream/ase/service/IPermissionService.java b/src/main/java/com/codesdream/ase/service/IPermissionService.java index f4d7108..77d96cc 100644 --- a/src/main/java/com/codesdream/ase/service/IPermissionService.java +++ b/src/main/java/com/codesdream/ase/service/IPermissionService.java @@ -1,4 +1,71 @@ package com.codesdream.ase.service; +import com.codesdream.ase.model.permission.*; +import com.sun.org.apache.xpath.internal.functions.FuncQname; +import javafx.util.Pair; + +import java.util.Collection; +import java.util.Optional; + public interface IPermissionService { + // 查找用户标签 + Optional findTag(String name); + + // 查找功能性权限容器 + Optional findFunctionalPermissionContainer(String name); + + // 查找范围性权限容器 + Optional findScopePermissionContainer(String name); + + // 标签下所有的获得权限容器集合列表 + Collection getPermissionContainerCollections(Tag tag); + + // 获得范围性权限容器下的所有标签列表 + Collection getTagsFromScopePermissionContainers( + ScopePermissionContainer scopePermissionContainer); + + // 查找用户下的所有标签列表 + Collection getTagsFromUser(User user); + + // 查找功能性权限容器下的所有范围性权限容器列表 + Collection getFunctionPermissionContainers( + PermissionContainersCollection permissionContainersCollection); + + // 查找标签下的所有用户 + Collection getUsersFromTag(Tag tag); + + // 指定一对功能性权限容器与对应的范围性权限容器并添加到指定权限容器集合中 + void addRelationItemToPermissionContainerCollectionPermissionContainerCollection( + PermissionContainersCollection permissionContainersCollection, + FunctionalPermissionContainer functionalPermissionContainer, + ScopePermissionContainer scopePermissionContainer); + + // 指定多对功能性权限容器与对应的范围性权限容器并添加到指定权限容器集合中 + void addRelationItemsToPermissionContainerCollectionPermissionContainerCollection( + PermissionContainersCollection permissionContainersCollection, + Collection> + functionalScopePermissionContainerPairs); + + // 添加一个用户到指定标签中 + void addUserToTag(Tag tag, User user); + + // 添加多个用户到指定标签中 + void addUsersToTag(Tag tag, Collection users); + + // 为功能性权限容器添加一个访问控制角色 + void addRoleToFunctionalPermissionContainer( + FunctionalPermissionContainer functionalPermissionContainer, + String role); + + // 为功能性权限容器添加多个访问控制角色 + void addRolesToFunctionalPermissionContainer( + FunctionalPermissionContainer functionalPermissionContainer, + Collection roles); + + void save(Tag tag); + + void save(FunctionalPermissionContainer functionalPermissionContainer); + + void save(ScopePermissionContainer scopePermissionContainer); + } diff --git a/src/main/java/com/codesdream/ase/service/IUserService.java b/src/main/java/com/codesdream/ase/service/IUserService.java index 2c68e50..ea92e36 100644 --- a/src/main/java/com/codesdream/ase/service/IUserService.java +++ b/src/main/java/com/codesdream/ase/service/IUserService.java @@ -1,18 +1,32 @@ package com.codesdream.ase.service; import com.codesdream.ase.model.permission.User; +import org.springframework.security.core.GrantedAuthority; +import java.util.Collection; import java.util.List; import java.util.Optional; public interface IUserService { + + // 获得一个空的默认用户 + User getDefaultUser(); + List findAll(); Optional findUserById(int id); Optional findUserByUsername(String username); + + // 获得用户所有的权限角色 + Collection getUserAuthorities(User user); + + // 更新用户的密码 + void updatePassword(User user, String password); + User save(User user); - // 获得默认用户 - User getDefaultUser(); + + User update(User user); + } diff --git a/src/main/java/com/codesdream/ase/service/PermissionService.java b/src/main/java/com/codesdream/ase/service/PermissionService.java index 8147826..056a6c1 100644 --- a/src/main/java/com/codesdream/ase/service/PermissionService.java +++ b/src/main/java/com/codesdream/ase/service/PermissionService.java @@ -1,8 +1,127 @@ package com.codesdream.ase.service; +import com.codesdream.ase.component.UserFunctionalPermissionContainersListGenerator; +import com.codesdream.ase.component.UserFunctionalScopeRelationsListGenerator; +import com.codesdream.ase.model.permission.*; +import com.codesdream.ase.repository.FunctionalPermissionRepository; +import com.codesdream.ase.repository.ScopePermissionRepository; +import com.codesdream.ase.repository.TagRepository; +import javafx.util.Pair; import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Optional; + @Service public class PermissionService implements IPermissionService { + @Resource + private TagRepository tagRepository; + + @Resource + private FunctionalPermissionRepository functionalPermissionRepository; + + @Resource + private ScopePermissionRepository scopePermissionRepository; + + @Resource + private UserFunctionalPermissionContainersListGenerator userFunctionalPermissionContainersListGenerator; + + @Resource + UserFunctionalScopeRelationsListGenerator userFunctionalScopeRelationsListGenerator; + + @Override + public Optional findTag(String name) { + return tagRepository.findByName(name); + } + + @Override + public Optional findFunctionalPermissionContainer(String name) { + return functionalPermissionRepository.findByName(name); + } + + @Override + public Optional findScopePermissionContainer(String name) { + return scopePermissionRepository.findByName(name); + } + + @Override + public Collection getPermissionContainerCollections(Tag tag) { + return new ArrayList<>(tag.getPermissionContainersCollections()); + } + + @Override + public Collection getTagsFromScopePermissionContainers(ScopePermissionContainer scopePermissionContainer) { + return new ArrayList<>(scopePermissionContainer.getTags()); + } + + @Override + public Collection getTagsFromUser(User user) { + return new ArrayList<>(user.getTags()); + } + + @Override + public Collection getFunctionPermissionContainers(PermissionContainersCollection permissionContainersCollection) { + + Collection permissionContainersCollections = new ArrayList(){{ + add(permissionContainersCollection); + }}; + + // 生成功能性与范围性权限容器关联对 + Collection functionalScopeRelations = + userFunctionalScopeRelationsListGenerator.generateFunctionalScopeRelations(permissionContainersCollections); + return userFunctionalPermissionContainersListGenerator.generateFunctionalContainers(functionalScopeRelations); + } + + @Override + public Collection getUsersFromTag(Tag tag) { + return null; + } + + @Override + public void addRelationItemToPermissionContainerCollectionPermissionContainerCollection(PermissionContainersCollection permissionContainersCollection, FunctionalPermissionContainer functionalPermissionContainer, ScopePermissionContainer scopePermissionContainer) { + + } + + @Override + public void addRelationItemsToPermissionContainerCollectionPermissionContainerCollection(PermissionContainersCollection permissionContainersCollection, Collection> functionalScopePermissionContainerPairs) { + + } + + @Override + public void addUserToTag(Tag tag, User user) { + + } + + @Override + public void addUsersToTag(Tag tag, Collection users) { + + } + + @Override + public void addRoleToFunctionalPermissionContainer(FunctionalPermissionContainer functionalPermissionContainer, String role) { + + } + + @Override + public void addRolesToFunctionalPermissionContainer(FunctionalPermissionContainer functionalPermissionContainer, Collection roles) { + + } + + @Override + public void save(Tag tag) { + + } + + @Override + public void save(FunctionalPermissionContainer functionalPermissionContainer) { + + } + + @Override + public void save(ScopePermissionContainer scopePermissionContainer) { + + } } diff --git a/src/main/java/com/codesdream/ase/service/UserService.java b/src/main/java/com/codesdream/ase/service/UserService.java index 6863e65..65ffbbf 100644 --- a/src/main/java/com/codesdream/ase/service/UserService.java +++ b/src/main/java/com/codesdream/ase/service/UserService.java @@ -1,16 +1,22 @@ package com.codesdream.ase.service; import com.codesdream.ase.component.ASEPasswordEncoder; +import com.codesdream.ase.component.UserRolesListGenerator; import com.codesdream.ase.model.permission.User; import com.codesdream.ase.repository.UserRepository; +import org.springframework.security.core.GrantedAuthority; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.Collection; import java.util.List; import java.util.Optional; @Service public class UserService implements IUserService { + @Resource + UserRolesListGenerator userRolesListGenerator; + @Resource UserRepository userRepository; @@ -32,6 +38,17 @@ public class UserService implements IUserService { return userRepository.findByUsername(username); } + @Override + public Collection getUserAuthorities(User user) { + return userRolesListGenerator.generateRoles(user); + } + + @Override + public void updatePassword(User user, String password) { + user.setPassword(asePasswordEncoder.encode(password)); + update(user); + } + @Override public User save(User user) { // 查找用户名是否已经被注册 @@ -41,11 +58,18 @@ public class UserService implements IUserService { return userRepository.save(user); } + @Override + public User update(User user) { + if(!userRepository.findByUsername(user.getUsername()).isPresent()) + throw new RuntimeException("Username Already Exists"); + return userRepository.save(user); + + } + // 获得一个默认初始化的用户对象 @Override public User getDefaultUser() { return new User(); } - } diff --git a/src/main/java/com/codesdream/ase/test/UserTest.java b/src/main/java/com/codesdream/ase/test/UserTest.java index 35539e4..374123e 100644 --- a/src/main/java/com/codesdream/ase/test/UserTest.java +++ b/src/main/java/com/codesdream/ase/test/UserTest.java @@ -47,6 +47,7 @@ public class UserTest { assertTrue(user.isEnabled()); assertFalse(user.isDeleted()); } + @Test public void UserBaseTest_2(){ // 用户 diff --git a/src/main/resources/templates/forget.html b/src/main/resources/templates/forget.html index e2e3398..1b65b94 100644 --- a/src/main/resources/templates/forget.html +++ b/src/main/resources/templates/forget.html @@ -27,13 +27,13 @@
- 获取密保问题 +
- +