Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ghsby
o2oa
提交
a084d063
o2oa
项目概览
ghsby
/
o2oa
落后 Fork 源项目 2880 个版本
Fork自
浙江兰德纵横网络技术股份有限公司 / o2oa
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
o2oa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a084d063
编写于
10月 14, 2020
作者:
Z
zhourui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加httpOnly配置
上级
8f47d123
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
22 addition
and
6 deletion
+22
-6
o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/Person.java
.../src/main/java/com/x/base/core/project/config/Person.java
+9
-0
o2server/x_base_core_project/src/main/java/com/x/base/core/project/http/HttpToken.java
...src/main/java/com/x/base/core/project/http/HttpToken.java
+13
-6
未找到文件。
o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/Person.java
浏览文件 @
a084d063
...
...
@@ -41,6 +41,7 @@ public class Person extends ConfigObject {
public
static
final
Integer
DEFAULT_FAILUREINTERVAL
=
10
;
public
static
final
Integer
DEFAULT_FAILURECOUNT
=
5
;
public
static
final
Integer
DEFAULT_TOKENEXPIREDMINUTES
=
60
*
24
*
15
;
public
static
final
Boolean
DEFAULT_TOKENCOOKIEHTTPONLY
=
false
;
public
static
final
String
DEFAULT_PASSWORDREGEX
=
"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,}$"
;
public
static
final
String
DEFAULT_PASSWORDREGEXHINT
=
"6位以上,包含数字和字母."
;
...
...
@@ -57,6 +58,7 @@ public class Person extends ConfigObject {
this
.
passwordRegex
=
DEFAULT_PASSWORDREGEX
;
this
.
passwordRegexHint
=
DEFAULT_PASSWORDREGEXHINT
;
this
.
personUnitOrderByAsc
=
DEFAULT_PERSONUNITORDERBYASC
;
this
.
tokenCookieHttpOnly
=
DEFAULT_TOKENCOOKIEHTTPONLY
;
}
public
static
Person
defaultInstance
()
{
...
...
@@ -110,9 +112,16 @@ public class Person extends ConfigObject {
@FieldDescribe
(
"token时长,分钟"
)
private
Integer
tokenExpiredMinutes
;
@FieldDescribe
(
"保存token的cookie是否启用httpOnly"
)
private
Boolean
tokenCookieHttpOnly
;
@FieldDescribe
(
"人员组织排序是否为升序,true为升序(默认),false为降序"
)
private
Boolean
personUnitOrderByAsc
;
public
Boolean
getTokenCookieHttpOnly
()
{
return
BooleanUtils
.
isTrue
(
this
.
tokenCookieHttpOnly
);
}
public
Integer
getTokenExpiredMinutes
()
{
return
(
this
.
tokenExpiredMinutes
==
null
||
this
.
tokenExpiredMinutes
<
0
)
?
DEFAULT_TOKENEXPIREDMINUTES
:
this
.
tokenExpiredMinutes
;
...
...
o2server/x_base_core_project/src/main/java/com/x/base/core/project/http/HttpToken.java
浏览文件 @
a084d063
...
...
@@ -33,6 +33,9 @@ public class HttpToken {
public
static
final
String
X_Client
=
"x-client"
;
public
static
final
String
X_Debugger
=
"x-debugger"
;
public
static
final
String
COOKIE_ANONYMOUS_VALUE
=
"anonymous"
;
public
static
final
String
SET_COOKIE
=
"Set-Cookie"
;
private
static
final
String
RegularExpression_IP
=
"([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}"
;
private
static
final
String
RegularExpression_Token
=
"^(anonymous|user|manager|cipher)([2][0][1-2][0-9][0-1][0-9][0-3][0-9][0-5][0-9][0-5][0-9][0-5][0-9])(\\S{1,})$"
;
...
...
@@ -99,8 +102,8 @@ public class HttpToken {
// String cookie = X_Token + "=; path=/; domain=" +
// this.domain(request) + "; max-age=0
String
cookie
=
X_Token
+
"="
+
COOKIE_ANONYMOUS_VALUE
+
"; path=/; domain="
+
this
.
domain
(
request
)
+
"; HttpOnly"
;
response
.
setHeader
(
"Set-Cookie"
,
cookie
);
+
(
BooleanUtils
.
isTrue
(
Config
.
person
().
getTokenCookieHttpOnly
())
?
"; HttpOnly"
:
""
)
;
response
.
setHeader
(
SET_COOKIE
,
cookie
);
}
catch
(
Exception
e
)
{
throw
new
Exception
(
"delete Token cookie error."
,
e
);
}
...
...
@@ -129,8 +132,8 @@ public class HttpToken {
EffectivePerson
effectivePerson
)
throws
Exception
{
if
(!
StringUtils
.
isEmpty
(
effectivePerson
.
getToken
()))
{
String
cookie
=
X_Token
+
"="
+
effectivePerson
.
getToken
()
+
"; path=/; domain="
+
this
.
domain
(
request
)
+
"; HttpOnly"
;
response
.
setHeader
(
"Set-Cookie"
,
cookie
);
+
(
BooleanUtils
.
isTrue
(
Config
.
person
().
getTokenCookieHttpOnly
())
?
"; HttpOnly"
:
""
)
;
response
.
setHeader
(
SET_COOKIE
,
cookie
);
response
.
setHeader
(
X_Token
,
effectivePerson
.
getToken
());
}
}
...
...
@@ -138,8 +141,9 @@ public class HttpToken {
public
void
setResponseToken
(
HttpServletRequest
request
,
HttpServletResponse
response
,
String
tokenName
,
String
token
)
throws
Exception
{
if
(!
StringUtils
.
isEmpty
(
token
))
{
String
cookie
=
tokenName
+
"="
+
token
+
"; path=/; domain="
+
this
.
domain
(
request
)
+
"; HttpOnly"
;
response
.
setHeader
(
"Set-Cookie"
,
cookie
);
String
cookie
=
tokenName
+
"="
+
token
+
"; path=/; domain="
+
this
.
domain
(
request
)
+
(
BooleanUtils
.
isTrue
(
Config
.
person
().
getTokenCookieHttpOnly
())
?
"; HttpOnly"
:
""
);
response
.
setHeader
(
SET_COOKIE
,
cookie
);
response
.
setHeader
(
tokenName
,
token
);
}
}
...
...
@@ -201,5 +205,8 @@ public class HttpToken {
private
String
userAgent
(
HttpServletRequest
request
)
{
return
Objects
.
toString
(
request
.
getHeader
(
"User-Agent"
),
""
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录