开始整新权限管理系统
This commit is contained in:
parent
d6734600fe
commit
590b26dac0
@ -16,12 +16,11 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("bili/live")
|
||||
public class Live {
|
||||
@Resource
|
||||
BilibiliLiveDao bilibiliLiveDao;
|
||||
|
||||
@RequestMapping(value = "add/url.do")
|
||||
@RequestMapping(value = "/bili/live/add/url.do")
|
||||
@ResponseBody
|
||||
public String addLiveUrl(String url){
|
||||
String cid;
|
||||
@ -49,7 +48,7 @@ public class Live {
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("get/url.do")
|
||||
@RequestMapping("/bili/live/get/url.do")
|
||||
public String getLiveUrl(){
|
||||
List<BilibiliLive> list=bilibiliLiveDao.selectByExample(new BilibiliLiveExample());
|
||||
JSONObject json=new JSONObject();
|
||||
@ -59,7 +58,7 @@ public class Live {
|
||||
return json.toJSONString();
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("set/update.do")
|
||||
@RequestMapping("/bili/live/set/update.do")
|
||||
public String configDown(String id,String url,String cid,String status){
|
||||
JSONObject json=new JSONObject();
|
||||
BilibiliLive live=bilibiliLiveDao.selectByPrimaryKey(Integer.parseInt(id));
|
||||
@ -86,7 +85,7 @@ public class Live {
|
||||
return json.toJSONString();
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("set/delete.do")
|
||||
@RequestMapping("/bili/live/set/delete.do")
|
||||
public String delUrl(String id){
|
||||
JSONObject json=new JSONObject();
|
||||
try{
|
||||
|
154
src/main/java/com/yutou/tools/Tools/AuthManagerController.java
Normal file
154
src/main/java/com/yutou/tools/Tools/AuthManagerController.java
Normal file
@ -0,0 +1,154 @@
|
||||
package com.yutou.tools.Tools;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.tools.mybatis.dao.PermissionDao;
|
||||
import com.yutou.tools.mybatis.dao.UKeyDao;
|
||||
import com.yutou.tools.mybatis.model.Permission;
|
||||
import com.yutou.tools.mybatis.model.PermissionExample;
|
||||
import com.yutou.tools.mybatis.model.UKey;
|
||||
import com.yutou.tools.mybatis.model.UKeyExample;
|
||||
import com.yutou.tools.utils.Tools;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
public class AuthManagerController {
|
||||
@Resource
|
||||
UKeyDao keyDao;
|
||||
@Resource
|
||||
PermissionDao permissionDao;
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/tools/auth/all.do")
|
||||
public JSONObject getUserList() {
|
||||
JSONObject json = new JSONObject();
|
||||
JSONArray array = new JSONArray();
|
||||
List<UKey> list = keyDao.selectByExample(new UKeyExample());
|
||||
for (UKey uKey : list) {
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("id", uKey.getId());
|
||||
item.put("key", uKey.getKey());
|
||||
item.put("authSize", JSONArray.parseArray(uKey.getPower()).size());
|
||||
array.add(item);
|
||||
}
|
||||
json.put("code", 0);
|
||||
json.put("msg", "ok");
|
||||
json.put("data", array);
|
||||
json.put("count", array.size());
|
||||
return json;
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/tools/auth/user.do")
|
||||
public JSONObject getUserAuth(String uid) {
|
||||
JSONObject json = new JSONObject();
|
||||
if (ObjectUtils.isEmpty(uid)) {
|
||||
json.put("code", -1);
|
||||
json.put("msg", "uid为空");
|
||||
return json;
|
||||
}
|
||||
JSONArray allPermission = new JSONArray();
|
||||
JSONArray userPermission = new JSONArray();
|
||||
UKey key = keyDao.selectByPrimaryKey(Integer.parseInt(uid));
|
||||
List<String> permission = Tools.getUrls("com.yutou.tools", null);
|
||||
JSONArray powers = JSONArray.parseArray(key.getPower());
|
||||
System.out.println("总权限:" + permission.size());
|
||||
JSONObject admin = new JSONObject();
|
||||
admin.put("value", "-1");
|
||||
admin.put("title", "管理员");
|
||||
admin.put("disabled", "");
|
||||
admin.put("checked", "");
|
||||
allPermission.add(admin);
|
||||
List<String> list = powers.toJavaList(String.class);
|
||||
if (list.contains("-1")) {
|
||||
userPermission.add("-1");
|
||||
}
|
||||
|
||||
int index = 1;
|
||||
for (String per : permission) {
|
||||
index++;
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("value", index + "");
|
||||
item.put("title", per);
|
||||
item.put("disabled", "");
|
||||
item.put("checked", "");
|
||||
PermissionExample example = new PermissionExample();
|
||||
example.createCriteria().andUrlEqualTo(per);
|
||||
List<Permission> permissions = permissionDao.selectByExample(example);
|
||||
allPermission.add(item);
|
||||
if (permissions.size() == 0) {
|
||||
Permission p = new Permission();
|
||||
p.setTitle(per);
|
||||
p.setUrl(per);
|
||||
permissionDao.insert(p);
|
||||
} else {
|
||||
permissions.get(0).getId();
|
||||
if (list.contains(permissions.get(0).getId() + "")) {
|
||||
userPermission.add(index + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("all", allPermission);
|
||||
data.put("user", userPermission);
|
||||
json.put("data", data);
|
||||
json.put("msg", "ok");
|
||||
json.put("code", 0);
|
||||
return json;
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("/a/t.do")
|
||||
public JSONObject test(){
|
||||
return new JSONObject();
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("/tools/auth/set.do")
|
||||
public JSONObject updateAuth(String uid, String auth, String type) {
|
||||
JSONObject json = new JSONObject();
|
||||
System.out.println("uid = " + uid + ", auth = " + auth + ", type = " + type);
|
||||
JSONArray array = JSONArray.parseArray(auth);
|
||||
UKey key = keyDao.selectByPrimaryKey(Integer.parseInt(uid));
|
||||
JSONArray powers = JSONArray.parseArray(key.getPower());
|
||||
if ("add".equals(type) && auth.contains("管理员")) {
|
||||
powers.clear();
|
||||
powers.add("-1");
|
||||
} else {
|
||||
for (Object o : array) {
|
||||
JSONObject item = (JSONObject) o;
|
||||
PermissionExample example = new PermissionExample();
|
||||
example.createCriteria().andUrlEqualTo(item.getString("auth"));
|
||||
List<Permission> list = permissionDao.selectByExample(example);
|
||||
Permission permission = null;
|
||||
if (list.size() > 0) {
|
||||
permission = list.get(0);
|
||||
}
|
||||
if ("add".equals(type)) {
|
||||
if (permission != null) {
|
||||
powers.remove("-1");
|
||||
powers.add(permission.getId() + "");
|
||||
}
|
||||
} else if ("remove".equals(type)) {
|
||||
if (permission == null) {
|
||||
powers.remove("-1");
|
||||
} else {
|
||||
System.out.println("移除:" + permission.getId());
|
||||
powers.remove(permission.getId() + "");
|
||||
}
|
||||
}
|
||||
System.out.println("设置权限:" + powers.toJSONString());
|
||||
}
|
||||
}
|
||||
key.setPower(powers.toJSONString());
|
||||
keyDao.updateByPrimaryKey(key);
|
||||
json.put("code", 0);
|
||||
json.put("msg", "操作成功");
|
||||
return json;
|
||||
}
|
||||
}
|
@ -21,7 +21,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/tools/password/")
|
||||
public class PasswordManager {
|
||||
|
||||
@Resource
|
||||
@ -32,7 +31,7 @@ public class PasswordManager {
|
||||
tools tls;
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "get/list.do",method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/tools/password/get/list.do",method = RequestMethod.GET)
|
||||
public String getPasswordList(HttpServletRequest request,String type){
|
||||
JSONObject json=new JSONObject();
|
||||
int id=tls.getUid(request);
|
||||
@ -48,7 +47,7 @@ public class PasswordManager {
|
||||
return json.toJSONString();
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "get/password.do",method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/tools/password/get/password.do",method = RequestMethod.GET)
|
||||
public String getPassword(HttpServletRequest request,String id){
|
||||
JSONObject json=new JSONObject();
|
||||
int uid=tls.getUid(request);
|
||||
@ -60,7 +59,7 @@ public class PasswordManager {
|
||||
return json.toJSONString();
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "get/all.do",method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/tools/password/get/all.do",method = RequestMethod.GET)
|
||||
public String getAllPassword(HttpServletRequest request){
|
||||
JSONObject json=new JSONObject();
|
||||
JSONArray array=new JSONArray();
|
||||
@ -84,7 +83,7 @@ public class PasswordManager {
|
||||
return json.toJSONString();
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "type/get/list.do",method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/tools/password/type/get/list.do",method = RequestMethod.GET)
|
||||
public String getPasswordType(HttpServletRequest request){
|
||||
JSONObject json=new JSONObject();
|
||||
int uid=tls.getUid(request);
|
||||
@ -97,7 +96,7 @@ public class PasswordManager {
|
||||
return json.toJSONString();
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "type/set/add.do",method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/tools/password/type/set/add.do",method = RequestMethod.POST)
|
||||
public String addPasswordType(HttpServletRequest request,String type){
|
||||
JSONObject json=new JSONObject();
|
||||
try{
|
||||
@ -116,7 +115,7 @@ public class PasswordManager {
|
||||
return json.toJSONString();
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "set/add.do",method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/tools/password/set/add.do",method = RequestMethod.POST)
|
||||
public String addPassword(HttpServletRequest request,String title,String username,String password,String url,String info,String type){
|
||||
JSONObject json=new JSONObject();
|
||||
try{
|
||||
@ -172,7 +171,7 @@ public class PasswordManager {
|
||||
return json.toJSONString();
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "set/update.do",method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/tools/password/set/update.do",method = RequestMethod.POST)
|
||||
public String updatePassword(HttpServletRequest request,String title,String username,String password,String url,String info,String id){
|
||||
JSONObject json=new JSONObject();
|
||||
try{
|
||||
@ -207,7 +206,7 @@ public class PasswordManager {
|
||||
return json.toJSONString();
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "type/set/update.do",method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/tools/password/type/set/update.do",method = RequestMethod.POST)
|
||||
public String updatePasswordType(HttpServletRequest request,String type,String id){
|
||||
JSONObject json=new JSONObject();
|
||||
try {
|
||||
@ -229,7 +228,7 @@ public class PasswordManager {
|
||||
return json.toJSONString();
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "set/remove.do",method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/tools/password/set/remove.do",method = RequestMethod.POST)
|
||||
public String removePassword(HttpServletRequest request,String id){
|
||||
JSONObject json=new JSONObject();
|
||||
try {
|
||||
@ -247,7 +246,7 @@ public class PasswordManager {
|
||||
return json.toJSONString();
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "type/set/remove.do",method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/tools/password/type/set/remove.do",method = RequestMethod.POST)
|
||||
public String removePasswordType(HttpServletRequest request,String id){
|
||||
JSONObject json=new JSONObject();
|
||||
try {
|
||||
|
@ -18,7 +18,6 @@ import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("anim/")
|
||||
public class AnimationController {
|
||||
@Resource
|
||||
BangumiListDao listDao;
|
||||
@ -26,7 +25,7 @@ public class AnimationController {
|
||||
BangumiItemDao itemDao;
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "rss/data.do", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/anim/rss/data.do", method = RequestMethod.GET)
|
||||
public String getAnimList(String key,String type,String team, int page) {
|
||||
boolean isNull = key.length() == 0;
|
||||
if(!StringUtils.isEmpty(type)&&type.length()>2) {
|
||||
@ -53,7 +52,7 @@ public class AnimationController {
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "type/add.do", method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/anim/type/add.do", method = RequestMethod.POST)
|
||||
public String addRssType(String title) {
|
||||
BangumiList bangumiList = new BangumiList();
|
||||
bangumiList.setTitle(title);
|
||||
@ -66,7 +65,7 @@ public class AnimationController {
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "type/list.do", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/anim/type/list.do", method = RequestMethod.GET)
|
||||
public String getRssTypeList() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", 0);
|
||||
@ -75,7 +74,7 @@ public class AnimationController {
|
||||
return json.toJSONString();
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "type/del.do", method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/anim/type/del.do", method = RequestMethod.POST)
|
||||
public String delType(int id){
|
||||
BangumiItemExample example=new BangumiItemExample();
|
||||
example.createCriteria().andBidEqualTo(id+"");
|
||||
@ -88,7 +87,7 @@ public class AnimationController {
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "rss/add.do", method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/anim/rss/add.do", method = RequestMethod.POST)
|
||||
public String addAnimationRss(String title, String author, String categories, String titleKey, String bid) {
|
||||
BangumiItem item = new BangumiItem();
|
||||
item.setTitle(title);
|
||||
@ -105,7 +104,7 @@ public class AnimationController {
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "rss/list.do", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/anim/rss/list.do", method = RequestMethod.GET)
|
||||
public String getAnimationRssList(String type) {
|
||||
JSONObject json = new JSONObject();
|
||||
BangumiItemExample example=new BangumiItemExample();
|
||||
@ -116,7 +115,7 @@ public class AnimationController {
|
||||
return json.toJSONString();
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "rss/del.do", method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/anim/rss/del.do", method = RequestMethod.POST)
|
||||
public String delAnimation(int id){
|
||||
int i=itemDao.deleteByPrimaryKey(id);
|
||||
JSONObject json=new JSONObject();
|
||||
@ -125,7 +124,7 @@ public class AnimationController {
|
||||
return json.toJSONString();
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "rss/edit.do",method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/anim/rss/edit.do",method = RequestMethod.POST)
|
||||
public JSONObject editAnimation(int id,String title, String author, String categories, String titleKey,String enable){
|
||||
JSONObject json=new JSONObject();
|
||||
BangumiItem item =itemDao.selectByPrimaryKey(id);
|
||||
@ -154,7 +153,7 @@ public class AnimationController {
|
||||
return json;
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "client/get.do", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/anim/client/get.do", method = RequestMethod.GET)
|
||||
public String clientApi(){
|
||||
AnimationData animationData=new AnimationData();
|
||||
List<BangumiItem> list=itemDao.selectByExample(new BangumiItemExample());
|
||||
|
@ -27,7 +27,7 @@ public class tools {
|
||||
UKeyDao keyDao;
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "tools/get.do")
|
||||
@RequestMapping(value = "/tools/get.do")
|
||||
public String getJs(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
Enumeration<String> name = request.getHeaderNames();
|
||||
while (name.hasMoreElements()) {
|
||||
|
@ -69,7 +69,7 @@ public class APIFilter implements Filter {
|
||||
pExample.createCriteria().andUrlEqualTo(url);
|
||||
List<Permission> permissions = permissionDao.selectByExample(pExample);
|
||||
if (permissions != null && permissions.size() > 0) {
|
||||
if (powers.toJavaList(Integer.class).contains(permissions.get(0).getId())) {
|
||||
if (powers.toJavaList(String.class).contains(permissions.get(0).getId()+"")) {
|
||||
isToken = true;
|
||||
}
|
||||
}
|
||||
|
@ -8,12 +8,11 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/nas/depot/")
|
||||
public class NasDepotManager {
|
||||
private static final String DEPOT_NAME = "nas_depot";
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/add.do")
|
||||
@RequestMapping("/nas/depot/add.do")
|
||||
public JSONObject addNasPath(String path,String type) {
|
||||
JSONObject json=new JSONObject();
|
||||
JSONObject item=new JSONObject();
|
||||
@ -32,7 +31,7 @@ public class NasDepotManager {
|
||||
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("/list.do")
|
||||
@RequestMapping("/nas/depot/list.do")
|
||||
public JSONObject getNasList() {
|
||||
JSONObject json=new JSONObject();
|
||||
json.put("code",1);
|
||||
@ -41,7 +40,7 @@ public class NasDepotManager {
|
||||
return json;
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("/remove.do")
|
||||
@RequestMapping("/nas/depot/remove.do")
|
||||
public JSONObject removeNas(String path) {
|
||||
JSONObject json=new JSONObject();
|
||||
json.put("code",1);
|
||||
|
@ -3,11 +3,18 @@ package com.yutou.tools.utils;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.yutou.tools.interfaces.DownloadInterface;
|
||||
import com.yutou.tools.nas.UpdateIp;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.type.filter.TypeFilter;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@ -15,6 +22,8 @@ import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
@ -22,9 +31,7 @@ import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
public class Tools {
|
||||
/**
|
||||
@ -351,4 +358,66 @@ public class Tools {
|
||||
public static String getToDayTime() {
|
||||
return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫描使用注解的类
|
||||
* @param packageName 扫描包名
|
||||
* @param annotation 注解类
|
||||
* @return 扫描到的集合
|
||||
*/
|
||||
public static List<Class> scanClass(String packageName, Class<? extends Annotation> annotation) {
|
||||
List<Class> classList = new ArrayList<>();
|
||||
if (ObjectUtils.isEmpty(packageName)) {
|
||||
return classList;
|
||||
}
|
||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||
TypeFilter includeFilter = (metadataReader, metadataReaderFactory) -> true;
|
||||
provider.addIncludeFilter(includeFilter);
|
||||
Set<BeanDefinition> beanDefinitionSet = new HashSet<>();
|
||||
// 指定扫描的包名
|
||||
Set<BeanDefinition> candidateComponents = provider.findCandidateComponents(packageName);
|
||||
beanDefinitionSet.addAll(candidateComponents);
|
||||
|
||||
beanDefinitionSet.forEach(beanDefinition -> {
|
||||
try {
|
||||
Class clazz = Class.forName(beanDefinition.getBeanClassName());
|
||||
|
||||
if (!ObjectUtils.isEmpty(annotation)) {
|
||||
if (!ObjectUtils.isEmpty(AnnotationUtils.getAnnotation(clazz, annotation))) {
|
||||
classList.add(clazz);
|
||||
}
|
||||
} else {
|
||||
classList.add(clazz);
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// System.out.println(definition.getBeanClassName());
|
||||
});
|
||||
return classList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Url
|
||||
* @param packageName 扫描包名
|
||||
* @param className 指定类,如无指定类,为null即可
|
||||
* @return url集合
|
||||
*/
|
||||
public static List<String> getUrls(String packageName,String className){
|
||||
List<Class> list= scanClass(packageName, Controller.class);
|
||||
List<String> urls=new ArrayList<>();
|
||||
for (Class aClass : list) {
|
||||
if(className!=null&&!aClass.getSimpleName().equals(className)){
|
||||
continue;
|
||||
}
|
||||
Method[] methods= aClass.getDeclaredMethods();
|
||||
for (Method method : methods) {
|
||||
RequestMapping ls=method.getAnnotation(RequestMapping.class);
|
||||
if(ls!=null) {
|
||||
urls.add(ls.value()[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return urls;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,14 @@
|
||||
package com.yutou.tools;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.tools.Tools.AuthManagerController;
|
||||
import com.yutou.tools.utils.Tools;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
class ToolsApplicationTests {
|
||||
@ -10,4 +17,16 @@ class ToolsApplicationTests {
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void main(){
|
||||
List<String> list=Tools.getUrls("com.yutou.tools",null);
|
||||
for (String aClass : list) {
|
||||
System.out.println(aClass);
|
||||
}
|
||||
}
|
||||
@Test
|
||||
void ptest(){
|
||||
JSONObject json=new AuthManagerController().getUserAuth("3");
|
||||
System.out.println(json.toJSONString());
|
||||
}
|
||||
}
|
||||
|
121
web/html/body/tools/auth.html
Normal file
121
web/html/body/tools/auth.html
Normal file
@ -0,0 +1,121 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<title>权限管理</title>
|
||||
<link rel="stylesheet" href="/layui/css/layui.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="layui-layout layui-layout-admin">
|
||||
<div id="header"></div>
|
||||
<div class="layui-body" style="left: 200px;">
|
||||
<div id="side"></div>
|
||||
<blockquote class="layui-elem-quote"><span id="ip">用户权限管理</span></blockquote>
|
||||
<table id="list" lay-filter="userList"></table>
|
||||
<div id="footer"></div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/layui/layui.js"></script>
|
||||
<script src="/js/jquery-3.2.1.js"></script>
|
||||
<script type="text/html" id="listTools">
|
||||
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
|
||||
</script>
|
||||
<script>
|
||||
$.get("/login/check.do", function (data) {
|
||||
let json = JSON.parse(data);
|
||||
if (json.code !== 0) {
|
||||
window.location.href = "/"
|
||||
}
|
||||
})
|
||||
layui.use(['layer', 'form', 'element'], function () {
|
||||
let layer = layui.layer
|
||||
, form = layui.form;
|
||||
let transfer = layui.transfer;
|
||||
let table = layui.table;
|
||||
|
||||
table.render({
|
||||
elem: "#list"
|
||||
, url: '/tools/auth/all.do'
|
||||
, page: false
|
||||
, cols: [[
|
||||
{field: "id", title: "id", width: 80, sort: true, fixed: 'left'}
|
||||
, {field: 'key', title: '授权码', width: 250}
|
||||
, {field: 'authSize', title: '授权数量', width: 150}
|
||||
, {field: "right", width: 80, toolbar: '#listTools'}
|
||||
]]
|
||||
, done: function (res, curr, count) {
|
||||
table.on('tool(userList)', function (obj) {
|
||||
console.log(obj.data)
|
||||
if (obj.event === 'edit') {
|
||||
let type;
|
||||
let values=[]
|
||||
layer.open({
|
||||
title: '设置权限'
|
||||
, content: '<div id="auth"></div>'
|
||||
, success: function (layero, index) {
|
||||
|
||||
$.post('/tools/auth/user.do', {'uid': obj.data.id}, function (json) {
|
||||
if (json.code === 0) {
|
||||
console.log(json.data.user)
|
||||
transfer.render({
|
||||
elem: '#auth', //绑定元素
|
||||
showSearch: true,
|
||||
title: ['未授权', '已授权'],
|
||||
data: json.data.all,
|
||||
value: json.data.user,
|
||||
onchange: function (data, index) {
|
||||
if(index===0){
|
||||
type='add';
|
||||
}else{
|
||||
type='remove';
|
||||
}
|
||||
for(let i in data){
|
||||
values[i]={
|
||||
"auth":data[i].title
|
||||
}
|
||||
}
|
||||
console.log(values)
|
||||
},
|
||||
id: 'auth' //定义索引
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
, yes: function (index, layero) {
|
||||
//do something
|
||||
$.post("/tools/auth/set.do",{"uid":obj.data.id,"type":type,"auth":JSON.stringify(values)},function (json) {
|
||||
|
||||
})
|
||||
layer.close(index); //如果设定了yes回调,需进行手工关闭
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
form.render();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
$.ajax({cache: false})
|
||||
$('#header').load("/html/header.html");
|
||||
$('#footer').load("/html/footer.html");
|
||||
$('#side').load("/html/body/nas/side.html");
|
||||
|
||||
</script>
|
||||
<style>
|
||||
#icon {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.body {
|
||||
bottom: 0;
|
||||
}
|
||||
</style>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -47,7 +47,7 @@
|
||||
|
||||
let tabid = -1;
|
||||
layui.use(['layer', 'form', 'element', 'table'], function () {
|
||||
var layer = layui.layer
|
||||
let layer = layui.layer
|
||||
, form = layui.form
|
||||
, table = layui.table
|
||||
, element = layui.element;
|
||||
@ -66,7 +66,6 @@
|
||||
}
|
||||
});
|
||||
form.render()
|
||||
console.log(1)
|
||||
element.on('tab(type)', function (data) {
|
||||
|
||||
tabid = $(this).attr('lay-id')
|
||||
@ -84,6 +83,9 @@
|
||||
, { field: 'info', title: '备注', width: 200 }
|
||||
, { field: "right", width: 200, toolbar: '#listTools' }
|
||||
]]
|
||||
,done:function (res,curr,count) {
|
||||
form.render();
|
||||
}
|
||||
});
|
||||
})
|
||||
element.on('tabDelete(type)', function (data) {
|
||||
@ -114,7 +116,6 @@
|
||||
})
|
||||
})
|
||||
table.on('tool(listTools)', function (obj) {
|
||||
|
||||
if (obj.event === 'edit') {
|
||||
$.get('/tools/password/get/password.do?id=' + obj.data.id, function (udata) {
|
||||
let json = JSON.parse(udata);
|
||||
|
Loading…
Reference in New Issue
Block a user