Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
administration
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OZG-Cloud
app
administration
Merge requests
!5
Ozg 6986 fix configurations link
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Ozg 6986 fix configurations link
OZG-6986-fix-configurations-link
into
main
Overview
0
Commits
2
Changes
7
Merged
Felix Reichenbach
requested to merge
OZG-6986-fix-configurations-link
into
main
5 months ago
Overview
0
Commits
2
Changes
7
Expand
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
0724caef
2 commits,
5 months ago
7 files
+
190
−
70
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
7
Search (e.g. *.vue) (Ctrl+P)
src/main/java/de/ozgcloud/admin/common/user/CurrentUserHelper.java
+
10
−
4
Options
@@ -26,9 +26,10 @@ package de.ozgcloud.admin.common.user;
import
java.util.Collection
;
import
java.util.Objects
;
import
java.util.Optional
;
import
java.util.Set
;
import
java.util.function.Predicate
;
import
java.util.stream.Collectors
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.security.authentication.AuthenticationTrustResolver
;
import
org.springframework.security.authentication.AuthenticationTrustResolverImpl
;
import
org.springframework.security.core.Authentication
;
@@ -46,20 +47,25 @@ class CurrentUserHelper {
private
static
final
Predicate
<
Authentication
>
IS_TRUSTED
=
auth
->
!
TRUST_RESOLVER
.
isAnonymous
(
auth
);
public
static
boolean
hasRole
(
String
role
)
{
return
hasAnyRole
(
Set
.
of
(
role
));
}
public
static
boolean
hasAnyRole
(
Set
<
String
>
roles
)
{
var
auth
=
getAuthentication
();
if
((
Objects
.
isNull
(
auth
))
||
(
Objects
.
isNull
(
auth
.
getPrincipal
())))
{
return
false
;
}
return
containsRole
(
auth
.
getAuthorities
(),
role
);
return
contains
Any
Role
(
auth
.
getAuthorities
(),
role
s
);
}
static
boolean
containsRole
(
Collection
<?
extends
GrantedAuthority
>
authorities
,
String
role
)
{
static
boolean
contains
Any
Role
(
Collection
<?
extends
GrantedAuthority
>
authorities
,
Set
<
String
>
role
s
)
{
if
(
Objects
.
isNull
(
authorities
))
{
return
false
;
}
return
authorities
.
stream
().
anyMatch
(
a
->
StringUtils
.
equalsIgnoreCase
(
addRolePrefixIfMissing
(
role
),
a
.
getAuthority
()));
var
rolesWithPrefix
=
roles
.
stream
().
map
(
CurrentUserHelper:
:
addRolePrefixIfMissing
).
collect
(
Collectors
.
toSet
());
return
authorities
.
stream
().
anyMatch
(
a
->
rolesWithPrefix
.
contains
(
a
.
getAuthority
()));
}
static
String
addRolePrefixIfMissing
(
String
roleToCheck
)
{
Loading