• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java UserRepresentation类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



UserRepresentation类属于org.keycloak.representations.idm包,在下文中一共展示了UserRepresentation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: setUserPassword

import org.keycloak.representations.idm.UserRepresentation; //导入依赖的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: createUser

import org.keycloak.representations.idm.UserRepresentation; //导入依赖的package包/类
@Override
public String createUser(String username, String password, String firstname, String lastname, String email, List<String> rolenames) {
	if (username.equals("user")) {
		throw new UnsupportedOperationException("Dont't do that! (Sso rest api doesn't create user with username 'user' properly)");
	}

	CredentialRepresentation cr = new CredentialRepresentation();
	cr.setType(CredentialRepresentation.PASSWORD);
	cr.setValue(password);
	cr.setTemporary(false);

	UserRepresentation ur = new UserRepresentation();
	ur.setUsername(username);
	ur.setCredentials(Arrays.asList(cr));
	ur.setFirstName(firstname);
	ur.setLastName(lastname);
	ur.setEmail(email);
	ur.setEnabled(true);

	Response response = client.realm(realmName).users().create(ur);
	response.close();

	String userId = getUserId(username);
	client.realm(realmName).users().get(userId).resetPassword(cr);

	if (rolenames != null && rolenames.size() > 0) {
		addRealmRolesToUser(userId, rolenames);
	}

	return userId;
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:32,代码来源:SsoRestApi.java


示例3: getEmailVerifiedUpdatedFlag

import org.keycloak.representations.idm.UserRepresentation; //导入依赖的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


示例4: getLastLoginTime

import org.keycloak.representations.idm.UserRepresentation; //导入依赖的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


示例5: setEmailVerifiedTrue

import org.keycloak.representations.idm.UserRepresentation; //导入依赖的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


示例6: setEmailVerifiedAsFalse

import org.keycloak.representations.idm.UserRepresentation; //导入依赖的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


示例7: checkUserExistence

import org.keycloak.representations.idm.UserRepresentation; //导入依赖的package包/类
/**
 * Check the existence of user with email.
 *
 * @param email         email of the user
 * @throws IOException
 */
public void checkUserExistence(String email) throws IOException, DuplicatedKeycloakEntry{
    // First try: Find the user by searching for the username field
    List<UserRepresentation> users = getProjectUserRealm().users().search(email, null, null, null, -1, -1);

    String errMsg = "";
    // If we found one, it already has the user
    if (users.size()>0){
        throw new DuplicatedKeycloakEntry("User with username: " +email + " already exists.", errMsg);
    }

    // Second try: Find the user by searching for the email field
    users = getProjectUserRealm().users().search(null, null, null, email, -1, -1);
    // If we found one, it already has the user
    if (users.size()>0){
        throw new DuplicatedKeycloakEntry("User with email: " +email + " already exists.", errMsg);
    }
}
 
开发者ID:MaritimeConnectivityPlatform,项目名称:IdentityRegistry,代码行数:24,代码来源:KeycloakAdminUtil.java


示例8: deleteUser

import org.keycloak.representations.idm.UserRepresentation; //导入依赖的package包/类
/**
 * Delete a user from Keycloak
 * 
 * @param email  email of the user to delete
 */
public void deleteUser(String email) {
    // First try: Find the user by searching for the username
    List<UserRepresentation> users = getProjectUserRealm().users().search(email, null, null, null, -1, -1);
    // If we found one, delete it
    if (!users.isEmpty()) {
        getProjectUserRealm().users().get(users.get(0).getId()).remove();
        return ;
    }
    // Second try: Find the user by searching for the email
    users = getProjectUserRealm().users().search(null, null, null, email, -1, -1);
    // If we found one, delete it
    if (!users.isEmpty()) {
        getProjectUserRealm().users().get(users.get(0).getId()).remove();
        return ;
    }
}
 
开发者ID:MaritimeConnectivityPlatform,项目名称:IdentityRegistry,代码行数:22,代码来源:KeycloakAdminUtil.java


示例9: createRealm

import org.keycloak.representations.idm.UserRepresentation; //导入依赖的package包/类
@Override
public void createRealm(String realmName, String realmAdminUser) {
    final RealmRepresentation newRealm = new RealmRepresentation();
    newRealm.setRealm(realmName);
    newRealm.setEnabled(true);
    newRealm.setPasswordPolicy("hashAlgorithm(scramsha1)");

    final UserRepresentation newUser = new UserRepresentation();
    newUser.setUsername(realmAdminUser);

    newUser.setEnabled(true);
    newUser.setClientRoles(Collections.singletonMap("realm-management", Collections.singletonList("manage-users")));

    newRealm.setUsers(Collections.singletonList(newUser));

    try (CloseableKeycloak wrapper = new CloseableKeycloak(params)) {
        wrapper.get().realms().create(newRealm);
    }
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:20,代码来源:Keycloak.java


示例10: update

import org.keycloak.representations.idm.UserRepresentation; //导入依赖的package包/类
@Override
public User update(User entity) throws SecurityManagementException {
    checkNotNull("entity",
                 entity);
    consumeRealm(realmResource -> {
        UsersResource usersResource = realmResource.users();
        UserResource userResource = getUserResource(usersResource,
                                                    entity.getIdentifier());
        if (userResource == null) {
            throw new UserNotFoundException(entity.getIdentifier());
        }
        UserRepresentation userRepresentation = new UserRepresentation();
        fillUserRepresentationAttributes(entity,
                                         userRepresentation);
        ClientResponse response = (ClientResponse) userResource.update(userRepresentation);
        handleResponse(response);
    });
    return entity;
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:20,代码来源:KeyCloakUserManager.java


示例11: getUserRepresentations

import org.keycloak.representations.idm.UserRepresentation; //导入依赖的package包/类
private List<UserRepresentation> getUserRepresentations(String pattern,
                                                        int start,
                                                        int size) {
    List<UserRepresentation> result = null;
    if (isEmpty(pattern)) {
        result = userRepresentations.subList(start,
                                             start + size);
    } else {
        UserResource userResource = getUser(userResources,
                                            pattern);
        if (userResource != null) {
            result = new ArrayList<UserRepresentation>(1);
            result.add(userResource.toRepresentation());
        }
    }
    return result;
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:18,代码来源:DefaultKeyCloakTest.java


示例12: updateUserDetails

import org.keycloak.representations.idm.UserRepresentation; //导入依赖的package包/类
@Override
public void updateUserDetails(User user) {
	UserRepresentation ur = client.realm(realmName).users().get(user.id).toRepresentation();
	ur.setFirstName(user.firstName);
	ur.setLastName(user.lastName);
	ur.setEmail(user.email);

	client.realm(realmName).users().get(user.id).update(ur);
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:10,代码来源:SsoRestApi.java


示例13: deactivateUser

import org.keycloak.representations.idm.UserRepresentation; //导入依赖的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


示例14: setEmailVerifiedUpdatedFlag

import org.keycloak.representations.idm.UserRepresentation; //导入依赖的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


示例15: addUserLoginTime

import org.keycloak.representations.idm.UserRepresentation; //导入依赖的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


示例16: deleteIdentityProvider

import org.keycloak.representations.idm.UserRepresentation; //导入依赖的package包/类
/**
 * Delete Identity Provider with the given alias
 * 
 * @param orgMrn  MRN of the IDP to delete.
 */
public void deleteIdentityProvider(String orgMrn) {
    // First delete any users associated with the IDP. Find it by username, which is the mrn
    String alias = MrnUtil.getOrgShortNameFromOrgMrn(orgMrn);
    String searchStr = MrnUtil.getMrnPrefix(orgMrn) + ":user:" + alias + ":";
    List<UserRepresentation> users = getBrokerRealm().users().search(/* username*/ searchStr, /* firstName */ null, /* lastName */ null, /* email */ null,  /* first */ 0, /* max*/ 0);
    for (UserRepresentation user : users) {
        if (user.getUsername().startsWith(searchStr)) {
            getBrokerRealm().users().get(user.getId()).remove();
        }
    }
    // Delete IDP
    getBrokerRealm().identityProviders().get(alias).remove();
}
 
开发者ID:MaritimeConnectivityPlatform,项目名称:IdentityRegistry,代码行数:19,代码来源:KeycloakAdminUtil.java


示例17: getClientId

import org.keycloak.representations.idm.UserRepresentation; //导入依赖的package包/类
private String getClientId(CloseableKeycloak keycloak, String realm, String username) {
    List<UserRepresentation> users = keycloak.get().realm(realm).users().search(username);
    if (!users.isEmpty()) {
        return users.get(0).getId();
    }
    throw new RuntimeException("Unable to find user: " + username);
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:8,代码来源:KeycloakClient.java


示例18: createUser

import org.keycloak.representations.idm.UserRepresentation; //导入依赖的package包/类
public void createUser(String realm, String userName, String password, long timeout, TimeUnit timeUnit) throws Exception {

        int maxRetries = 10;
        try (CloseableKeycloak keycloak = new CloseableKeycloak(endpoint, credentials, trustStore)) {
            RealmResource realmResource = waitForRealm(keycloak.get(), realm, timeout, timeUnit);

            for (int retries = 0; retries < maxRetries; retries++) {
                try {
                    if (realmResource.users().search(userName).isEmpty()) {
                        UserRepresentation userRep = new UserRepresentation();
                        userRep.setUsername(userName);
                        CredentialRepresentation cred = new CredentialRepresentation();
                        cred.setType(CredentialRepresentation.PASSWORD);
                        cred.setValue(password);
                        cred.setTemporary(false);
                        userRep.setCredentials(Arrays.asList(cred));
                        userRep.setEnabled(true);
                        Response response = keycloak.get().realm(realm).users().create(userRep);
                        if (response.getStatus() != 201) {
                            throw new RuntimeException("Unable to create user: " + response.getStatus());
                        }
                    } else {
                        Logging.log.info("User " + userName + " already created, skipping");
                    }
                    break;
                } catch (Exception e) {
                    Logging.log.info("Exception querying keycloak ({}), retrying", e.getMessage());
                    Thread.sleep(2000);
                }
            }
        }
    }
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:33,代码来源:KeycloakClient.java


示例19: getUsers

import org.keycloak.representations.idm.UserRepresentation; //导入依赖的package包/类
@Override
public Set<String> getUsers(String criteria) {
    RealmResource realm = connectToRealm();

    List<UserRepresentation> users = realm.users().search(criteria, 0, 10);
    return users.stream().map(u -> u.getUsername()).collect(Collectors.toSet());
}
 
开发者ID:martin-kanis,项目名称:relax-dms,代码行数:8,代码来源:KeycloakAdminClientImpl.java


示例20: userExists

import org.keycloak.representations.idm.UserRepresentation; //导入依赖的package包/类
@Override
public boolean userExists(String user) {
    RealmResource realm = connectToRealm();
    
    List<UserRepresentation> users = realm.users().search(user, 0, 100);
    Set<String> usersSet = users.stream().map(u -> u.getUsername()).collect(Collectors.toSet());

    return usersSet.contains(user);
}
 
开发者ID:martin-kanis,项目名称:relax-dms,代码行数:10,代码来源:KeycloakAdminClientImpl.java



注:本文中的org.keycloak.representations.idm.UserRepresentation类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Tuples类代码示例发布时间:2022-05-22
下一篇:
Java ErrorMessageFactory类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap