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
c0d25a19
Commit
c0d25a19
authored
Sep 26, 2019
by
Jan Hrabal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
15e1a975
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
1 deletion
+22
-1
SecurityHelper.java
src/main/java/com/jh/boot/security/SecurityHelper.java
+22
-1
No files found.
src/main/java/com/jh/boot/security/SecurityHelper.java
View file @
c0d25a19
package
com
.
jh
.
boot
.
security
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
com.jh.boot.security.model.AppRole
;
import
com.jh.boot.security.model.AppUser
;
public
class
SecurityHelper
{
public
static
final
String
ADMIN_ROLE
=
"ROLE_ADMIM"
;
private
SecurityHelper
()
{
}
public
boolean
hasRole
(
AppUser
user
,
String
...
roles
)
{
public
boolean
hasAnyRole
(
AppUser
user
,
String
...
roles
)
{
if
(
user
==
null
||
user
.
getRoles
()
==
null
||
roles
==
null
||
roles
.
length
==
0
)
{
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
)
{
if
(
set
.
contains
(
role
))
{
return
true
;
}
}
return
false
;
}
}
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