本文整理匯總了Java中org.keycloak.admin.client.resource.UserResource.resetPassword方法的典型用法代碼示例。如果您正苦於以下問題:Java UserResource.resetPassword方法的具體用法?Java UserResource.resetPassword怎麽用?Java UserResource.resetPassword使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.keycloak.admin.client.resource.UserResource
的用法示例。
在下文中一共展示了UserResource.resetPassword方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: 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");
}
}
示例3: migrateUserStore
import org.keycloak.admin.client.resource.UserResource; //導入方法依賴的package包/類
void migrateUserStore(List<UserProfileDAO> userProfiles, String targetRealm, String tempPassword, Map<String,String> roleConversionMap){
Map<String, RoleRepresentation> allRealmRoles = getRealmRoleNameMap(targetRealm);
for(UserProfileDAO userProfile : userProfiles){
UserRepresentation user = new UserRepresentation();
user.setUsername(userProfile.getUserName());
user.setFirstName(userProfile.getFirstName());
user.setLastName(userProfile.getLastName());
user.setEmail(userProfile.getEmail());
user.setEmailVerified(true);
user.setEnabled(true);
List<String> requiredActionList = new ArrayList<>();
requiredActionList.add("UPDATE_PASSWORD");
user.setRequiredActions(requiredActionList);
Response httpResponse = this.client.realm(targetRealm).users().create(user);
System.out.println(httpResponse.getStatus());
if(httpResponse.getStatus() == 201){ //HTTP code for record creation: HTTP 201
List<UserRepresentation> retrieveCreatedUserList = this.client.realm(targetRealm).users().search(user.getUsername(),
user.getFirstName(),
user.getLastName(),
user.getEmail(),
0,1);
UserResource retirievedUser = this.client.realm(targetRealm).users().get(retrieveCreatedUserList.get(0).getId());
// Add user to realm roles
List<RoleRepresentation> userRealmRoles = userProfile.getRoles().stream()
.filter(r -> roleConversionMap.containsKey(r))
// Convert from IS role name to Keycloak role name
.map(r -> roleConversionMap.get(r))
// Convert from Keycloak role name to RoleRepresentation
.map(r -> allRealmRoles.get(r))
.collect(Collectors.toList());
retirievedUser.roles().realmLevel().add(userRealmRoles);
CredentialRepresentation credential = new CredentialRepresentation();
credential.setType(CredentialRepresentation.PASSWORD);
credential.setValue(tempPassword);
credential.setTemporary(true);
retirievedUser.resetPassword(credential);
System.out.println("User profile for user " + userProfile.getUserName() + " successfully migrated");
} else {
String response = httpResponse.readEntity(String.class);
System.err.println("Failed to add user [" + userProfile.getUserName() + "] to Keycloak");
System.err.println("Response: " + response);
}
if (httpResponse != null) {
httpResponse.close();
}
}
}
示例4: createUser
import org.keycloak.admin.client.resource.UserResource; //導入方法依賴的package包/類
@Override
public boolean createUser(PasswordCredential realmAdminCreds, String tenantId, String username, String emailAddress, String firstName, String lastName, String newPassword) throws IamAdminServicesException{
Keycloak client = null;
try{
client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), tenantId, realmAdminCreds);
UserRepresentation user = new UserRepresentation();
user.setUsername(username);
user.setFirstName(firstName);
user.setLastName(lastName);
user.setEmail(emailAddress);
user.setEnabled(false);
Response httpResponse = client.realm(tenantId).users().create(user);
if (httpResponse.getStatus() == 201) { //HTTP code for record creation: HTTP 201
List<UserRepresentation> retrieveCreatedUserList = client.realm(tenantId).users().search(user.getUsername(),
user.getFirstName(),
user.getLastName(),
user.getEmail(),
0, 1);
UserResource retrievedUser = client.realm(tenantId).users().get(retrieveCreatedUserList.get(0).getId());
CredentialRepresentation credential = new CredentialRepresentation();
credential.setType(CredentialRepresentation.PASSWORD);
credential.setValue(newPassword);
credential.setTemporary(false);
retrievedUser.resetPassword(credential);
} else {
logger.error("Request for user Account Creation failed with HTTP code : " + httpResponse.getStatus());
logger.error("Reason for user account creation failure : " + httpResponse.getStatusInfo());
return false;
}
}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();
}
}
return false;
}