org.keycloak.models.utils

## Class KeycloakModelUtils

- java.lang.Object
- - org.keycloak.models.utils.KeycloakModelUtils

-     public final class KeycloakModelUtils
      extends Object

  Set of helper methods, which are useful in various model implementations.
  Author:
    Marek Posolda

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static ApplicationModel` | `createApplication(RealmModel realm, String name)`
    `static UserModel` | `findUserByNameOrEmail(KeycloakSession session, RealmModel realm, String username)` Try to find user by given username.
    `static String` | `generateId()`
    `static void` | `generateRealmKeys(RealmModel realm)`
    `static UserCredentialModel` | `generateSecret(ClientModel app)`
    `static String` | `getMasterRealmAdminApplicationName(RealmModel realm)`
    `static String` | `getPemFromKey(Key key)`
    `static PrivateKey` | `getPrivateKey(String privateKeyPem)`
    `static PublicKey` | `getPublicKey(String publicKeyPem)`
    `static void` | `runJobInTransaction(KeycloakSessionFactory factory, KeycloakSessionTask task)` Wrap given runnable job into KeycloakTransaction.
    `static boolean` | `searchFor(RoleModel role, RoleModel composite, Set<RoleModel> visited)` Deep search if given role is descendant of composite role

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### generateId

          public static String generateId()

    - #### getPublicKey

          public static PublicKey getPublicKey(String publicKeyPem)

    - #### getPrivateKey

          public static PrivateKey getPrivateKey(String privateKeyPem)

    - #### getPemFromKey

          public static String getPemFromKey(Key key)

    - #### generateRealmKeys

          public static void generateRealmKeys(RealmModel realm)

    - #### generateSecret

          public static UserCredentialModel generateSecret(ClientModel app)

    - #### createApplication

          public static ApplicationModel createApplication(RealmModel realm,
                                           String name)

    - #### searchFor

          public static boolean searchFor(RoleModel role,
                          RoleModel composite,
                          Set<RoleModel> visited)

      Deep search if given role is descendant of composite role
      Parameters:
        `role` - role to check
        `composite` - composite role
        `visited` - set of already visited roles (used for recursion)
      Returns:
        true if "role" is descendant of "composite"

    - #### findUserByNameOrEmail

          public static UserModel findUserByNameOrEmail(KeycloakSession session,
                                        RealmModel realm,
                                        String username)

      Try to find user by given username. If it fails, then fallback to find him by email
      Parameters:
        `realm` - realm
        `username` - username or email of user
      Returns:
        found user

    - #### runJobInTransaction

          public static void runJobInTransaction(KeycloakSessionFactory factory,
                                 KeycloakSessionTask task)

      Wrap given runnable job into KeycloakTransaction.
      Parameters:
        `factory` -
        `task` -

    - #### getMasterRealmAdminApplicationName

          public static String getMasterRealmAdminApplicationName(RealmModel realm)

Copyright © 2014. All Rights Reserved.