[keycloak-user] can not delete user using REST API -401 unauthorized.

harsh mahey harshmahey at gmail.com
Wed Nov 11 19:08:38 EST 2015


I am getting 401 unAuthorized when im trying to delete a user.I was able to
create the user with this id.And i am able to delete the user using
Advanced REST Chrome client using same DELETE URL.

Can you guide what am i doing wrong here.


Thanks


*****************ERROR***********************************************************

org.springframework.web.client.HttpClientErrorException: 401 Unauthorized

at org.springframework.web.client.DefaultResponseErrorHandler.handleError(
DefaultResponseErrorHandler.java:91)

at org.springframework.web.client.RestTemplate.handleResponse(
RestTemplate.java:641)

at org.springframework.web.client.RestTemplate.doExecute(
RestTemplate.java:597)

at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557
)

at org.springframework.web.client.RestTemplate.delete(RestTemplate.java:429)

at com.snrapps.mwp.domain.security.KeyCloakAdminAdapter.deleteUser(
KeyCloakAdminAdapter.java:256)

at com.snrapps.mwp.domain.security.KeyCloakAdminAdapter.main(
KeyCloakAdminAdapter.java:55)

*****************CODE**************************************************************

public boolean deleteUser(String userId) {

AccessTokenResponse accessTokenResponse = getToken();

org.springframework.http.HttpEntity<String> entity = new
org.springframework.http.HttpEntity<String>(getHeaders(accessTokenResponse
.getToken()));

HttpHeaders httpHeaders=entity.getHeaders();

System.out.println(httpHeaders);

RestTemplate restTemplate = new RestTemplate();

String urlForDeleteUser = "http://XXXXX.com:XXXX
/auth/admin/realmsMyAppsRealm/users/" + userId;

System.out.println(urlForDeleteUser);

restTemplate.delete(urlForDeleteUser, entity);

System.out.println("done");


return true;

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20151111/135ef9f5/attachment-0001.html 


More information about the keycloak-user mailing list