Class ContextPolicyEnforcementPoint

java.lang.Object
org.gcube.informationsystem.resourceregistry.pep.PolicyEnforcementPoint
org.gcube.informationsystem.resourceregistry.contexts.ContextPolicyEnforcementPoint

public class ContextPolicyEnforcementPoint extends PolicyEnforcementPoint
Policy Enforcement Point (PEP) for the Context collection.

Applies role-based visibility filtering on top of the raw context data served by ContextRepository (Redis-first, DB fallback) and enforces administrative write-permission rules before delegating mutations.

ContextRepository has zero auth logic and zero visibility filters. This class owns all role/visibility policy and is the single entry point for REST-facing context operations.

Internal reads that need unfiltered data (e.g. state checks, path lookups) must go directly through ContextRepository.

Author:
Luca Frosini (ISTI - CNR)
  • Constructor Details

    • ContextPolicyEnforcementPoint

      public ContextPolicyEnforcementPoint(jakarta.ws.rs.container.ContainerRequestContext requestContext)
      Creates a new PEP instance for the current HTTP request.
      Parameters:
      requestContext - the JAX-RS ContainerRequestContext for the current request
  • Method Details

    • setBypassRootScopeCheck

      public void setBypassRootScopeCheck(boolean bypass)
      Sets whether the Root Context Bootstrap Exception's token-scope check should be bypassed. Internal API only — must never be wired to a REST query parameter.
      Parameters:
      bypass - true to bypass the check, false for normal enforcement
    • isBypassRootScopeCheck

      public boolean isBypassRootScopeCheck()
      Returns whether the Root Context Bootstrap Exception's token-scope check is currently bypassed.
      Returns:
      true if bypassed, false otherwise
    • readCurrent

      public String readCurrent() throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Returns the role-filtered JSON for the context associated with the caller's current authorization token, resolving the context UUID from the request environment.
      Returns:
      role-filtered JSON string for the current context
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if the context cannot be found or read
    • read

      public String read(UUID uuid) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Returns the role-filtered JSON for the context identified by uuid. Delegates data retrieval to ContextRepository.read(UUID, int, ContextProjection, ContextLifecycle) (Redis-first, DB fallback) and then applies the visibility filter for the current request.

      Query parameters are validated before the read; unrecognised or inapplicable parameters accumulate as X-Warning entries (see PolicyEnforcementPoint.getAllWarnings()).

      Parameters:
      uuid - the UUID of the context to read
      Returns:
      role-filtered JSON string
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if the context cannot be found or read
    • all

      public PageResult all() throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Returns the role-filtered, paginated JSON array of all contexts as a PageResult. Equivalent to all(false).
      Returns:
      PageResult with the page JSON and pagination state
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if contexts cannot be read
    • all

      public PageResult all(boolean polymorphic) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Returns the role-filtered, paginated JSON array of all contexts as a PageResult.

      Resolves limit, offset, and visibility flags from the current request and delegates to ContextRepository.all(boolean, ContextProjection, int, int, ContextLifecycle).

      Parameters:
      polymorphic - whether to include subclasses of Context
      Returns:
      PageResult with the page JSON and pagination state
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if contexts cannot be read
    • query

      public PageResult query(String jsonQuery) throws org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException, org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Executes a JSON query against the Context collection under authorized constraints, returning a role-filtered, paginated PageResult.

      Resolves limit, offset, lifecycle, and visibility flags from the current request and delegates to ContextRepository.query(String, ContextProjection, int, int, ContextLifecycle).

      Parameters:
      jsonQuery - the JSON query payload describing the Context search criteria
      Returns:
      PageResult with the page JSON and pagination state
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException - if the query syntax or structure is invalid
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if contexts cannot be read
    • create

      public ContextCreationResult create(UUID uuid, String json) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Creates a Context after validating its complete creation representation and strict immediate-parent authorization scope.

      The body must explicitly define matching id, valid name, and parent; a JSON null parent denotes Root creation. For a Root Context, enforceRootScopeCheck(String) additionally validates that the caller's token was issued for that exact Root Context, unless setBypassRootScopeCheck(boolean) was set by an internal caller. A deleted Root with the same path does not prevent the creation.

      Parameters:
      uuid - the UUID of the context to create
      json - the JSON body of the request
      Returns:
      the ContextCreationResult wrapping the serialized JSON of the created Context and whether a brand new Context was registered (created = false for an idempotent re-submit of an already-existing, congruent Context)
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if the operation fails
    • changeState

      public String changeState(UUID uuid, String json) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Applies a validated tracked update to an existing live Context under immediate-parent scope or, for a reparenting, under the scope of the closest common ancestor of the two parents.
      Parameters:
      uuid - the UUID of the context
      json - the JSON merge-patch containing state, name, parent, or previousPaths
      Returns:
      the serialized JSON of the updated context
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if the operation fails
    • delete

      public void delete(UUID uuid) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Moves the live Context identified by uuid to the cemetery under strict parent scope. Deleting a Context that is already in the cemetery is a no-op for the global managers.
      Parameters:
      uuid - the UUID of the context to delete
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if the operation fails
    • readHistory

      public String readHistory(UUID uuid) throws org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException
      Reads the reverse-chronological audit trail of the Context identified by uuid, enforcing administrative read privileges and the role-specific token scope.

      Only IS-Manager, Infrastructure-Manager, IS-Admin, and Context-Manager are authorized to view Context history (see enforceHistoryReadScope(UUID)). The who of every event is returned in full to the universal roles and as "[REDACTED]" to Context-Manager.

      Parameters:
      uuid - the UUID of the context whose history to read
      Returns:
      JSON array string of history events, newest first
      Throws:
      org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException - if the lookup fails, or if the caller lacks authorization