Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jh-boot
Project
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
Jan Hrabal
jh-boot
Commits
39d253af
Commit
39d253af
authored
Oct 06, 2019
by
Jan Hrabal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xwip
parent
6cfa95a8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
12 deletions
+18
-12
SecurityHelper.java
src/main/java/com/jh/boot/security/SecurityHelper.java
+18
-12
No files found.
src/main/java/com/jh/boot/security/SecurityHelper.java
View file @
39d253af
package
com
.
jh
.
boot
.
security
;
package
com
.
jh
.
boot
.
security
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
com.jh.boot.security.model.AppRole
;
import
com.jh.boot.security.model.AppUser
;
import
com.jh.boot.security.model.AppUser
;
public
class
SecurityHelper
{
public
class
SecurityHelper
{
public
static
final
String
ADMIN_ROLE
=
"ROLE_ADMIM"
;
private
SecurityHelper
()
{
private
SecurityHelper
()
{
}
}
public
boolean
hasAnyRole
(
Authentication
auth
,
String
...
roles
)
{
public
static
AppUser
getUser
()
{
return
(
AppUser
)
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
}
public
static
AppUser
getUser
(
Authentication
auth
)
{
if
(
auth
==
null
)
{
return
null
;
}
return
(
AppUser
)
auth
.
getPrincipal
();
}
public
static
boolean
hasAnyRole
(
Authentication
auth
,
String
...
roles
)
{
AppUser
user
=
auth
instanceof
AppUserAuthentication
?
((
AppUserAuthentication
)
auth
).
getUser
()
:
null
;
AppUser
user
=
auth
instanceof
AppUserAuthentication
?
((
AppUserAuthentication
)
auth
).
getUser
()
:
null
;
if
(
user
==
null
||
user
.
getRoles
()
==
null
||
roles
==
null
||
roles
.
length
==
0
)
{
if
(
user
==
null
||
user
.
getRoles
()
==
null
||
roles
==
null
||
roles
.
length
==
0
)
{
return
false
;
return
false
;
}
}
Set
<
String
>
set
=
user
.
getRoles
().
stream
().
map
(
AppRole:
:
getName
).
collect
(
Collectors
.
toSet
());
if
(
set
.
contains
(
ADMIN_ROLE
))
{
return
true
;
}
for
(
String
role
:
roles
)
{
for
(
String
role
:
roles
)
{
if
(
set
.
contains
(
role
))
{
if
(
user
.
getRolesMap
().
containsKey
(
role
))
{
return
true
;
return
true
;
}
}
}
}
...
...
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