That looks correct to me. What status code do you get back? Any errors in
the log?
On 5 January 2016 at 07:51, PAA KOJO KONDUAH AMOS <pkkamos(a)gmail.com> wrote:
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/
<
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 <
http://go.microsoft.com/fwlink/?LinkId=550986> for
Windows 10
_______________________________________________
keycloak-user mailing list
keycloak-user(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/keycloak-user