forked from github/dataease
feat: 适配新前端
This commit is contained in:
parent
b427e0b95f
commit
61dea50701
@ -14,7 +14,7 @@ public interface AuthApi {
|
||||
|
||||
|
||||
@PostMapping("/login")
|
||||
void login(LoginDto loginDto);
|
||||
Object login(LoginDto loginDto);
|
||||
|
||||
|
||||
@PostMapping("/userInfo")
|
||||
|
@ -0,0 +1,21 @@
|
||||
package io.dataease.auth.api;
|
||||
|
||||
|
||||
import io.dataease.auth.api.dto.DynamicMenuDto;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import java.util.List;
|
||||
|
||||
@Api(tags = "权限:动态菜单")
|
||||
@RequestMapping("/api/dynamicMenu")
|
||||
public interface DynamicMenuApi {
|
||||
|
||||
/**
|
||||
* 根据heads中获取的token 获取username 获取对应权限的菜单
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/menus")
|
||||
List<DynamicMenuDto> menus();
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package io.dataease.auth.api.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class DynamicMenuDto implements Serializable {
|
||||
|
||||
private String path;
|
||||
|
||||
private String component;
|
||||
|
||||
private String redirect;
|
||||
|
||||
private String name;
|
||||
|
||||
private MenuMeta meta;
|
||||
|
||||
private Long pid;
|
||||
|
||||
private Long id;
|
||||
|
||||
private List<DynamicMenuDto> children;
|
||||
|
||||
}
|
14
backend/src/main/java/io/dataease/auth/api/dto/MenuMeta.java
Normal file
14
backend/src/main/java/io/dataease/auth/api/dto/MenuMeta.java
Normal file
@ -0,0 +1,14 @@
|
||||
package io.dataease.auth.api.dto;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class MenuMeta implements Serializable {
|
||||
|
||||
private String title;
|
||||
|
||||
private String icon;
|
||||
}
|
@ -50,10 +50,10 @@ public class ShiroConfig {
|
||||
//filterMap.put("f2cRoles", new F2CRolesFilter());
|
||||
filterMap.put("jwt", new JWTFilter());
|
||||
filterMap.put("logout", new F2CLogoutFilter());
|
||||
factoryBean.setFilters(filterMap);
|
||||
factoryBean.setSecurityManager(securityManager);
|
||||
factoryBean.setUnauthorizedUrl("/permissionMiss");
|
||||
factoryBean.setFilterChainDefinitionMap(shiroService.loadFilterChainDefinitionMap());
|
||||
factoryBean.setFilters(filterMap);
|
||||
return factoryBean;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -28,7 +27,7 @@ public class AuthServer implements AuthApi {
|
||||
|
||||
|
||||
@Override
|
||||
public void login(@RequestBody LoginDto loginDto) {
|
||||
public Object login(@RequestBody LoginDto loginDto) {
|
||||
String username = loginDto.getUsername();
|
||||
String password = loginDto.getPassword();
|
||||
SysUserEntity user = authUserService.getUser(username);
|
||||
@ -48,6 +47,9 @@ public class AuthServer implements AuthApi {
|
||||
result.put("token", JWTUtils.sign(username, realPwd));*/
|
||||
String token = JWTUtils.sign(username, realPwd);
|
||||
ServletUtils.setToken(token);
|
||||
Map<String,Object> result = new HashMap<>();
|
||||
result.put("token", token);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,20 @@
|
||||
package io.dataease.auth.server;
|
||||
|
||||
import io.dataease.auth.api.DynamicMenuApi;
|
||||
import io.dataease.auth.api.dto.DynamicMenuDto;
|
||||
import io.dataease.auth.service.DynamicMenuService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
public class DynamicMenuServer implements DynamicMenuApi {
|
||||
@Autowired
|
||||
private DynamicMenuService dynamicMenuService;
|
||||
|
||||
@Override
|
||||
public List<DynamicMenuDto> menus() {
|
||||
//ServletUtils.getToken()
|
||||
return dynamicMenuService.load(null);
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package io.dataease.auth.service;
|
||||
|
||||
import io.dataease.auth.api.dto.DynamicMenuDto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DynamicMenuService {
|
||||
|
||||
List<DynamicMenuDto> load(String userId);
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package io.dataease.auth.service.impl;
|
||||
|
||||
import io.dataease.auth.api.dto.DynamicMenuDto;
|
||||
import io.dataease.auth.api.dto.MenuMeta;
|
||||
import io.dataease.auth.service.DynamicMenuService;
|
||||
import io.dataease.base.domain.SysMenu;
|
||||
import io.dataease.base.domain.SysMenuExample;
|
||||
import io.dataease.base.mapper.SysMenuMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class DynamicMenuServiceImpl implements DynamicMenuService {
|
||||
|
||||
@Autowired(required = false)
|
||||
private SysMenuMapper sysMenuMapper;
|
||||
|
||||
@Override
|
||||
public List<DynamicMenuDto> load(String userId) {
|
||||
SysMenuExample sysMenuExample = new SysMenuExample();
|
||||
sysMenuExample.setOrderByClause(" menu_sort ");
|
||||
List<SysMenu> sysMenus = sysMenuMapper.selectByExample(sysMenuExample);
|
||||
List<DynamicMenuDto> dynamicMenuDtos = sysMenus.stream().map(this::convert).collect(Collectors.toList());
|
||||
List<DynamicMenuDto> result = buildTree(dynamicMenuDtos);
|
||||
return result;
|
||||
}
|
||||
|
||||
private DynamicMenuDto convert(SysMenu sysMenu){
|
||||
DynamicMenuDto dynamicMenuDto = new DynamicMenuDto();
|
||||
dynamicMenuDto.setId(sysMenu.getMenuId());
|
||||
dynamicMenuDto.setPid(sysMenu.getPid());
|
||||
dynamicMenuDto.setName(sysMenu.getName());
|
||||
dynamicMenuDto.setPath(sysMenu.getPath());
|
||||
dynamicMenuDto.setRedirect(null);
|
||||
dynamicMenuDto.setComponent(sysMenu.getComponent());
|
||||
MenuMeta menuMeta = new MenuMeta();
|
||||
menuMeta.setTitle(sysMenu.getTitle());
|
||||
menuMeta.setIcon(sysMenu.getIcon());
|
||||
dynamicMenuDto.setMeta(menuMeta);
|
||||
return dynamicMenuDto;
|
||||
}
|
||||
|
||||
private List<DynamicMenuDto> buildTree(List<DynamicMenuDto> lists){
|
||||
List<DynamicMenuDto> rootNodes = new ArrayList<>();
|
||||
lists.forEach(node -> {
|
||||
if (isParent(node.getPid())) {
|
||||
rootNodes.add(node);
|
||||
}
|
||||
lists.forEach(tNode -> {
|
||||
if (tNode.getPid() == node.getId()) {
|
||||
if (node.getChildren() == null) {
|
||||
node.setChildren(new ArrayList<DynamicMenuDto>());
|
||||
node.setRedirect(node.getPath()+"/"+tNode.getPath());//第一个子节点的path
|
||||
}
|
||||
node.getChildren().add(tNode);
|
||||
}
|
||||
});
|
||||
});
|
||||
return rootNodes;
|
||||
|
||||
}
|
||||
|
||||
private Boolean isParent(Long pid){
|
||||
return null == pid || pid==0L;
|
||||
}
|
||||
}
|
@ -21,14 +21,17 @@ public class ShiroServiceImpl implements ShiroService {
|
||||
// 放行Swagger2页面,需要放行这些
|
||||
|
||||
filterChainDefinitionMap.put("/swagger-ui.html","anon");
|
||||
filterChainDefinitionMap.put("/swagger-ui/**","anon");
|
||||
|
||||
filterChainDefinitionMap.put("/swagger/**","anon");
|
||||
filterChainDefinitionMap.put("/webjars/**", "anon");
|
||||
filterChainDefinitionMap.put("/swagger-resources/**","anon");
|
||||
filterChainDefinitionMap.put("/v2/**","anon");
|
||||
filterChainDefinitionMap.put("/v3/**","anon");
|
||||
filterChainDefinitionMap.put("/static/**", "anon");
|
||||
|
||||
// 登陆
|
||||
filterChainDefinitionMap.put("/api/auth/**", "anon");
|
||||
filterChainDefinitionMap.put("/api/auth/login", "anon");
|
||||
// 退出
|
||||
//filterChainDefinitionMap.put("/logout", "anon");
|
||||
// 放行未授权接口,重定向使用
|
||||
|
@ -40,6 +40,7 @@ public class JWTUtils {
|
||||
DecodedJWT jwt = JWT.decode(token);
|
||||
return jwt.getClaim("username").asString();
|
||||
} catch (JWTDecodeException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -56,6 +57,7 @@ public class JWTUtils {
|
||||
DecodedJWT jwt = JWT.decode(token);
|
||||
return jwt.getClaim("exp").asDate();
|
||||
} catch (JWTDecodeException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user