Class QualifiedSubject

java.lang.Object
io.confluent.kafka.schemaregistry.utils.QualifiedSubject
All Implemented Interfaces:
Comparable<QualifiedSubject>

public class QualifiedSubject extends Object implements Comparable<QualifiedSubject>
A qualified subject consists of a tenant, a context, and a subject name. The qualification refers to the context and subject being qualified with a tenant. The qualified subject string has the following format:

[tenant_][:.context:]subject

where tenant is optional and defaults to "default", context is optional and defaults to ".", and subject is required and may be empty.

The special context name ".__GLOBAL" is used for global configuration and mode settings. The special subject name "__GLOBAL" is used to store global permissions. The special subject name "__EMPTY" represents an empty string.

  • Field Details

  • Constructor Details

    • QualifiedSubject

      protected QualifiedSubject(String tenant, String qualifiedSubject)
    • QualifiedSubject

      public QualifiedSubject(String tenant, String context, String subject)
  • Method Details

    • getTenant

      public String getTenant()
    • getContext

      public String getContext()
    • getSubject

      public String getSubject()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toQualifiedContext

      public String toQualifiedContext()
    • toUnqualifiedContext

      public String toUnqualifiedContext()
      Returns the context without the tenant prefix.
    • toQualifiedSubject

      public String toQualifiedSubject()
      Returns the context and subject with the tenant prefix.
    • toUnqualifiedSubject

      public String toUnqualifiedSubject()
      Returns the context and subject without the tenant prefix.
    • isQualified

      public static boolean isQualified(String tenant, String qualifiedSubject)
      Checks if the given subject is qualified with the given tenant.
      Parameters:
      tenant - the tenant
      qualifiedSubject - the subject with a tenant prefix
      Returns:
      true if the subject is qualified with the tenant, false otherwise
    • create

      public static QualifiedSubject create(String tenant, String qualifiedSubject)
      Creates a QualifiedSubject from the given tenant and qualified subject.
      Parameters:
      tenant - the tenant
      qualifiedSubject - the subject with a tenant prefix
      Returns:
      the QualifiedSubject, or null if the qualified subject is null or invalid
    • createFromUnqualified

      public static QualifiedSubject createFromUnqualified(String tenant, String unqualifiedSubject)
      Creates a QualifiedSubject from the given tenant and unqualified subject.
      Parameters:
      tenant - the tenant
      unqualifiedSubject - the subject without a tenant prefix
      Returns:
      the QualifiedSubject, or null if the unqualified subject is null or invalid
    • contextFor

      public static String contextFor(String tenant, String qualifiedSubject)
      Returns the context for the given qualified subject.
      Parameters:
      tenant - the tenant
      qualifiedSubject - the subject with a tenant prefix
      Returns:
      the context, or DEFAULT_CONTEXT if the qualified subject is null or invalid
    • qualifiedContextFor

      public static String qualifiedContextFor(String tenant, String qualifiedSubject)
      Returns the qualified context for the given qualified subject.
      Parameters:
      tenant - the tenant
      qualifiedSubject - the subject with a tenant prefix
      Returns:
      the qualified context, or empty string if the qualified subject is null or invalid
    • isSubjectInContext

      public static boolean isSubjectInContext(String tenant, String qualifiedSubject, QualifiedSubject qualifiedContext)
      Checks if the given qualified subject is a context for the given qualified subject.
      Parameters:
      tenant - the tenant
      qualifiedSubject - the subject with a tenant prefix
      qualifiedContext - the context with a tenant prefix, which must not specify a subject
      Returns:
      true if the subject is in the context, false otherwise
    • qualifySubjectWithParent

      public static QualifiedSubject qualifySubjectWithParent(String tenant, String parent, String subjectWithoutTenant)
      Qualifies the given subject (which has no tenant) with the given parent context (which may have a tenant). If the parent has a context, it is used as the context for the subject. If the parent has no context, the subject is placed in the default context.
      Parameters:
      tenant - the tenant to use if the parent has no tenant
      parent - the parent context, which may have a tenant
      subjectWithoutTenant - the subject without a tenant
      Returns:
      the qualified subject, or null if the subjectWithoutTenant is null or invalid
    • qualifySubjectWithParent

      public static QualifiedSubject qualifySubjectWithParent(String tenant, String parent, String subjectWithoutTenant, boolean prefixTenant)
      Qualifies the given subject (which has no tenant) with the given parent context (which may have a tenant). If the parent has a context, it is used as the context for the subject. If the parent has no context, the subject is placed in the default context.
      Parameters:
      tenant - the tenant to use if the parent has no tenant
      parent - the parent context, which may have a tenant
      subjectWithoutTenant - the subject without a tenant
      prefixTenant - if true, the returned qualified subject will have the tenant prefixed
      Returns:
      the qualified subject, or null if the subjectWithoutTenant is null or invalid
    • normalize

      public static String normalize(String tenant, String qualifiedSubject)
      Normalizes the given qualified subject name.
      Parameters:
      tenant - the tenant
      qualifiedSubject - the subject with a tenant prefix
      Returns:
      the normalized subject name
    • normalizeContext

      public static String normalizeContext(String context)
      Normalizes the given context name.
      Parameters:
      context - the context name
      Returns:
      the normalized context name, or null if the context is null
      Throws:
      IllegalArgumentException - if the context name is invalid
    • isContext

      public static boolean isContext(String tenant, String qualifiedSubject)
      Checks if the given qualified subject represents a context (i.e., has no subject part). A context has the format ":.context:" with an empty subject part, or null for default context.
      Parameters:
      tenant - the tenant
      qualifiedSubject - the subject with a tenant prefix
      Returns:
      true if the qualified subject is a context, false otherwise
    • isDefaultContext

      public static boolean isDefaultContext(String tenant, String qualifiedSubject)
      Checks if the given qualified subject is the default context for the given tenant. The default context is the context with name "." and an empty subject.
      Parameters:
      tenant - the tenant
      qualifiedSubject - the subject with a tenant prefix
      Returns:
      true if the qualified subject is the default context, false otherwise
    • isGlobalContext

      public static boolean isGlobalContext(String tenant, String qualifiedSubject)
      Checks if the given qualified subject is the global context for the given tenant. The global context is the context with name ".__GLOBAL" and an empty subject.
      Parameters:
      tenant - the tenant
      qualifiedSubject - the subject with a tenant prefix
      Returns:
      true if the qualified subject is the global context, false otherwise
    • isValidSubject

      public static boolean isValidSubject(String tenant, String qualifiedSubject)
      Validates the given qualified subject for the given tenant. A valid subject must not be null, must not contain control characters, must not be "__GLOBAL" or "__EMPTY", and must not be in the global context unless isConfigOrMode is true.
      Parameters:
      tenant - the tenant
      qualifiedSubject - the subject with a tenant prefix
      Returns:
      true if the qualified subject is valid, false otherwise
    • isValidSubject

      public static boolean isValidSubject(String tenant, String qualifiedSubject, boolean isConfigOrMode)
      Validates the given qualified subject for the given tenant. A valid subject must not be null, must not contain control characters, must not be "__GLOBAL" or "__EMPTY", and must not be in the global context unless isConfigOrMode is true.
      Parameters:
      tenant - the tenant
      qualifiedSubject - the subject with a tenant prefix
      isConfigOrMode - true if the subject is for config or mode settings
      Returns:
      true if the qualified subject is valid, false otherwise
    • compareTo

      public int compareTo(QualifiedSubject that)
      Specified by:
      compareTo in interface Comparable<QualifiedSubject>