-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic permissions checking from Subject
Adds capability for subject to check if a permission is allowed or not and creates a mechanism for actions to describe the permissinos associated with them. Signed-off-by: Peter Nied <[email protected]>
- Loading branch information
Showing
9 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
sandbox/libs/authn/src/main/java/org/opensearch/authn/Permission.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 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.authn; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class Permission { | ||
private final String[] permissionChunks; | ||
|
||
public Permission(final String permission) { | ||
this.permissionChunks = permission.split("\\."); | ||
} | ||
|
||
public boolean matches(final String permissionRequired) { | ||
Objects.nonNull(permissionRequired); | ||
|
||
final Permission required = new Permission(permissionRequired); | ||
for(int i = 0; i < this.permissionChunks.length; i++) { | ||
if (!this.permissionChunks[i].equals(required.permissionChunks[i])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
sandbox/libs/authn/src/main/java/org/opensearch/authn/UnauthorizedException.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,18 @@ | ||
package org.opensearch.authn; | ||
|
||
import org.opensearch.authn.Subject; | ||
import org.opensearch.authn.Permission; | ||
|
||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
public class UnauthorizedException extends RuntimeException { | ||
public UnauthorizedException(final String message) { | ||
super(message); | ||
} | ||
} |
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
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