KEYCLOAK-3406 OIDC dynamic client registrations specs fixes
This commit is contained in:
1 parent
c34d175572
commit
a8fb988e31
18 files changed
+445
-94
No files matched your search
+21
-2
@@ -18,6 +18,8 @@
|
||||
package org.keycloak.client.registration;
|
||||
|
||||
import org.apache.http.StatusLine;
|
||||
import org.keycloak.representations.idm.OAuth2ErrorRepresentation;
|
||||
import org.keycloak.util.JsonSerialization;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -26,14 +28,31 @@ import java.io.IOException;
|
||||
*/
|
||||
public class HttpErrorException extends IOException {
|
||||
|
||||
private StatusLine statusLine;
|
||||
private final StatusLine statusLine;
|
||||
private final String errorResponse;
|
||||
|
||||
public HttpErrorException(StatusLine statusLine) {
|
||||
public HttpErrorException(StatusLine statusLine, String errorResponse) {
|
||||
this.statusLine = statusLine;
|
||||
this.errorResponse = errorResponse;
|
||||
}
|
||||
|
||||
public StatusLine getStatusLine() {
|
||||
return statusLine;
|
||||
}
|
||||
|
||||
public String getErrorResponse() {
|
||||
return errorResponse;
|
||||
}
|
||||
|
||||
public OAuth2ErrorRepresentation toErrorRepresentation() {
|
||||
if (errorResponse == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return JsonSerialization.readValue(errorResponse, OAuth2ErrorRepresentation.class);
|
||||
} catch (IOException ioe) {
|
||||
throw new RuntimeException("Not OAuth2 error");
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
-18
@@ -23,9 +23,7 @@ import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.*;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.keycloak.client.registration.Auth;
|
||||
import org.keycloak.client.registration.ClientRegistrationException;
|
||||
import org.keycloak.client.registration.HttpErrorException;
|
||||
import org.keycloak.common.util.StreamUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -69,8 +67,7 @@ class HttpUtil {
|
||||
if (response.getStatusLine().getStatusCode() == 201) {
|
||||
return responseStream;
|
||||
} else {
|
||||
responseStream.close();
|
||||
throw new HttpErrorException(response.getStatusLine());
|
||||
throw httpErrorException(response, responseStream);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ClientRegistrationException("Failed to send request", e);
|
||||
@@ -97,10 +94,7 @@ class HttpUtil {
|
||||
responseStream.close();
|
||||
return null;
|
||||
} else {
|
||||
if (responseStream != null) {
|
||||
responseStream.close();
|
||||
}
|
||||
throw new HttpErrorException(response.getStatusLine());
|
||||
throw httpErrorException(response, responseStream);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ClientRegistrationException("Failed to send request", e);
|
||||
@@ -118,9 +112,6 @@ class HttpUtil {
|
||||
addAuth(request);
|
||||
|
||||
HttpResponse response = httpClient.execute(request);
|
||||
if (response.getEntity() != null) {
|
||||
response.getEntity().getContent();
|
||||
}
|
||||
|
||||
InputStream responseStream = null;
|
||||
if (response.getEntity() != null) {
|
||||
@@ -130,10 +121,7 @@ class HttpUtil {
|
||||
if (response.getStatusLine().getStatusCode() == 200) {
|
||||
return responseStream;
|
||||
} else {
|
||||
if (responseStream != null) {
|
||||
responseStream.close();
|
||||
}
|
||||
throw new HttpErrorException(response.getStatusLine());
|
||||
throw httpErrorException(response, responseStream);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ClientRegistrationException("Failed to send request", e);
|
||||
@@ -147,12 +135,13 @@ class HttpUtil {
|
||||
addAuth(request);
|
||||
|
||||
HttpResponse response = httpClient.execute(request);
|
||||
InputStream responseStream = null;
|
||||
if (response.getEntity() != null) {
|
||||
response.getEntity().getContent().close();
|
||||
responseStream = response.getEntity().getContent();
|
||||
}
|
||||
|
||||
if (response.getStatusLine().getStatusCode() != 204) {
|
||||
throw new HttpErrorException(response.getStatusLine());
|
||||
throw httpErrorException(response, responseStream);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ClientRegistrationException("Failed to send request", e);
|
||||
@@ -185,4 +174,13 @@ class HttpUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private HttpErrorException httpErrorException(HttpResponse response, InputStream responseStream) throws IOException {
|
||||
if (responseStream != null) {
|
||||
String errorResponse = StreamUtil.readString(responseStream);
|
||||
return new HttpErrorException(response.getStatusLine(), errorResponse);
|
||||
} else {
|
||||
return new HttpErrorException(response.getStatusLine(), null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user