Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gic-enterprise-base
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
base_platform_enterprise
gic-enterprise-base
Commits
8fad1544
Commit
8fad1544
authored
Jun 15, 2020
by
陶光胜
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'developer' into 'master'
Developer See merge request
!5
parents
1f28f9e6
a2a7aed3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
33 deletions
+32
-33
UserContext.java
...src/main/java/com/gic/enterprise/context/UserContext.java
+9
-10
AuthInterceptor.java
.../java/com/gic/enterprise/interceptor/AuthInterceptor.java
+23
-23
No files found.
gic-enterprise-base-api/src/main/java/com/gic/enterprise/context/UserContext.java
View file @
8fad1544
...
...
@@ -14,7 +14,10 @@ import javax.servlet.http.HttpServletResponse;
import
java.util.concurrent.TimeUnit
;
public
class
UserContext
{
public
static
final
Long
expireLength
=
1
l
;
/**
* 有效期4小时
*/
public
static
final
Long
expireLength
=
4L
;
private
static
UserContext
userContext
=
null
;
private
static
final
Logger
log
=
LogManager
.
getLogger
(
UserContext
.
class
);
...
...
@@ -34,16 +37,12 @@ public class UserContext {
}
public
UserDetail
get
(){
String
token
=
getToken
();
if
(
StringUtils
.
isBlank
(
token
)){
return
new
UserDetail
();
}
String
key
=
Constants
.
TOKEN_KEY
+
token
;
Object
cache
=
RedisUtil
.
getCache
(
key
);
if
(
cache
!=
null
){
return
(
UserDetail
)
cache
;
return
(
UserDetail
)
RequestContext
.
getContext
().
getRequest
().
getAttribute
(
"user"
);
}
return
new
UserDetail
();
public
UserDetail
getByRedis
(){
String
token
=
getToken
();
return
getByToken
(
token
);
}
public
UserDetail
getByToken
(
String
token
)
{
...
...
gic-enterprise-common/src/main/java/com/gic/enterprise/interceptor/AuthInterceptor.java
View file @
8fad1544
package
com
.
gic
.
enterprise
.
interceptor
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.dubbo.rpc.RpcContext
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.springframework.web.method.HandlerMethod
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
com.alibaba.fastjson.JSON
;
import
com.gic.enterprise.ano.IgnoreLogin
;
import
com.gic.enterprise.base.MenuInfo
;
...
...
@@ -23,7 +8,19 @@ import com.gic.enterprise.context.UserContext;
import
com.gic.enterprise.error.ErrorCode
;
import
com.gic.enterprise.exception.CommonException
;
import
com.gic.enterprise.utils.UserDetail
;
import
com.gic.enterprise.utils.UserDetailUtils
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.dubbo.rpc.RpcContext
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.springframework.web.method.HandlerMethod
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
public
class
AuthInterceptor
extends
HandlerInterceptorAdapter
{
...
...
@@ -63,12 +60,6 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
String
uri
=
request
.
getRequestURI
();
log
.
info
(
"权限拦截token url:{}"
,
uri
);
HandlerMethod
handler
=
(
HandlerMethod
)
object
;
//免登录接口路由
IgnoreLogin
ignoreLogin
=
handler
.
getMethodAnnotation
(
IgnoreLogin
.
class
);
if
(
null
!=
ignoreLogin
)
{
return
true
;
}
//操作项标志位
String
isControl
=
request
.
getHeader
(
"isControl"
);
...
...
@@ -81,10 +72,19 @@ public class AuthInterceptor extends HandlerInterceptorAdapter {
return
true
;
}
//判断是否有权限的路径
UserDetail
userDetail
=
User
DetailUtils
.
getUserDetail
();
UserDetail
userDetail
=
User
Context
.
getContext
().
getByRedis
();
if
(
userDetail
==
null
||
userDetail
.
getUserInfo
()
==
null
)
{
throw
new
CommonException
(
ErrorCode
.
LOGIN_INVALID
.
getErrorCode
(),
"登录信息不存在,请登录"
);
}
request
.
setAttribute
(
"user"
,
userDetail
);
HandlerMethod
handler
=
(
HandlerMethod
)
object
;
//免登录接口路由
IgnoreLogin
ignoreLogin
=
handler
.
getMethodAnnotation
(
IgnoreLogin
.
class
);
if
(
null
!=
ignoreLogin
)
{
return
true
;
}
//不需要拦截的路径
if
(
ignoreUriAfterLoginMap
.
containsKey
(
uri
))
{
...
...
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