增加允许跨域

This commit is contained in:
LuoYe_MyWork 2020-04-13 17:12:56 +08:00
parent fad520cb97
commit de9c974bbf
4 changed files with 34 additions and 8 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Created by .ignore support plugin (hsz.mobi)
/.idea/
/target/

View File

@ -1,17 +1,14 @@
package io.qyi.e5.config.security.filter; package io.qyi.e5.config.security.filter;
import com.google.gson.Gson; import com.google.gson.Gson;
import io.qyi.e5.bean.result.Result; import com.google.gson.JsonElement;
import io.qyi.e5.bean.result.ResultEnum; import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken; import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken;
import io.qyi.e5.util.ResultUtil;
import io.qyi.e5.util.SpringUtil; import io.qyi.e5.util.SpringUtil;
import io.qyi.e5.util.redis.RedisUtil; 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.authority.AuthorityUtils;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter; import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
@ -49,6 +46,13 @@ public class LinkTokenAuthenticationFilter extends OncePerRequestFilter {
} }
} }
System.out.println("--------------Token鉴权---------------"); 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); filterChain.doFilter(httpServletRequest, httpServletResponse);
} }

View File

@ -34,7 +34,6 @@ public class LoginAuthenticationFilter extends AbstractAuthenticationProcessingF
public LoginAuthenticationFilter() { public LoginAuthenticationFilter() {
super(new AntPathRequestMatcher("/auth2/receive", "GET")); super(new AntPathRequestMatcher("/auth2/receive", "GET"));
} }

View File

@ -1,7 +1,13 @@
package io.qyi.e5.string; 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 org.junit.jupiter.api.Test;
import java.util.Iterator;
/** /**
* @program: e5 * @program: e5
* @description: * @description:
@ -9,6 +15,7 @@ import org.junit.jupiter.api.Test;
* @create: 2020-03-05 17:09 * @create: 2020-03-05 17:09
**/ **/
public class dome01 { public class dome01 {
@Test @Test
public void test01() { public void test01() {
String[] s = new String[]{"CompactToken validation", "Access token has expired.", "Access token validation failure"}; String[] s = new String[]{"CompactToken validation", "Access token has expired.", "Access token validation failure"};
@ -17,4 +24,17 @@ public class dome01 {
System.out.println(s[1]); System.out.println(s[1]);
System.out.println(msg.indexOf(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();
}
}
} }