Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ghsby
o2oa
提交
85eb124c
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,发现更多精彩内容 >>
提交
85eb124c
编写于
10月 19, 2020
作者:
Z
zhourui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix/bearer_oauth
上级
01fd8b05
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
63 addition
and
64 deletion
+63
-64
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
+4
-6
o2server/x_base_core_project/src/main/java/com/x/base/core/project/jaxrs/ResponseFactory.java
...n/java/com/x/base/core/project/jaxrs/ResponseFactory.java
+3
-1
o2server/x_base_core_project/src/main/java/com/x/base/core/project/jaxrs/WoText.java
...t/src/main/java/com/x/base/core/project/jaxrs/WoText.java
+15
-1
o2server/x_base_core_project/src/main/java/com/x/base/core/project/logger/Logger.java
.../src/main/java/com/x/base/core/project/logger/Logger.java
+2
-1
o2server/x_organization_assemble_authentication/src/main/java/com/x/organization/assemble/authentication/jaxrs/oauth/ActionInfo.java
...ation/assemble/authentication/jaxrs/oauth/ActionInfo.java
+14
-5
o2server/x_organization_assemble_authentication/src/main/java/com/x/organization/assemble/authentication/jaxrs/oauth/ActionToken.java
...tion/assemble/authentication/jaxrs/oauth/ActionToken.java
+13
-10
o2server/x_organization_assemble_authentication/src/main/java/com/x/organization/assemble/authentication/jaxrs/oauth/OauthAction.java
...tion/assemble/authentication/jaxrs/oauth/OauthAction.java
+12
-40
未找到文件。
o2server/x_base_core_project/src/main/java/com/x/base/core/project/http/HttpToken.java
浏览文件 @
85eb124c
...
...
@@ -34,8 +34,6 @@ public class HttpToken {
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,})$"
;
...
...
@@ -165,7 +163,10 @@ public class HttpToken {
token
=
request
.
getHeader
(
X_Token
);
}
if
(
StringUtils
.
isEmpty
(
token
))
{
token
=
request
.
getHeader
(
X_Authorization
);
String
value
=
request
.
getHeader
(
X_Authorization
);
if
(!
StringUtils
.
contains
(
value
,
" "
))
{
token
=
value
;
}
}
// 此代码将导致input被关闭.
// if (StringUtils.isEmpty(token)) {
...
...
@@ -205,8 +206,5 @@ public class HttpToken {
private
String
userAgent
(
HttpServletRequest
request
)
{
return
Objects
.
toString
(
request
.
getHeader
(
"User-Agent"
),
""
);
}
}
\ No newline at end of file
o2server/x_base_core_project/src/main/java/com/x/base/core/project/jaxrs/ResponseFactory.java
浏览文件 @
85eb124c
...
...
@@ -97,7 +97,9 @@ public class ResponseFactory {
if
(
notModified
(
request
,
tag
))
{
return
Response
.
notModified
().
tag
(
tag
).
build
();
}
return
Response
.
ok
(
wo
.
getText
()).
type
(
HttpMediaType
.
TEXT_PLAIN_UTF_8
).
tag
(
tag
).
build
();
// return
// Response.ok(wo.getText()).type(HttpMediaType.TEXT_PLAIN_UTF_8).tag(tag).build();
return
Response
.
ok
(
wo
.
getText
()).
type
(
wo
.
getContentType
()).
tag
(
tag
).
build
();
}
else
if
((
null
!=
result
.
getData
())
&&
(
result
.
getData
()
instanceof
WoContentType
))
{
WoContentType
wo
=
(
WoContentType
)
result
.
getData
();
EntityTag
tag
=
new
EntityTag
(
etagWoContentType
(
wo
));
...
...
o2server/x_base_core_project/src/main/java/com/x/base/core/project/jaxrs/WoText.java
浏览文件 @
85eb124c
package
com.x.base.core.project.jaxrs
;
import
org.apache.commons.lang3.StringUtils
;
import
com.x.base.core.project.annotation.FieldDescribe
;
import
com.x.base.core.project.gson.GsonPropertyObject
;
import
com.x.base.core.project.http.HttpMediaType
;
public
class
WoText
extends
GsonPropertyObject
{
public
class
WoText
extends
GsonPropertyObject
{
public
WoText
()
{
}
...
...
@@ -15,6 +18,17 @@ public class WoText extends GsonPropertyObject {
@FieldDescribe
(
"text"
)
private
String
text
;
@FieldDescribe
(
"返回Content_Type"
)
private
String
contentType
;
public
String
getContentType
()
{
return
StringUtils
.
isEmpty
(
this
.
contentType
)
?
HttpMediaType
.
APPLICATION_JSON_UTF_8
:
this
.
contentType
;
}
public
void
setContentType
(
String
contentType
)
{
this
.
contentType
=
contentType
;
}
public
String
getText
()
{
return
text
;
}
...
...
o2server/x_base_core_project/src/main/java/com/x/base/core/project/logger/Logger.java
浏览文件 @
85eb124c
...
...
@@ -198,7 +198,8 @@ public class Logger {
sb
.
append
(
e
.
getMessage
());
String
headString
=
this
.
headToString
(
request
);
String
bodyString
=
this
.
bodyToString
(
body
);
String
requestUrl
=
request
.
getRequestURL
().
toString
();
String
requestUrl
=
request
.
getRequestURL
().
toString
()
+
(
StringUtils
.
isEmpty
(
request
.
getQueryString
())
?
""
:
"?"
+
request
.
getQueryString
());
String
stackTraceString
=
ExceptionUtils
.
getStackTrace
(
e
);
Object
[]
arr
=
new
String
[]
{
effectivePerson
.
getDistinguishedName
(),
request
.
getMethod
(),
requestUrl
,
request
.
getRemoteHost
(),
request
.
getRemoteAddr
(),
headString
,
bodyString
};
...
...
o2server/x_organization_assemble_authentication/src/main/java/com/x/organization/assemble/authentication/jaxrs/oauth/ActionInfo.java
浏览文件 @
85eb124c
package
com.x.organization.assemble.authentication.jaxrs.oauth
;
import
java.math.BigDecimal
;
import
java.util.LinkedHashMap
;
import
java.util.Objects
;
import
java.util.Optional
;
...
...
@@ -10,6 +9,7 @@ import java.util.regex.Pattern;
import
javax.script.CompiledScript
;
import
javax.script.ScriptContext
;
import
javax.script.SimpleScriptContext
;
import
javax.servlet.http.HttpServletRequest
;
import
org.apache.commons.beanutils.PropertyUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -18,11 +18,15 @@ import org.apache.commons.text.StringEscapeUtils;
import
com.x.base.core.container.EntityManagerContainer
;
import
com.x.base.core.container.factory.EntityManagerContainerFactory
;
import
com.x.base.core.entity.annotation.CheckRemoveType
;
import
com.x.base.core.project.cache.Cache.CacheCategory
;
import
com.x.base.core.project.cache.Cache.CacheKey
;
import
com.x.base.core.project.cache.CacheManager
;
import
com.x.base.core.project.config.Config
;
import
com.x.base.core.project.config.Token.InitialManager
;
import
com.x.base.core.project.config.Token.Oauth
;
import
com.x.base.core.project.http.ActionResult
;
import
com.x.base.core.project.http.EffectivePerson
;
import
com.x.base.core.project.http.HttpToken
;
import
com.x.base.core.project.jaxrs.WoText
;
import
com.x.base.core.project.logger.Logger
;
import
com.x.base.core.project.logger.LoggerFactory
;
...
...
@@ -30,9 +34,6 @@ import com.x.base.core.project.script.ScriptFactory;
import
com.x.organization.assemble.authentication.Business
;
import
com.x.organization.core.entity.OauthCode
;
import
com.x.organization.core.entity.Person
;
import
com.x.base.core.project.cache.Cache.CacheCategory
;
import
com.x.base.core.project.cache.Cache.CacheKey
;
import
com.x.base.core.project.cache.CacheManager
;
class
ActionInfo
extends
BaseAction
{
...
...
@@ -42,10 +43,17 @@ class ActionInfo extends BaseAction {
private
static
CacheCategory
cache
=
new
CacheCategory
(
Person
.
class
);
ActionResult
<
Wo
>
execute
(
EffectivePerson
effectivePerson
,
String
accessToken
)
throws
Exception
{
ActionResult
<
Wo
>
execute
(
HttpServletRequest
request
,
EffectivePerson
effectivePerson
,
String
accessToken
,
String
contentType
)
throws
Exception
{
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
ActionResult
<
Wo
>
result
=
new
ActionResult
<>();
Business
business
=
new
Business
(
emc
);
if
(
StringUtils
.
isEmpty
(
accessToken
))
{
String
bearer
=
request
.
getHeader
(
HttpToken
.
X_Authorization
);
if
(
StringUtils
.
isNotEmpty
(
bearer
))
{
accessToken
=
StringUtils
.
substringAfter
(
bearer
,
" "
);
}
}
if
(
StringUtils
.
isEmpty
(
accessToken
))
{
throw
new
ExceptionAccessTokenEmpty
();
}
...
...
@@ -63,6 +71,7 @@ class ActionInfo extends BaseAction {
Info
info
=
this
.
info
(
business
,
oauthCode
,
oauth
);
Wo
wo
=
new
Wo
();
wo
.
setText
(
gson
.
toJson
(
info
));
wo
.
setContentType
(
contentType
);
result
.
setData
(
wo
);
return
result
;
}
...
...
o2server/x_organization_assemble_authentication/src/main/java/com/x/organization/assemble/authentication/jaxrs/oauth/ActionToken.java
浏览文件 @
85eb124c
...
...
@@ -4,7 +4,6 @@ import org.apache.commons.lang3.StringUtils;
import
com.x.base.core.container.EntityManagerContainer
;
import
com.x.base.core.container.factory.EntityManagerContainerFactory
;
import
com.x.base.core.project.config.Token.Oauth
;
import
com.x.base.core.project.gson.GsonPropertyObject
;
import
com.x.base.core.project.http.ActionResult
;
import
com.x.base.core.project.http.EffectivePerson
;
...
...
@@ -18,7 +17,8 @@ class ActionToken extends StandardJaxrsAction {
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
ActionToken
.
class
);
ActionResult
<
Wo
>
execute
(
EffectivePerson
effectivePerson
,
String
code
,
String
grant_type
)
throws
Exception
{
ActionResult
<
Wo
>
execute
(
EffectivePerson
effectivePerson
,
String
code
,
String
grant_type
,
String
contentType
)
throws
Exception
{
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
ActionResult
<
Wo
>
result
=
new
ActionResult
<>();
if
(
StringUtils
.
isEmpty
(
code
))
{
...
...
@@ -44,6 +44,7 @@ class ActionToken extends StandardJaxrsAction {
woToken
.
setExpires_in
(
3600
);
Wo
wo
=
new
Wo
();
wo
.
setText
(
gson
.
toJson
(
woToken
));
wo
.
setContentType
(
contentType
);
result
.
setData
(
wo
);
return
result
;
}
...
...
@@ -52,15 +53,17 @@ class ActionToken extends StandardJaxrsAction {
public
static
class
WoToken
extends
GsonPropertyObject
{
private
String
access_token
;
private
Integer
expires_in
;
private
String
token_type
=
"bearer"
;
// private String token_type = "bearer";
// private String refresh_token = "123";
// private String scope = "read";
public
String
getToken_type
()
{
return
token_type
;
}
public
void
setToken_type
(
String
token_type
)
{
this
.
token_type
=
token_type
;
}
//
public String getToken_type() {
//
return token_type;
//
}
//
//
public void setToken_type(String token_type) {
//
this.token_type = token_type;
//
}
public
String
getAccess_token
()
{
return
access_token
;
...
...
o2server/x_organization_assemble_authentication/src/main/java/com/x/organization/assemble/authentication/jaxrs/oauth/OauthAction.java
浏览文件 @
85eb124c
...
...
@@ -7,7 +7,6 @@ import javax.ws.rs.FormParam;
import
javax.ws.rs.GET
;
import
javax.ws.rs.POST
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.QueryParam
;
import
javax.ws.rs.container.AsyncResponse
;
...
...
@@ -32,37 +31,6 @@ public class OauthAction extends StandardJaxrsAction {
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
OauthAction
.
class
);
// response_type:表示授权类型,必选项,此处的值固定为"code"
// client_id:表示客户端的ID,必选项
// client_secret:表示客户端的密钥,必选项
// redirect_uri:表示重定向URI,可选项
// scope:表示申请的权限范围,可选项
// state:表示客户端的当前状态,可以指定任意值,认证服务器会原封不动地返回这个值。
// @JaxrsMethodDescribe(value = "POST方法实现oauth认证auth方法", action = ActionAuth.class)
// @POST
// @Path("auth")
// @Consumes({ MediaType.MULTIPART_FORM_DATA, MediaType.APPLICATION_FORM_URLENCODED })
// public void postAuth(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
// @Context HttpServletResponse response,
// @JaxrsParameterDescribe("表示授权类型,必选项,此处的值固定为code") @FormParam("response_type") String response_type,
// @JaxrsParameterDescribe("表示客户端的ID") @FormParam("client_id") String client_id,
// @JaxrsParameterDescribe("表示客户端的密钥") @FormParam("client_secret") String client_secret,
// @JaxrsParameterDescribe("表示重定向URI") @FormParam("redirect_uri") String redirect_uri,
// @JaxrsParameterDescribe("表示申请的权限范围") @FormParam("scope") String scope,
// @JaxrsParameterDescribe("表示客户端的当前状态,可以指定任意值,认证服务器会原封不动地返回这个值") @FormParam("state") String state) {
// ActionResult<ActionAuth.Wo> result = new ActionResult<>();
// EffectivePerson effectivePerson = this.effectivePerson(request);
// try {
// result = new ActionAuth().execute(effectivePerson, response_type, client_id, client_secret, redirect_uri,
// scope, state);
// } catch (Exception e) {
// logger.error(e, effectivePerson, request, null);
// result.error(e);
// }
// asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
// }
@JaxrsMethodDescribe
(
value
=
"GET方法实现oauth认证auth方法"
,
action
=
ActionAuth
.
class
)
@GET
@Path
(
"auth"
)
...
...
@@ -90,11 +58,12 @@ public class OauthAction extends StandardJaxrsAction {
@Consumes
({
MediaType
.
MULTIPART_FORM_DATA
,
MediaType
.
APPLICATION_FORM_URLENCODED
})
public
void
postToken
(
@Suspended
final
AsyncResponse
asyncResponse
,
@Context
HttpServletRequest
request
,
@Context
HttpServletResponse
response
,
@FormParam
(
"code"
)
String
code
,
@FormParam
(
"grant_type"
)
String
grant_type
)
{
@FormParam
(
"grant_type"
)
String
grant_type
,
@JaxrsParameterDescribe
(
"response CONTENT_TYPE 设置 默认为text/plain; charset=UTF-8"
)
@FormParam
(
"contentType"
)
String
contentType
)
{
ActionResult
<
ActionToken
.
Wo
>
result
=
new
ActionResult
<>();
EffectivePerson
effectivePerson
=
this
.
effectivePerson
(
request
);
try
{
result
=
new
ActionToken
().
execute
(
effectivePerson
,
code
,
grant_type
);
result
=
new
ActionToken
().
execute
(
effectivePerson
,
code
,
grant_type
,
contentType
);
}
catch
(
Exception
e
)
{
logger
.
error
(
e
,
effectivePerson
,
request
,
null
);
result
.
error
(
e
);
...
...
@@ -107,11 +76,12 @@ public class OauthAction extends StandardJaxrsAction {
@Path
(
"token"
)
public
void
getToken
(
@Suspended
final
AsyncResponse
asyncResponse
,
@Context
HttpServletRequest
request
,
@Context
HttpServletResponse
response
,
@QueryParam
(
"code"
)
String
code
,
@QueryParam
(
"grant_type"
)
String
grant_type
)
{
@QueryParam
(
"grant_type"
)
String
grant_type
,
@JaxrsParameterDescribe
(
"response CONTENT_TYPE 设置 默认为text/plain; charset=UTF-8"
)
@QueryParam
(
"contentType"
)
String
contentType
)
{
ActionResult
<
ActionToken
.
Wo
>
result
=
new
ActionResult
<>();
EffectivePerson
effectivePerson
=
this
.
effectivePerson
(
request
);
try
{
result
=
new
ActionToken
().
execute
(
effectivePerson
,
code
,
grant_type
);
result
=
new
ActionToken
().
execute
(
effectivePerson
,
code
,
grant_type
,
contentType
);
}
catch
(
Exception
e
)
{
logger
.
error
(
e
,
effectivePerson
,
request
,
null
);
result
.
error
(
e
);
...
...
@@ -124,11 +94,12 @@ public class OauthAction extends StandardJaxrsAction {
@Path
(
"info"
)
@Consumes
({
MediaType
.
MULTIPART_FORM_DATA
,
MediaType
.
APPLICATION_FORM_URLENCODED
})
public
void
postInfo
(
@Suspended
final
AsyncResponse
asyncResponse
,
@Context
HttpServletRequest
request
,
@Context
HttpServletResponse
response
,
@FormParam
(
"access_token"
)
String
access_token
)
{
@Context
HttpServletResponse
response
,
@FormParam
(
"access_token"
)
String
access_token
,
@JaxrsParameterDescribe
(
"response CONTENT_TYPE 设置 默认为text/plain; charset=UTF-8"
)
@FormParam
(
"contentType"
)
String
contentType
)
{
ActionResult
<
ActionInfo
.
Wo
>
result
=
new
ActionResult
<>();
EffectivePerson
effectivePerson
=
this
.
effectivePerson
(
request
);
try
{
result
=
new
ActionInfo
().
execute
(
effectivePerson
,
access_token
);
result
=
new
ActionInfo
().
execute
(
request
,
effectivePerson
,
access_token
,
contentType
);
}
catch
(
Exception
e
)
{
logger
.
error
(
e
,
effectivePerson
,
request
,
null
);
result
.
error
(
e
);
...
...
@@ -141,11 +112,12 @@ public class OauthAction extends StandardJaxrsAction {
@Path
(
"info"
)
@Produces
(
HttpMediaType
.
APPLICATION_JSON_UTF_8
)
public
void
getInfo
(
@Suspended
final
AsyncResponse
asyncResponse
,
@Context
HttpServletRequest
request
,
@Context
HttpServletResponse
response
,
@QueryParam
(
"access_token"
)
String
access_token
)
{
@Context
HttpServletResponse
response
,
@QueryParam
(
"access_token"
)
String
access_token
,
@JaxrsParameterDescribe
(
"response CONTENT_TYPE 设置 默认为text/plain; charset=UTF-8"
)
@QueryParam
(
"contentType"
)
String
contentType
)
{
ActionResult
<
ActionInfo
.
Wo
>
result
=
new
ActionResult
<>();
EffectivePerson
effectivePerson
=
this
.
effectivePerson
(
request
);
try
{
result
=
new
ActionInfo
().
execute
(
effectivePerson
,
access_token
);
result
=
new
ActionInfo
().
execute
(
request
,
effectivePerson
,
access_token
,
contentType
);
}
catch
(
Exception
e
)
{
logger
.
error
(
e
,
effectivePerson
,
request
,
null
);
result
.
error
(
e
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录