diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..95713bb --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# Created by .ignore support plugin (hsz.mobi) +/.idea/ +/target/ diff --git a/src/main/java/io/qyi/e5/config/security/filter/LinkTokenAuthenticationFilter.java b/src/main/java/io/qyi/e5/config/security/filter/LinkTokenAuthenticationFilter.java index 2073427..d5ae9d8 100644 --- a/src/main/java/io/qyi/e5/config/security/filter/LinkTokenAuthenticationFilter.java +++ b/src/main/java/io/qyi/e5/config/security/filter/LinkTokenAuthenticationFilter.java @@ -1,17 +1,14 @@ package io.qyi.e5.config.security.filter; import com.google.gson.Gson; -import io.qyi.e5.bean.result.Result; -import io.qyi.e5.bean.result.ResultEnum; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken; -import io.qyi.e5.util.ResultUtil; import io.qyi.e5.util.SpringUtil; import io.qyi.e5.util.redis.RedisUtil; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Configurable; import org.springframework.security.core.authority.AuthorityUtils; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.stereotype.Component; import org.springframework.web.filter.OncePerRequestFilter; import javax.servlet.FilterChain; @@ -49,6 +46,13 @@ public class LinkTokenAuthenticationFilter extends OncePerRequestFilter { } } System.out.println("--------------Token鉴权---------------"); + /*设置跨域*/ + HttpServletResponse response = httpServletResponse; + response.setHeader("Access-Control-Allow-Origin","*"); + response.setHeader("Access-Control-Allow-Credentials", "true"); + response.setHeader("Access-Control-Allow-Methods", "POST, GET, PATCH, DELETE, PUT"); + response.setHeader("Access-Control-Max-Age", "3600"); + response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); filterChain.doFilter(httpServletRequest, httpServletResponse); } diff --git a/src/main/java/io/qyi/e5/config/security/filter/LoginAuthenticationFilter.java b/src/main/java/io/qyi/e5/config/security/filter/LoginAuthenticationFilter.java index 2fb64d3..7ea95d9 100644 --- a/src/main/java/io/qyi/e5/config/security/filter/LoginAuthenticationFilter.java +++ b/src/main/java/io/qyi/e5/config/security/filter/LoginAuthenticationFilter.java @@ -34,7 +34,6 @@ public class LoginAuthenticationFilter extends AbstractAuthenticationProcessingF public LoginAuthenticationFilter() { super(new AntPathRequestMatcher("/auth2/receive", "GET")); - } diff --git a/src/test/java/io/qyi/e5/string/dome01.java b/src/test/java/io/qyi/e5/string/dome01.java index 78f2443..b4d9f08 100644 --- a/src/test/java/io/qyi/e5/string/dome01.java +++ b/src/test/java/io/qyi/e5/string/dome01.java @@ -1,7 +1,13 @@ package io.qyi.e5.string; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import org.junit.jupiter.api.Test; +import java.util.Iterator; + /** * @program: e5 * @description: @@ -9,12 +15,26 @@ import org.junit.jupiter.api.Test; * @create: 2020-03-05 17:09 **/ public class dome01 { + @Test - public void test01(){ + public void test01() { String[] s = new String[]{"CompactToken validation", "Access token has expired.", "Access token validation failure"}; String msg = "Access token has expired."; System.out.println(s[1]); System.out.println(msg.indexOf(s[1])); } + + @Test + public void test() { + JsonObject jsonObject = new Gson().fromJson("", JsonObject.class); + JsonArray data = jsonObject.getAsJsonArray("data"); + for (JsonElement j : data) { + int pid = j.getAsJsonObject().get("pid").getAsInt(); + } + for (int i = 0; i < data.size(); i++) { + JsonObject JsonObject = data.get(i).getAsJsonObject(); + JsonObject.get("pid").getAsInt(); + } + } }