当前位置: 首页>>代码示例>>Java>>正文


Java UserResource类代码示例

本文整理汇总了Java中org.keycloak.admin.client.resource.UserResource的典型用法代码示例。如果您正苦于以下问题:Java UserResource类的具体用法?Java UserResource怎么用?Java UserResource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


UserResource类属于org.keycloak.admin.client.resource包,在下文中一共展示了UserResource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: doPasswordUpdate

import org.keycloak.admin.client.resource.UserResource; //导入依赖的package包/类
/**
  * This method will do the user password update.
  * @param userId String
  * @param password String
  * @return boolean true/false
  */
 @Override
 public boolean doPasswordUpdate(String userId, String password) {
 boolean response = false;
try {  
   UserResource resource =
       keycloak.realm(KeyCloakConnectionProvider.SSO_REALM).users().get(userId);
   CredentialRepresentation newCredential = new CredentialRepresentation();
   newCredential.setValue(password);
   newCredential.setType(CredentialRepresentation.PASSWORD);
   newCredential.setTemporary(true);
   resource.resetPassword(newCredential);
   response = true;
   } catch (Exception ex) {
    ProjectLogger.log(ex.getMessage(),ex);
   }
return response;
 }
 
开发者ID:project-sunbird,项目名称:sunbird-utils,代码行数:24,代码来源:KeyCloakServiceImpl.java

示例3: removeUser

import org.keycloak.admin.client.resource.UserResource; //导入依赖的package包/类
/**
 * Method to remove the user on basis of user id.
 *
 * @param request Map
 * @return boolean true if success otherwise false .
 */
@Override
public String removeUser(Map<String, Object> request) {
  Keycloak keycloak = KeyCloakConnectionProvider.getConnection();
  String userId = (String) request.get(JsonKey.USER_ID);
  UserResource resource =
      keycloak.realm(KeyCloakConnectionProvider.SSO_REALM).users().get(userId);

  if (isNotNull(resource)) {
    try {
      resource.remove();
    } catch (Exception ex) {
      throw new ProjectCommonException(ex.getMessage(), ex.getMessage(),
          ResponseCode.CLIENT_ERROR.getResponseCode());
    }

  }
  return JsonKey.SUCCESS;
}
 
开发者ID:project-sunbird,项目名称:sunbird-utils,代码行数:25,代码来源:KeyCloakServiceImpl.java

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: isEmailVerified

import org.keycloak.admin.client.resource.UserResource; //导入依赖的package包/类
@Override
public boolean isEmailVerified(String userId) {
  UserResource resource =
      keycloak.realm(KeyCloakConnectionProvider.SSO_REALM).users().get(userId);
  if (isNull(resource)) {
    return false;
  }
  return resource.toRepresentation().isEmailVerified();
}
 
开发者ID:project-sunbird,项目名称:sunbird-utils,代码行数:10,代码来源:KeyCloakServiceImpl.java

示例10: 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

示例11: 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

示例12: 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

示例13: addRoleToUser

import org.keycloak.admin.client.resource.UserResource; //导入依赖的package包/类
@Override
public boolean addRoleToUser(PasswordCredential realmAdminCreds, String tenantId, String username, String roleName) throws IamAdminServicesException {

    Keycloak client = null;
    try{
        client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), tenantId, realmAdminCreds);
        List<UserRepresentation> retrieveCreatedUserList = client.realm(tenantId).users().search(username,
                null,
                null,
                null,
                0, 1);
        UserResource retrievedUser = client.realm(tenantId).users().get(retrieveCreatedUserList.get(0).getId());

        // Add user to the role
        RoleResource roleResource = client.realm(tenantId).roles().get(roleName);
        retrievedUser.roles().realmLevel().add(Arrays.asList(roleResource.toRepresentation()));
        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,代码行数:29,代码来源:TenantManagementKeycloakImpl.java

示例14: removeRoleFromUser

import org.keycloak.admin.client.resource.UserResource; //导入依赖的package包/类
@Override
public boolean removeRoleFromUser(PasswordCredential realmAdminCreds, String tenantId, String username, String roleName) throws IamAdminServicesException {

    Keycloak client = null;
    try{
        client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), tenantId, realmAdminCreds);
        List<UserRepresentation> retrieveCreatedUserList = client.realm(tenantId).users().search(username,
                null,
                null,
                null,
                0, 1);
        UserResource retrievedUser = client.realm(tenantId).users().get(retrieveCreatedUserList.get(0).getId());

        // Remove role from user
        RoleResource roleResource = client.realm(tenantId).roles().get(roleName);
        retrievedUser.roles().realmLevel().remove(Arrays.asList(roleResource.toRepresentation()));
        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,代码行数:29,代码来源:TenantManagementKeycloakImpl.java

示例15: 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类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。