Class Oso
- java.lang.Object
-
- com.osohq.oso_cloud.Oso
-
public class Oso extends java.lang.ObjectOso Cloud client.For more detailed documentation, see https://www.osohq.com/docs/app-integration/client-apis/java
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classOso.Async
-
Constructor Summary
Constructors Constructor Description Oso(java.lang.String apiKey)Construct an Oso Cloud client with the provided API keyOso(java.lang.String apiKey, java.net.URI uri)Construct an Oso Cloud client with the provided API key and URIOso(java.lang.String apiKey, java.net.URI uri, OsoClientOptions options)Construct an Oso Cloud client with the provided API key, URI, and optional configuration parametersOso(java.lang.String apiKey, java.net.URI uri, java.net.URI fallbackUri)Construct an Oso Cloud client with the provided API key, custom Oso Cloud URI, and fallback URI.Oso(java.lang.String apiKey, java.net.URI uri, java.net.URI fallbackUri, java.nio.file.Path dataBindingsPath)Construct an Oso Cloud client with the provided API key, custom Oso Cloud URI, fallback URI, and local authorization data bindings config.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.lang.String[]actions(Value actor, Value resource)Get a list of actions an actor is allowed to perform on a resourcejava.lang.String[]actions(Value actor, Value resource, java.util.List<Fact> contextFacts)Get a list of actions an actor is allowed to perform on a resourcejava.lang.StringactionsLocal(Value actor, Value resource)Fetch a query that can be run against your database to determine the actions an actor can perform on a resource.java.lang.StringactionsLocal(Value actor, Value resource, java.util.List<Fact> contextFacts)Fetch a query that can be run against your database to determine the actions an actor can perform on a resource.java.lang.StringactionsLocal(Value actor, java.lang.String action, Value resource)Deprecated.Use the two argument version of this method instead.booleanauthorize(Value actor, java.lang.String action, Value resource)Check if an actor is allowed to perform an action on a resourcebooleanauthorize(Value actor, java.lang.String action, Value resource, ParityHandle parityHandle)Check if an actor is allowed to perform an action on a resourcebooleanauthorize(Value actor, java.lang.String action, Value resource, java.util.List<Fact> contextFacts)Check if an actor is allowed to perform an action on a resourcebooleanauthorize(Value actor, java.lang.String action, Value resource, java.util.List<Fact> contextFacts, ParityHandle parityHandle)Check if an actor is allowed to perform an action on a resourcejava.lang.StringauthorizeLocal(Value actor, java.lang.String action, Value resource)Check if an actor is allowed to perform an action on a resource depending on data both in Oso Cloud and stored in a local database.java.lang.StringauthorizeLocal(Value actor, java.lang.String action, Value resource, ParityHandle parityHandle)Check if an actor is allowed to perform an action on a resource depending on data both in Oso Cloud and stored in a local database.java.lang.StringauthorizeLocal(Value actor, java.lang.String action, Value resource, java.util.List<Fact> contextFacts)Check if an actor is allowed to perform an action on a resource depending on data both in Oso Cloud and stored in a local database.java.lang.StringauthorizeLocal(Value actor, java.lang.String action, Value resource, java.util.List<Fact> contextFacts, ParityHandle parityHandle)Check if an actor is allowed to perform an action on a resource depending on data both in Oso Cloud and stored in a local database.voidbatch(java.util.function.Consumer<BatchTransaction> fn)Transactionally delete and add facts.QueryBuilderbuildQuery(java.lang.String predicate, QueryArg... args)Query for an arbitrary expression.ParityHandlecreateParityHandle()Creates a new ParityHandle for testing authorization results in the Oso Dev Server Debugger.voiddelete(Fact fact)Delete a single fact.voiddelete(FactPattern pattern)Delete facts matching the provided pattern.Fact[]get(FactPattern pattern)Get facts matching the provided pattern.voidinsert(Fact fact)Insert a single fact.java.lang.String[]list(Value actor, java.lang.String action, java.lang.String resourceType)Get a list of which resources of the provided type an actor is allowed to perform an action onjava.lang.String[]list(Value actor, java.lang.String action, java.lang.String resourceType, java.util.List<Fact> contextFacts)Get a list of which resources of the provided type an actor is allowed to perform an action onjava.lang.StringlistLocal(Value actor, java.lang.String action, java.lang.String resourceType, java.lang.String column)Get a list of which resources of the provided type an actor is allowed to perform an action on depending on data both in Oso Cloud and stored in a local database.java.lang.StringlistLocal(Value actor, java.lang.String action, java.lang.String resourceType, java.lang.String column, java.util.List<Fact> contextFacts)Get a list of which resources of the provided type an actor is allowed to perform an action on depending on data both in Oso Cloud and stored in a local database.java.lang.Stringpolicy()Get the Polar policy currently active in Oso Cloudvoidpolicy(java.lang.String policy)Set the Polar policy currently active in Oso CloudPolicyMetadatapolicyMetadata()Get metadata about the currently active policy.voidsetMaxConnections(int maxConnections)Set the maximum number of connections the connection pool will use when communicating with Oso Cloud.Oso.AsyncwithAsyncExecutor(java.util.concurrent.Executor executor)Returns a handle to the Async API, which returns CompletableFutures that run on the given executor.
-
-
-
Constructor Detail
-
Oso
public Oso(java.lang.String apiKey)
Construct an Oso Cloud client with the provided API key- Parameters:
apiKey- The API key to use for authentication
-
Oso
public Oso(java.lang.String apiKey, java.net.URI uri)Construct an Oso Cloud client with the provided API key and URI- Parameters:
apiKey- The API key to use for authenticationuri- An alternate URI by which to access Oso Cloud. This is useful for testing against the Local Development binary.
-
Oso
public Oso(java.lang.String apiKey, java.net.URI uri, java.net.URI fallbackUri)Construct an Oso Cloud client with the provided API key, custom Oso Cloud URI, and fallback URI.- Parameters:
apiKey- The API key to use for authenticationuri- An alternate URI by which to access Oso Cloud. This is useful for testing against the Local Development binary.fallbackUri- The URI of your Oso Fallback node
-
Oso
public Oso(java.lang.String apiKey, java.net.URI uri, java.net.URI fallbackUri, java.nio.file.Path dataBindingsPath)Construct an Oso Cloud client with the provided API key, custom Oso Cloud URI, fallback URI, and local authorization data bindings config.- Parameters:
apiKey- The API key to use for authenticationuri- An alternate URI by which to access Oso Cloud. This is useful for testing against the Local Development binary.fallbackUri- The URI of your Oso Fallback nodedataBindingsPath- The path to your data bindings configuration YAML file
-
Oso
public Oso(java.lang.String apiKey, java.net.URI uri, OsoClientOptions options)Construct an Oso Cloud client with the provided API key, URI, and optional configuration parameters- Parameters:
apiKey- The API key to use for authenticationuri- An alternate URI by which to access Oso Cloud. This is useful for testing against the Local Development binary.options- Additional configuration options for the Oso client- See Also:
to construct an OsoClientOptions instance
-
-
Method Detail
-
setMaxConnections
public void setMaxConnections(int maxConnections)
Set the maximum number of connections the connection pool will use when communicating with Oso Cloud.Defaults to 20. A higher number will enable more concurrent requests to Oso Cloud, but may consume more resources.
- Parameters:
maxConnections- The maximum number of pooled connections to Oso Cloud
-
policy
public java.lang.String policy() throws java.io.IOException, ApiExceptionGet the Polar policy currently active in Oso Cloud- Returns:
- The Polar policy currently active in Oso Cloud
- Throws:
java.io.IOExceptionApiException
-
policyMetadata
public PolicyMetadata policyMetadata() throws java.io.IOException, ApiException
Get metadata about the currently active policy.- Returns:
- Metadata about the currently active policy.
- Throws:
java.io.IOExceptionApiException
-
policy
public void policy(java.lang.String policy) throws java.io.IOException, ApiExceptionSet the Polar policy currently active in Oso Cloud- Parameters:
policy- The Polar policy to set- Throws:
java.io.IOExceptionApiException
-
insert
public void insert(Fact fact) throws java.io.IOException, ApiException
Insert a single fact.- Parameters:
fact- The fact to insert.- Throws:
java.io.IOExceptionApiException
-
get
public Fact[] get(FactPattern pattern) throws java.io.IOException, ApiException
Get facts matching the provided pattern.Use
ValueOfTypeorValuePattern.ANYin the arguments list to represent wildcards.- Parameters:
pattern- The fact pattern to match.- Returns:
- An array of facts matching the provided pattern.
- Throws:
java.io.IOExceptionApiException
-
delete
public void delete(Fact fact) throws java.io.IOException, ApiException
Delete a single fact. Does not throw an exception if a matching fact does not exist.- Parameters:
fact- The fact to delete.- Throws:
java.io.IOExceptionApiException
-
delete
public void delete(FactPattern pattern) throws java.io.IOException, ApiException
Delete facts matching the provided pattern. Does not throw an exception if a matching fact does not exist.Use
ValueOfTypeorValuePattern.ANYin the arguments list to represent wildcards.- Parameters:
pattern- The fact pattern to match for deletion.- Throws:
java.io.IOExceptionApiException
-
batch
public void batch(java.util.function.Consumer<BatchTransaction> fn) throws java.io.IOException, ApiException
Transactionally delete and add facts.Allows deleting and inserting many facts in one atomic transaction. Deletions and insertions are run in the order they appear in the closure.
Use
ValueOfTypeorValuePattern.ANYin the arguments list passed toBatchTransaction.delete(FactPattern)to represent wildcards.- Parameters:
fn- The function which runs the inserts and deletes via the providedBatchTransaction.- Throws:
java.io.IOExceptionApiException
-
authorize
public boolean authorize(Value actor, java.lang.String action, Value resource, java.util.List<Fact> contextFacts, ParityHandle parityHandle) throws java.io.IOException, ApiException
Check if an actor is allowed to perform an action on a resource- Parameters:
actor- The actor performing the actionaction- The action being performedresource- The resource the action is being performed oncontextFacts- Additional context to consider when making the decisionparityHandle- A handle to indicate the expected decision- Returns:
- Whether the actor is allowed to perform the action on the resource
- Throws:
java.io.IOExceptionApiException
-
authorize
public boolean authorize(Value actor, java.lang.String action, Value resource, java.util.List<Fact> contextFacts) throws java.io.IOException, ApiException
Check if an actor is allowed to perform an action on a resource- Parameters:
actor- The actor performing the actionaction- The action being performedresource- The resource the action is being performed oncontextFacts- Additional context to consider when making the decision- Returns:
- Whether the actor is allowed to perform the action on the resource
- Throws:
java.io.IOExceptionApiException
-
authorize
public boolean authorize(Value actor, java.lang.String action, Value resource, ParityHandle parityHandle) throws java.io.IOException, ApiException
Check if an actor is allowed to perform an action on a resource- Parameters:
actor- The actor performing the actionaction- The action being performedresource- The resource the action is being performed onparityHandle- A handle to indicate the expected decision- Returns:
- Whether the actor is allowed to perform the action on the resource
- Throws:
java.io.IOExceptionApiException
-
authorize
public boolean authorize(Value actor, java.lang.String action, Value resource) throws java.io.IOException, ApiException
Check if an actor is allowed to perform an action on a resource- Parameters:
actor- The actor performing the actionaction- The action being performedresource- The resource the action is being performed on- Returns:
- Whether the actor is allowed to perform the action on the resource
- Throws:
java.io.IOExceptionApiException
-
list
public java.lang.String[] list(Value actor, java.lang.String action, java.lang.String resourceType, java.util.List<Fact> contextFacts) throws java.io.IOException, ApiException
Get a list of which resources of the provided type an actor is allowed to perform an action on- Parameters:
actor- The actor performing the actionaction- The action being performedresourceType- The type of resource to listcontextFacts- Additional context to consider when making the decisions- Returns:
- The resources of the provided type on which the actor is allowed to perform the action
- Throws:
java.io.IOExceptionApiException
-
list
public java.lang.String[] list(Value actor, java.lang.String action, java.lang.String resourceType) throws java.io.IOException, ApiException
Get a list of which resources of the provided type an actor is allowed to perform an action on- Parameters:
actor- The actor performing the actionaction- The action being performedresourceType- The type of resource to list- Returns:
- The resources of the provided type on which the actor is allowed to perform the action
- Throws:
java.io.IOExceptionApiException
-
actions
public java.lang.String[] actions(Value actor, Value resource, java.util.List<Fact> contextFacts) throws java.io.IOException, ApiException
Get a list of actions an actor is allowed to perform on a resource- Parameters:
actor- The actor performing the actionresource- The resource the action is being performed oncontextFacts- Additional context to consider when making the decisions- Returns:
- The actions the actor is allowed to perform on the resource
- Throws:
java.io.IOExceptionApiException
-
actions
public java.lang.String[] actions(Value actor, Value resource) throws java.io.IOException, ApiException
Get a list of actions an actor is allowed to perform on a resource- Parameters:
actor- The actor performing the actionresource- The resource the action is being performed on- Returns:
- The actions the actor is allowed to perform on the resource
- Throws:
java.io.IOExceptionApiException
-
authorizeLocal
public java.lang.String authorizeLocal(Value actor, java.lang.String action, Value resource, java.util.List<Fact> contextFacts, ParityHandle parityHandle) throws java.io.IOException, ApiException
Check if an actor is allowed to perform an action on a resource depending on data both in Oso Cloud and stored in a local database.- Parameters:
actor- The actor performing the actionaction- The action being performedresource- The resource the action is being performed oncontextFacts- Additional context to consider when making the decisionsparityHandle- A handle to indicate the expected decision- Returns:
- A SQL query to run against the local database
- Throws:
java.io.IOExceptionApiException
-
authorizeLocal
public java.lang.String authorizeLocal(Value actor, java.lang.String action, Value resource, java.util.List<Fact> contextFacts) throws java.io.IOException, ApiException
Check if an actor is allowed to perform an action on a resource depending on data both in Oso Cloud and stored in a local database.- Parameters:
actor- The actor performing the actionaction- The action being performedresource- The resource the action is being performed oncontextFacts- Additional context to consider when making the decisions- Returns:
- A SQL query to run against the local database
- Throws:
java.io.IOExceptionApiException
-
authorizeLocal
public java.lang.String authorizeLocal(Value actor, java.lang.String action, Value resource, ParityHandle parityHandle) throws java.io.IOException, ApiException
Check if an actor is allowed to perform an action on a resource depending on data both in Oso Cloud and stored in a local database.- Parameters:
actor- The actor performing the actionaction- The action being performedresource- The resource the action is being performed onparityHandle- A handle to indicate the expected decision- Returns:
- A SQL query to run against the local database
- Throws:
java.io.IOExceptionApiException
-
authorizeLocal
public java.lang.String authorizeLocal(Value actor, java.lang.String action, Value resource) throws java.io.IOException, ApiException
Check if an actor is allowed to perform an action on a resource depending on data both in Oso Cloud and stored in a local database.- Parameters:
actor- The actor performing the actionaction- The action being performedresource- The resource the action is being performed on- Returns:
- A SQL query to run against the local database
- Throws:
java.io.IOExceptionApiException
-
listLocal
public java.lang.String listLocal(Value actor, java.lang.String action, java.lang.String resourceType, java.lang.String column) throws java.io.IOException, ApiException
Get a list of which resources of the provided type an actor is allowed to perform an action on depending on data both in Oso Cloud and stored in a local database.- Parameters:
actor- The actor performing the actionaction- The action being performedresourceType- The type of resource to listcolumn- The name of the column that contains the resource ID- Returns:
- A SQL query to run against the local database
- Throws:
java.io.IOExceptionApiException
-
listLocal
public java.lang.String listLocal(Value actor, java.lang.String action, java.lang.String resourceType, java.lang.String column, java.util.List<Fact> contextFacts) throws java.io.IOException, ApiException
Get a list of which resources of the provided type an actor is allowed to perform an action on depending on data both in Oso Cloud and stored in a local database.- Parameters:
actor- The actor performing the actionaction- The action being performedresourceType- The type of resource to listcolumn- The name of the column that contains the resource IDcontextFacts- Additional context to consider when making the decisions- Returns:
- A SQL query to run against the local database
- Throws:
java.io.IOExceptionApiException
-
actionsLocal
@Deprecated public java.lang.String actionsLocal(Value actor, java.lang.String action, Value resource) throws java.io.IOException, ApiException
Deprecated.Use the two argument version of this method instead.- Throws:
java.io.IOExceptionApiException
-
actionsLocal
public java.lang.String actionsLocal(Value actor, Value resource) throws java.io.IOException, ApiException
Fetch a query that can be run against your database to determine the actions an actor can perform on a resource.- Parameters:
actor- The actor performing the actionresource- The resource the action is being performed on- Returns:
- A SQL query to run against the local database
- Throws:
java.io.IOExceptionApiException
-
actionsLocal
public java.lang.String actionsLocal(Value actor, Value resource, java.util.List<Fact> contextFacts) throws java.io.IOException, ApiException
Fetch a query that can be run against your database to determine the actions an actor can perform on a resource.- Parameters:
actor- The actor performing the actionresource- The resource the action is being performed oncontextFacts- Additional context to consider when making the decisions- Returns:
- A SQL query to run against the local database
- Throws:
java.io.IOExceptionApiException
-
buildQuery
public QueryBuilder buildQuery(java.lang.String predicate, QueryArg... args)
Query for an arbitrary expression.- Parameters:
predicate- The predicate of the queryargs- The arguments to the predicate, which can be: - Concrete values created withValueconstructors - Variables created withTypedVarconstructor- Returns:
- A QueryBuilder for chaining additional constraints
Example:
TypedVar actor = new TypedVar("actor"); QueryBuilder builder = oso.buildQuery( "has_permission", actor, // Variable binding new Value("read"), // Concrete string new Value("Repository", "oso") // Concrete Value ); // The builder can now be used to add constraints or execute the query.
-
createParityHandle
public ParityHandle createParityHandle()
Creates a new ParityHandle for testing authorization results in the Oso Dev Server Debugger.- Returns:
- A new ParityHandle
-
withAsyncExecutor
public Oso.Async withAsyncExecutor(java.util.concurrent.Executor executor)
Returns a handle to the Async API, which returns CompletableFutures that run on the given executor.Useful for interoperation with Kotlin coroutines- eg in Kotlin, `oso.withAsyncExecutor(Dispatchers.IO.asExecutor()).authorize(...).await()`
Cancelling the CompletableFutures returned by the Async API will also cancel the underlying HTTP request.
- Parameters:
executor- Executor the executor to run requests on- eg `Executors.newSingleThreadExecutor()` to run the Async API in a new thread- Returns:
- Async
-
-