2017-06-28 20 views
0

keycloak REST APIを使用してユーザーセッションを削除しようとしています。 しかし、403の禁止HTTPステータスコードを取得しています。 私はトークンとクッキーをヘッダーに渡しています。何か不足している場合はお知らせください。Keycloak REST API 403が禁止されています

静的な無効ログアウト(文字列のuserId、KeycloakSecurityContextセッション){

userId = "a12c13b7-fa2e-412f-ac8e-376fdca16a83"; 

    String url = "http://localhost:8081/auth/admin/realms/TestRealm/users/a12c13b7-fa2e-412f-ac8e-376fdca16a83/logout"; 
    HttpClient httpclient = HttpClients.createDefault(); 
    HttpPost httppost = new HttpPost(url); 

    HttpResponse response; 
    try { 

     httppost.addHeader("Accept", "application/json"); 
     httppost.addHeader("Content-Type","application/json"); 
     httppost.addHeader("Cookie", "JSESSIONID=CABD8A135C74864F0961FA629D6D489B"); 
     httppost.addHeader("Authorization", "Bearer "+session.getTokenString()); 


     response = httpclient.execute(httppost); 
     HttpEntity entity = response.getEntity(); 

     System.out.println("entity :"+response.getStatusLine()); 

     if (entity != null) { 
      String responseString = EntityUtils.toString(entity, "UTF-8"); 
      System.out.println("body ....."+responseString); 
     } 
    } catch (ClientProtocolException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

} 

答えて

0

あなたがアクセス応じて機能を使用するユーザーは、レルムの権利に従って必要。

たとえば、私の 'admin'ユーザーは、ユーザーに関する情報を取得するためにCLIENT "realm-management"のCLIENT ROLE "view-users"が必要でした。あなたの場合、ユーザーを削除する必要があるときは、「manage-users」という役割が必要な場合や、より強力なものが必要な場合があります。

関連する問題