1、eldialog优化

Former-commit-id: 3394b272a3678b698ce332eb39ddebfeed0b0291
master
wangbing 5 years ago
parent 27d2dfe293
commit 4a05d55f1f

@ -46,7 +46,7 @@ public class AjaxController {
if (token == null) {
token = LocalData.getTempToken();
}
if (!token.hasResource(method)) {
if (!token.hasRes(method)) {
baseResponse.addError(new Error(ErrorType.BUSINESS_ERROR, "无权调用该接口!"));
return baseResponse;
}

@ -355,7 +355,7 @@ public class GlobalController implements ErrorController {
}
// 权限验证
if (!LocalData.getToken().hasResource(httpServletRequest.getServletPath())) {
if (!LocalData.getToken().hasRes(httpServletRequest.getServletPath())) {
response.addError(ErrorType.BUSINESS_ERROR, "[" + httpServletRequest.getServletPath() + "]未授权的资源!");
return AESUtil.encrypt2Base64(MapperUtil.toJson(response).getBytes(), appSecret);
}

@ -21,18 +21,22 @@ import ${basePackage}.module.system.ent.User;
import ${basePackage}.module.system.mgr.TokensManager;
import ${basePackage}.module.system.mgr.UserManager;
import ${basePackage}.module.system.req.TokensCreateRequest;
import ${basePackage}.module.system.req.TokensLogoutRequest;
import ${basePackage}.module.system.req.UserCreateRequest;
import ${basePackage}.module.system.req.UserDeleteRequest;
import ${basePackage}.module.system.req.UserFindRequest;
import ${basePackage}.module.system.req.UserGetRequest;
import ${basePackage}.module.system.req.UserLoginRequest;
import ${basePackage}.module.system.req.UserLogoutRequest;
import ${basePackage}.module.system.req.UserUpdateRequest;
import ${basePackage}.module.system.rsp.TokensCreateResponse;
import ${basePackage}.module.system.rsp.TokensLogoutResponse;
import ${basePackage}.module.system.rsp.UserCreateResponse;
import ${basePackage}.module.system.rsp.UserDeleteResponse;
import ${basePackage}.module.system.rsp.UserFindResponse;
import ${basePackage}.module.system.rsp.UserGetResponse;
import ${basePackage}.module.system.rsp.UserLoginResponse;
import ${basePackage}.module.system.rsp.UserLogoutResponse;
import ${basePackage}.module.system.rsp.UserUpdateResponse;
import javax.servlet.http.Cookie;
@ -174,6 +178,23 @@ public class UserAjax {
return response;
}
public UserLogoutResponse logout(UserLogoutRequest request) {
UserLogoutResponse response = new UserLogoutResponse();
TokensLogoutRequest tokensLogoutRequest = new TokensLogoutRequest();
tokensLogoutRequest.setToken(LocalData.getToken().getToken());
TokensLogoutResponse tokensLogoutResponse = tokensManager.logout(tokensLogoutRequest, LocalData.getSysToken());
if (tokensLogoutResponse.hasError()) {
response.addErrors(tokensLogoutResponse.getErrors());
return response;
}
HttpServletResponse HttpServletResponse = LocalData.getResponse();
Cookie token = CookieUtil.newCookie("token", "");
HttpServletResponse.addCookie(token);
return response;
}
public Object template() {
return ResponseUtil.apply(new WSheet<>(User.class));
}

@ -15,7 +15,7 @@ public class CacheConfig {
public static final String TOKEN_CACHE = "tokenCache";
@Bean(name = TOKEN_CACHE)
@Bean
public EhCacheCacheManager getCacheManager() {
net.sf.ehcache.config.Configuration configuration = new net.sf.ehcache.config.Configuration();
configuration.setMaxBytesLocalHeap("100M");

@ -121,7 +121,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
// 授权
Token token_ = LocalData.getToken();
if (token_ != null && token_.hasResource(request.getServletPath())) {
if (token_ != null && token_.hasRes(request.getServletPath())) {
return true;
}

@ -28,7 +28,7 @@ public class LocalData {
system.setId(0);
system.setUserId(0);
system.setUserName("system");
system.putResource(".*");
system.putRes(".*");
}
public static Token getSysToken() {

@ -1,7 +1,10 @@
package ${basePackage}.frame.base;
import ${basePackage}.module.system.ent.Res;
import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
@ -13,14 +16,52 @@ import java.util.Set;
*/
public class Token implements Serializable {
private static final Long serialVersionUID = 1L;
/** ID */
/**
* ID
*/
private long id;
/** 用户ID */
/**
* TOKEN
*/
private String token;
/**
* ID
*/
private long userId;
/** 用户名称 */
/**
*
*/
private String userName;
private Set<String> resourceSet = new HashSet<>();
private Set<String> resSet = new HashSet<>();
public boolean hasRes(String resource) {
for (String s : resSet) {
if (resource.matches(s)) {
return true;
}
}
return false;
}
public void putRes(String resource) {
resSet.add(resource);
}
public void putRes(Set<String> resourceSet) {
this.resSet.addAll(resourceSet);
}
public void putRes(List<Res> resList) {
if (resList == null) return;
for (Res res : resList) {
this.resSet.add(res.getResValue());
}
}
public Set<String> getResSet() {
return resSet;
}
public long getId() {
@ -47,28 +88,11 @@ public class Token implements Serializable {
this.userName = userName;
}
public boolean hasResource(String resource){
for (String s : resourceSet) {
if (resource.matches(s)){
return true;
}
}
return false;
}
public void putResource(String resource){
resourceSet.add(resource);
}
public Set<String> getResourceSet() {
return resourceSet;
}
public void addResourceSet(Set<String> resourceSet){
this.resourceSet.addAll(resourceSet);
public String getToken() {
return token;
}
public void addResourceSet(Token token){
addResourceSet(token.getResourceSet());
public void setToken(String token) {
this.token = token;
}
}

@ -205,7 +205,9 @@ public class RoleResManagerImpl implements RoleResManager {
if (request.getChecked() && roleResFindResponse.getResult().size() == 0) {
RoleResCreateRequest roleResCreateRequest = new RoleResCreateRequest();
roleResCreateRequest.setRoleId(request.getRoleId());
roleResCreateRequest.setRoleCode(request.getRoleCode());
roleResCreateRequest.setResId(request.getResId());
roleResCreateRequest.setResCode(request.getResCode());
RoleResCreateResponse roleResCreateResponse = this.create(roleResCreateRequest, token);
if (roleResCreateResponse.hasError()) {
response.addErrors(roleResCreateResponse.getErrors());

@ -86,5 +86,5 @@ public interface TokensManager {
* @param token
* @return
*/
${basePackage}.module.system.rsp.TokensLogoutResponse logout(${basePackage}.module.system.req.TokensLogoutRequest request, Token token);
TokensLogoutResponse logout(TokensLogoutRequest request, Token token);
}

@ -18,6 +18,7 @@ import ${basePackage}.frame.utils.Message;
import ${basePackage}.frame.utils.ValidationUtil;
import ${basePackage}.module.system.ent.Tokens;
import ${basePackage}.module.system.mpr.TokensMapper;
import ${basePackage}.module.system.req.ResFindRequest;
import ${basePackage}.module.system.req.TokensBuildRequest;
import ${basePackage}.module.system.req.TokensCreateRequest;
import ${basePackage}.module.system.req.TokensDeleteRequest;
@ -25,6 +26,7 @@ import ${basePackage}.module.system.req.TokensFindRequest;
import ${basePackage}.module.system.req.TokensGetRequest;
import ${basePackage}.module.system.req.TokensLogoutRequest;
import ${basePackage}.module.system.req.TokensUpdateRequest;
import ${basePackage}.module.system.rsp.ResFindResponse;
import ${basePackage}.module.system.rsp.TokensBuildResponse;
import ${basePackage}.module.system.rsp.TokensCreateResponse;
import ${basePackage}.module.system.rsp.TokensDeleteResponse;
@ -42,12 +44,16 @@ import ${basePackage}.module.system.rsp.TokensUpdateResponse;
*/
@Transactional
@Service
public class TokensManagerImpl implements ${basePackage}.module.system.mgr.TokensManager {
public class TokensManagerImpl implements xyz.wbsite.module.system.mgr.TokensManager {
@Value("${r'${web.url.auth.admin}'}")
@Value("${web.url.auth.admin}")
private String admin;
@Autowired
private TokensMapper tokensMapper;
@Autowired
private UserRoleManager userRoleManager;
@Autowired
private ResManager resManager;
/**
*
@ -221,15 +227,38 @@ public class TokensManagerImpl implements ${basePackage}.module.system.mgr.Token
} else {
Tokens tokens = tokensFindResponse.getResult().get(0);
Token newToken = new Token();
if (tokens.getUserName().equals(admin)) {
if (tokens.getUserName().equals(admin)) {//超级管理员
newToken.setId(0);
newToken.setToken(tokensFindResponse.getResult().get(0).getToken());
newToken.setUserId(0);
newToken.setUserName(admin);
newToken.putResource(".*");
} else {
newToken.putRes(".*");
// 获取用户的资源
ResFindRequest resFindRequest = new ResFindRequest();
resFindRequest.setPageSize(0);
ResFindResponse resFindResponse = resManager.find(resFindRequest, token);
if (resFindResponse.hasError()) {
response.addErrors(resFindResponse.getErrors());
return response;
}
newToken.putRes(resFindResponse.getResult());
} else { // 管理员或用户
newToken.setId(tokens.getId());
newToken.setToken(tokensFindResponse.getResult().get(0).getToken());
newToken.setUserId(tokens.getUserId());
newToken.setUserName(tokens.getUserName());
// 获取用户的资源
ResFindRequest resFindRequest = new ResFindRequest();
resFindRequest.setPageSize(0);
resFindRequest.setUserId(token.getUserId());
ResFindResponse resFindResponse = resManager.find(resFindRequest, token);
if (resFindResponse.hasError()) {
response.addErrors(resFindResponse.getErrors());
return response;
}
newToken.putRes(resFindResponse.getResult());
}
response.setToken(newToken);

@ -55,6 +55,24 @@
<if test="request.valid != null">
AND `VALID` = ${r'#'}{request.valid}
</if>
<if test="request.userId != null">
AND `ID` IN (
SELECT
t2.RES_ID
FROM
`sys_user_role` t1,
`sys_role_res` t2
WHERE t1.ROLE_ID = t2.ROLE_ID
AND t1.IS_DELETED = '0'
AND t2.IS_DELETED = '0'
AND t1.USER_ID = ${r'#'}{request.userId}
)
</if>
<if test="request.roleCode != null">
AND `ID` IN (
SELECT RES_ID FROM `sys_role_res` WHERE ROLE_CODE = ${r'#'}{request.roleCode}
)
</if>
</select>
<select id="search" resultMap="res">

@ -48,6 +48,16 @@ public class ResFindRequest extends BaseFindRequest {
*/
private Boolean valid;
/**
* ID
*/
private Long userId;
/**
*
*/
private Long roleCode;
public String getResCode() {
return this.resCode;
}
@ -103,4 +113,20 @@ public class ResFindRequest extends BaseFindRequest {
public void setValid(Boolean valid) {
this.valid = valid;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public Long getRoleCode() {
return roleCode;
}
public void setRoleCode(Long roleCode) {
this.roleCode = roleCode;
}
}

@ -0,0 +1,14 @@
package ${basePackage}.module.system.req;
import ${basePackage}.frame.base.BaseRequest;
/**
* UserLogoutRequest -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class UserLogoutRequest extends BaseRequest {
}

@ -0,0 +1,14 @@
package ${basePackage}.module.system.rsp;
import ${basePackage}.frame.base.BaseResponse;
/**
* UserLoginResponse -
*
* @author wangbing
* @version 0.0.1
* @since 2017-01-01
*/
public class UserLogoutResponse extends BaseResponse {
}

@ -151,6 +151,7 @@
this.mModule = module;
this.mTarget = target;
this.mMethod = method;
this.mData = {};
this.module = function (module) {
this.mModule = module;

@ -313,8 +313,18 @@
onCommand: function (cmd) {
switch (cmd) {
case "logout":
new Ajax()
.module("system")
.target("user")
.method("logout")
.post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {
nav.clearCookie("token");
nav.toOpen("/login.htm");
}
}.bind(this));
break;
default:
nav.w("未找到对应的命令");

@ -149,7 +149,7 @@
:default-expand-all="true"
:expand-on-click-node="false">
<div class="tree" slot-scope="{ node, data }">
<span>{{ data.comment }}<span style="color: #409EFF">[{{data.code}}]</span></span>
<span>{{ data.resName }}<span style="color: #409EFF">[{{data.resCode}}]</span></span>
</div>
</el-tree>
@ -188,6 +188,7 @@
title: "",
dialog: false,
roleId: '',
roleCode: ''
},
formRules: {
code: [
@ -229,7 +230,8 @@
case "resourceEdit":
this.formResource.title = "分配资源";
this.formResource.dialog = true;
this.formResource.roleId = item.id
this.formResource.roleId = item.id;
this.formResource.roleCode = item.code;
new Ajax()
.module("system")
.target("roleRes")
@ -241,7 +243,7 @@
this.$refs.tree.setCheckedKeys([]);
var ids = [];
for (var i = 0; i < response.result.length; i++) {
ids.push(response.result[i].resourceId);
ids.push(response.result[i].resId);
}
this.$refs.tree.setCheckedKeys(ids);
}
@ -262,10 +264,12 @@
.method("check")
.data({
roleId: this.formResource.roleId,
resourceId: item.id,
roleCode: this.formResource.roleCode,
resId: item.id,
resCode: item.resCode,
checked: status.checkedKeys.indexOf(item.id) !== -1,
})
.find(function (response) {
.post(function (response) {
if (response.errors.length > 0) {
nav.e(response.errors[0].message);
} else {

Loading…
Cancel
Save

Powered by TurnKey Linux.