diff --git a/src/main/java/io/qyi/e5/controller/admin/AdminController.java b/src/main/java/io/qyi/e5/controller/admin/AdminController.java index a1ce8ca..b3ae392 100644 --- a/src/main/java/io/qyi/e5/controller/admin/AdminController.java +++ b/src/main/java/io/qyi/e5/controller/admin/AdminController.java @@ -1,15 +1,25 @@ package io.qyi.e5.controller.admin; +import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken; import io.qyi.e5.outlook.service.IOutlookService; import io.qyi.e5.service.task.ITask; +import io.qyi.e5.util.EncryptUtil; +import io.qyi.e5.util.StringUtil; import io.qyi.e5.util.redis.RedisUtil; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.security.core.authority.AuthorityUtils; +import org.springframework.util.ResourceUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.*; + /** * @program: 此类里大多都是测试 * @description: @@ -34,6 +44,15 @@ public class AdminController { @Value("user.admin.githubId") String adminGithubId; + @Value("${user.admin.debug.passwd}") + String userAdminDebugPasswd; + + @Value("${redis.user.token}") + String token_; + + @Value("${user.token.expire}") + private int tokenExpire; + /** * 测试队列 * @Author: 落叶随风 @@ -73,4 +92,40 @@ public class AdminController { public String test() { return "ok"; } + + @RequestMapping("setAnnouncement") + public String setAnnouncement(String text) throws IOException { + File file = ResourceUtils.getFile("classpath:announcement.txt"); + FileWriter writer = new FileWriter(file); + writer.write(text); + writer.close(); + return "ok"; + } + + @RequestMapping("getDebugAdminToken") + public String getDebugAdminToken(String passwd) { + if (userAdminDebugPasswd.equals(passwd)) { + String token = EncryptUtil.getInstance().SHA1Hex(UUID.randomUUID().toString()); + /*配置角色,这里只是简单的配置,实际上需要从数据库中读取角色*/ + List list_Authority = new ArrayList<>(); + list_Authority.add("user"); + list_Authority.add("admin"); + String[] Authority = list_Authority.toArray(new String[list_Authority.size()]); + /*写token信息到redis*/ + Map userInfo_redis = new HashMap<>(); + userInfo_redis.put("github_name", "admin"); + userInfo_redis.put("github_id", 0000); + userInfo_redis.put("avatar_url", "https://www.baidu.com"); + userInfo_redis.put("authority", list_Authority); + redisUtil.hmset(token_ + token, userInfo_redis, tokenExpire); + + +// 创建一个已认证的token +// UsernamePasswordAuthenticationToken authenticationToken1 = new UsernamePasswordAuthenticationToken(userInfo_redis.get("github_name").toString(), +// userInfo_redis.get("github_name").toString(), (int)userInfo_redis.get("github_name"), token, "user", AuthorityUtils.createAuthorityList(Authority)); + return token; + } + return "la la la"; + } + } diff --git a/src/main/java/io/qyi/e5/controller/web/WebController.java b/src/main/java/io/qyi/e5/controller/web/WebController.java index 48390a1..04acdb7 100644 --- a/src/main/java/io/qyi/e5/controller/web/WebController.java +++ b/src/main/java/io/qyi/e5/controller/web/WebController.java @@ -6,13 +6,17 @@ import io.qyi.e5.github.service.IGithubService; import io.qyi.e5.outlook.service.IOutlookService; import io.qyi.e5.outlook_log.service.IOutlookLogService; import io.qyi.e5.util.ResultUtil; +import io.qyi.e5.util.StringUtil; import io.qyi.e5.util.redis.RedisUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.util.ResourceUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.io.FileNotFoundException; +import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -72,4 +76,10 @@ public class WebController { } + @RequestMapping("getAnnouncement") + public String getAnnouncement() throws IOException { + String s = StringUtil.readTxt(ResourceUtils.getFile("classpath:announcement.txt")); + return s; + } + } diff --git a/src/main/java/io/qyi/e5/util/StringUtil.java b/src/main/java/io/qyi/e5/util/StringUtil.java index 676657d..1196112 100644 --- a/src/main/java/io/qyi/e5/util/StringUtil.java +++ b/src/main/java/io/qyi/e5/util/StringUtil.java @@ -1,5 +1,6 @@ package io.qyi.e5.util; +import java.io.*; import java.util.HashMap; import java.util.Map; @@ -24,4 +25,15 @@ public class StringUtil { } return map; } + + public static String readTxt(File file) throws IOException { + String s = ""; + InputStreamReader in = new InputStreamReader(new FileInputStream(file),"UTF-8"); + BufferedReader br = new BufferedReader(in); + StringBuffer content = new StringBuffer(); + while ((s=br.readLine())!=null){ + content = content.append(s); + } + return content.toString(); + } } diff --git a/src/main/resources/announcement.txt b/src/main/resources/announcement.txt new file mode 100644 index 0000000..fe078f4 --- /dev/null +++ b/src/main/resources/announcement.txt @@ -0,0 +1 @@ +点击小猫咪头像进行登录。 \ No newline at end of file