Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
8
8timerapiv200
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
8timerv2
8timerapiv200
Commits
492cc399
Commit
492cc399
authored
Mar 25, 2020
by
Administrator
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'zyq' into 'develop'
Zyq See merge request 8timerv2/8timerapiv200!1
parents
db73852e
8f375736
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
0 deletions
+52
-0
src/main/java/cn/timer/api/Application.java
+19
-0
src/main/java/cn/timer/api/config/interceptor/RedisSessionInterceptor.java
+18
-0
src/main/java/cn/timer/api/config/interceptor/WebSecurityConfig.java
+15
-0
No files found.
src/main/java/cn/timer/api/Application.java
View file @
492cc399
...
...
@@ -11,6 +11,9 @@ import org.springframework.http.converter.HttpMessageConverter;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.cors.CorsConfiguration
;
import
org.springframework.web.cors.UrlBasedCorsConfigurationSource
;
import
org.springframework.web.filter.CorsFilter
;
import
com.alibaba.fastjson.serializer.SerializerFeature
;
import
com.alibaba.fastjson.support.config.FastJsonConfig
;
...
...
@@ -55,6 +58,22 @@ public class Application{
public
RestTemplate
getRestTemplate
()
{
return
restTemplateBuilder
.
build
();
}
private
CorsConfiguration
buildConfig
()
{
CorsConfiguration
corsConfiguration
=
new
CorsConfiguration
();
corsConfiguration
.
addAllowedOrigin
(
"*"
);
// 1允许任何域名使用
corsConfiguration
.
addAllowedHeader
(
"*"
);
// 2允许任何头
corsConfiguration
.
addAllowedMethod
(
"*"
);
// 3允许任何方法(post、get等)
corsConfiguration
.
setAllowCredentials
(
true
);
return
corsConfiguration
;
}
@Bean
public
CorsFilter
corsFilter
()
{
UrlBasedCorsConfigurationSource
source
=
new
UrlBasedCorsConfigurationSource
();
source
.
registerCorsConfiguration
(
"/**"
,
buildConfig
());
// 4
return
new
CorsFilter
(
source
);
}
// @Override
// protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
...
...
src/main/java/cn/timer/api/config/interceptor/RedisSessionInterceptor.java
View file @
492cc399
...
...
@@ -5,6 +5,8 @@ import java.io.IOException;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
org.springframework.web.servlet.ModelAndView
;
...
...
@@ -12,12 +14,28 @@ import cn.hutool.json.JSONObject;
import
cn.timer.api.utils.ResponseResult
;
//拦截登录失效的请求
@Component
public
class
RedisSessionInterceptor
implements
HandlerInterceptor
{
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
Exception
{
// response.setHeader("Access-Control-Allow-Origin","http://120.24.24.239:8088");
//// response.setHeader("Access-Control-Allow-Origin",request.getHeader("Origin"));
// response.setHeader("Access-Control-Allow-Methods", "*");
// response.setHeader("Access-Control-Allow-Credentials", "true");
// response.setHeader("Access-Control-Allow-Headers", "*");
//
// System.out.print("request.Origin>"+request.getHeader("Origin"));
// //option预检查,直接通过请求
// if ("OPTIONS".equals(request.getMethod())){
// return true;
// }
/*
* Enumeration<String> names = request.getHeaderNames();
* while(names.hasMoreElements()) { String name = (String)names.nextElement();
...
...
src/main/java/cn/timer/api/config/interceptor/WebSecurityConfig.java
View file @
492cc399
...
...
@@ -10,6 +10,7 @@ import org.springframework.context.annotation.Configuration;
import
org.springframework.http.MediaType
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolver
;
import
org.springframework.web.servlet.config.annotation.CorsRegistry
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
...
...
@@ -79,4 +80,18 @@ public class WebSecurityConfig implements WebMvcConfigurer {
argumentResolvers
.
add
(
userMethodArgumentResolver
);
}
// @Override
// public void addCorsMappings(CorsRegistry registry) {
//// System.out.println("我是MyWebConfig跨域");
// //设置允许跨域的路径
// registry.addMapping("/**")
// //设置允许跨域请求的域名
// .allowedOrigins("*")
// //是否允许证书 不再默认开启
// .allowCredentials(true)
// //设置允许的方法
// .allowedMethods("*")
// //跨域允许时间
// .maxAge(3600);
// }
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment