<div dir="ltr">So this is what i see in my header<div><br></div><div>********</div><div>







<p class="">entity:&lt;{Content-Type=[application/json], Authorization=[Bearer eyJhbGciOiJSUzI1NiJ9.eyJqdGkiOiIzYjk2NTI0ZC0yYzY3LTRlY2YtOWRiYS1kMTNiYWZkZDc3OTIiLCJleHAiOjE0NDczMzgwODQsIm5iZiI6MCwiaWF0IjoxNDQ3MzM3Nzg0LCJpc3MiOiJodHRwOi8vc2Vuc2VucmVzcG9uZC5jb206OTkxMi9hdXRoL3JlYWxtcy9TbnJBcHBzUmVhbG0iLCJhdWQiOiJzbnJhcHBzLXdlYiIsInN1YiI6IjU1ODhmOWViLTg5ZDItNGVmMi04ZTM3LWVkM2RkY2RhMDdhMSIsInR5cCI6IkJlYXJlciIsImF6cCI6InNucmFwcHMtd2ViIiwic2Vzc2lvbl9zdGF0ZSI6ImVmZjFlY2Q0LWZjMTUtNGJjMi05MDgxLWM2YTA5NGMxODFmOCIsImNsaWVudF9zZXNzaW9uIjoiN2ZjZWU5ZDItN2I4Yi00ZmVmLTkzYjEtZjAwNzI3YWNkNzA2IiwiYWxsb3dlZC1vcmlnaW5zIjpbIioiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbImFkbWluIiwidXNlciJdfSwicmVzb3VyY2VfYWNjZXNzIjp7InNucmFwcHMtd2ViIjp7InJvbGVzIjpbInVzZXIiXX0sImFjY291bnQiOnsicm9sZXMiOlsidmlldy1wcm9maWxlIiwibWFuYWdlLWFjY291bnQiXX0sInJlYWxtLW1hbmFnZW1lbnQiOnsicm9sZXMiOlsidmlldy1yZWFsbSIsIm1hbmFnZS1jbGllbnRzIiwibWFuYWdlLWV2ZW50cyIsInZpZXctZXZlbnRzIiwidmlldy1pZGVudGl0eS1wcm92aWRlcnMiLCJtYW5hZ2UtaWRlbnRpdHktcHJvdmlkZXJzIiwidmlldy11c2VycyIsInZpZXctY2xpZW50cyIsInJlYWxtLWFkbWluIiwiY3JlYXRlLWNsaWVudCIsImltcGVyc29uYXRpb24iLCJtYW5hZ2UtdXNlcnMiLCJtYW5hZ2UtcmVhbG0iXX19LCJlbWFpbCI6ImhhcnNobWFoZXlAZ21haWwuY29tIiwibmFtZSI6IkNoYXJhbiBTaW5naCIsImZhbWlseV9uYW1lIjoiU2luZ2giLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJzbnJhcHBzLXVzZXIiLCJnaXZlbl9uYW1lIjoiQ2hhcmFuIn0.eyyqyobdaYesLH13zoPSwxd1yj3HE5GsshLXgQIaucJ9uVs7LpoiXedB0NfLf2rMYVHW6Yo0tX9DA2o_tGdlmNnbFnNqh3GDXIIcqQwIrYTGGzTFQo8k-8TzWlg5GXjuc3_b0GRGdbUd_BgbqahcxhHyciXNTzOM9iuzObXwfmKjCTy8FU-QxNntC-yThOidFoUOYxjmUxyfubq13GH0VVm_1obxQcI5_B6WnIubNFBpyjb70SgZZSVjM1-22WDm_TRlqtKomDALqsD6SAep-fV1yAxR9RLXTJzJpMb5a6Zt2PGOiE2G0cBq_KyfEO33v6IsxYTmIke3_2oV939jbA]}&gt;</p></div><div><br></div><div>*******</div><div><br></div><div>Here is my updated code</div><div><br></div><div>*********</div><div>







<p class=""><span class="">public</span> <span class="">boolean</span> deleteUser(String <span class="">userId</span>) {</p>
<p class=""><span class="">        </span><span class="">        </span>AccessTokenResponse <span class="">accessTokenResponse</span> = getToken();</p>
<p class=""><br></p>
<p class=""><span class="">        </span><span class="">        </span>org.springframework.http.HttpEntity&lt;String&gt; <span class="">entity</span> = <span class="">new</span> org.springframework.http.HttpEntity&lt;String (getHeaders(<span class="">accessTokenResponse</span>.getToken()));</p>
<p class=""><span class="">        </span><span class="">        </span></p>
<p class=""><span class="">        </span><span class="">        </span>System.<span class="">out</span>.println(<span class="">&quot;entity:&quot;</span>+<span class="">entity</span>);</p>
<p class=""><span class="">        </span><span class="">        </span></p>
<p class=""><span class="">        </span><span class="">        </span></p>
<p class=""><span class="">        </span><span class="">        </span>RestTemplate <span class="">restTemplate</span> = <span class="">new</span> RestTemplate();</p>
<p class=""><span class=""><span class="">        </span><span class="">        </span>String </span><span class="">urlForDeleteUser</span><span class=""> = </span>&quot;http://XXXX.com:XXX/auth/admin/realms/MyAppsRealm/users/&quot;<span class=""> + </span><span class="">userId</span><span class="">;</span></p>
<p class=""><span class="">        </span><span class="">        </span>System.<span class="">out</span>.println(<span class="">urlForDeleteUser</span>);</p>
<p class=""><span class=""><span class="">        </span><span class="">        </span></span>restTemplate<span class="">.delete(</span>urlForDeleteUser<span class="">, </span>entity<span class="">,String.</span><span class="">class</span><span class="">);</span></p>
<p class=""><span class="">        </span><span class="">        </span></p>
<p class=""><span class="">        </span><span class="">        </span>System.<span class="">out</span>.println(<span class="">&quot;done&quot;</span>);</p>
<p class=""><br></p>
<p class=""><span class=""><span class="">        </span><span class="">        </span></span>return<span class=""> </span>true<span class="">;</span></p>
<p class=""><span class="">        </span>}</p></div><div><br></div><div>********</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 12, 2015 at 1:50 AM, Marek Posolda <span dir="ltr">&lt;<a href="mailto:mposolda@redhat.com" target="_blank">mposolda@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    <div>What&#39;s the output of the &quot;System.<span>out</span>.println(<span>httpHeaders</span>);&quot;
      command?<br>
      <br>
      Basically you need to include Authorization header with the
      content like: <br>
      <br>
      Authorization: Bearer your-access-token-here<br>
      <br>
      TBH I am not familiar with spring http client library you&#39;re
      using, so not sure if you&#39;re sending headers correctly.<br>
      <br>
      Marek<br>
      <br>
      On 12/11/15 01:08, harsh mahey wrote:<br>
    </div>
    <blockquote type="cite">
      <div dir="ltr">
        <p>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.</p>
        <p>Can you guide what am i doing wrong here.</p>
        <p><br>
        </p>
        <p>Thanks</p>
        <p><br>
        </p>
        <p>*****************ERROR***********************************************************</p>
        <p><span>org.springframework.web.client.HttpClientErrorException</span><span>: 401 Unauthorized</span></p>
        <p><span> </span>at
          org.springframework.web.client.DefaultResponseErrorHandler.handleError(<span>DefaultResponseErrorHandler.java:91</span>)</p>
        <p><span> </span>at
          org.springframework.web.client.RestTemplate.handleResponse(<span>RestTemplate.java:641</span>)</p>
        <p><span> </span>at
          org.springframework.web.client.RestTemplate.doExecute(<span>RestTemplate.java:597</span>)</p>
        <p><span> </span>at
          org.springframework.web.client.RestTemplate.execute(<span>RestTemplate.java:557</span>)</p>
        <p><span> </span>at
          org.springframework.web.client.RestTemplate.delete(<span>RestTemplate.java:429</span>)</p>
        <p><span> </span>at
          com.snrapps.mwp.domain.security.KeyCloakAdminAdapter.deleteUser(<span>KeyCloakAdminAdapter.java:256</span>)</p>
        <p><span>
          </span></p>
        <p><span> </span>at
          com.snrapps.mwp.domain.security.KeyCloakAdminAdapter.main(<span>KeyCloakAdminAdapter.java:55</span>)</p>
        <p><span>*****************CODE**************************************************************</span></p>
        <p><span> </span><span>public</span>
          <span>boolean</span> deleteUser(String <span>userId</span>) {</p>
        <p><span> </span><span> </span>AccessTokenResponse
          <span>accessTokenResponse</span> = getToken();</p>
        <p>org.springframework.http.HttpEntity&lt;String&gt; <span>entity</span> = <span>new</span>
          org.springframework.http.HttpEntity&lt;String&gt;(getHeaders(<span>accessTokenResponse</span>.getToken()));</p>
        <p><span> </span><span> </span>HttpHeaders
          <span>httpHeaders</span>=<span>entity</span>.getHeaders();</p>
        <p><span> </span><span> </span>System.<span>out</span>.println(<span>httpHeaders</span>);</p>
        <p><span> </span><span> </span>RestTemplate
          <span>restTemplate</span> = <span>new</span>
          RestTemplate();</p>
        <p><span><span> </span><span> </span>String </span><span>urlForDeleteUser</span><span> = </span>&quot;http://XXXXX.com:XXXX/auth/admin/realmsMyAppsRealm/users/&quot;<span> + </span><span>userId</span><span>;</span></p>
        <p><span> </span><span> </span>System.<span>out</span>.println(<span>urlForDeleteUser</span>);</p>
        <p><span><span> </span><span> </span></span>restTemplate<span>.delete(</span>urlForDeleteUser<span>, </span>entity<span>);</span></p>
        <p><span> </span><span> </span></p>
        <p><span> </span><span> </span></p>
        <p><span> </span><span> </span></p>
        <p><span> </span><span> </span></p>
        <p><span> </span><span> </span>System.<span>out</span>.println(<span>&quot;done&quot;</span>);</p>
        <p><br>
        </p>
        <p><span><span> </span><span> </span></span>return<span> </span>true<span>;</span></p>
        <p><span> </span>}</p>
      </div>
      <br>
      <fieldset></fieldset>
      <br>
      <pre>_______________________________________________
keycloak-user mailing list
<a href="mailto:keycloak-user@lists.jboss.org" target="_blank">keycloak-user@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a></pre>
    </blockquote>
    <br>
  </div>

</blockquote></div><br></div>