添加权限管理子系统的服务层接口,修正组件层问题
This commit is contained in:
parent
18050e037f
commit
c567d961c1
@ -1,23 +1,22 @@
|
|||||||
package com.codesdream.ase.component;
|
package com.codesdream.ase.component;
|
||||||
|
|
||||||
import com.codesdream.ase.model.permission.*;
|
import com.codesdream.ase.model.permission.*;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成功能性权限容器列表
|
* 生成功能性权限容器列表
|
||||||
*/
|
*/
|
||||||
@Component
|
|
||||||
public class UserFunctionalPermissionContainersListGenerator {
|
public class UserFunctionalPermissionContainersListGenerator {
|
||||||
|
|
||||||
private UserFunctionalScopeRelationsListGenerator functionalScopeRelationsListGenerator;
|
private UserFunctionalScopeRelationsListGenerator functionalScopeRelationsListGenerator;
|
||||||
|
|
||||||
public UserFunctionalPermissionContainersListGenerator(){
|
public UserFunctionalPermissionContainersListGenerator(
|
||||||
this.functionalScopeRelationsListGenerator =
|
UserFunctionalScopeRelationsListGenerator userFunctionalScopeRelationsListGenerator)
|
||||||
new UserFunctionalScopeRelationsListGenerator();
|
{
|
||||||
|
if(userFunctionalScopeRelationsListGenerator == null) throw new NullPointerException();
|
||||||
|
this.functionalScopeRelationsListGenerator = userFunctionalScopeRelationsListGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<FunctionalPermissionContainer> generateFunctionalContainers(
|
public Collection<FunctionalPermissionContainer> generateFunctionalContainers(
|
||||||
|
@ -3,23 +3,23 @@ package com.codesdream.ase.component;
|
|||||||
import com.codesdream.ase.model.permission.FunctionalScopeRelation;
|
import com.codesdream.ase.model.permission.FunctionalScopeRelation;
|
||||||
import com.codesdream.ase.model.permission.PermissionContainersCollection;
|
import com.codesdream.ase.model.permission.PermissionContainersCollection;
|
||||||
import com.codesdream.ase.model.permission.User;
|
import com.codesdream.ase.model.permission.User;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成功能性权限容器与范围性权限容器关联对列表
|
* 生成功能性权限容器与范围性权限容器关联对列表
|
||||||
*/
|
*/
|
||||||
@Component
|
|
||||||
public class UserFunctionalScopeRelationsListGenerator {
|
public class UserFunctionalScopeRelationsListGenerator {
|
||||||
|
|
||||||
private UserPermissionContainersCollectionsListGenerator userPermissionContainersCollectionsListGenerator;
|
private UserPermissionContainersCollectionsListGenerator userPermissionContainersCollectionsListGenerator;
|
||||||
|
|
||||||
public UserFunctionalScopeRelationsListGenerator(){
|
public UserFunctionalScopeRelationsListGenerator(
|
||||||
|
UserPermissionContainersCollectionsListGenerator userPermissionContainersCollectionsListGenerator)
|
||||||
|
{
|
||||||
|
if(userPermissionContainersCollectionsListGenerator == null) throw new NullPointerException();
|
||||||
this.userPermissionContainersCollectionsListGenerator =
|
this.userPermissionContainersCollectionsListGenerator =
|
||||||
new UserPermissionContainersCollectionsListGenerator();
|
userPermissionContainersCollectionsListGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<FunctionalScopeRelation> generateFunctionalScopeRelations(
|
public Collection<FunctionalScopeRelation> generateFunctionalScopeRelations(
|
||||||
|
@ -3,25 +3,21 @@ package com.codesdream.ase.component;
|
|||||||
import com.codesdream.ase.model.permission.PermissionContainersCollection;
|
import com.codesdream.ase.model.permission.PermissionContainersCollection;
|
||||||
import com.codesdream.ase.model.permission.Tag;
|
import com.codesdream.ase.model.permission.Tag;
|
||||||
import com.codesdream.ase.model.permission.User;
|
import com.codesdream.ase.model.permission.User;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成权限容器集合列表
|
* 生成权限容器集合列表
|
||||||
*/
|
*/
|
||||||
@Component
|
|
||||||
public class UserPermissionContainersCollectionsListGenerator {
|
public class UserPermissionContainersCollectionsListGenerator {
|
||||||
|
|
||||||
private UserTagsListGenerator userTagsListGenerator;
|
private UserTagsListGenerator userTagsListGenerator;
|
||||||
|
|
||||||
public UserPermissionContainersCollectionsListGenerator(){
|
public UserPermissionContainersCollectionsListGenerator(UserTagsListGenerator userTagsListGenerator)
|
||||||
this.userTagsListGenerator =
|
{
|
||||||
new UserTagsListGenerator();
|
if(userTagsListGenerator == null) throw new NullPointerException();
|
||||||
|
this.userTagsListGenerator = userTagsListGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<PermissionContainersCollection> generatePermissionContainerCollections(
|
public Collection<PermissionContainersCollection> generatePermissionContainerCollections(
|
||||||
|
@ -2,27 +2,25 @@ package com.codesdream.ase.component;
|
|||||||
|
|
||||||
import com.codesdream.ase.model.permission.FunctionalPermissionContainer;
|
import com.codesdream.ase.model.permission.FunctionalPermissionContainer;
|
||||||
import com.codesdream.ase.model.permission.User;
|
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.GrantedAuthority;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成用户访问权限角色列表
|
* 生成用户访问权限角色列表
|
||||||
*/
|
*/
|
||||||
@Component
|
|
||||||
public class UserRolesListGenerator {
|
public class UserRolesListGenerator {
|
||||||
|
|
||||||
private UserFunctionalPermissionContainersListGenerator functionalPermissionContainersListGenerator;
|
private UserFunctionalPermissionContainersListGenerator functionalPermissionContainersListGenerator;
|
||||||
|
|
||||||
public UserRolesListGenerator(){
|
public UserRolesListGenerator(
|
||||||
|
UserFunctionalPermissionContainersListGenerator userFunctionalPermissionContainersListGenerator)
|
||||||
|
{
|
||||||
this.functionalPermissionContainersListGenerator =
|
this.functionalPermissionContainersListGenerator =
|
||||||
new UserFunctionalPermissionContainersListGenerator();
|
userFunctionalPermissionContainersListGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<GrantedAuthority> generateRoles(
|
public Collection<GrantedAuthority> generateRoles(
|
||||||
|
@ -14,7 +14,6 @@ import java.util.Optional;
|
|||||||
/**
|
/**
|
||||||
* 生成用户标签列表
|
* 生成用户标签列表
|
||||||
*/
|
*/
|
||||||
@Component
|
|
||||||
public class UserTagsListGenerator {
|
public class UserTagsListGenerator {
|
||||||
@Resource
|
@Resource
|
||||||
UserRepository userRepository;
|
UserRepository userRepository;
|
||||||
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -16,4 +16,5 @@ import java.util.Map;
|
|||||||
public class GlobalConfigure {
|
public class GlobalConfigure {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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";
|
||||||
|
}
|
||||||
|
}
|
@ -49,8 +49,8 @@ public class RegisterController {
|
|||||||
if (password.equals(retry_password)) {
|
if (password.equals(retry_password)) {
|
||||||
user.setPassword(password);
|
user.setPassword(password);
|
||||||
userService.save(user);
|
userService.save(user);
|
||||||
|
// 返回登录界面
|
||||||
return "index";
|
return "login";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public class Tag {
|
|||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
// 标签关联用户
|
// 标签关联用户
|
||||||
@ManyToMany(mappedBy = "tags", cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
@ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
||||||
private Set<User> users;
|
private Set<User> users;
|
||||||
|
|
||||||
// 启用标志
|
// 启用标志
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package com.codesdream.ase.model.permission;
|
package com.codesdream.ase.model.permission;
|
||||||
|
|
||||||
import com.codesdream.ase.component.UserRolesListGenerator;
|
import com.codesdream.ase.component.UserRolesListGenerator;
|
||||||
|
import com.codesdream.ase.service.UserService;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.annotation.Resource;
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -14,6 +17,10 @@ import java.util.Set;
|
|||||||
@Entity
|
@Entity
|
||||||
@Table(name = "user")
|
@Table(name = "user")
|
||||||
public class User implements UserDetails {
|
public class User implements UserDetails {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private transient UserService userService;
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private int id;
|
private int id;
|
||||||
@ -45,9 +52,14 @@ public class User implements UserDetails {
|
|||||||
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
private Set<Tag> tags;
|
private Set<Tag> tags;
|
||||||
|
|
||||||
|
// 用户详细信息
|
||||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
private UserDetail userDetail;
|
private UserDetail userDetail;
|
||||||
|
|
||||||
|
// 用户认证表
|
||||||
|
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
|
private UserAuth userAuth;
|
||||||
|
|
||||||
|
|
||||||
public User(String username, String password) {
|
public User(String username, String password) {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
@ -73,12 +85,12 @@ public class User implements UserDetails {
|
|||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
this.tags = new HashSet<>();
|
this.tags = new HashSet<>();
|
||||||
this.userDetail = new UserDetail();
|
this.userDetail = new UserDetail();
|
||||||
|
this.userAuth = new UserAuth();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||||
UserRolesListGenerator userRolesListGenerator = new UserRolesListGenerator();
|
return userService.getUserAuthorities(this);
|
||||||
return userRolesListGenerator.generateRoles(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
@ -35,4 +35,7 @@ public class UserDetail {
|
|||||||
|
|
||||||
// 学生ID
|
// 学生ID
|
||||||
private String studentID;
|
private String studentID;
|
||||||
|
|
||||||
|
// 在校状态
|
||||||
|
private boolean atSchool;
|
||||||
}
|
}
|
||||||
|
@ -8,5 +8,5 @@ import java.util.Optional;
|
|||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface FunctionalPermissionRepository extends CrudRepository<FunctionalPermissionContainer, Integer> {
|
public interface FunctionalPermissionRepository extends CrudRepository<FunctionalPermissionContainer, Integer> {
|
||||||
Optional<FunctionalPermissionRepository> findByName(String name);
|
Optional<FunctionalPermissionContainer> findByName(String name);
|
||||||
}
|
}
|
||||||
|
@ -6,5 +6,5 @@ import org.springframework.data.repository.CrudRepository;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface ScopePermissionRepository extends CrudRepository<ScopePermissionContainer, Integer> {
|
public interface ScopePermissionRepository extends CrudRepository<ScopePermissionContainer, Integer> {
|
||||||
Optional<ScopePermissionRepository> findByName(String name);
|
Optional<ScopePermissionContainer> findByName(String name);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,71 @@
|
|||||||
package com.codesdream.ase.service;
|
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 {
|
public interface IPermissionService {
|
||||||
|
// 查找用户标签
|
||||||
|
Optional<Tag> findTag(String name);
|
||||||
|
|
||||||
|
// 查找功能性权限容器
|
||||||
|
Optional<FunctionalPermissionContainer> findFunctionalPermissionContainer(String name);
|
||||||
|
|
||||||
|
// 查找范围性权限容器
|
||||||
|
Optional<ScopePermissionContainer> findScopePermissionContainer(String name);
|
||||||
|
|
||||||
|
// 标签下所有的获得权限容器集合列表
|
||||||
|
Collection<PermissionContainersCollection> getPermissionContainerCollections(Tag tag);
|
||||||
|
|
||||||
|
// 获得范围性权限容器下的所有标签列表
|
||||||
|
Collection<Tag> getTagsFromScopePermissionContainers(
|
||||||
|
ScopePermissionContainer scopePermissionContainer);
|
||||||
|
|
||||||
|
// 查找用户下的所有标签列表
|
||||||
|
Collection<Tag> getTagsFromUser(User user);
|
||||||
|
|
||||||
|
// 查找功能性权限容器下的所有范围性权限容器列表
|
||||||
|
Collection<FunctionalPermissionContainer> getFunctionPermissionContainers(
|
||||||
|
PermissionContainersCollection permissionContainersCollection);
|
||||||
|
|
||||||
|
// 查找标签下的所有用户
|
||||||
|
Collection<User> getUsersFromTag(Tag tag);
|
||||||
|
|
||||||
|
// 指定一对功能性权限容器与对应的范围性权限容器并添加到指定权限容器集合中
|
||||||
|
void addRelationItemToPermissionContainerCollectionPermissionContainerCollection(
|
||||||
|
PermissionContainersCollection permissionContainersCollection,
|
||||||
|
FunctionalPermissionContainer functionalPermissionContainer,
|
||||||
|
ScopePermissionContainer scopePermissionContainer);
|
||||||
|
|
||||||
|
// 指定多对功能性权限容器与对应的范围性权限容器并添加到指定权限容器集合中
|
||||||
|
void addRelationItemsToPermissionContainerCollectionPermissionContainerCollection(
|
||||||
|
PermissionContainersCollection permissionContainersCollection,
|
||||||
|
Collection<Pair<FunctionalPermissionContainer, ScopePermissionContainer>>
|
||||||
|
functionalScopePermissionContainerPairs);
|
||||||
|
|
||||||
|
// 添加一个用户到指定标签中
|
||||||
|
void addUserToTag(Tag tag, User user);
|
||||||
|
|
||||||
|
// 添加多个用户到指定标签中
|
||||||
|
void addUsersToTag(Tag tag, Collection<User> users);
|
||||||
|
|
||||||
|
// 为功能性权限容器添加一个访问控制角色
|
||||||
|
void addRoleToFunctionalPermissionContainer(
|
||||||
|
FunctionalPermissionContainer functionalPermissionContainer,
|
||||||
|
String role);
|
||||||
|
|
||||||
|
// 为功能性权限容器添加多个访问控制角色
|
||||||
|
void addRolesToFunctionalPermissionContainer(
|
||||||
|
FunctionalPermissionContainer functionalPermissionContainer,
|
||||||
|
Collection<String> roles);
|
||||||
|
|
||||||
|
void save(Tag tag);
|
||||||
|
|
||||||
|
void save(FunctionalPermissionContainer functionalPermissionContainer);
|
||||||
|
|
||||||
|
void save(ScopePermissionContainer scopePermissionContainer);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,32 @@
|
|||||||
package com.codesdream.ase.service;
|
package com.codesdream.ase.service;
|
||||||
|
|
||||||
import com.codesdream.ase.model.permission.User;
|
import com.codesdream.ase.model.permission.User;
|
||||||
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
||||||
public interface IUserService {
|
public interface IUserService {
|
||||||
|
|
||||||
|
// 获得一个空的默认用户
|
||||||
|
User getDefaultUser();
|
||||||
|
|
||||||
List<User> findAll();
|
List<User> findAll();
|
||||||
|
|
||||||
Optional<User> findUserById(int id);
|
Optional<User> findUserById(int id);
|
||||||
Optional<User> findUserByUsername(String username);
|
Optional<User> findUserByUsername(String username);
|
||||||
|
|
||||||
|
// 获得用户所有的权限角色
|
||||||
|
Collection<? extends GrantedAuthority> getUserAuthorities(User user);
|
||||||
|
|
||||||
|
// 更新用户的密码
|
||||||
|
void updatePassword(User user, String password);
|
||||||
|
|
||||||
User save(User user);
|
User save(User user);
|
||||||
// 获得默认用户
|
|
||||||
User getDefaultUser();
|
User update(User user);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,127 @@
|
|||||||
package com.codesdream.ase.service;
|
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 org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PermissionService implements IPermissionService {
|
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<Tag> findTag(String name) {
|
||||||
|
return tagRepository.findByName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<FunctionalPermissionContainer> findFunctionalPermissionContainer(String name) {
|
||||||
|
return functionalPermissionRepository.findByName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<ScopePermissionContainer> findScopePermissionContainer(String name) {
|
||||||
|
return scopePermissionRepository.findByName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<PermissionContainersCollection> getPermissionContainerCollections(Tag tag) {
|
||||||
|
return new ArrayList<>(tag.getPermissionContainersCollections());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Tag> getTagsFromScopePermissionContainers(ScopePermissionContainer scopePermissionContainer) {
|
||||||
|
return new ArrayList<>(scopePermissionContainer.getTags());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Tag> getTagsFromUser(User user) {
|
||||||
|
return new ArrayList<>(user.getTags());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<FunctionalPermissionContainer> getFunctionPermissionContainers(PermissionContainersCollection permissionContainersCollection) {
|
||||||
|
|
||||||
|
Collection<PermissionContainersCollection> permissionContainersCollections = new ArrayList<PermissionContainersCollection>(){{
|
||||||
|
add(permissionContainersCollection);
|
||||||
|
}};
|
||||||
|
|
||||||
|
// 生成功能性与范围性权限容器关联对
|
||||||
|
Collection<FunctionalScopeRelation> functionalScopeRelations =
|
||||||
|
userFunctionalScopeRelationsListGenerator.generateFunctionalScopeRelations(permissionContainersCollections);
|
||||||
|
return userFunctionalPermissionContainersListGenerator.generateFunctionalContainers(functionalScopeRelations);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<User> getUsersFromTag(Tag tag) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addRelationItemToPermissionContainerCollectionPermissionContainerCollection(PermissionContainersCollection permissionContainersCollection, FunctionalPermissionContainer functionalPermissionContainer, ScopePermissionContainer scopePermissionContainer) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addRelationItemsToPermissionContainerCollectionPermissionContainerCollection(PermissionContainersCollection permissionContainersCollection, Collection<Pair<FunctionalPermissionContainer, ScopePermissionContainer>> functionalScopePermissionContainerPairs) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addUserToTag(Tag tag, User user) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addUsersToTag(Tag tag, Collection<User> users) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addRoleToFunctionalPermissionContainer(FunctionalPermissionContainer functionalPermissionContainer, String role) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addRolesToFunctionalPermissionContainer(FunctionalPermissionContainer functionalPermissionContainer, Collection<String> roles) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(Tag tag) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(FunctionalPermissionContainer functionalPermissionContainer) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(ScopePermissionContainer scopePermissionContainer) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,22 @@
|
|||||||
package com.codesdream.ase.service;
|
package com.codesdream.ase.service;
|
||||||
|
|
||||||
import com.codesdream.ase.component.ASEPasswordEncoder;
|
import com.codesdream.ase.component.ASEPasswordEncoder;
|
||||||
|
import com.codesdream.ase.component.UserRolesListGenerator;
|
||||||
import com.codesdream.ase.model.permission.User;
|
import com.codesdream.ase.model.permission.User;
|
||||||
import com.codesdream.ase.repository.UserRepository;
|
import com.codesdream.ase.repository.UserRepository;
|
||||||
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserService implements IUserService {
|
public class UserService implements IUserService {
|
||||||
|
@Resource
|
||||||
|
UserRolesListGenerator userRolesListGenerator;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
UserRepository userRepository;
|
UserRepository userRepository;
|
||||||
|
|
||||||
@ -32,6 +38,17 @@ public class UserService implements IUserService {
|
|||||||
return userRepository.findByUsername(username);
|
return userRepository.findByUsername(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<? extends GrantedAuthority> getUserAuthorities(User user) {
|
||||||
|
return userRolesListGenerator.generateRoles(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePassword(User user, String password) {
|
||||||
|
user.setPassword(asePasswordEncoder.encode(password));
|
||||||
|
update(user);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User save(User user) {
|
public User save(User user) {
|
||||||
// 查找用户名是否已经被注册
|
// 查找用户名是否已经被注册
|
||||||
@ -41,11 +58,18 @@ public class UserService implements IUserService {
|
|||||||
return userRepository.save(user);
|
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
|
@Override
|
||||||
public User getDefaultUser() {
|
public User getDefaultUser() {
|
||||||
return new User();
|
return new User();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,7 @@ public class UserTest {
|
|||||||
assertTrue(user.isEnabled());
|
assertTrue(user.isEnabled());
|
||||||
assertFalse(user.isDeleted());
|
assertFalse(user.isDeleted());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void UserBaseTest_2(){
|
public void UserBaseTest_2(){
|
||||||
// 用户
|
// 用户
|
||||||
|
@ -27,13 +27,13 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="username">用户名</label>
|
<label for="username">用户名</label>
|
||||||
<input type="text" class="form-control" id="username" name="username" placeholder="这里输入用户名" style="width:70%,display:inline,float:left" >
|
<input type="text" class="form-control" id="username" name="username" placeholder="这里输入用户名" style="width:70%,display:inline,float:left" >
|
||||||
<buttontype="submit" class="btn btn-primary btn-block"><b>获取密保问题</b></button>
|
<button type="submit" class="btn btn-primary btn-block"><b>获取密保问题</b></button>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="userquestion">(密保问题)</label>
|
<label for="user-question">(密保问题)</label>
|
||||||
<input type="text" class="form-control" id="answer" name="answer" placeholder="这里输入答案">
|
<input type="text" class="form-control" id="answer" name="answer" placeholder="这里输入答案">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
Loading…
Reference in New Issue
Block a user