♻️ 重构代码,R 、 @Inner

This commit is contained in:
冷冷 committed 2018-12-24 23:49:14 +08:00
1 parent 7d832f295c
commit 1fe7703246
12 files changed
+45 -32

No files matched your search

@@ -96,7 +96,7 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
@Bean
public TokenEnhancer tokenEnhancer() {
return (accessToken, authentication) -> {
final Map<String, Object> additionalInfo = new HashMap<>(4);
final Map<String, Object> additionalInfo = new HashMap<>(8);
PigxUser pigxUser = (PigxUser) authentication.getUserAuthentication().getPrincipal();
additionalInfo.put("user_id", pigxUser.getId());
additionalInfo.put("dept_id", pigxUser.getDeptId());
@@ -22,6 +22,7 @@ package com.pig4cloud.pigx.auth.endpoint;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
import com.pig4cloud.pigx.common.core.constant.PaginationConstants;
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
import com.pig4cloud.pigx.common.core.util.R;
@@ -79,20 +80,26 @@ public class PigxTokenEndpoint {
* @param authHeader Authorization
*/
@DeleteMapping("/logout")
public R<Boolean> logout(@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authHeader) {
public R logout(@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authHeader) {
if (StrUtil.isBlank(authHeader)) {
return new R<>(false, "退出失败,token 为空");
return R.builder()
.code(CommonConstants.FAIL)
.data(Boolean.FALSE)
.msg("退出失败,token 为空").build();
}
String tokenValue = authHeader.replace("Bearer", "").trim();
OAuth2AccessToken accessToken = tokenStore.readAccessToken(tokenValue);
if (accessToken == null || StrUtil.isBlank(accessToken.getValue())) {
return new R<>(false, "退出失败,token 无效");
return R.builder()
.code(CommonConstants.FAIL)
.data(Boolean.FALSE)
.msg("退出失败,token 无效").build();
}
OAuth2Authentication auth2Authentication = tokenStore.readAuthentication(accessToken);
cacheManager.getCache("user_details")
.evict(auth2Authentication.getName());
.evict(auth2Authentication.getName());
tokenStore.removeAccessToken(accessToken);
return new R<>(Boolean.TRUE);
}
@@ -101,14 +108,10 @@ public class PigxTokenEndpoint {
* 令牌管理调用
*
* @param token token
* @param from 内部调用标志
* @return
*/
@DeleteMapping("/{token}")
public R<Boolean> delToken(@PathVariable("token") String token, @RequestHeader(required = false) String from) {
if (StrUtil.isBlank(from)) {
return null;
}
public R<Boolean> delToken(@PathVariable("token") String token) {
return new R<>(redisTemplate.delete(PIGX_OAUTH_ACCESS + token));
}
-6
View File
@@ -40,12 +40,6 @@
<artifactId>pigx-common-core</artifactId>
<version>2.0.0</version>
</dependency>
<!---依赖扩展缓存-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-cache</artifactId>
<version>2.0.0</version>
</dependency>
<!--安全模块-->
<dependency>
<groupId>org.springframework.cloud</groupId>
@@ -47,9 +47,8 @@ public interface RemoteTokenService {
* 删除token
*
* @param token token
* @param from 调用标志
* @return
*/
@DeleteMapping("/token/{token}")
R<Boolean> removeTokenById(@PathVariable("token") String token, @RequestHeader(SecurityConstants.FROM) String from);
R<Boolean> removeTokenById(@PathVariable("token") String token);
}
@@ -54,11 +54,10 @@ public class RemoteTokenServiceFallbackImpl implements RemoteTokenService {
* 删除token
*
* @param token
* @param from
* @return
*/
@Override
public R<Boolean> removeTokenById(String token, String from) {
public R<Boolean> removeTokenById(String token) {
log.error("删除token 失败 {}", token, cause);
return null;
}
@@ -62,12 +62,12 @@ public class MenuController {
// 获取符合条件的菜单
Set<MenuVO> all = new HashSet<>();
SecurityUtils.getRoles()
.forEach(roleId -> all.addAll(sysMenuService.findMenuByRoleId(roleId)));
.forEach(roleId -> all.addAll(sysMenuService.findMenuByRoleId(roleId)));
List<MenuTree> menuTreeList = all.stream()
.filter(menuVo -> CommonConstants.MENU.equals(menuVo.getType()))
.map(MenuTree::new)
.sorted(Comparator.comparingInt(MenuTree::getSort))
.collect(Collectors.toList());
.filter(menuVo -> CommonConstants.MENU.equals(menuVo.getType()))
.map(MenuTree::new)
.sorted(Comparator.comparingInt(MenuTree::getSort))
.collect(Collectors.toList());
return new R<>(TreeUtil.bulid(menuTreeList, -1));
}
@@ -90,9 +90,9 @@ public class MenuController {
@GetMapping("/tree/{roleId}")
public List getRoleTree(@PathVariable Integer roleId) {
return sysMenuService.findMenuByRoleId(roleId)
.stream()
.map(MenuVO::getMenuId)
.collect(Collectors.toList());
.stream()
.map(MenuVO::getMenuId)
.collect(Collectors.toList());
}
/**
@@ -128,7 +128,7 @@ public class MenuController {
@SysLog("删除菜单")
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('sys_menu_del')")
public R removeById(@PathVariable SysMenu id) {
public R removeById(@PathVariable Integer id) {
return sysMenuService.removeMenuById(id);
}
@@ -61,6 +61,6 @@ public class TokenController {
@DeleteMapping("/{token}")
@PreAuthorize("@pms.hasPermission('sys_token_del')")
public R removeById(@PathVariable String token) {
return remoteTokenService.removeTokenById(token, SecurityConstants.FROM_IN);
return remoteTokenService.removeTokenById(token);
}
}
@@ -50,7 +50,7 @@ public interface SysMenuService extends IService<SysMenu> {
* @param id 菜单ID
* @return 成功、失败
*/
R removeMenuById(SysMenu id);
R removeMenuById(Integer id);
/**
* 更新菜单信息
@@ -60,7 +60,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
@Override
@Transactional(rollbackFor = Exception.class)
@CacheEvict(value = "menu_details", allEntries = true)
public R removeMenuById(SysMenu id) {
public R removeMenuById(Integer id) {
// 查询父节点为当前节点的节点
List<SysMenu> menuList = this.list(Wrappers.<SysMenu>query()
.lambda().eq(SysMenu::getParentId, id));
+6
View File
@@ -43,6 +43,12 @@
<artifactId>pigx-common-core</artifactId>
<version>2.0.0</version>
</dependency>
<!--缓存依赖-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-cache</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-upms-api</artifactId>
+6
View File
@@ -26,6 +26,12 @@
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<!--缓存依赖-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-cache</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
+6
View File
@@ -48,6 +48,12 @@
<artifactId>pigx-common-swagger</artifactId>
<version>2.0.0</version>
</dependency>
<!--缓存依赖-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-cache</artifactId>
<version>2.0.0</version>
</dependency>
<!--mybatis-->
<dependency>
<groupId>com.baomidou</groupId>