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 void` | `generateClientKeyPairCertificate(ClientModel client)`
    `static String` | `generateCodeSecret()`
    `static String` | `generateId()`
    `static void` | `generateRealmCertificate(RealmModel realm)`
    `static void` | `generateRealmKeys(RealmModel realm)`
    `static UserCredentialModel` | `generateSecret(ClientModel app)`
    `static X509Certificate` | `getCertificate(String cert)`
    `static String` | `getMasterRealmAdminApplicationName(RealmModel realm)`
    `static String` | `getPemFromCertificate(X509Certificate certificate)`
    `static String` | `getPemFromKey(Key key)`
    `static PrivateKey` | `getPrivateKey(String privateKeyPem)`
    `static PublicKey` | `getPublicKey(String publicKeyPem)`
    `static Key` | `getSecretKey(String secret)`
    `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)

    - #### getCertificate

          public static X509Certificate getCertificate(String cert)

    - #### getPrivateKey

          public static PrivateKey getPrivateKey(String privateKeyPem)

    - #### getSecretKey

          public static Key getSecretKey(String secret)

    - #### getPemFromKey

          public static String getPemFromKey(Key key)

    - #### getPemFromCertificate

          public static String getPemFromCertificate(X509Certificate certificate)

    - #### generateRealmKeys

          public static void generateRealmKeys(RealmModel realm)

    - #### generateRealmCertificate

          public static void generateRealmCertificate(RealmModel realm)

    - #### generateClientKeyPairCertificate

          public static void generateClientKeyPairCertificate(ClientModel client)

    - #### generateSecret

          public static UserCredentialModel generateSecret(ClientModel app)

    - #### generateCodeSecret

          public static String generateCodeSecret()

    - #### 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 © 2015. All rights reserved.