-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0df415d
commit 9998347
Showing
7 changed files
with
65 additions
and
61 deletions.
There are no files selected for viewing
29 changes: 0 additions & 29 deletions
29
config/src/main/java/com/epam/aidial/core/config/AccessControlled.java
This file was deleted.
Oops, something went wrong.
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
34 changes: 34 additions & 0 deletions
34
config/src/main/java/com/epam/aidial/core/config/RoleBasedEntity.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,34 @@ | ||
package com.epam.aidial.core.config; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAlias; | ||
import lombok.Data; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
@Data | ||
public abstract class RoleBasedEntity { | ||
|
||
private String name; | ||
|
||
@JsonAlias({"userRoles", "user_roles"}) | ||
private Set<String> userRoles; | ||
|
||
/** | ||
* Checks if the actual user roles ({@code actualUserRoles} parameter) contain any of the expected user roles ({@code userRoles} field). | ||
* The method verifies if any of the passed role is allowed to operate with the deployment, route or any other instance that extends {@link RoleBasedEntity}. | ||
* | ||
* @return true if one of the {@code actualUserRoles} exists in the {@code userRoles} or if {@code userRoles} field is empty, | ||
* meaning that the current descendant of {@link RoleBasedEntity} allows access to it for any role. | ||
*/ | ||
public boolean hasAccess(List<String> actualUserRoles) { | ||
Set<String> expectedUserRoles = getUserRoles(); | ||
|
||
if (expectedUserRoles == null) { | ||
return true; | ||
} | ||
|
||
return !expectedUserRoles.isEmpty() | ||
&& actualUserRoles.stream().anyMatch(expectedUserRoles::contains); | ||
} | ||
} |
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
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