-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove ROLE_ from system roles + refactoring (#4126)
Signed-off-by: Iliyan Velichkov <[email protected]>
- Loading branch information
1 parent
1d9f33b
commit f1be555
Showing
5 changed files
with
37 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...ants/src/main/java/org/eclipse/dirigible/components/tenants/security/AuthoritiesUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.eclipse.dirigible.components.tenants.security; | ||
|
||
import org.springframework.security.core.GrantedAuthority; | ||
import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class AuthoritiesUtil { | ||
|
||
private static final String ROLE_PREFIX = "ROLE_"; | ||
|
||
public static Set<GrantedAuthority> toAuthorities(String... roleNames) { | ||
return toAuthorities(Arrays.stream(roleNames)); | ||
} | ||
|
||
public static Set<GrantedAuthority> toAuthorities(Stream<String> roleNames) { | ||
return roleNames.map((r -> r.startsWith(ROLE_PREFIX) ? r : (ROLE_PREFIX + r))) | ||
.map(r -> new SimpleGrantedAuthority(r)) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
public static Set<GrantedAuthority> toAuthorities(Collection<String> roleNames) { | ||
return toAuthorities(roleNames.stream()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters