[keycloak-user] Setting Password for Users.

PAA KOJO KONDUAH AMOS pkkamos at gmail.com
Tue Jan 5 01:51:17 EST 2016


Hello.

I am using Keycloak admin client version 1.7.0. Final to create users from an external application. I am able to create Users (with user.setEnabled set to true)and set the password as well. However, when I try to login it fails.

Please can anyone show me a sample code for password reset?

This is what I have so far:

URL: http://localhost:8888/auth/admin/realms/crusadersterling/users/

public void resetPassword(String userId, String token) throws IOException, Failure {

		CredentialRepresentation credential = new CredentialRepresentation();
		credential.setType(CredentialRepresentation.PASSWORD);
		credential.setValue("123456");
		credential.setTemporary(true);

		HttpClient client = HttpClientBuilder.create().build();
		ObjectMapper mapper = new ObjectMapper();
		String json = null;
		try {
			String usesUrl = PropertiesUtil.getValue("reset_password");
			HttpPut put = new HttpPut(usesUrl + userId + "/reset-password");
			put.addHeader("Authorization", "Bearer " + token);
			put.setHeader("Content-Type", "application/json");
			put.setHeader("Accept", "application/json");
			json = mapper.writeValueAsString(credential);
			StringEntity entity = new StringEntity(json);
			put.setEntity(entity);
			try {
				HttpResponse response = client.execute(put);

				

				if (!String.valueOf(response.getStatusLine().getStatusCode()).startsWith("20")) {
					System.err.println(response.getStatusLine().getReasonPhrase());
					throw new Failure(response.getStatusLine().getStatusCode());
				}

			} catch (IOException | Failure | IllegalStateException e) {

				throw e;
			}
		} catch (IOException e) {
			throw new RuntimeException(e);
		} finally {
			client.getConnectionManager().shutdown();
		}
		
	}

Sent from Mail for Windows 10

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20160105/45ea9998/attachment.html 


More information about the keycloak-user mailing list