Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
App Blocks
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Genesys PGR
App Blocks
Commits
b89154be
Commit
b89154be
authored
Nov 07, 2018
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix: SecurityContextUtil should re-check context for `permissionEvaluator`
parent
f1e08edb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
4 deletions
+20
-4
security/src/main/java/org/genesys/blocks/security/SecurityContextUtil.java
...java/org/genesys/blocks/security/SecurityContextUtil.java
+20
-4
No files found.
security/src/main/java/org/genesys/blocks/security/SecurityContextUtil.java
View file @
b89154be
...
...
@@ -48,16 +48,26 @@ public class SecurityContextUtil {
// Context initialization
static
{
updatePermissionEvaluator
();
}
/**
* Try to obtain permissionEvaluator bean from context
* @return true if obtained, false if not obtained.
*/
private
static
synchronized
boolean
updatePermissionEvaluator
()
{
ApplicationContext
context
=
CurrentApplicationContext
.
getContext
();
if
(
context
!=
null
)
{
try
{
permissionEvaluator
=
context
.
getBean
(
PermissionEvaluator
.
class
);
return
true
;
}
catch
(
BeansException
e
)
{
LOG
.
warn
(
"Could not find PermissionEvaluator instance in your context"
);
}
}
else
{
LOG
.
warn
(
"You should initialize a bean instance of org.genesys.blocks.util.CurrentApplicationContext in your context"
);
}
return
false
;
}
/**
...
...
@@ -146,8 +156,11 @@ public class SecurityContextUtil {
*/
public
static
boolean
hasPermission
(
Object
targetDomainObject
,
Object
permission
)
{
if
(
permissionEvaluator
==
null
)
{
LOG
.
warn
(
"permissionEvaluator not available. No permissions."
);
return
false
;
LOG
.
info
(
"permissionEvaluator not available. Checking context again"
);
if
(!
updatePermissionEvaluator
())
{
LOG
.
warn
(
"permissionEvaluator not available. No permissions."
);
return
false
;
}
}
final
Authentication
auth
=
SecurityContextHolder
.
getContext
().
getAuthentication
();
...
...
@@ -167,8 +180,11 @@ public class SecurityContextUtil {
*/
public
static
boolean
anyoneHasPermission
(
Object
targetDomainObject
,
Object
permission
)
{
if
(
permissionEvaluator
==
null
)
{
LOG
.
warn
(
"permissionEvaluator not available. No permissions."
);
return
false
;
LOG
.
info
(
"permissionEvaluator not available. Checking context again"
);
if
(!
updatePermissionEvaluator
())
{
LOG
.
warn
(
"permissionEvaluator not available. No permissions."
);
return
false
;
}
}
if
(
ANONYMOUS_AUTH
!=
null
)
{
...
...
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