Class RolesPartialImport

  • All Implemented Interfaces:
    PartialImport<org.keycloak.representations.idm.RolesRepresentation>

    public class RolesPartialImport
    extends Object
    implements PartialImport<org.keycloak.representations.idm.RolesRepresentation>
    This class handles both realm roles and client roles. It delegates to RealmRolesPartialImport and ClientRolesPartialImport, which are no longer used directly by the PartialImportManager. The strategy is to utilize RepresentationToModel.importRoles(). That way, the complex code for bulk creation of roles is kept in one place. To do this, the logic for skip needs to remove the roles that are going to be skipped so that importRoles() doesn't know about them. The logic for overwrite needs to delete the overwritten roles before importRoles() is called.
    Author:
    Stan Silvert [email protected] (C) 2016 Red Hat Inc.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.keycloak.partialimport.PartialImportResults doImport​(org.keycloak.representations.idm.PartialImportRepresentation rep, org.keycloak.models.RealmModel realm, org.keycloak.models.KeycloakSession session)
      Create (or re-create) all the imported resources.
      void prepare​(org.keycloak.representations.idm.PartialImportRepresentation rep, org.keycloak.models.RealmModel realm, org.keycloak.models.KeycloakSession session)
      Find which resources will need to be skipped or overwritten.
      void removeOverwrites​(org.keycloak.models.RealmModel realm, org.keycloak.models.KeycloakSession session)
      Delete resources that will be overwritten.
    • Constructor Detail

      • RolesPartialImport

        public RolesPartialImport()
    • Method Detail

      • prepare

        public void prepare​(org.keycloak.representations.idm.PartialImportRepresentation rep,
                            org.keycloak.models.RealmModel realm,
                            org.keycloak.models.KeycloakSession session)
                     throws ErrorResponseException
        Description copied from interface: PartialImport
        Find which resources will need to be skipped or overwritten. Also, do a preliminary check for errors.
        Specified by:
        prepare in interface PartialImport<org.keycloak.representations.idm.RolesRepresentation>
        Parameters:
        rep - Everything in the PartialImport request.
        realm - Realm to be imported into.
        session - The KeycloakSession.
        Throws:
        ErrorResponseException - If the PartialImport can not be performed, throw this exception.
      • removeOverwrites

        public void removeOverwrites​(org.keycloak.models.RealmModel realm,
                                     org.keycloak.models.KeycloakSession session)
        Description copied from interface: PartialImport
        Delete resources that will be overwritten. This is done separately so that it can be called for all resource types before calling all the doImports. It was found that doing delete/add per resource causes errors because of cascading deletes.
        Specified by:
        removeOverwrites in interface PartialImport<org.keycloak.representations.idm.RolesRepresentation>
        Parameters:
        realm - Realm to be imported into.
        session - The KeycloakSession
      • doImport

        public org.keycloak.partialimport.PartialImportResults doImport​(org.keycloak.representations.idm.PartialImportRepresentation rep,
                                                                        org.keycloak.models.RealmModel realm,
                                                                        org.keycloak.models.KeycloakSession session)
                                                                 throws ErrorResponseException
        Description copied from interface: PartialImport
        Create (or re-create) all the imported resources.
        Specified by:
        doImport in interface PartialImport<org.keycloak.representations.idm.RolesRepresentation>
        Parameters:
        rep - Everything in the PartialImport request.
        realm - Realm to be imported into.
        session - The KeycloakSession.
        Returns:
        The final results of the PartialImport request.
        Throws:
        ErrorResponseException - if an error was detected trying to doImport a resource.