mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-09 04:49:02 +08:00
✨ 添加新特性。 oauth execption response format
This commit is contained in:
1 parent
955fd80929
commit
517c86b900
20 files changed
+88
-47
No files matched your search
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2025, lengleng All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the pig4cloud.com developer nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
* Author: lengleng (wangiegie@gmail.com)
|
||||
*/
|
||||
|
||||
package com.pig4cloud.pigx.common.security.component;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
import com.pig4cloud.pigx.common.security.exception.PigxAuth2Exception;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/11/16
|
||||
* <p>
|
||||
* OAuth2 异常格式化
|
||||
*/
|
||||
public class PigxAuth2ExceptionSerializer extends StdSerializer<PigxAuth2Exception> {
|
||||
public PigxAuth2ExceptionSerializer() {
|
||||
super(PigxAuth2Exception.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(PigxAuth2Exception value, JsonGenerator gen, SerializerProvider provider) throws IOException {
|
||||
gen.writeStartObject();
|
||||
gen.writeObjectField("code", 1);
|
||||
gen.writeStringField("message", value.getMessage());
|
||||
gen.writeStringField("data", value.getOAuth2ErrorCode());
|
||||
gen.writeEndObject();
|
||||
}
|
||||
}
|
||||
+3
@@ -17,12 +17,15 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.security.exception;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.pig4cloud.pigx.common.security.component.PigxAuth2ExceptionSerializer;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/7/8
|
||||
*/
|
||||
@JsonSerialize(using = PigxAuth2ExceptionSerializer.class)
|
||||
public class ForbiddenException extends PigxAuth2Exception {
|
||||
|
||||
public ForbiddenException(String msg, Throwable t) {
|
||||
|
||||
+4
@@ -17,10 +17,14 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.security.exception;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.pig4cloud.pigx.common.security.component.PigxAuth2ExceptionSerializer;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/7/8
|
||||
*/
|
||||
@JsonSerialize(using = PigxAuth2ExceptionSerializer.class)
|
||||
public class InvalidException extends PigxAuth2Exception {
|
||||
|
||||
public InvalidException(String msg, Throwable t) {
|
||||
|
||||
+3
@@ -17,12 +17,15 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.security.exception;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.pig4cloud.pigx.common.security.component.PigxAuth2ExceptionSerializer;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/7/8
|
||||
*/
|
||||
@JsonSerialize(using = PigxAuth2ExceptionSerializer.class)
|
||||
public class MethodNotAllowed extends PigxAuth2Exception {
|
||||
|
||||
public MethodNotAllowed(String msg, Throwable t) {
|
||||
|
||||
+3
@@ -17,6 +17,8 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.security.exception;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.pig4cloud.pigx.common.security.component.PigxAuth2ExceptionSerializer;
|
||||
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
|
||||
|
||||
/**
|
||||
@@ -24,6 +26,7 @@ import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
|
||||
* @date 2018/7/8
|
||||
* 自定义OAuth2Exception
|
||||
*/
|
||||
@JsonSerialize(using = PigxAuth2ExceptionSerializer.class)
|
||||
public class PigxAuth2Exception extends OAuth2Exception {
|
||||
|
||||
public PigxAuth2Exception(String msg) {
|
||||
|
||||
+3
@@ -17,12 +17,15 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.security.exception;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.pig4cloud.pigx.common.security.component.PigxAuth2ExceptionSerializer;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/7/8
|
||||
*/
|
||||
@JsonSerialize(using = PigxAuth2ExceptionSerializer.class)
|
||||
public class ServerErrorException extends PigxAuth2Exception {
|
||||
|
||||
public ServerErrorException(String msg, Throwable t) {
|
||||
|
||||
+3
@@ -17,12 +17,15 @@
|
||||
|
||||
package com.pig4cloud.pigx.common.security.exception;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.pig4cloud.pigx.common.security.component.PigxAuth2ExceptionSerializer;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/7/8
|
||||
*/
|
||||
@JsonSerialize(using = PigxAuth2ExceptionSerializer.class)
|
||||
public class UnauthorizedException extends PigxAuth2Exception {
|
||||
|
||||
public UnauthorizedException(String msg, Throwable t) {
|
||||
|
||||
+1
-1
@@ -102,6 +102,6 @@ public class PigxUserDetailsServiceImpl implements PigxUserDetailsService {
|
||||
// 构造security用户
|
||||
|
||||
return new PigxUser(user.getUserId(), user.getDeptId(), user.getTenantId(), user.getUsername(), SecurityConstants.BCRYPT + user.getPassword(), enabled,
|
||||
true, true, true, authorities);
|
||||
true, true, !CommonConstant.STATUS_LOCK.equals(user.getLockFlag()), authorities);
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,11 @@ public class SysUser implements Serializable {
|
||||
@TableLogic
|
||||
private String delFlag;
|
||||
|
||||
/**
|
||||
* 锁定标记
|
||||
*/
|
||||
private String lockFlag;
|
||||
|
||||
/**
|
||||
* 简介
|
||||
*/
|
||||
|
||||
@@ -73,6 +73,11 @@ public class UserVO implements Serializable {
|
||||
* 0-正常,1-删除
|
||||
*/
|
||||
private String delFlag;
|
||||
|
||||
/**
|
||||
* 锁定标记
|
||||
*/
|
||||
private String lockFlag;
|
||||
/**
|
||||
* 简介
|
||||
*/
|
||||
|
||||
-2
@@ -23,7 +23,6 @@ import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.pig4cloud.pigx.admin.api.dto.DeptTree;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysDept;
|
||||
import com.pig4cloud.pigx.admin.service.SysDeptService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -69,7 +68,6 @@ public class DeptController {
|
||||
@GetMapping(value = "/tree")
|
||||
public List<DeptTree> getTree() {
|
||||
SysDept condition = new SysDept();
|
||||
condition.setDelFlag(CommonConstant.STATUS_NORMAL);
|
||||
return sysDeptService.selectListTree(new EntityWrapper<>(condition));
|
||||
}
|
||||
|
||||
|
||||
-2
@@ -24,7 +24,6 @@ import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysDict;
|
||||
import com.pig4cloud.pigx.admin.service.SysDictService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
|
||||
import com.pig4cloud.pigx.common.core.util.Query;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.log.annotation.SysLog;
|
||||
@@ -86,7 +85,6 @@ public class DictController {
|
||||
@Cacheable(value = "dict_details", key = "#type")
|
||||
public List<SysDict> findDictByType(@PathVariable String type) {
|
||||
SysDict condition = new SysDict();
|
||||
condition.setDelFlag(CommonConstant.STATUS_NORMAL);
|
||||
condition.setType(type);
|
||||
return sysDictService.selectList(new EntityWrapper<>(condition));
|
||||
}
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ public class LogController {
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("@pms.hasPermission('sys_log_del')")
|
||||
public R<Boolean> delete(@PathVariable Long id) {
|
||||
return new R<>(sysLogService.updateByLogId(id));
|
||||
return new R<>(sysLogService.deleteById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-4
@@ -47,7 +47,7 @@ import java.util.stream.Collectors;
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("/menu")
|
||||
@Api(value = "menu",description = "菜单管理模块")
|
||||
@Api(value = "menu", description = "菜单管理模块")
|
||||
public class MenuController {
|
||||
private final SysMenuService sysMenuService;
|
||||
|
||||
@@ -77,9 +77,7 @@ public class MenuController {
|
||||
*/
|
||||
@GetMapping(value = "/tree")
|
||||
public List<MenuTree> getTree() {
|
||||
SysMenu condition = new SysMenu();
|
||||
condition.setDelFlag(CommonConstant.STATUS_NORMAL);
|
||||
return TreeUtil.bulidTree(sysMenuService.selectList(new EntityWrapper<>(condition)), -1);
|
||||
return TreeUtil.bulidTree(sysMenuService.selectList(new EntityWrapper<>()), -1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-4
@@ -24,7 +24,6 @@ import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysRole;
|
||||
import com.pig4cloud.pigx.admin.service.SysRoleMenuService;
|
||||
import com.pig4cloud.pigx.admin.service.SysRoleService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
|
||||
import com.pig4cloud.pigx.common.core.util.Query;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -85,9 +84,7 @@ public class RoleController {
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("@pms.hasPermission('sys_role_del')")
|
||||
public R<Boolean> roleDel(@PathVariable Integer id) {
|
||||
SysRole sysRole = sysRoleService.selectById(id);
|
||||
sysRole.setDelFlag(CommonConstant.STATUS_DEL);
|
||||
return new R<>(sysRoleService.updateById(sysRole));
|
||||
return new R<>(sysRoleService.deleteById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
-8
@@ -35,14 +35,6 @@ import java.util.List;
|
||||
*/
|
||||
public interface SysLogService extends IService<SysLog> {
|
||||
|
||||
/**
|
||||
* 通过ID删除日志(逻辑删除)
|
||||
*
|
||||
* @param id 日志ID
|
||||
* @return true/false
|
||||
*/
|
||||
Boolean updateByLogId(Long id);
|
||||
|
||||
/**
|
||||
* 批量插入前端错误日志
|
||||
*
|
||||
|
||||
+1
-7
@@ -28,12 +28,10 @@ import com.pig4cloud.pigx.admin.api.vo.TreeUtil;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysDeptMapper;
|
||||
import com.pig4cloud.pigx.admin.service.SysDeptRelationService;
|
||||
import com.pig4cloud.pigx.admin.service.SysDeptService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -74,11 +72,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteDeptById(Integer id) {
|
||||
SysDept sysDept = new SysDept();
|
||||
sysDept.setDeptId(id);
|
||||
sysDept.setUpdateTime(LocalDateTime.now());
|
||||
sysDept.setDelFlag(CommonConstant.STATUS_DEL);
|
||||
this.deleteById(sysDept);
|
||||
this.deleteById(id);
|
||||
sysDeptRelationService.deleteAllDeptRealtion(id);
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
-10
@@ -42,16 +42,6 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService {
|
||||
|
||||
@Override
|
||||
public Boolean updateByLogId(Long id) {
|
||||
|
||||
SysLog sysLog = new SysLog();
|
||||
sysLog.setId(id);
|
||||
sysLog.setDelFlag(CommonConstant.STATUS_DEL);
|
||||
sysLog.setUpdateTime(LocalDateTime.now());
|
||||
return updateById(sysLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量插入前端错误日志
|
||||
*
|
||||
|
||||
+2
-8
@@ -25,7 +25,6 @@ import com.pig4cloud.pigx.admin.api.entity.SysMenu;
|
||||
import com.pig4cloud.pigx.admin.api.vo.MenuVO;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysMenuMapper;
|
||||
import com.pig4cloud.pigx.admin.service.SysMenuService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CommonConstant;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -53,17 +52,12 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
@CacheEvict(value = "menu_details", allEntries = true)
|
||||
public Boolean deleteMenu(Integer id) {
|
||||
// 删除当前节点
|
||||
SysMenu condition1 = new SysMenu();
|
||||
condition1.setMenuId(id);
|
||||
condition1.setDelFlag(CommonConstant.STATUS_DEL);
|
||||
this.updateById(condition1);
|
||||
this.deleteById(id);
|
||||
|
||||
// 删除父节点为当前节点的节点
|
||||
SysMenu conditon2 = new SysMenu();
|
||||
conditon2.setParentId(id);
|
||||
SysMenu sysMenu = new SysMenu();
|
||||
sysMenu.setDelFlag(CommonConstant.STATUS_DEL);
|
||||
return this.update(sysMenu, new EntityWrapper<>(conditon2));
|
||||
return this.delete(new EntityWrapper<>(conditon2));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="del_flag" property="delFlag"/>
|
||||
<result column="lock_flag" property="lockFlag"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- userVo结果集 -->
|
||||
@@ -49,6 +50,7 @@
|
||||
<result column="qq_openid" property="qqOpenid"/>
|
||||
<result column="ucreate_time" property="createTime"/>
|
||||
<result column="uupdate_time" property="updateTime"/>
|
||||
<result column="lock_flag" property="lockFlag"/>
|
||||
<result column="udel_flag" property="delFlag"/>
|
||||
<result column="deptId" property="deptId"/>
|
||||
<result column="tenantId" property="tenantId"/>
|
||||
@@ -77,6 +79,7 @@
|
||||
`user`.create_time AS ucreate_time,
|
||||
`user`.update_time AS uupdate_time,
|
||||
`user`.del_flag AS udel_flag,
|
||||
`user`.lock_flag AS lock_flag,
|
||||
`user`.dept_id AS deptId,
|
||||
`user`.tenant_id AS tenantId,
|
||||
r.role_id,
|
||||
@@ -109,6 +112,7 @@
|
||||
`user`.create_time AS ucreate_time,
|
||||
`user`.update_time AS uupdate_time,
|
||||
`user`.del_flag AS udel_flag,
|
||||
`user`.lock_flag AS lock_flag,
|
||||
`user`.tenant_id AS tenantId,
|
||||
r.role_id,
|
||||
r.role_name,
|
||||
@@ -140,6 +144,7 @@
|
||||
`user`.create_time AS ucreate_time,
|
||||
`user`.update_time AS uupdate_time,
|
||||
`user`.del_flag AS udel_flag,
|
||||
`user`.lock_flag AS lock_flag,
|
||||
`user`.tenant_id AS tenantId,
|
||||
r.role_id,
|
||||
r.role_name,
|
||||
|
||||
Reference in new issue
Block a user