Class JpaOrganizationProvider

java.lang.Object
org.keycloak.organization.jpa.JpaOrganizationProvider
All Implemented Interfaces:
OrganizationProvider, Provider

public class JpaOrganizationProvider extends Object implements OrganizationProvider
  • Constructor Details

    • JpaOrganizationProvider

      public JpaOrganizationProvider(KeycloakSession session)
  • Method Details

    • create

      public OrganizationModel create(String name)
      Description copied from interface: OrganizationProvider
      Creates a new organization with given name to the realm. The internal ID of the organization will be created automatically.
      Specified by:
      create in interface OrganizationProvider
      Parameters:
      name - String name of the organization.
      Returns:
      Model of the created organization.
    • remove

      public boolean remove(OrganizationModel organization)
      Description copied from interface: OrganizationProvider
      Removes the given organization from the realm together with the data associated with it, e.g. its members etc.
      Specified by:
      remove in interface OrganizationProvider
      Parameters:
      organization - Organization to be removed.
      Returns:
      true if the organization was removed, false otherwise
    • removeAll

      public void removeAll()
      Description copied from interface: OrganizationProvider
      Removes all organizations from the realm.
      Specified by:
      removeAll in interface OrganizationProvider
    • addMember

      public boolean addMember(OrganizationModel organization, UserModel user)
      Description copied from interface: OrganizationProvider
      Adds the given UserModel as a member of the given OrganizationModel.
      Specified by:
      addMember in interface OrganizationProvider
      Parameters:
      organization - the organization
      user - the user
      Returns:
      true if the user was added as a member. Otherwise, returns false
    • getById

      public OrganizationModel getById(String id)
      Description copied from interface: OrganizationProvider
      Returns a OrganizationModel by its id;
      Specified by:
      getById in interface OrganizationProvider
      Parameters:
      id - the id of an organization
      Returns:
      the organization with the given id or null if there is no such an organization.
    • getByDomainName

      public OrganizationModel getByDomainName(String domain)
      Description copied from interface: OrganizationProvider
      Returns a OrganizationModel by its internet domain.
      Specified by:
      getByDomainName in interface OrganizationProvider
      Parameters:
      domain - the organization's internet domain (e.g. redhat.com)
      Returns:
      the organization that is linked to the given internet domain
    • getAllStream

      public Stream<OrganizationModel> getAllStream(String search, Boolean exact, Integer first, Integer max)
      Description copied from interface: OrganizationProvider
      Returns all organizations in the realm filtered according to the specified parameters.
      Specified by:
      getAllStream in interface OrganizationProvider
      Parameters:
      search - a String representing either an organization name or domain.
      exact - if true, the organizations will be searched using exact match for the search param - i.e. either the organization name or one of its domains must match exactly the search param. If false, the method returns all organizations whose name or (domains) partially match the search param.
      first - the position of the first result to be processed (pagination offset). Ignored if negative or null.
      max - the maximum number of results to be returned. Ignored if negative or null.
      Returns:
      a Stream of the matched organizations. Never returns null.
    • getAllStream

      public Stream<OrganizationModel> getAllStream(Map<String,String> attributes, Integer first, Integer max)
      Description copied from interface: OrganizationProvider
      Returns all organizations in the realm filtered according to the specified parameters.
      Specified by:
      getAllStream in interface OrganizationProvider
      Parameters:
      attributes - a Map containig the attributes (name/value) that must match organization attributes.
      first - the position of the first result to be processed (pagination offset). Ignored if negative or null.
      max - the maximum number of results to be returned. Ignored if negative or null.
      Returns:
      a Stream of the matched organizations. Never returns null.
    • getMembersStream

      public Stream<UserModel> getMembersStream(OrganizationModel organization, String search, Boolean exact, Integer first, Integer max)
      Description copied from interface: OrganizationProvider
      Returns the members of a given OrganizationModel filtered according to the specified parameters.
      Specified by:
      getMembersStream in interface OrganizationProvider
      Parameters:
      organization - the organization
      Returns:
      Stream of the members. Never returns null.
    • getMemberById

      public UserModel getMemberById(OrganizationModel organization, String id)
      Description copied from interface: OrganizationProvider
      Returns the member of the OrganizationModel by its id.
      Specified by:
      getMemberById in interface OrganizationProvider
      Parameters:
      organization - the organization
      id - the member id
      Returns:
      the member of the OrganizationModel with the given id
    • getByMember

      public OrganizationModel getByMember(UserModel member)
      Description copied from interface: OrganizationProvider
      Returns the OrganizationModel that the member belongs to.
      Specified by:
      getByMember in interface OrganizationProvider
      Parameters:
      member - the member of a organization
      Returns:
      the organization the member belongs to or null if the user doesn't belong to any.
    • addIdentityProvider

      public boolean addIdentityProvider(OrganizationModel organization, IdentityProviderModel identityProvider)
      Description copied from interface: OrganizationProvider
      Associate the given IdentityProviderModel with the given OrganizationModel.
      Specified by:
      addIdentityProvider in interface OrganizationProvider
      Parameters:
      organization - the organization
      identityProvider - the identityProvider
      Returns:
      true if the identityProvider was associated with the organization. Otherwise, returns false
    • getIdentityProviders

      public Stream<IdentityProviderModel> getIdentityProviders(OrganizationModel organization)
      Specified by:
      getIdentityProviders in interface OrganizationProvider
      Parameters:
      organization - the organization
      Returns:
      The identityProvider associated with a given organization or null if there is none.
    • removeIdentityProvider

      public boolean removeIdentityProvider(OrganizationModel organization, IdentityProviderModel identityProvider)
      Description copied from interface: OrganizationProvider
      Removes the link between the given OrganizationModel and identity provider associated with it if such a link exists.
      Specified by:
      removeIdentityProvider in interface OrganizationProvider
      Parameters:
      organization - the organization
      identityProvider - the identity provider
      Returns:
      true if the link was removed, false otherwise
    • isManagedMember

      public boolean isManagedMember(OrganizationModel organization, UserModel member)
      Description copied from interface: OrganizationProvider

      Indicates if the given member is managed by the organization.

      A member is managed by the organization whenever the member cannot exist without the organization they belong to so that their lifecycle is bound to the organization lifecycle. For instance, when a member is federated from the identity provider associated with an organization, there is a strong relationship between the member identity and the organization.

      On the other hand, existing realm users whose identities are not intrinsically linked to an organization but are eventually joining an organization are not managed by the organization. They have a lifecycle that does not depend on the organization they are linked to.

      Specified by:
      isManagedMember in interface OrganizationProvider
      Parameters:
      organization - the organization
      member - the member
      Returns:
      true if the member is managed by the given organization. Otherwise, returns false
    • removeMember

      public boolean removeMember(OrganizationModel organization, UserModel member)
      Description copied from interface: OrganizationProvider

      Removes a member from the organization.

      This method can either remove the given member entirely from the realm (and the organization) or only remove the link to the organization so that the user still exists but is no longer a member of the organization. The decision to remove the user entirely or only the link depends on whether the user is managed by the organization or not, respectively.

      Specified by:
      removeMember in interface OrganizationProvider
      Parameters:
      organization - the organization
      member - the member
      Returns:
      true if the given member is a member and was successfully removed from the organization. Otherwise, returns false
    • count

      public long count()
      Description copied from interface: OrganizationProvider
      Returns number of organizations in the realm.
      Specified by:
      count in interface OrganizationProvider
      Returns:
      long Number of organizations
    • isEnabled

      public boolean isEnabled()
      Description copied from interface: OrganizationProvider
      Indicates if the current realm supports organization.
      Specified by:
      isEnabled in interface OrganizationProvider
      Returns:
      true if organization is supported. Otherwise, returns false
    • close

      public void close()
      Specified by:
      close in interface Provider