Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cash-loan-flow-boss
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QG
cash-loan-flow-boss
Commits
cf1d130c
Commit
cf1d130c
authored
Jan 02, 2020
by
suntao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
未登录 或者 无权限 时 不抛出异常
parent
0d18c3c2
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
15 deletions
+21
-15
SecurityHandler.java
.../cashloanflowboss/component/security/SecurityHandler.java
+3
-1
SecurityInterceptor.java
...hloanflowboss/component/security/SecurityInterceptor.java
+6
-3
Assert.java
...a/cn/quantgroup/cashloanflowboss/core/asserts/Assert.java
+0
-4
ApplicationSecurityHandler.java
...owboss/core/configuration/ApplicationSecurityHandler.java
+11
-6
BossCorsConfiguration.java
...oanflowboss/core/configuration/BossCorsConfiguration.java
+1
-1
No files found.
src/main/java/cn/quantgroup/cashloanflowboss/component/security/SecurityHandler.java
View file @
cf1d130c
package
cn
.
quantgroup
.
cashloanflowboss
.
component
.
security
;
package
cn
.
quantgroup
.
cashloanflowboss
.
component
.
security
;
import
cn.quantgroup.cashloanflowboss.core.base.Tuple
;
import
cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus
;
import
org.aopalliance.intercept.MethodInvocation
;
import
org.aopalliance.intercept.MethodInvocation
;
/**
/**
...
@@ -8,5 +10,5 @@ import org.aopalliance.intercept.MethodInvocation;
...
@@ -8,5 +10,5 @@ import org.aopalliance.intercept.MethodInvocation;
* Created by WeiWei on 2018/12/24.
* Created by WeiWei on 2018/12/24.
*/
*/
public
interface
SecurityHandler
{
public
interface
SecurityHandler
{
boolean
doAuthentication
(
final
MethodInvocation
invocation
,
String
authorityId
,
Authority
[]
authority
)
throws
Throwable
;
Tuple
<
Boolean
,
ApplicationStatus
>
doAuthentication
(
final
MethodInvocation
invocation
,
String
authorityId
,
Authority
[]
authority
)
throws
Throwable
;
}
}
\ No newline at end of file
src/main/java/cn/quantgroup/cashloanflowboss/component/security/SecurityInterceptor.java
View file @
cf1d130c
...
@@ -2,9 +2,11 @@ package cn.quantgroup.cashloanflowboss.component.security;
...
@@ -2,9 +2,11 @@ package cn.quantgroup.cashloanflowboss.component.security;
import
cn.quantgroup.cashloanflowboss.component.security.annotiation.Security
;
import
cn.quantgroup.cashloanflowboss.component.security.annotiation.Security
;
import
cn.quantgroup.cashloanflowboss.core.base.Result
;
import
cn.quantgroup.cashloanflowboss.core.base.Result
;
import
cn.quantgroup.cashloanflowboss.core.base.Tuple
;
import
cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus
;
import
cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus
;
import
org.aopalliance.intercept.MethodInterceptor
;
import
org.aopalliance.intercept.MethodInterceptor
;
import
org.aopalliance.intercept.MethodInvocation
;
import
org.aopalliance.intercept.MethodInvocation
;
import
org.apache.commons.lang3.BooleanUtils
;
import
org.springframework.context.support.ApplicationObjectSupport
;
import
org.springframework.context.support.ApplicationObjectSupport
;
import
java.io.Serializable
;
import
java.io.Serializable
;
...
@@ -18,9 +20,10 @@ public class SecurityInterceptor extends ApplicationObjectSupport implements Met
...
@@ -18,9 +20,10 @@ public class SecurityInterceptor extends ApplicationObjectSupport implements Met
public
Object
invoke
(
final
MethodInvocation
invocation
)
throws
Throwable
{
public
Object
invoke
(
final
MethodInvocation
invocation
)
throws
Throwable
{
Security
security
=
invocation
.
getMethod
().
getAnnotation
(
Security
.
class
);
Security
security
=
invocation
.
getMethod
().
getAnnotation
(
Security
.
class
);
Tuple
<
Boolean
,
ApplicationStatus
>
doAuthentication
=
this
.
getApplicationContext
().
getBean
(
SecurityHandler
.
class
).
doAuthentication
(
invocation
,
security
.
authorityId
(),
security
.
authorities
());
if
(!
this
.
getApplicationContext
().
getBean
(
SecurityHandler
.
class
).
doAuthentication
(
invocation
,
security
.
authorityId
(),
security
.
authorities
()))
{
if
(
BooleanUtils
.
isFalse
(
doAuthentication
.
getKey
()))
{
return
Result
.
buildFail
(
ApplicationStatus
.
INVALID_AUTHORITY
);
// 未通过验证
return
Result
.
buildFail
(
doAuthentication
.
getValue
());
}
}
return
invocation
.
proceed
();
return
invocation
.
proceed
();
...
...
src/main/java/cn/quantgroup/cashloanflowboss/core/asserts/Assert.java
View file @
cf1d130c
...
@@ -325,26 +325,22 @@ public class Assert {
...
@@ -325,26 +325,22 @@ public class Assert {
public
static
Boolean
isLastLogin
(
Map
<
String
,
Object
>
concurrentHashMapLoginInfo
)
{
public
static
Boolean
isLastLogin
(
Map
<
String
,
Object
>
concurrentHashMapLoginInfo
)
{
HttpSession
session
=
Application
.
getSession
();
HttpSession
session
=
Application
.
getSession
();
if
(
Objects
.
isNull
(
session
))
{
if
(
Objects
.
isNull
(
session
))
{
System
.
out
.
println
(
"session 为空"
);
return
false
;
return
false
;
}
}
Principal
principal
=
Application
.
getPrincipal
();
Principal
principal
=
Application
.
getPrincipal
();
if
(
Objects
.
isNull
(
principal
))
{
if
(
Objects
.
isNull
(
principal
))
{
System
.
out
.
println
(
"principal 为空"
);
return
false
;
return
false
;
}
}
Object
userLastLoginTimeObject
=
concurrentHashMapLoginInfo
.
get
(
principal
.
getUserInfo
().
getUserId
()+
""
);
Object
userLastLoginTimeObject
=
concurrentHashMapLoginInfo
.
get
(
principal
.
getUserInfo
().
getUserId
()+
""
);
if
(
Objects
.
isNull
(
userLastLoginTimeObject
))
{
if
(
Objects
.
isNull
(
userLastLoginTimeObject
))
{
// 没有登陆时间 不处理
// 没有登陆时间 不处理
System
.
out
.
println
(
"userLastLoginTimeObject 为空"
);
return
false
;
return
false
;
}
}
// 获取session最后登陆时间
// 获取session最后登陆时间
Object
creationTimeObject
=
session
.
getAttribute
(
ApplicationDictionary
.
USER_SESSION_LOGIN_TIME
);
Object
creationTimeObject
=
session
.
getAttribute
(
ApplicationDictionary
.
USER_SESSION_LOGIN_TIME
);
if
(
Objects
.
isNull
(
creationTimeObject
))
{
if
(
Objects
.
isNull
(
creationTimeObject
))
{
System
.
out
.
println
(
"lastAccessedTime 为空"
);
return
false
;
return
false
;
}
}
...
...
src/main/java/cn/quantgroup/cashloanflowboss/core/configuration/ApplicationSecurityHandler.java
View file @
cf1d130c
...
@@ -8,10 +8,12 @@ import cn.quantgroup.cashloanflowboss.component.security.Authority;
...
@@ -8,10 +8,12 @@ import cn.quantgroup.cashloanflowboss.component.security.Authority;
import
cn.quantgroup.cashloanflowboss.component.security.SecurityHandler
;
import
cn.quantgroup.cashloanflowboss.component.security.SecurityHandler
;
import
cn.quantgroup.cashloanflowboss.core.Application
;
import
cn.quantgroup.cashloanflowboss.core.Application
;
import
cn.quantgroup.cashloanflowboss.core.asserts.Assert
;
import
cn.quantgroup.cashloanflowboss.core.asserts.Assert
;
import
cn.quantgroup.cashloanflowboss.core.base.Tuple
;
import
cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus
;
import
cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus
;
import
cn.quantgroup.cashloanflowboss.core.exception.ApplicationException
;
import
cn.quantgroup.cashloanflowboss.core.exception.ApplicationException
;
import
org.aopalliance.intercept.MethodInvocation
;
import
org.aopalliance.intercept.MethodInvocation
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.BooleanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -29,31 +31,34 @@ public class ApplicationSecurityHandler implements SecurityHandler {
...
@@ -29,31 +31,34 @@ public class ApplicationSecurityHandler implements SecurityHandler {
private
LoginService
loginService
;
private
LoginService
loginService
;
@Override
@Override
public
boolean
doAuthentication
(
MethodInvocation
invocation
,
String
authorityId
,
Authority
[]
authority
)
throws
Throwable
{
public
Tuple
<
Boolean
,
ApplicationStatus
>
doAuthentication
(
MethodInvocation
invocation
,
String
authorityId
,
Authority
[]
authority
)
{
Principal
principal
=
Application
.
getPrincipal
();
Principal
principal
=
Application
.
getPrincipal
();
// 检查是否已登录
// 检查是否已登录
Assert
.
isNull
(
principal
,
ApplicationStatus
.
AUTHENTICATION_LOGIN
);
if
(
principal
==
null
)
{
return
new
Tuple
<>(
Boolean
.
FALSE
,
ApplicationStatus
.
AUTHENTICATION_LOGIN
);
}
// 是否 被挤下线
// 是否 被挤下线
Boolean
isLogin
=
Assert
.
isLastLogin
(
loginService
.
getConcurrentHashMapLoginInfo
());
Boolean
isLogin
=
Assert
.
isLastLogin
(
loginService
.
getConcurrentHashMapLoginInfo
());
if
(
isLogin
!=
null
&&
isLogin
)
{
if
(
BooleanUtils
.
isTrue
(
isLogin
)
)
{
// 退出登陆
// 退出登陆
loginService
.
logout
();
loginService
.
logout
();
// 返回 信息
// 返回 信息
throw
new
ApplicationException
(
ApplicationStatus
.
AUTHENTICATION_LOGIN_CROWD_OUT
);
return
new
Tuple
<>(
Boolean
.
FALSE
,
ApplicationStatus
.
AUTHENTICATION_LOGIN_CROWD_OUT
);
}
}
// 如果是超级管理员跳过权限验证
// 如果是超级管理员跳过权限验证
return
principal
.
isSuperAdministrator
()
||
principal
.
getRoles
().
stream
().
anyMatch
(
role
->
{
boolean
hasPrivilege
=
principal
.
isSuperAdministrator
()
||
principal
.
getRoles
().
stream
().
anyMatch
(
role
->
{
List
<
Role
>
roleList
=
getRoleAndParent
(
role
);
List
<
Role
>
roleList
=
getRoleAndParent
(
role
);
if
(
CollectionUtils
.
isEmpty
(
roleList
))
{
if
(
CollectionUtils
.
isEmpty
(
roleList
))
{
return
false
;
return
false
;
}
}
return
roleList
.
stream
().
anyMatch
(
_role
->
this
.
checkAuthority
(
authorityId
,
_role
));
return
roleList
.
stream
().
anyMatch
(
roleItem
->
this
.
checkAuthority
(
authorityId
,
roleItem
));
});
});
return
new
Tuple
<>(
hasPrivilege
,
hasPrivilege
?
null
:
ApplicationStatus
.
INVALID_AUTHORITY
);
}
}
...
...
src/main/java/cn/quantgroup/cashloanflowboss/core/configuration/BossCorsConfiguration.java
View file @
cf1d130c
...
@@ -43,7 +43,7 @@ public class BossCorsConfiguration extends WebMvcConfigurerAdapter {
...
@@ -43,7 +43,7 @@ public class BossCorsConfiguration extends WebMvcConfigurerAdapter {
corsConfiguration
.
addAllowedMethod
(
"*"
);
corsConfiguration
.
addAllowedMethod
(
"*"
);
return
corsConfiguration
;
return
corsConfiguration
;
}
}
@Bean
//
@Bean
public
CorsFilter
corsFilter
()
{
public
CorsFilter
corsFilter
()
{
UrlBasedCorsConfigurationSource
source
=
new
UrlBasedCorsConfigurationSource
();
UrlBasedCorsConfigurationSource
source
=
new
UrlBasedCorsConfigurationSource
();
source
.
registerCorsConfiguration
(
"/**"
,
buildConfig
());
source
.
registerCorsConfiguration
(
"/**"
,
buildConfig
());
...
...
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