Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
DolphinScheduler
提交
99c5d151
DolphinScheduler
项目概览
apache
/
DolphinScheduler
上一次同步 接近 2 年
通知
707
Star
9572
Fork
3514
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
DolphinScheduler
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
99c5d151
编写于
2月 02, 2021
作者:
S
Shiwen Cheng
提交者:
GitHub
2月 02, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[1.3.5-prepare][cherry-pick]#4490 improve cors (#4661)
上级
19f4fa33
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
135 addition
and
24 deletion
+135
-24
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/configuration/AppConfiguration.java
.../dolphinscheduler/api/configuration/AppConfiguration.java
+20
-24
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/interceptor/LocaleChangeInterceptor.java
...hinscheduler/api/interceptor/LocaleChangeInterceptor.java
+56
-0
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/interceptor/LocaleChangeInterceptorTest.java
...cheduler/api/interceptor/LocaleChangeInterceptorTest.java
+48
-0
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java
...in/java/org/apache/dolphinscheduler/common/Constants.java
+5
-0
dolphinscheduler-ui/package.json
dolphinscheduler-ui/package.json
+1
-0
dolphinscheduler-ui/src/js/module/io/index.js
dolphinscheduler-ui/src/js/module/io/index.js
+4
-0
pom.xml
pom.xml
+1
-0
未找到文件。
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/configuration/AppConfiguration.java
浏览文件 @
99c5d151
...
...
@@ -16,17 +16,20 @@
*/
package
org.apache.dolphinscheduler.api.configuration
;
import
org.apache.dolphinscheduler.api.interceptor.LocaleChangeInterceptor
;
import
org.apache.dolphinscheduler.api.interceptor.LoginHandlerInterceptor
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.cors.CorsConfiguration
;
import
org.springframework.web.cors.UrlBasedCorsConfigurationSource
;
import
org.springframework.web.filter.CorsFilter
;
import
org.springframework.web.servlet.LocaleResolver
;
import
org.springframework.web.servlet.config.annotation.*
;
import
org.springframework.web.servlet.i18n.CookieLocaleResolver
;
import
org.springframework.web.servlet.i18n.LocaleChangeInterceptor
;
import
java.util.Locale
;
/**
* application configuration
*/
...
...
@@ -37,15 +40,23 @@ public class AppConfiguration implements WebMvcConfigurer {
public
static
final
String
LOGIN_PATH_PATTERN
=
"/login"
;
public
static
final
String
PATH_PATTERN
=
"/**"
;
public
static
final
String
LOCALE_LANGUAGE_COOKIE
=
"language"
;
public
static
final
int
COOKIE_MAX_AGE
=
3600
;
@Bean
public
CorsFilter
corsFilter
()
{
CorsConfiguration
config
=
new
CorsConfiguration
();
config
.
addAllowedOrigin
(
"*"
);
config
.
addAllowedMethod
(
"*"
);
config
.
addAllowedHeader
(
"*"
);
UrlBasedCorsConfigurationSource
configSource
=
new
UrlBasedCorsConfigurationSource
();
configSource
.
registerCorsConfiguration
(
PATH_PATTERN
,
config
);
return
new
CorsFilter
(
configSource
);
}
@Bean
public
LoginHandlerInterceptor
loginInterceptor
()
{
return
new
LoginHandlerInterceptor
();
}
/**
* Cookie
* @return local resolver
...
...
@@ -56,30 +67,24 @@ public class AppConfiguration implements WebMvcConfigurer {
localeResolver
.
setCookieName
(
LOCALE_LANGUAGE_COOKIE
);
/** set default locale **/
localeResolver
.
setDefaultLocale
(
Locale
.
US
);
/** set
cookie max age
**/
localeResolver
.
set
CookieMaxAge
(
COOKIE_MAX_AGE
);
/** set
language tag compliant
**/
localeResolver
.
set
LanguageTagCompliant
(
false
);
return
localeResolver
;
}
@Bean
public
LocaleChangeInterceptor
localeChangeInterceptor
()
{
LocaleChangeInterceptor
lci
=
new
LocaleChangeInterceptor
();
/** **/
lci
.
setParamName
(
"language"
);
return
lci
;
return
new
LocaleChangeInterceptor
();
}
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
//i18n
//
i18n
registry
.
addInterceptor
(
localeChangeInterceptor
());
// login
registry
.
addInterceptor
(
loginInterceptor
()).
addPathPatterns
(
LOGIN_INTERCEPTOR_PATH_PATTERN
).
excludePathPatterns
(
LOGIN_PATH_PATTERN
,
"/swagger-resources/**"
,
"/webjars/**"
,
"/v2/**"
,
"/doc.html"
,
"*.html"
,
"/ui/**"
);
}
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
registry
.
addResourceHandler
(
"/static/**"
).
addResourceLocations
(
"classpath:/static/"
);
...
...
@@ -94,12 +99,6 @@ public class AppConfiguration implements WebMvcConfigurer {
registry
.
addViewController
(
"/"
).
setViewName
(
"forward:/ui/index.html"
);
}
@Override
public
void
addCorsMappings
(
CorsRegistry
registry
)
{
registry
.
addMapping
(
PATH_PATTERN
).
allowedOrigins
(
"*"
).
allowedMethods
(
"*"
);
}
/**
* Turn off suffix-based content negotiation
*
...
...
@@ -110,7 +109,4 @@ public class AppConfiguration implements WebMvcConfigurer {
configurer
.
favorPathExtension
(
false
);
}
}
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/interceptor/LocaleChangeInterceptor.java
0 → 100644
浏览文件 @
99c5d151
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.dolphinscheduler.api.interceptor
;
import
org.apache.dolphinscheduler.api.service.BaseService
;
import
org.apache.dolphinscheduler.common.Constants
;
import
java.util.Locale
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.lang.Nullable
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
public
class
LocaleChangeInterceptor
extends
HandlerInterceptorAdapter
{
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
{
Cookie
cookie
=
BaseService
.
getCookie
(
request
,
Constants
.
LOCALE_LANGUAGE
);
if
(
cookie
!=
null
)
{
// Proceed in cookie
return
true
;
}
// Proceed in header
String
newLocale
=
request
.
getHeader
(
Constants
.
LOCALE_LANGUAGE
);
if
(
newLocale
!=
null
)
{
LocaleContextHolder
.
setLocale
(
parseLocaleValue
(
newLocale
));
}
return
true
;
}
@Nullable
protected
Locale
parseLocaleValue
(
String
localeValue
)
{
return
StringUtils
.
parseLocale
(
localeValue
);
}
}
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/interceptor/LocaleChangeInterceptorTest.java
0 → 100644
浏览文件 @
99c5d151
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.dolphinscheduler.api.interceptor
;
import
org.apache.dolphinscheduler.api.ApiApplicationServer
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mockito
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
ApiApplicationServer
.
class
)
public
class
LocaleChangeInterceptorTest
{
@Autowired
LocaleChangeInterceptor
interceptor
;
@Test
public
void
testPreHandle
()
{
HttpServletRequest
request
=
Mockito
.
mock
(
HttpServletRequest
.
class
);
HttpServletResponse
response
=
Mockito
.
mock
(
HttpServletResponse
.
class
);
// test no language
Assert
.
assertTrue
(
interceptor
.
preHandle
(
request
,
response
,
null
));
}
}
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java
浏览文件 @
99c5d151
...
...
@@ -890,6 +890,11 @@ public final class Constants {
public
static
final
String
PASSWORD_DEFAULT
=
"******"
;
/**
* locale
*/
public
static
final
String
LOCALE_LANGUAGE
=
"language"
;
/**
* driver
*/
...
...
dolphinscheduler-ui/package.json
浏览文件 @
99c5d151
...
...
@@ -36,6 +36,7 @@
"vuex-router-sync"
:
"^5.0.0"
},
"devDependencies"
:
{
"acorn"
:
"^7.4.1"
,
"autoprefixer"
:
"^9.1.0"
,
"babel-core"
:
"^6.25.0"
,
"babel-helper-vue-jsx-merge-props"
:
"^2.0.2"
,
...
...
dolphinscheduler-ui/src/js/module/io/index.js
浏览文件 @
99c5d151
...
...
@@ -84,6 +84,10 @@ io.interceptors.request.use(
_t
:
Math
.
random
()
})
}
config
.
headers
=
config
.
headers
||
{}
const
language
=
cookies
.
get
(
'
language
'
)
if
(
language
)
config
.
headers
.
language
=
language
if
(
sIdCookie
)
config
.
headers
.
sessionId
=
sIdCookie
return
config
}
},
error
=>
{
...
...
pom.xml
浏览文件 @
99c5d151
...
...
@@ -704,6 +704,7 @@
<include>
**/api/enums/StatusTest.java
</include>
<include>
**/api/exceptions/ApiExceptionHandlerTest.java
</include>
<include>
**/api/exceptions/ServiceExceptionTest.java
</include>
<include>
**/api/interceptor/LocaleChangeInterceptorTest.java
</include>
<include>
**/api/interceptor/LoginHandlerInterceptorTest.java
</include>
<include>
**/api/security/PasswordAuthenticatorTest.java
</include>
<include>
**/api/security/SecurityConfigTest.java
</include>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录