keycloak
クラス | 静的公開メンバ関数 | 静的限定公開メンバ関数 | 静的非公開変数類 | 全メンバ一覧
org.keycloak.adapters.ServerRequest クラス
org.keycloak.adapters.ServerRequest 連携図
Collaboration graph

クラス

class  HttpFailure
 

静的公開メンバ関数

static void invokeLogout (KeycloakDeployment deployment, String refreshToken) throws IOException, HttpFailure
 
static AccessTokenResponse invokeAccessCodeToToken (KeycloakDeployment deployment, String code, String redirectUri, String sessionId) throws IOException, HttpFailure
 
static AccessTokenResponse invokeAccessCodeToToken (KeycloakDeployment deployment, String code, String redirectUri, String sessionId, String codeVerifier) throws IOException, HttpFailure
 
static AccessTokenResponse invokeRefresh (KeycloakDeployment deployment, String refreshToken) throws IOException, HttpFailure
 
static void invokeRegisterNode (KeycloakDeployment deployment, String host) throws HttpFailure, IOException
 
static void invokeUnregisterNode (KeycloakDeployment deployment, String host) throws HttpFailure, IOException
 
static void invokeClientManagementRequest (KeycloakDeployment deployment, String host, String endpointUrl) throws HttpFailure, IOException
 
static void error (int status, HttpEntity entity) throws HttpFailure, IOException
 

静的限定公開メンバ関数

static String stripOauthParametersFromRedirect (String uri)
 

静的非公開変数類

static Logger logger = Logger.getLogger(ServerRequest.class)
 

詳解

著者
Bill Burke
バージョン
Revision
1

関数詳解

◆ error()

static void org.keycloak.adapters.ServerRequest.error ( int  status,
HttpEntity  entity 
) throws HttpFailure, IOException
inlinestatic
272  {
273  String body = null;
274  if (entity != null) {
275  InputStream is = entity.getContent();
276  try {
277  body = StreamUtil.readString(is);
278  } catch (IOException e) {
279 
280  } finally {
281  try {
282  is.close();
283  } catch (IOException ignored) {
284 
285  }
286  }
287  }
288  throw new HttpFailure(status, body);
289  }

◆ invokeAccessCodeToToken() [1/2]

static AccessTokenResponse org.keycloak.adapters.ServerRequest.invokeAccessCodeToToken ( KeycloakDeployment  deployment,
String  code,
String  redirectUri,
String  sessionId 
) throws IOException, HttpFailure
inlinestatic
95  {
96  List<NameValuePair> formparams = new ArrayList<>();
97  redirectUri = stripOauthParametersFromRedirect(redirectUri);
98  formparams.add(new BasicNameValuePair(OAuth2Constants.GRANT_TYPE, "authorization_code"));
99  formparams.add(new BasicNameValuePair(OAuth2Constants.CODE, code));
100  formparams.add(new BasicNameValuePair(OAuth2Constants.REDIRECT_URI, redirectUri));
101  if (sessionId != null) {
102  formparams.add(new BasicNameValuePair(AdapterConstants.CLIENT_SESSION_STATE, sessionId));
103  formparams.add(new BasicNameValuePair(AdapterConstants.CLIENT_SESSION_HOST, HostUtils.getHostName()));
104  }
105 
106  HttpPost post = new HttpPost(deployment.getTokenUrl());
107  ClientCredentialsProviderUtils.setClientCredentials(deployment, post, formparams);
108 
109  UrlEncodedFormEntity form = new UrlEncodedFormEntity(formparams, "UTF-8");
110  post.setEntity(form);
111  HttpResponse response = deployment.getClient().execute(post);
112  int status = response.getStatusLine().getStatusCode();
113  HttpEntity entity = response.getEntity();
114  if (status != 200) {
115  error(status, entity);
116  }
117  if (entity == null) {
118  throw new HttpFailure(status, null);
119  }
120  InputStream is = entity.getContent();
121  try {
122  ByteArrayOutputStream os = new ByteArrayOutputStream();
123  int c;
124  while ((c = is.read()) != -1) {
125  os.write(c);
126  }
127  byte[] bytes = os.toByteArray();
128  String json = new String(bytes);
129  try {
130  return JsonSerialization.readValue(json, AccessTokenResponse.class);
131  } catch (IOException e) {
132  throw new IOException(json, e);
133  }
134  } finally {
135  try {
136  is.close();
137  } catch (IOException ignored) {
138 
139  }
140  }
141  }
static void error(int status, HttpEntity entity)
Definition: ServerRequest.java:272
static String stripOauthParametersFromRedirect(String uri)
Definition: ServerRequest.java:291

◆ invokeAccessCodeToToken() [2/2]

static AccessTokenResponse org.keycloak.adapters.ServerRequest.invokeAccessCodeToToken ( KeycloakDeployment  deployment,
String  code,
String  redirectUri,
String  sessionId,
String  codeVerifier 
) throws IOException, HttpFailure
inlinestatic
144  {
145  List<NameValuePair> formparams = new ArrayList<>();
146  redirectUri = stripOauthParametersFromRedirect(redirectUri);
147  formparams.add(new BasicNameValuePair(OAuth2Constants.GRANT_TYPE, "authorization_code"));
148  formparams.add(new BasicNameValuePair(OAuth2Constants.CODE, code));
149  formparams.add(new BasicNameValuePair(OAuth2Constants.REDIRECT_URI, redirectUri));
150  if (sessionId != null) {
151  formparams.add(new BasicNameValuePair(AdapterConstants.CLIENT_SESSION_STATE, sessionId));
152  formparams.add(new BasicNameValuePair(AdapterConstants.CLIENT_SESSION_HOST, HostUtils.getHostName()));
153  }
154  // https://tools.ietf.org/html/rfc7636#section-4
155  if (codeVerifier != null) {
156  logger.debugf("add to POST parameters of Token Request, codeVerifier = %s", codeVerifier);
157  formparams.add(new BasicNameValuePair(OAuth2Constants.CODE_VERIFIER, codeVerifier));
158  } else {
159  logger.debug("add to POST parameters of Token Request without codeVerifier");
160  }
161 
162  HttpPost post = new HttpPost(deployment.getTokenUrl());
163  ClientCredentialsProviderUtils.setClientCredentials(deployment, post, formparams);
164 
165  UrlEncodedFormEntity form = new UrlEncodedFormEntity(formparams, "UTF-8");
166  post.setEntity(form);
167  HttpResponse response = deployment.getClient().execute(post);
168  int status = response.getStatusLine().getStatusCode();
169  HttpEntity entity = response.getEntity();
170  if (status != 200) {
171  error(status, entity);
172  }
173  if (entity == null) {
174  throw new HttpFailure(status, null);
175  }
176  InputStream is = entity.getContent();
177  try {
178  ByteArrayOutputStream os = new ByteArrayOutputStream();
179  int c;
180  while ((c = is.read()) != -1) {
181  os.write(c);
182  }
183  byte[] bytes = os.toByteArray();
184  String json = new String(bytes);
185  try {
186  return JsonSerialization.readValue(json, AccessTokenResponse.class);
187  } catch (IOException e) {
188  throw new IOException(json, e);
189  }
190  } finally {
191  try {
192  is.close();
193  } catch (IOException ignored) {
194 
195  }
196  }
197  }
static void error(int status, HttpEntity entity)
Definition: ServerRequest.java:272
static String stripOauthParametersFromRedirect(String uri)
Definition: ServerRequest.java:291
static Logger logger
Definition: ServerRequest.java:51

◆ invokeClientManagementRequest()

static void org.keycloak.adapters.ServerRequest.invokeClientManagementRequest ( KeycloakDeployment  deployment,
String  host,
String  endpointUrl 
) throws HttpFailure, IOException
inlinestatic
251  {
252  if (endpointUrl == null) {
253  throw new IOException("You need to configure URI for register/unregister node for application " + deployment.getResourceName());
254  }
255 
256  List<NameValuePair> formparams = new ArrayList<NameValuePair>();
257  formparams.add(new BasicNameValuePair(AdapterConstants.CLIENT_CLUSTER_HOST, host));
258 
259  HttpPost post = new HttpPost(endpointUrl);
260  ClientCredentialsProviderUtils.setClientCredentials(deployment, post, formparams);
261 
262  UrlEncodedFormEntity form = new UrlEncodedFormEntity(formparams, "UTF-8");
263  post.setEntity(form);
264  HttpResponse response = deployment.getClient().execute(post);
265  int status = response.getStatusLine().getStatusCode();
266  if (status != 204) {
267  HttpEntity entity = response.getEntity();
268  error(status, entity);
269  }
270  }
static void error(int status, HttpEntity entity)
Definition: ServerRequest.java:272

◆ invokeLogout()

static void org.keycloak.adapters.ServerRequest.invokeLogout ( KeycloakDeployment  deployment,
String  refreshToken 
) throws IOException, HttpFailure
inlinestatic
71  {
72  HttpClient client = deployment.getClient();
73  URI uri = deployment.getLogoutUrl().clone().build();
74  List<NameValuePair> formparams = new ArrayList<>();
75 
76  formparams.add(new BasicNameValuePair(OAuth2Constants.REFRESH_TOKEN, refreshToken));
77  HttpPost post = new HttpPost(uri);
78  ClientCredentialsProviderUtils.setClientCredentials(deployment, post, formparams);
79 
80  UrlEncodedFormEntity form = new UrlEncodedFormEntity(formparams, "UTF-8");
81  post.setEntity(form);
82  HttpResponse response = client.execute(post);
83  int status = response.getStatusLine().getStatusCode();
84  HttpEntity entity = response.getEntity();
85  if (status != 204) {
86  error(status, entity);
87  }
88  if (entity == null) {
89  return;
90  }
91  InputStream is = entity.getContent();
92  if (is != null) is.close();
93  }
static void error(int status, HttpEntity entity)
Definition: ServerRequest.java:272

◆ invokeRefresh()

static AccessTokenResponse org.keycloak.adapters.ServerRequest.invokeRefresh ( KeycloakDeployment  deployment,
String  refreshToken 
) throws IOException, HttpFailure
inlinestatic
199  {
200  List<NameValuePair> formparams = new ArrayList<NameValuePair>();
201  formparams.add(new BasicNameValuePair(OAuth2Constants.GRANT_TYPE, OAuth2Constants.REFRESH_TOKEN));
202  formparams.add(new BasicNameValuePair(OAuth2Constants.REFRESH_TOKEN, refreshToken));
203 
204  HttpPost post = new HttpPost(deployment.getTokenUrl());
205  ClientCredentialsProviderUtils.setClientCredentials(deployment, post, formparams);
206 
207  UrlEncodedFormEntity form = new UrlEncodedFormEntity(formparams, "UTF-8");
208  post.setEntity(form);
209  HttpResponse response = deployment.getClient().execute(post);
210  int status = response.getStatusLine().getStatusCode();
211  HttpEntity entity = response.getEntity();
212  if (status != 200) {
213  error(status, entity);
214  }
215  if (entity == null) {
216  throw new HttpFailure(status, null);
217  }
218  InputStream is = entity.getContent();
219  try {
220  ByteArrayOutputStream os = new ByteArrayOutputStream();
221  int c;
222  while ((c = is.read()) != -1) {
223  os.write(c);
224  }
225  byte[] bytes = os.toByteArray();
226  String json = new String(bytes);
227  try {
228  return JsonSerialization.readValue(json, AccessTokenResponse.class);
229  } catch (IOException e) {
230  throw new IOException(json, e);
231  }
232  } finally {
233  try {
234  is.close();
235  } catch (IOException ignored) {
236 
237  }
238  }
239  }
static void error(int status, HttpEntity entity)
Definition: ServerRequest.java:272

◆ invokeRegisterNode()

static void org.keycloak.adapters.ServerRequest.invokeRegisterNode ( KeycloakDeployment  deployment,
String  host 
) throws HttpFailure, IOException
inlinestatic
241  {
242  String registerNodeUrl = deployment.getRegisterNodeUrl();
243  invokeClientManagementRequest(deployment, host, registerNodeUrl);
244  }
static void invokeClientManagementRequest(KeycloakDeployment deployment, String host, String endpointUrl)
Definition: ServerRequest.java:251

◆ invokeUnregisterNode()

static void org.keycloak.adapters.ServerRequest.invokeUnregisterNode ( KeycloakDeployment  deployment,
String  host 
) throws HttpFailure, IOException
inlinestatic
246  {
247  String unregisterNodeUrl = deployment.getUnregisterNodeUrl();
248  invokeClientManagementRequest(deployment, host, unregisterNodeUrl);
249  }
static void invokeClientManagementRequest(KeycloakDeployment deployment, String host, String endpointUrl)
Definition: ServerRequest.java:251

◆ stripOauthParametersFromRedirect()

static String org.keycloak.adapters.ServerRequest.stripOauthParametersFromRedirect ( String  uri)
inlinestaticprotected
291  {
292  KeycloakUriBuilder builder = KeycloakUriBuilder.fromUri(uri)
293  .replaceQueryParam(OAuth2Constants.CODE, null)
294  .replaceQueryParam(OAuth2Constants.STATE, null);
295  return builder.build().toString();
296  }

メンバ詳解

◆ logger

Logger org.keycloak.adapters.ServerRequest.logger = Logger.getLogger(ServerRequest.class)
staticprivate

このクラス詳解は次のファイルから抽出されました: