Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
haifeng414 2020-02-19 11:47:51 +08:00
commit a2c9277c61
5 changed files with 70 additions and 98 deletions

View File

@ -1,18 +1,22 @@
package io.metersphere.security; package io.metersphere.security;
import io.metersphere.base.domain.Role;
import io.metersphere.dto.UserDTO; import io.metersphere.dto.UserDTO;
import io.metersphere.service.UserService; import io.metersphere.service.UserService;
import io.metersphere.user.SessionUser; import io.metersphere.user.SessionUser;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*; import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo; import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm; import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection; import org.apache.shiro.subject.PrincipalCollection;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Set;
import java.util.stream.Collectors;
/** /**
@ -34,8 +38,16 @@ public class ShiroDBRealm extends AuthorizingRealm {
* 权限认证 * 权限认证
*/ */
@Override @Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) { protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
return null; String userName = (String) principals.getPrimaryPrincipal();
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
// roles 内容填充
UserDTO userDTO = userService.getUserDTO(userName);
Set<String> roles = userDTO.getRoles().stream().map(Role::getId).collect(Collectors.toSet());
authorizationInfo.setRoles(roles);
return authorizationInfo;
} }
/** /**
@ -53,7 +65,7 @@ public class ShiroDBRealm extends AuthorizingRealm {
logger.warn(msg); logger.warn(msg);
throw new UnknownAccountException(msg); throw new UnknownAccountException(msg);
} }
// TODO 密码验证roles 等内容填充 // TODO 密码验证
SessionUser sessionUser = SessionUser.fromUser(user); SessionUser sessionUser = SessionUser.fromUser(user);
SecurityUtils.getSubject().getSession().setAttribute("user", sessionUser); SecurityUtils.getSubject().getSession().setAttribute("user", sessionUser);

View File

@ -14,7 +14,7 @@
</span> </span>
</el-row> </el-row>
</div> </div>
<el-table :data="items" style="width: 100%"> <el-table :data="items" style="width: 100%" v-loading="loading">
<el-table-column prop="name" label="名称"/> <el-table-column prop="name" label="名称"/>
<el-table-column prop="description" label="描述"/> <el-table-column prop="description" label="描述"/>
<el-table-column> <el-table-column>

View File

@ -133,15 +133,11 @@
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
this.$get(this.deletePath + row.id).then(response => { this.$get(this.deletePath + row.id,() => {
if (response.data.success) {
this.$message({ this.$message({
type: 'success', type: 'success',
message: '删除成功!' message: '删除成功!'
}); });
} else {
this.$message.error(response.message);
}
this.initTableData() this.initTableData()
}); });
}).catch(() => { }).catch(() => {
@ -154,17 +150,12 @@
createOrganization(createOrganizationForm) { createOrganization(createOrganizationForm) {
this.$refs[createOrganizationForm].validate( valide => { this.$refs[createOrganizationForm].validate( valide => {
if (valide) { if (valide) {
this.$post(this.createPath, this.form) this.$post(this.createPath, this.form,() => {
.then(response => {
if (response.data.success) {
this.$message({ this.$message({
type: 'success', type: 'success',
message: '添加成功!' message: '添加成功!'
}); });
this.initTableData(); this.initTableData();
} else {
this.$message.error(response.message);
}
this.createVisible = false; this.createVisible = false;
}); });
} else { } else {
@ -175,17 +166,12 @@
updateOrganization(udpateOrganizationForm) { updateOrganization(udpateOrganizationForm) {
this.$refs[udpateOrganizationForm].validate(valide => { this.$refs[udpateOrganizationForm].validate(valide => {
if (valide) { if (valide) {
this.$post(this.updatePath, this.form) this.$post(this.updatePath, this.form,() => {
.then(response => {
if (response.data.success) {
this.$message({ this.$message({
type: 'success', type: 'success',
message: '修改成功!' message: '修改成功!'
}); });
this.updateVisible = false; this.updateVisible = false;
} else {
this.$message.error(response.message);
}
this.initTableData(); this.initTableData();
self.loading = false; self.loading = false;
}); });
@ -195,14 +181,10 @@
}) })
}, },
initTableData() { initTableData() {
this.$post(this.buildPagePath(this.queryPath)).then(response => { this.$post(this.buildPagePath(this.queryPath),{},response => {
if (response.data.success) { let data = response.data;
let data = response.data.data;
this.total = data.itemCount; this.total = data.itemCount;
this.tableData = data.listObject; this.tableData = data.listObject;
} else {
this.$message.error(response.message);
}
}) })
}, },
closeFunc() { closeFunc() {

View File

@ -180,16 +180,12 @@
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
this.$get(this.deletePath + row.id).then(response => { this.$get(this.deletePath + row.id, () => {
if (response.data.success) {
this.$message({ this.$message({
type: 'success', type: 'success',
message: '删除成功!' message: '删除成功!'
}); });
this.initTableData() this.initTableData();
} else {
this.$message.error(response.message)
}
}); });
}).catch(() => { }).catch(() => {
this.$message({ this.$message({
@ -201,17 +197,12 @@
createUser(createUserForm) { createUser(createUserForm) {
this.$refs[createUserForm].validate(valide => { this.$refs[createUserForm].validate(valide => {
if (valide) { if (valide) {
this.$post(this.createPath, this.form) this.$post(this.createPath, this.form, () => {
.then(response => {
if (response.data.success) {
this.$message({ this.$message({
type: 'success', type: 'success',
message: '添加成功!' message: '添加成功!'
}); });
this.initTableData(); this.initTableData();
} else {
this.$message.error(response.message);
}
this.createVisible = false; this.createVisible = false;
}); });
} else { } else {
@ -222,17 +213,12 @@
updateUser(updateUserForm) { updateUser(updateUserForm) {
this.$refs[updateUserForm].validate(valide => { this.$refs[updateUserForm].validate(valide => {
if (valide) { if (valide) {
this.$post(this.updatePath, this.form) this.$post(this.updatePath, this.form,() => {
.then(response => {
if (response.data.success) {
this.$message({ this.$message({
type: 'success', type: 'success',
message: '修改成功!' message: '修改成功!'
}); });
this.updateVisible = false; this.updateVisible = false;
} else {
this.$message.error(response.message);
}
this.initTableData(); this.initTableData();
self.loading = false; self.loading = false;
}); });
@ -242,29 +228,21 @@
}) })
}, },
initTableData() { initTableData() {
this.$post(this.buildPagePath(this.queryPath)).then(response => { this.$post(this.buildPagePath(this.queryPath),{},response => {
if (response.data.success) { let data = response.data;
let data = response.data.data;
this.total = data.itemCount; this.total = data.itemCount;
this.tableData = data.listObject; this.tableData = data.listObject;
} else {
this.$message.error(response.message);
}
}) })
}, },
closeFunc() { closeFunc() {
this.form = {}; this.form = {};
}, },
changeSwitch(row) { changeSwitch(row) {
this.$post(this.updatePath, row).then(response =>{ this.$post(this.updatePath, row,() =>{
if (response.data.success) {
this.$message({ this.$message({
type: 'success', type: 'success',
message: '状态修改成功!' message: '状态修改成功!'
}); });
} else {
this.$message.error(response.message);
}
}) })
}, },
buildPagePath(path) { buildPagePath(path) {

View File

@ -1,5 +1,5 @@
<template> <template>
<div v-loading="loading"> <div>
<el-card> <el-card>
<div slot="header"> <div slot="header">
<el-row type="flex" justify="space-between" align="middle"> <el-row type="flex" justify="space-between" align="middle">
@ -13,7 +13,7 @@
</span> </span>
</el-row> </el-row>
</div> </div>
<el-table :data="items" style="width: 100%"> <el-table :data="items" style="width: 100%" v-loading="loading">
<el-table-column prop="name" label="名称"/> <el-table-column prop="name" label="名称"/>
<el-table-column prop="description" label="描述"/> <el-table-column prop="description" label="描述"/>
<el-table-column> <el-table-column>