基本完成权限管理子系统的编写;修改权限管理子系统及用户管理子系统的服务层接口;
This commit is contained in:
parent
85b0b27938
commit
fd44c3d939
@ -19,36 +19,31 @@ public class FunctionalPermissionContainer {
|
|||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
// 功能性权限容器名
|
// 功能性权限容器名
|
||||||
@Column(nullable = false, unique = true)
|
@Column(unique = true)
|
||||||
private String name;
|
private String name = "";
|
||||||
|
|
||||||
// 功能性权限容器解释
|
// 功能性权限容器解释
|
||||||
private String description;
|
private String description = "";
|
||||||
|
|
||||||
// 对应访问控制角色列表
|
// 对应访问控制角色列表
|
||||||
@ElementCollection
|
@ElementCollection
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private List<String> roles;
|
private List<String> roles = new LinkedList<>();
|
||||||
|
|
||||||
// 是否启用
|
// 是否启用
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private boolean enabled;
|
private boolean enabled = true;
|
||||||
|
|
||||||
// 是否删除
|
// 是否删除
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private boolean deleted;
|
private boolean deleted = false;
|
||||||
|
|
||||||
|
public FunctionalPermissionContainer(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
public FunctionalPermissionContainer(){
|
public FunctionalPermissionContainer(){
|
||||||
initDefault();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public FunctionalPermissionContainer(String name, String description) {
|
|
||||||
this.name = name;
|
|
||||||
this.description = description;
|
|
||||||
initDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initDefault(){
|
|
||||||
this.roles = new LinkedList<>();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.codesdream.ase.model.permission;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,13 +17,21 @@ public class PermissionContainersCollection {
|
|||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
// 权限容器集合名称
|
// 权限容器集合名称
|
||||||
@Column(nullable = false)
|
@Column(unique = true)
|
||||||
private String name;
|
private String name = "";
|
||||||
|
|
||||||
// 权限容器集合概述
|
// 权限容器集合概述
|
||||||
private String description;
|
private String description = "";
|
||||||
|
|
||||||
// 对应功能性权限容器与范围性权限容器关联对
|
// 对应功能性权限容器与范围性权限容器关联对
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
private Set<FunctionalScopeRelation> functionalScopeRelations;
|
private Set<FunctionalScopeRelation> functionalScopeRelations = new HashSet<>();
|
||||||
|
|
||||||
|
public PermissionContainersCollection(String name){
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PermissionContainersCollection(){
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.codesdream.ase.model.permission;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -14,17 +15,25 @@ public class ScopePermissionContainer {
|
|||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
@Column(unique = true, nullable = false)
|
@Column(unique = true)
|
||||||
private String name;
|
private String name = "";
|
||||||
|
|
||||||
private String description;
|
private String description = "";
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH}, fetch = FetchType.LAZY)
|
||||||
private List<Tag> tags;
|
private List<Tag> tags = new LinkedList<>();
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private boolean enabled;
|
private boolean enabled = true;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private boolean deleted;
|
private boolean deleted = false;
|
||||||
|
|
||||||
|
public ScopePermissionContainer(String name){
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScopePermissionContainer(){
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,40 +19,34 @@ public class Tag {
|
|||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
// 标签名
|
// 标签名
|
||||||
@Column(nullable = false, unique = true)
|
@Column(unique = true)
|
||||||
private String name;
|
private String name = "";
|
||||||
|
|
||||||
// 标签解释
|
// 标签解释
|
||||||
private String description;
|
private String description = "";
|
||||||
|
|
||||||
// 标签关联用户
|
// 标签关联用户
|
||||||
@ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
@ManyToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH}, fetch = FetchType.LAZY)
|
||||||
private Set<User> users;
|
private Set<User> users = new HashSet<>();
|
||||||
|
|
||||||
// 启用标志
|
// 启用标志
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private boolean enabled;
|
private boolean enabled = true;
|
||||||
|
|
||||||
// 删除标志
|
// 删除标志
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private boolean deleted;
|
private boolean deleted = false;
|
||||||
|
|
||||||
// 对应权限容器集合
|
// 对应权限容器集合
|
||||||
@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
|
@ManyToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH}, fetch = FetchType.LAZY)
|
||||||
private Set<PermissionContainersCollection> permissionContainersCollections;
|
private Set<PermissionContainersCollection> permissionContainersCollections = new HashSet<>();
|
||||||
|
|
||||||
public Tag(String name, String description) {
|
public Tag(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
|
||||||
this.deleted = false;
|
|
||||||
this.enabled = true;
|
|
||||||
this.users = new HashSet<User>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tag() {
|
public Tag(){
|
||||||
this.deleted = false;
|
|
||||||
this.enabled = true;
|
|
||||||
this.users = new HashSet<User>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,14 +14,14 @@ public class UserAuth {
|
|||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
// 密保问题
|
// 密保问题
|
||||||
private String userQuestion;
|
private String userQuestion = null;
|
||||||
|
|
||||||
// 密保问题答案
|
// 密保问题答案
|
||||||
private String userAnswer;
|
private String userAnswer = null;
|
||||||
|
|
||||||
// 用户邮箱
|
// 用户邮箱
|
||||||
private String mail;
|
private String mail = null;
|
||||||
|
|
||||||
// 学生ID
|
// 学生ID
|
||||||
private String studentID;
|
private String studentID = null;
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ public class UserDetail {
|
|||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
// 学生班号
|
// 学生班号
|
||||||
private String classId = "";
|
private String classId = null;
|
||||||
|
|
||||||
// 所属地区
|
// 所属地区
|
||||||
@OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
@OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
||||||
@ -40,7 +40,7 @@ public class UserDetail {
|
|||||||
private BasePoliticalStatus basePoliticalStatus = null;
|
private BasePoliticalStatus basePoliticalStatus = null;
|
||||||
|
|
||||||
// 真实姓名
|
// 真实姓名
|
||||||
private String realName = "";
|
private String realName = null;
|
||||||
|
|
||||||
// 在校认证状态
|
// 在校认证状态
|
||||||
private boolean atSchool = false;
|
private boolean atSchool = false;
|
||||||
|
@ -1,13 +1,21 @@
|
|||||||
package com.codesdream.ase.service;
|
package com.codesdream.ase.service;
|
||||||
|
|
||||||
import com.codesdream.ase.model.permission.*;
|
import com.codesdream.ase.model.permission.*;
|
||||||
import com.sun.org.apache.xpath.internal.functions.FuncQname;
|
|
||||||
import javafx.util.Pair;
|
import javafx.util.Pair;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface IPermissionService {
|
public interface IPermissionService {
|
||||||
|
|
||||||
|
FunctionalPermissionContainer getDefaultFPC(String name);
|
||||||
|
|
||||||
|
ScopePermissionContainer getDefaultSPC(String name);
|
||||||
|
|
||||||
|
PermissionContainersCollection getDefaultPCC(String name);
|
||||||
|
|
||||||
|
Tag getDefaultTag(String name);
|
||||||
|
|
||||||
// 查找用户标签
|
// 查找用户标签
|
||||||
Optional<Tag> findTag(String name);
|
Optional<Tag> findTag(String name);
|
||||||
|
|
||||||
@ -41,45 +49,59 @@ public interface IPermissionService {
|
|||||||
Collection<User> getUsersFromTag(Tag tag);
|
Collection<User> getUsersFromTag(Tag tag);
|
||||||
|
|
||||||
// 指定一对功能性权限容器与对应的范围性权限容器并添加到指定权限容器集合中
|
// 指定一对功能性权限容器与对应的范围性权限容器并添加到指定权限容器集合中
|
||||||
void addRelationItemToPCCollection(
|
PermissionContainersCollection addRelationItemToPCC(
|
||||||
PermissionContainersCollection pcc,
|
PermissionContainersCollection pcc,
|
||||||
FunctionalPermissionContainer fpc,
|
FunctionalPermissionContainer fpc,
|
||||||
ScopePermissionContainer spc);
|
ScopePermissionContainer spc);
|
||||||
|
|
||||||
// 指定多对功能性权限容器与对应的范围性权限容器并添加到指定权限容器集合中
|
// 指定多对功能性权限容器与对应的范围性权限容器并添加到指定权限容器集合中
|
||||||
void addRelationItemsToPCC(
|
PermissionContainersCollection addRelationItemsToPCC(
|
||||||
PermissionContainersCollection pcc,
|
PermissionContainersCollection pcc,
|
||||||
Collection<Pair<FunctionalPermissionContainer, ScopePermissionContainer>>
|
Collection<Pair<FunctionalPermissionContainer, ScopePermissionContainer>>
|
||||||
fspcPairs);
|
fspcPairs);
|
||||||
|
|
||||||
// 添加一个用户到指定标签中
|
// 添加一个用户到指定标签中
|
||||||
void addUserToTag(Tag tag, User user);
|
Tag addUserToTag(Tag tag, User user);
|
||||||
|
|
||||||
// 添加多个用户到指定标签中
|
// 添加多个用户到指定标签中
|
||||||
void addUsersToTag(Tag tag, Collection<User> users);
|
Tag addUsersToTag(Tag tag, Collection<User> users);
|
||||||
|
|
||||||
// 为功能性权限容器添加一个访问控制角色
|
// 为功能性权限容器添加一个访问控制角色
|
||||||
void addRoleToFPC(
|
FunctionalPermissionContainer addRoleToFPC(
|
||||||
FunctionalPermissionContainer fpc,
|
FunctionalPermissionContainer fpc,
|
||||||
String role);
|
String role);
|
||||||
|
|
||||||
// 为功能性权限容器添加多个访问控制角色
|
// 为功能性权限容器添加多个访问控制角色
|
||||||
void addRolesToFPC(
|
FunctionalPermissionContainer addRolesToFPC(
|
||||||
FunctionalPermissionContainer fpc,
|
FunctionalPermissionContainer fpc,
|
||||||
Collection<String> roles);
|
Collection<String> roles);
|
||||||
|
|
||||||
void save(Tag tag);
|
// 为范围性权限容器添加一个标签
|
||||||
|
ScopePermissionContainer addTagToSPC(ScopePermissionContainer spc, Tag tag);
|
||||||
|
|
||||||
void save(FunctionalPermissionContainer fpc);
|
// 为范围性权限容器添加多个标签
|
||||||
|
ScopePermissionContainer addTagsToSPC(ScopePermissionContainer spc, Collection<Tag> tags);
|
||||||
|
|
||||||
void save(ScopePermissionContainer spc);
|
// 将一个权限容器集合添加到标签中
|
||||||
|
Tag addPCCToTag(Tag tag, PermissionContainersCollection pcc);
|
||||||
|
|
||||||
void save(PermissionContainersCollection pcc);
|
// 将多个权限容器集合添加到标签中
|
||||||
|
Tag addPCCsToTag(Tag tag, Collection<PermissionContainersCollection> pccs);
|
||||||
|
|
||||||
void update(FunctionalPermissionContainer fpc);
|
Tag save(Tag tag);
|
||||||
|
|
||||||
void update(ScopePermissionContainer spc);
|
FunctionalPermissionContainer save(FunctionalPermissionContainer fpc);
|
||||||
|
|
||||||
void update(PermissionContainersCollection pcc);
|
ScopePermissionContainer save(ScopePermissionContainer spc);
|
||||||
|
|
||||||
|
PermissionContainersCollection save(PermissionContainersCollection pcc);
|
||||||
|
|
||||||
|
Tag update(Tag tag);
|
||||||
|
|
||||||
|
FunctionalPermissionContainer update(FunctionalPermissionContainer fpc);
|
||||||
|
|
||||||
|
ScopePermissionContainer update(ScopePermissionContainer spc);
|
||||||
|
|
||||||
|
PermissionContainersCollection update(PermissionContainersCollection pcc);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,10 +30,10 @@ public interface IUserService {
|
|||||||
Collection<? extends GrantedAuthority> getUserAuthorities(User user);
|
Collection<? extends GrantedAuthority> getUserAuthorities(User user);
|
||||||
|
|
||||||
// 更新用户的密码
|
// 更新用户的密码
|
||||||
void updatePassword(User user, String password);
|
User updatePassword(User user, String password);
|
||||||
|
|
||||||
// 封禁用户
|
// 封禁用户
|
||||||
void disableUser(User user);
|
User disableUser(User user);
|
||||||
|
|
||||||
// 根据学号生成随机用户名
|
// 根据学号生成随机用户名
|
||||||
void generateRandomUsernameByStudentID(User user, String id);
|
void generateRandomUsernameByStudentID(User user, String id);
|
||||||
|
@ -4,9 +4,11 @@ import com.codesdream.ase.component.permission.UserFPCListGenerator;
|
|||||||
import com.codesdream.ase.component.permission.UserFSRGenerator;
|
import com.codesdream.ase.component.permission.UserFSRGenerator;
|
||||||
import com.codesdream.ase.model.permission.*;
|
import com.codesdream.ase.model.permission.*;
|
||||||
import com.codesdream.ase.repository.permission.FunctionalPermissionContainerRepository;
|
import com.codesdream.ase.repository.permission.FunctionalPermissionContainerRepository;
|
||||||
|
import com.codesdream.ase.repository.permission.PermissionContainersCollectionRepository;
|
||||||
import com.codesdream.ase.repository.permission.ScopePermissionContainerRepository;
|
import com.codesdream.ase.repository.permission.ScopePermissionContainerRepository;
|
||||||
import com.codesdream.ase.repository.permission.TagRepository;
|
import com.codesdream.ase.repository.permission.TagRepository;
|
||||||
import javafx.util.Pair;
|
import javafx.util.Pair;
|
||||||
|
import org.apache.poi.ss.formula.functions.T;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@ -26,12 +28,38 @@ public class PermissionService implements IPermissionService {
|
|||||||
@Resource
|
@Resource
|
||||||
private ScopePermissionContainerRepository spcRepository;
|
private ScopePermissionContainerRepository spcRepository;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PermissionContainersCollectionRepository pccRepository;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IUserService userService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private UserFPCListGenerator userFPCListGenerator;
|
private UserFPCListGenerator userFPCListGenerator;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private UserFSRGenerator userFSRGenerator;
|
private UserFSRGenerator userFSRGenerator;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FunctionalPermissionContainer getDefaultFPC(String name) {
|
||||||
|
return new FunctionalPermissionContainer(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ScopePermissionContainer getDefaultSPC(String name) {
|
||||||
|
return new ScopePermissionContainer(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PermissionContainersCollection getDefaultPCC(String name) {
|
||||||
|
return new PermissionContainersCollection(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tag getDefaultTag(String name) {
|
||||||
|
return new Tag(name);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Tag> findTag(String name) {
|
public Optional<Tag> findTag(String name) {
|
||||||
return tagRepository.findByName(name);
|
return tagRepository.findByName(name);
|
||||||
@ -94,80 +122,150 @@ public class PermissionService implements IPermissionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addRelationItemToPCCollection(PermissionContainersCollection pcc,
|
public PermissionContainersCollection addRelationItemToPCC(PermissionContainersCollection pcc,
|
||||||
FunctionalPermissionContainer fpc,
|
FunctionalPermissionContainer fpc,
|
||||||
ScopePermissionContainer spc)
|
ScopePermissionContainer spc)
|
||||||
{
|
{
|
||||||
if(!findFPC(fpc.getId()).isPresent()){
|
if(!findFPC(fpc.getId()).isPresent()){
|
||||||
|
throw new RuntimeException("FPC NOT In Database");
|
||||||
|
}
|
||||||
|
if(!findSPC(spc.getId()).isPresent()){
|
||||||
|
throw new RuntimeException("SPC NOT In Database");
|
||||||
}
|
}
|
||||||
FunctionalScopeRelation relation = new FunctionalScopeRelation();
|
FunctionalScopeRelation relation = new FunctionalScopeRelation();
|
||||||
relation.setFunctionalPermissionContainer(fpc);
|
relation.setFunctionalPermissionContainer(fpc);
|
||||||
relation.setScopePermissionContainer(spc);
|
relation.setScopePermissionContainer(spc);
|
||||||
pcc.getFunctionalScopeRelations().add(relation);
|
pcc.getFunctionalScopeRelations().add(relation);
|
||||||
update(pcc);
|
return update(pcc);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addRelationItemsToPCC(PermissionContainersCollection pcc,
|
public PermissionContainersCollection addRelationItemsToPCC(PermissionContainersCollection pcc,
|
||||||
Collection<Pair<FunctionalPermissionContainer, ScopePermissionContainer>> fspcPairs)
|
Collection<Pair<FunctionalPermissionContainer, ScopePermissionContainer>> fspcPairs)
|
||||||
{
|
{
|
||||||
|
for(Pair<FunctionalPermissionContainer, ScopePermissionContainer> fspc :fspcPairs){
|
||||||
|
pcc = addRelationItemToPCC(pcc, fspc.getKey(), fspc.getValue());
|
||||||
|
}
|
||||||
|
return pcc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addUserToTag(Tag tag, User user) {
|
public Tag addUserToTag(Tag tag, User user) {
|
||||||
|
// 检查用户是否存在
|
||||||
|
if(!userService.checkIfUserExists(user.getUsername()).getKey())
|
||||||
|
throw new RuntimeException("User Not Exist");
|
||||||
|
tag.getUsers().add(user);
|
||||||
|
return update(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addUsersToTag(Tag tag, Collection<User> users) {
|
public Tag addUsersToTag(Tag tag, Collection<User> users) {
|
||||||
|
for(User user :users){
|
||||||
|
tag = addUserToTag(tag, user);
|
||||||
|
}
|
||||||
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addRoleToFPC(FunctionalPermissionContainer fpc, String role) {
|
public FunctionalPermissionContainer addRoleToFPC(FunctionalPermissionContainer fpc, String role) {
|
||||||
|
fpc.getRoles().add(role);
|
||||||
|
return update(fpc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addRolesToFPC(FunctionalPermissionContainer fpc, Collection<String> roles) {
|
public FunctionalPermissionContainer addRolesToFPC(FunctionalPermissionContainer fpc, Collection<String> roles) {
|
||||||
|
for(String role : roles){
|
||||||
|
fpc = addRoleToFPC(fpc, role);
|
||||||
|
}
|
||||||
|
return fpc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(Tag tag) {
|
public ScopePermissionContainer addTagToSPC(ScopePermissionContainer spc, Tag tag) {
|
||||||
|
if(!tagRepository.findByName(tag.getName()).isPresent())
|
||||||
|
throw new RuntimeException("Tag Not Exist");
|
||||||
|
spc.getTags().add(tag);
|
||||||
|
return update(spc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(FunctionalPermissionContainer fpc) {
|
public ScopePermissionContainer addTagsToSPC(ScopePermissionContainer spc, Collection<Tag> tags) {
|
||||||
|
for(Tag tag :tags){
|
||||||
|
spc = addTagToSPC(spc, tag);
|
||||||
|
}
|
||||||
|
return spc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(ScopePermissionContainer spc) {
|
public Tag addPCCToTag(Tag tag, PermissionContainersCollection pcc) {
|
||||||
|
if(!pccRepository.findByName(pcc.getName()).isPresent())
|
||||||
|
throw new RuntimeException("PCC Not Exist");
|
||||||
|
tag.getPermissionContainersCollections().add(pcc);
|
||||||
|
return update(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(PermissionContainersCollection pcc) {
|
public Tag addPCCsToTag(Tag tag, Collection<PermissionContainersCollection> pccs) {
|
||||||
|
for(PermissionContainersCollection pcc : pccs) {
|
||||||
|
tag = addPCCToTag(tag, pcc);
|
||||||
|
}
|
||||||
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(FunctionalPermissionContainer fpc) {
|
public Tag save(Tag tag) {
|
||||||
|
if(tagRepository.findByName(tag.getName()).isPresent())
|
||||||
|
throw new RuntimeException("Tag Already Exist");
|
||||||
|
return tagRepository.save(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(ScopePermissionContainer spc) {
|
public FunctionalPermissionContainer save(FunctionalPermissionContainer fpc) {
|
||||||
|
if(fpcRepository.findByName(fpc.getName()).isPresent())
|
||||||
|
throw new RuntimeException("FPC Already Exist");
|
||||||
|
return fpcRepository.save(fpc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(PermissionContainersCollection pcc) {
|
public ScopePermissionContainer save(ScopePermissionContainer spc) {
|
||||||
|
if(spcRepository.findByName(spc.getName()).isPresent())
|
||||||
|
throw new RuntimeException("SPC Already Exist");
|
||||||
|
return spcRepository.save(spc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PermissionContainersCollection save(PermissionContainersCollection pcc) {
|
||||||
|
if(pccRepository.findByName(pcc.getName()).isPresent())
|
||||||
|
throw new RuntimeException("PCC Already Exist");
|
||||||
|
return pccRepository.save(pcc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tag update(Tag tag) {
|
||||||
|
if(!tagRepository.findByName(tag.getName()).isPresent())
|
||||||
|
throw new RuntimeException(("Tag Not Exist"));
|
||||||
|
return tagRepository.save(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FunctionalPermissionContainer update(FunctionalPermissionContainer fpc) {
|
||||||
|
if(!fpcRepository.findByName(fpc.getName()).isPresent())
|
||||||
|
throw new RuntimeException("FPC Not Exist");
|
||||||
|
return fpcRepository.save(fpc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ScopePermissionContainer update(ScopePermissionContainer spc) {
|
||||||
|
if(!spcRepository.findByName(spc.getName()).isPresent())
|
||||||
|
throw new RuntimeException("SPC Not Exist");
|
||||||
|
return spcRepository.save(spc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PermissionContainersCollection update(PermissionContainersCollection pcc) {
|
||||||
|
if(!pccRepository.findByName(pcc.getName()).isPresent())
|
||||||
|
throw new RuntimeException("PCC Not Exist");
|
||||||
|
return pccRepository.save(pcc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,16 +63,16 @@ public class UserService implements IUserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePassword(User user, String password) {
|
public User updatePassword(User user, String password) {
|
||||||
user.setPassword(passwordEncoder.encode(password));
|
user.setPassword(passwordEncoder.encode(password));
|
||||||
update(user);
|
return update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 封禁用户
|
// 封禁用户
|
||||||
@Override
|
@Override
|
||||||
public void disableUser(User user){
|
public User disableUser(User user){
|
||||||
user.setEnabled(false);
|
user.setEnabled(false);
|
||||||
update(user);
|
return update(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -37,6 +37,5 @@ public class BaseInformationTest {
|
|||||||
Assert.assertTrue(informationService.checkEthnic("汉族"));
|
Assert.assertTrue(informationService.checkEthnic("汉族"));
|
||||||
Assert.assertTrue(informationService.checkMajor("软件工程"));
|
Assert.assertTrue(informationService.checkMajor("软件工程"));
|
||||||
Assert.assertTrue(informationService.checkPoliticalStatus("群众"));
|
Assert.assertTrue(informationService.checkPoliticalStatus("群众"));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,61 @@
|
|||||||
package com.codesdream.ase.test;
|
package com.codesdream.ase.test;
|
||||||
|
|
||||||
|
import com.codesdream.ase.model.permission.FunctionalPermissionContainer;
|
||||||
|
import com.codesdream.ase.model.permission.PermissionContainersCollection;
|
||||||
|
import com.codesdream.ase.model.permission.ScopePermissionContainer;
|
||||||
|
import com.codesdream.ase.model.permission.Tag;
|
||||||
|
import com.codesdream.ase.service.IPermissionService;
|
||||||
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
public class PermissionServiceTest {
|
public class PermissionServiceTest {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IPermissionService permissionService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void PermissionServiceBaseTest(){
|
||||||
|
FunctionalPermissionContainer fpc = permissionService.getDefaultFPC("活动管理权");
|
||||||
|
fpc = permissionService.save(fpc);
|
||||||
|
|
||||||
|
Tag tag1 = permissionService.getDefaultTag("九班班长"),
|
||||||
|
tag2 = permissionService.getDefaultTag("九班班委"),
|
||||||
|
tag3 = permissionService.getDefaultTag("九班普通学生");
|
||||||
|
tag1 = permissionService.save(tag1);
|
||||||
|
tag2 = permissionService.save(tag2);
|
||||||
|
tag3 = permissionService.save(tag3);
|
||||||
|
|
||||||
|
ScopePermissionContainer spc = permissionService.getDefaultSPC("九班全体学生");
|
||||||
|
spc = permissionService.save(spc);
|
||||||
|
|
||||||
|
PermissionContainersCollection pcc = permissionService.getDefaultPCC("九班班长权限容器集合");
|
||||||
|
pcc = permissionService.save(pcc);
|
||||||
|
|
||||||
|
// 给活动管理权赋予添加/参与/管理的权力
|
||||||
|
fpc = permissionService.addRoleToFPC(fpc, "activity_create");
|
||||||
|
fpc = permissionService.addRoleToFPC(fpc, "activity_participate");
|
||||||
|
fpc = permissionService.addRoleToFPC(fpc, "activity_manage");
|
||||||
|
|
||||||
|
// 把九班班委加入到九班全体学生中
|
||||||
|
spc = permissionService.addTagToSPC(spc, tag2);
|
||||||
|
// 将九班普通学生加入到九班全体学生中
|
||||||
|
spc = permissionService.addTagToSPC(spc, tag3);
|
||||||
|
|
||||||
|
// 把活动管理权赋予范围九班全体学生,加入到九班班长权限容器集合中
|
||||||
|
pcc = permissionService.addRelationItemToPCC(pcc, fpc, spc);
|
||||||
|
// 将设置好的权限容器集合赋予九班班长
|
||||||
|
tag1 = permissionService.addPCCToTag(tag1, pcc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void PermissionServiceBaseTest2() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user