Commit d6fc69c1 authored by shishir suman's avatar shishir suman
Browse files

changes for keycloak admin token method

Showing with 26 additions and 1 deletion
+26 -1
......@@ -62,7 +62,7 @@ public class KeycloakTokenRetriever {
String requestBody = "username=" + ADMIN_USERNAME +
"&password=" + ADMIN_PASSWORD +
"&grant_type=password" +
"&grant_type=client_credentials" +
"&client_id=admin-cli" +
"&client_secret=" + ADMIN_TOKEN_SECRET;
logger.info("Request body: {}", requestBody);
......@@ -76,4 +76,29 @@ public class KeycloakTokenRetriever {
return jsonNode;
}
public JsonNode getAdminTokenRead() throws IOException {
String tokenEndpoint = ADMIN_TOKEN_ENDPOINT;
logger.info("Token endpoint: {}" ,tokenEndpoint);
HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(tokenEndpoint);
httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
String requestBody = "username=" + ADMIN_USERNAME +
"&password=" + ADMIN_PASSWORD +
"&grant_type=password" +
"&client_id=admin-cli" +
"&client_secret=" + ADMIN_TOKEN_SECRET;
logger.info("Request body: {}", requestBody);
StringEntity entity = new StringEntity(requestBody);
httpPost.setEntity(entity);
org.apache.http.HttpResponse response = httpClient.execute(httpPost);
String responseBody = EntityUtils.toString(response.getEntity());
JsonNode jsonNode = mapper.readTree(responseBody);
return jsonNode;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment