@Override
 public Identity getIdentity(Long id) {
   Account account = getAccountById(id);
   if (account == null || account.getKind().equalsIgnoreCase(ProjectConstants.TYPE)) {
     return null;
   }
   Credential credential =
       create()
           .selectFrom(CREDENTIAL)
           .where(
               CREDENTIAL
                   .KIND
                   .equalIgnoreCase(CredentialConstants.KIND_PASSWORD)
                   .and(CREDENTIAL.ACCOUNT_ID.eq(id))
                   .and(CREDENTIAL.STATE.equalIgnoreCase(CommonStatesConstants.ACTIVE)))
           .fetchAny();
   String accountId =
       (String)
           ApiContext.getContext()
               .getIdFormatter()
               .formatId(objectManager.getType(Account.class), account.getId());
   return new Identity(
       ProjectConstants.RANCHER_ID,
       accountId,
       account.getName(),
       null,
       null,
       credential == null ? null : credential.getPublicValue());
 }
 @Override
 public List<Account> searchUsers(String username) {
   return create()
       .select(ACCOUNT.fields())
       .from(ACCOUNT)
       .join(CREDENTIAL)
       .on(CREDENTIAL.ACCOUNT_ID.eq(ACCOUNT.ID))
       .where(
           ACCOUNT
               .STATE
               .eq(CommonStatesConstants.ACTIVE)
               .and(CREDENTIAL.STATE.eq(CommonStatesConstants.ACTIVE))
               .and(CREDENTIAL.PUBLIC_VALUE.contains(username))
               .and(CREDENTIAL.KIND.eq(CredentialConstants.KIND_PASSWORD)))
       .orderBy(ACCOUNT.ID.asc())
       .fetchInto(Account.class);
 }
 @Override
 public Account getByUsername(String username) {
   try {
     return create()
         .select(ACCOUNT.fields())
         .from(ACCOUNT)
         .join(CREDENTIAL)
         .on(CREDENTIAL.ACCOUNT_ID.eq(ACCOUNT.ID))
         .where(
             ACCOUNT
                 .STATE
                 .eq(CommonStatesConstants.ACTIVE)
                 .and(CREDENTIAL.STATE.eq(CommonStatesConstants.ACTIVE))
                 .and(CREDENTIAL.PUBLIC_VALUE.eq(username)))
         .and(CREDENTIAL.KIND.eq(CredentialConstants.KIND_PASSWORD))
         .fetchOneInto(AccountRecord.class);
   } catch (InvalidResultException e) {
     throw new ClientVisibleException(ResponseCodes.CONFLICT, "MultipleOfUsername");
   }
 }