當前位置: 首頁>>代碼示例>>Java>>正文


Java UserResource.toRepresentation方法代碼示例

本文整理匯總了Java中org.keycloak.admin.client.resource.UserResource.toRepresentation方法的典型用法代碼示例。如果您正苦於以下問題:Java UserResource.toRepresentation方法的具體用法?Java UserResource.toRepresentation怎麽用?Java UserResource.toRepresentation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.keycloak.admin.client.resource.UserResource的用法示例。


在下文中一共展示了UserResource.toRepresentation方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setUserPassword

import org.keycloak.admin.client.resource.UserResource; //導入方法依賴的package包/類
public void setUserPassword(String realmId, String username, String newPassword) {
    List<UserRepresentation> retrieveUserList = client.realm(realmId).users().search(username,
            null,
            null,
            null,
            0, 1);
    if (!retrieveUserList.isEmpty()) {
        UserResource retrievedUser = client.realm(realmId).users().get(retrieveUserList.get(0).getId());
        CredentialRepresentation credential = new CredentialRepresentation();
        credential.setType(CredentialRepresentation.PASSWORD);
        credential.setValue(newPassword);
        credential.setTemporary(false);
        retrievedUser.resetPassword(credential);
        // Remove the UPDATE_PASSWORD required action
        UserRepresentation userRepresentation = retrievedUser.toRepresentation();
        userRepresentation.getRequiredActions().remove("UPDATE_PASSWORD");
        retrievedUser.update(userRepresentation);
    } else {
        throw new RuntimeException("Requested user not found");
    }
}
 
開發者ID:apache,項目名稱:airavata,代碼行數:22,代碼來源:KeycloakIdentityServerClient.java

示例2: getEmailVerifiedUpdatedFlag

import org.keycloak.admin.client.resource.UserResource; //導入方法依賴的package包/類
@Override
public String getEmailVerifiedUpdatedFlag(String userId) {
  UserResource resource =
      keycloak.realm(KeyCloakConnectionProvider.SSO_REALM).users().get(userId);
  UserRepresentation user = resource.toRepresentation();
  Map<String, List<String>> map = user.getAttributes();
  List<String> list = map.get(JsonKey.EMAIL_VERIFIED_UPDATED);
  if (!list.isEmpty()) {
    return list.get(0);
  } else {
    return "";
  }
}
 
開發者ID:project-sunbird,項目名稱:sunbird-utils,代碼行數:14,代碼來源:KeyCloakServiceImpl.java

示例3: getLastLoginTime

import org.keycloak.admin.client.resource.UserResource; //導入方法依賴的package包/類
@Override
public String getLastLoginTime(String userId) {
  String lastLoginTime = null;
  try {
    UserResource resource =
        keycloak.realm(KeyCloakConnectionProvider.SSO_REALM).users().get(userId);
    UserRepresentation ur = resource.toRepresentation();
    Map<String, List<String>> map = ur.getAttributes();
    if (map == null) {
      map = new HashMap<>();
    }
    List<String> list = map.get(JsonKey.LAST_LOGIN_TIME);
    if (list != null && !list.isEmpty()) {
      lastLoginTime = list.get(0);
    }
  } catch (Exception e) {
    ProjectLogger.log(e.getMessage(), e);
  }
  return lastLoginTime;
}
 
開發者ID:project-sunbird,項目名稱:sunbird-utils,代碼行數:21,代碼來源:KeyCloakServiceImpl.java

示例4: setEmailVerifiedTrue

import org.keycloak.admin.client.resource.UserResource; //導入方法依賴的package包/類
@Override
public String setEmailVerifiedTrue(String userId) {
  try {
    UserResource resource =
        keycloak.realm(KeyCloakConnectionProvider.SSO_REALM).users().get(userId);
    UserRepresentation ur = resource.toRepresentation();
    ur.setEmailVerified(true);
    if (isNotNull(resource)) {
      try {
        resource.update(ur);
      } catch (Exception ex) {
        ProjectLogger.log(ex.getMessage(), ex);
        throw new ProjectCommonException(ResponseCode.invalidUsrData.getErrorCode(),
            ResponseCode.invalidUsrData.getErrorMessage(),
            ResponseCode.CLIENT_ERROR.getResponseCode());
      }

    }
  } catch (Exception e) {
    ProjectLogger.log(e.getMessage(), e);
    throw new ProjectCommonException(ResponseCode.invalidUsrData.getErrorCode(),
        ResponseCode.invalidUsrData.getErrorMessage(),
        ResponseCode.CLIENT_ERROR.getResponseCode());
  }
  return JsonKey.SUCCESS;
}
 
開發者ID:project-sunbird,項目名稱:sunbird-utils,代碼行數:27,代碼來源:KeyCloakServiceImpl.java

示例5: setEmailVerifiedAsFalse

import org.keycloak.admin.client.resource.UserResource; //導入方法依賴的package包/類
@Override
public String setEmailVerifiedAsFalse(String userId) {
  try {
    UserResource resource =
        keycloak.realm(KeyCloakConnectionProvider.SSO_REALM).users().get(userId);
    UserRepresentation ur = resource.toRepresentation();
    ur.setEmailVerified(false);
    if (isNotNull(resource)) {
      try {
        resource.update(ur);
      } catch (Exception ex) {
        ProjectLogger.log(ex.getMessage(), ex);
        throw new ProjectCommonException(ResponseCode.invalidUsrData.getErrorCode(),
            ResponseCode.invalidUsrData.getErrorMessage(),
            ResponseCode.CLIENT_ERROR.getResponseCode());
      }

    }
  } catch (Exception e) {
    ProjectLogger.log(e.getMessage(), e);
    throw new ProjectCommonException(ResponseCode.invalidUsrData.getErrorCode(),
        ResponseCode.invalidUsrData.getErrorMessage(),
        ResponseCode.CLIENT_ERROR.getResponseCode());
  }
  return JsonKey.SUCCESS;
}
 
開發者ID:project-sunbird,項目名稱:sunbird-utils,代碼行數:27,代碼來源:KeyCloakServiceImpl.java

示例6: deactivateUser

import org.keycloak.admin.client.resource.UserResource; //導入方法依賴的package包/類
/**
 * Method to deactivate the user on basis of user id.
 *
 * @param request Map
 * @return boolean true if success otherwise false .
 */
@Override
public String deactivateUser(Map<String, Object> request) {
  try {
    Keycloak keycloak = KeyCloakConnectionProvider.getConnection();
    String userId = (String) request.get(JsonKey.USER_ID);
    UserResource resource =
        keycloak.realm(KeyCloakConnectionProvider.SSO_REALM).users().get(userId);
    UserRepresentation ur = resource.toRepresentation();
    ur.setEnabled(false);
    if (isNotNull(resource)) {
      try {
        resource.update(ur);
      } catch (Exception ex) {
        ProjectLogger.log(ex.getMessage(), ex);
        throw new ProjectCommonException(ResponseCode.invalidUsrData.getErrorCode(),
            ResponseCode.invalidUsrData.getErrorMessage(),
            ResponseCode.CLIENT_ERROR.getResponseCode());
      }

    }
  } catch (Exception e) {
    ProjectLogger.log(e.getMessage(), e);
    throw new ProjectCommonException(ResponseCode.invalidUsrData.getErrorCode(),
        ResponseCode.invalidUsrData.getErrorMessage(),
        ResponseCode.CLIENT_ERROR.getResponseCode());
  }
  return JsonKey.SUCCESS;
}
 
開發者ID:project-sunbird,項目名稱:sunbird-utils,代碼行數:35,代碼來源:KeyCloakServiceImpl.java

示例7: setEmailVerifiedUpdatedFlag

import org.keycloak.admin.client.resource.UserResource; //導入方法依賴的package包/類
@Override
public void setEmailVerifiedUpdatedFlag(String userId, String flag) {
  UserResource resource =
      keycloak.realm(KeyCloakConnectionProvider.SSO_REALM).users().get(userId);
  UserRepresentation user = resource.toRepresentation();
  Map<String, List<String>> map = user.getAttributes();
  List<String> list = new ArrayList<>();
  list.add(flag);
  if (map == null) {
    map = new HashMap<>();
  }
  map.put(JsonKey.EMAIL_VERIFIED_UPDATED, list);
  user.setAttributes(map);
  resource.update(user);
}
 
開發者ID:project-sunbird,項目名稱:sunbird-utils,代碼行數:16,代碼來源:KeyCloakServiceImpl.java

示例8: addUserLoginTime

import org.keycloak.admin.client.resource.UserResource; //導入方法依賴的package包/類
@Override
public boolean addUserLoginTime(String userId) {
  boolean response = true;
  try {
    UserResource resource =
        keycloak.realm(KeyCloakConnectionProvider.SSO_REALM).users().get(userId);
    UserRepresentation ur = resource.toRepresentation();
    Map<String, List<String>> map = ur.getAttributes();
    List<String> list = new ArrayList<>();
    if (map == null) {
      map = new HashMap<>();
    }
    List<String> currentLogTime = map.get(JsonKey.CURRENT_LOGIN_TIME);
    if (currentLogTime == null || currentLogTime.isEmpty()) {
      currentLogTime = new ArrayList<>();
      currentLogTime.add(Long.toString(System.currentTimeMillis()));
    } else {
      list.add(currentLogTime.get(0));
      currentLogTime.clear();
      currentLogTime.add(0, Long.toString(System.currentTimeMillis()));
    }
    map.put(JsonKey.CURRENT_LOGIN_TIME, currentLogTime);
    map.put(JsonKey.LAST_LOGIN_TIME, list);
    ur.setAttributes(map);
    resource.update(ur);
  } catch (Exception e) {
    ProjectLogger.log(e.getMessage(), e);
    response = false;
  }
  return response;
}
 
開發者ID:project-sunbird,項目名稱:sunbird-utils,代碼行數:32,代碼來源:KeyCloakServiceImpl.java

示例9: enableUserAccount

import org.keycloak.admin.client.resource.UserResource; //導入方法依賴的package包/類
@Override
public boolean enableUserAccount(PasswordCredential realmAdminCreds, String tenantId, String username) throws IamAdminServicesException{
    Keycloak client = null;
    try{
        client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), tenantId, realmAdminCreds);
        List<UserRepresentation> userResourceList = client.realm(tenantId).users().search(username,0,1);
        UserResource userResource = client.realm(tenantId).users().get(userResourceList.get(0).getId());
        UserRepresentation profile = userResource.toRepresentation();
        profile.setEnabled(true);
        // We require that a user verify their email before enabling the account
        profile.setEmailVerified(true);
        userResource.update(profile);
        return true;
    } catch (ApplicationSettingsException ex) {
        logger.error("Error getting values from property file, reason: " + ex.getMessage(), ex);
        IamAdminServicesException exception = new IamAdminServicesException();
        exception.setMessage("Error getting values from property file, reason " + ex.getMessage());
        throw exception;
    } finally {
        if (client != null) {
            client.close();
        }
    }
}
 
開發者ID:apache,項目名稱:airavata,代碼行數:25,代碼來源:TenantManagementKeycloakImpl.java

示例10: activateUser

import org.keycloak.admin.client.resource.UserResource; //導入方法依賴的package包/類
/**
 * Method to activate the user on basis of user id.
 *
 * @param request Map
 * @return boolean true if success otherwise false .
 */
@Override
public String activateUser(Map<String, Object> request) {
  try {
    Keycloak keycloak = KeyCloakConnectionProvider.getConnection();
    String userId = (String) request.get(JsonKey.USER_ID);
    UserResource resource =
        keycloak.realm(KeyCloakConnectionProvider.SSO_REALM).users().get(userId);
    UserRepresentation ur = resource.toRepresentation();
    ur.setEnabled(true);
    if (isNotNull(resource)) {
      try {
        resource.update(ur);
      } catch (Exception ex) {
        ProjectLogger.log(ex.getMessage(), ex);
        throw new ProjectCommonException(ResponseCode.invalidUsrData.getErrorCode(),
            ResponseCode.invalidUsrData.getErrorMessage(),
            ResponseCode.CLIENT_ERROR.getResponseCode());
      }

    }
  } catch (Exception e) {
    ProjectLogger.log(e.getMessage(), e);
    throw new ProjectCommonException(ResponseCode.invalidUsrData.getErrorCode(),
        ResponseCode.invalidUsrData.getErrorMessage(),
        ResponseCode.CLIENT_ERROR.getResponseCode());
  }
  return JsonKey.SUCCESS;
}
 
開發者ID:project-sunbird,項目名稱:sunbird-utils,代碼行數:35,代碼來源:KeyCloakServiceImpl.java


注:本文中的org.keycloak.admin.client.resource.UserResource.toRepresentation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。