Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
10a9991252
|
@ -35,7 +35,8 @@ public class LoginController {
|
||||||
try {
|
try {
|
||||||
subject.login(token);
|
subject.login(token);
|
||||||
if (subject.isAuthenticated()) {
|
if (subject.isAuthenticated()) {
|
||||||
return ResultHolder.success("");
|
// 返回 userDTO
|
||||||
|
return ResultHolder.success(subject.getSession().getAttribute("user"));
|
||||||
} else {
|
} else {
|
||||||
return ResultHolder.error("login fail");
|
return ResultHolder.error("login fail");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package io.metersphere.security;
|
package io.metersphere.security;
|
||||||
|
|
||||||
|
|
||||||
|
import io.metersphere.dto.UserDTO;
|
||||||
|
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.*;
|
||||||
|
@ -10,6 +12,8 @@ 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;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义Realm 注入service 可能会导致在 service的aop 失效,例如@Transactional,
|
* 自定义Realm 注入service 可能会导致在 service的aop 失效,例如@Transactional,
|
||||||
|
@ -23,6 +27,8 @@ import org.slf4j.LoggerFactory;
|
||||||
public class ShiroDBRealm extends AuthorizingRealm {
|
public class ShiroDBRealm extends AuthorizingRealm {
|
||||||
|
|
||||||
private Logger logger = LoggerFactory.getLogger(ShiroDBRealm.class);
|
private Logger logger = LoggerFactory.getLogger(ShiroDBRealm.class);
|
||||||
|
@Resource
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 权限认证
|
* 权限认证
|
||||||
|
@ -40,10 +46,16 @@ public class ShiroDBRealm extends AuthorizingRealm {
|
||||||
UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken;
|
UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken;
|
||||||
String userId = token.getUsername();
|
String userId = token.getUsername();
|
||||||
String password = String.valueOf(token.getPassword());
|
String password = String.valueOf(token.getPassword());
|
||||||
SessionUser sessionUser = new SessionUser();
|
UserDTO user = userService.getUserDTO(userId);
|
||||||
|
String msg;
|
||||||
|
if (user == null) {
|
||||||
|
msg = "not exist user is trying to login, user:" + userId;
|
||||||
|
logger.warn(msg);
|
||||||
|
throw new UnknownAccountException(msg);
|
||||||
|
}
|
||||||
|
// TODO 密码验证,roles 等内容填充
|
||||||
|
|
||||||
sessionUser.setName(userId);
|
SessionUser sessionUser = SessionUser.fromUser(user);
|
||||||
sessionUser.setId(userId);
|
|
||||||
SecurityUtils.getSubject().getSession().setAttribute("user", sessionUser);
|
SecurityUtils.getSubject().getSession().setAttribute("user", sessionUser);
|
||||||
return new SimpleAuthenticationInfo(userId, password, getName());
|
return new SimpleAuthenticationInfo(userId, password, getName());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +1,18 @@
|
||||||
package io.metersphere.user;
|
package io.metersphere.user;
|
||||||
|
|
||||||
|
import io.metersphere.dto.UserDTO;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
public class SessionUser implements Serializable {
|
public class SessionUser extends UserDTO implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -7149638440406959033L;
|
private static final long serialVersionUID = -7149638440406959033L;
|
||||||
private String id;
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
public String getId() {
|
public static SessionUser fromUser(UserDTO user) {
|
||||||
return id;
|
SessionUser sessionUser = new SessionUser();
|
||||||
|
BeanUtils.copyProperties(user, sessionUser);
|
||||||
|
return sessionUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,10 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import Cookies from 'js-cookie';
|
||||||
|
|
||||||
|
const TokenKey = 'Admin-Token';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Login",
|
name: "Login",
|
||||||
data() {
|
data() {
|
||||||
|
@ -102,7 +106,9 @@
|
||||||
submit(form) {
|
submit(form) {
|
||||||
this.$refs[form].validate((valid) => {
|
this.$refs[form].validate((valid) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
this.$post("signin", this.form, function () {
|
this.$post("signin", this.form, (response) => {
|
||||||
|
// 登录信息保存 cookie
|
||||||
|
Cookies.set(TokenKey, response.data);
|
||||||
window.location.href = "/"
|
window.location.href = "/"
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -13,15 +13,10 @@
|
||||||
<el-table :data="items" style="width: 100%">
|
<el-table :data="items" style="width: 100%">
|
||||||
<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 width="100">
|
<el-table-column>
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-button @click="edit(scope.row)" type="primary" icon="el-icon-edit" size="mini" circle
|
<el-button @click="edit(scope.row)" type="primary" icon="el-icon-edit" size="mini" circle/>
|
||||||
class="edit"/>
|
<el-button @click="del(scope.row)" type="danger" icon="el-icon-delete" size="mini" circle/>
|
||||||
<el-popconfirm title="这个工作空间确定要删除吗?" @onConfirm="del(scope.row)">
|
|
||||||
<el-button slot="reference" type="primary" icon="el-icon-delete" size="mini"
|
|
||||||
circle
|
|
||||||
class="edit"/>
|
|
||||||
</el-popconfirm>
|
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
|
@ -88,9 +83,17 @@
|
||||||
// });
|
// });
|
||||||
},
|
},
|
||||||
del(row) {
|
del(row) {
|
||||||
this.$get('/workspace/delete/' + row.id, () => {
|
this.$confirm('这个工作空间确定要删除吗?', '提示', {
|
||||||
Message.success('删除成功');
|
confirmButtonText: '确定',
|
||||||
this.list();
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning'
|
||||||
|
}).then(() => {
|
||||||
|
this.$get('/workspace/delete/' + row.id, () => {
|
||||||
|
Message.success('删除成功');
|
||||||
|
this.list();
|
||||||
|
});
|
||||||
|
}).catch(() => {
|
||||||
|
|
||||||
});
|
});
|
||||||
window.console.log(row);
|
window.console.log(row);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue