Class Oso.Async

  • Enclosing class:
    Oso

    public class Oso.Async
    extends java.lang.Object
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletableFuture<java.lang.String[]> actions​(Value actor, Value resource)
      Get a list of actions an actor is allowed to perform on a resource
      java.util.concurrent.CompletableFuture<java.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 resource
      java.util.concurrent.CompletableFuture<java.lang.String> actionsLocal​(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.util.concurrent.CompletableFuture<java.lang.String> actionsLocal​(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.util.concurrent.CompletableFuture<java.lang.Boolean> authorize​(Value actor, java.lang.String action, Value resource)
      Check if an actor is allowed to perform an action on a resource
      java.util.concurrent.CompletableFuture<java.lang.Boolean> authorize​(Value actor, java.lang.String action, Value resource, ParityHandle parityHandle)
      Check if an actor is allowed to perform an action on a resource
      java.util.concurrent.CompletableFuture<java.lang.Boolean> authorize​(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
      java.util.concurrent.CompletableFuture<java.lang.Boolean> authorize​(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
      java.util.concurrent.CompletableFuture<java.lang.String> authorizeLocal​(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.util.concurrent.CompletableFuture<java.lang.String> authorizeLocal​(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.util.concurrent.CompletableFuture<java.lang.String> authorizeLocal​(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.util.concurrent.CompletableFuture<java.lang.String> authorizeLocal​(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.
      java.util.concurrent.CompletableFuture<java.lang.Void> batch​(java.util.function.Consumer<BatchTransaction> fn)
      Transactionally delete and add facts.
      AsyncQueryBuilder buildQuery​(java.lang.String predicate, QueryArg... args)
      Query for an arbitrary expression.
      java.util.concurrent.CompletableFuture<java.lang.Void> delete​(Fact fact)
      Delete a single fact.
      java.util.concurrent.CompletableFuture<java.lang.Void> delete​(FactPattern pattern)
      Delete facts matching the provided pattern.
      java.util.concurrent.CompletableFuture<Fact[]> get​(FactPattern pattern)
      Get facts matching the provided pattern.
      java.util.concurrent.CompletableFuture<java.lang.Void> insert​(Fact fact)
      Insert a single fact.
      java.util.concurrent.CompletableFuture<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 on
      java.util.concurrent.CompletableFuture<java.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 on
      java.util.concurrent.CompletableFuture<java.lang.String> listLocal​(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.util.concurrent.CompletableFuture<java.lang.String> listLocal​(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.util.concurrent.CompletableFuture<java.lang.String> policy()
      Get the Polar policy currently active in Oso Cloud
      java.util.concurrent.CompletableFuture<java.lang.Void> policy​(java.lang.String policy)
      Set the Polar policy currently active in Oso Cloud
      java.util.concurrent.CompletableFuture<PolicyMetadata> policyMetadata()
      Get metadata about the currently active policy.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • authorize

        public java.util.concurrent.CompletableFuture<java.lang.Boolean> authorize​(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
        Parameters:
        actor - The actor performing the action
        action - The action being performed
        resource - The resource the action is being performed on
        contextFacts - Additional context to consider when making the decision
        parityHandle - A handle to indicate the expected decision
        Returns:
        A Future containing whether the actor is allowed to perform the action on the resource
      • authorize

        public java.util.concurrent.CompletableFuture<java.lang.Boolean> authorize​(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
        Parameters:
        actor - The actor performing the action
        action - The action being performed
        resource - The resource the action is being performed on
        contextFacts - Additional context to consider when making the decision
        Returns:
        Whether the actor is allowed to perform the action on the resource
      • authorize

        public java.util.concurrent.CompletableFuture<java.lang.Boolean> authorize​(Value actor,
                                                                                   java.lang.String action,
                                                                                   Value resource,
                                                                                   ParityHandle parityHandle)
        Check if an actor is allowed to perform an action on a resource
        Parameters:
        actor - The actor performing the action
        action - The action being performed
        resource - The resource the action is being performed on
        parityHandle - A handle to indicate the expected decision
        Returns:
        Whether the actor is allowed to perform the action on the resource
      • authorize

        public java.util.concurrent.CompletableFuture<java.lang.Boolean> authorize​(Value actor,
                                                                                   java.lang.String action,
                                                                                   Value resource)
        Check if an actor is allowed to perform an action on a resource
        Parameters:
        actor - The actor performing the action
        action - The action being performed
        resource - The resource the action is being performed on
        Returns:
        Whether the actor is allowed to perform the action on the resource
      • policy

        public java.util.concurrent.CompletableFuture<java.lang.String> policy()
        Get the Polar policy currently active in Oso Cloud
        Returns:
        The Polar policy currently active in Oso Cloud
      • policyMetadata

        public java.util.concurrent.CompletableFuture<PolicyMetadata> policyMetadata()
        Get metadata about the currently active policy.
        Returns:
        Metadata about the currently active policy.
      • policy

        public java.util.concurrent.CompletableFuture<java.lang.Void> policy​(java.lang.String policy)
        Set the Polar policy currently active in Oso Cloud
        Parameters:
        policy - The Polar policy to set
      • insert

        public java.util.concurrent.CompletableFuture<java.lang.Void> insert​(Fact fact)
        Insert a single fact.
        Parameters:
        fact - The fact to insert.
      • get

        public java.util.concurrent.CompletableFuture<Fact[]> get​(FactPattern pattern)
        Get facts matching the provided pattern.

        Use ValueOfType or ValuePattern.ANY in the arguments list to represent wildcards.

        Parameters:
        pattern - The fact pattern to match.
        Returns:
        An array of facts matching the provided pattern.
      • delete

        public java.util.concurrent.CompletableFuture<java.lang.Void> delete​(Fact fact)
        Delete a single fact. Does not throw an exception if a matching fact does not exist.
        Parameters:
        fact - The fact to delete.
      • delete

        public java.util.concurrent.CompletableFuture<java.lang.Void> delete​(FactPattern pattern)
        Delete facts matching the provided pattern. Does not throw an exception if a matching fact does not exist.

        Use ValueOfType or ValuePattern.ANY in the arguments list to represent wildcards.

        Parameters:
        pattern - The fact pattern to match for deletion.
      • batch

        public java.util.concurrent.CompletableFuture<java.lang.Void> batch​(java.util.function.Consumer<BatchTransaction> fn)
        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 ValueOfType or ValuePattern.ANY in the arguments list passed to BatchTransaction.delete(FactPattern) to represent wildcards.

        Parameters:
        fn - The function which runs the inserts and deletes via the provided BatchTransaction.
      • list

        public java.util.concurrent.CompletableFuture<java.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 on
        Parameters:
        actor - The actor performing the action
        action - The action being performed
        resourceType - The type of resource to list
        contextFacts - 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
      • list

        public java.util.concurrent.CompletableFuture<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 on
        Parameters:
        actor - The actor performing the action
        action - The action being performed
        resourceType - The type of resource to list
        Returns:
        The resources of the provided type on which the actor is allowed to perform the action
      • actions

        public java.util.concurrent.CompletableFuture<java.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 resource
        Parameters:
        actor - The actor performing the action
        resource - The resource the action is being performed on
        contextFacts - Additional context to consider when making the decisions
        Returns:
        The actions the actor is allowed to perform on the resource
      • actions

        public java.util.concurrent.CompletableFuture<java.lang.String[]> actions​(Value actor,
                                                                                  Value resource)
        Get a list of actions an actor is allowed to perform on a resource
        Parameters:
        actor - The actor performing the action
        resource - The resource the action is being performed on
        Returns:
        The actions the actor is allowed to perform on the resource
      • authorizeLocal

        public java.util.concurrent.CompletableFuture<java.lang.String> authorizeLocal​(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.
        Parameters:
        actor - The actor performing the action
        action - The action being performed
        resource - The resource the action is being performed on
        contextFacts - Additional context to consider when making the decisions
        parityHandle - A handle to indicate the expected decision
        Returns:
        A SQL query to run against the local database
      • authorizeLocal

        public java.util.concurrent.CompletableFuture<java.lang.String> authorizeLocal​(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.
        Parameters:
        actor - The actor performing the action
        action - The action being performed
        resource - The resource the action is being performed on
        contextFacts - Additional context to consider when making the decisions
        Returns:
        A SQL query to run against the local database
      • authorizeLocal

        public java.util.concurrent.CompletableFuture<java.lang.String> authorizeLocal​(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.
        Parameters:
        actor - The actor performing the action
        action - The action being performed
        resource - The resource the action is being performed on
        parityHandle - A handle to indicate the expected decision
        Returns:
        A SQL query to run against the local database
      • authorizeLocal

        public java.util.concurrent.CompletableFuture<java.lang.String> authorizeLocal​(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.
        Parameters:
        actor - The actor performing the action
        action - The action being performed
        resource - The resource the action is being performed on
        Returns:
        A SQL query to run against the local database
      • listLocal

        public java.util.concurrent.CompletableFuture<java.lang.String> listLocal​(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.
        Parameters:
        actor - The actor performing the action
        action - The action being performed
        resourceType - The type of resource to list
        column - The name of the column that contains the resource ID
        Returns:
        A SQL query to run against the local database
      • listLocal

        public java.util.concurrent.CompletableFuture<java.lang.String> listLocal​(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.
        Parameters:
        actor - The actor performing the action
        action - The action being performed
        resourceType - The type of resource to list
        column - The name of the column that contains the resource ID
        contextFacts - Additional context to consider when making the decisions
        Returns:
        A SQL query to run against the local database
      • actionsLocal

        public java.util.concurrent.CompletableFuture<java.lang.String> actionsLocal​(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.
        Parameters:
        actor - The actor performing the action
        resource - The resource the action is being performed on
        Returns:
        A SQL query to run against the local database
      • actionsLocal

        public java.util.concurrent.CompletableFuture<java.lang.String> actionsLocal​(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.
        Parameters:
        actor - The actor performing the action
        resource - The resource the action is being performed on
        contextFacts - Additional context to consider when making the decisions
        Returns:
        A SQL query to run against the local database
      • buildQuery

        public AsyncQueryBuilder buildQuery​(java.lang.String predicate,
                                            QueryArg... args)
        Query for an arbitrary expression.
        Parameters:
        predicate - The predicate of the query
        args - The arguments to the predicate, which can be: - Concrete values created with Value constructors - Variables created with TypedVar constructor
        Returns:
        A QueryBuilder for chaining additional constraints

        Example: TypedVar actor = new TypedVar("actor"); AsyncQueryBuilder builder = oso.withAsyncExecutor(Executors.newSingleThreadExecutor()).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.