use of com.canoo.dp.impl.platform.core.http.HttpClientConnection in project dolphin-platform by canoo.
the class KeycloakLogoutServlet method doPost.
@Override
protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
try {
LOG.debug("Logout endpoint called");
final String realmName = Optional.ofNullable(req.getHeader(REALM_NAME_HEADER)).orElse(configuration.getRealmName());
final String authEndPoint = configuration.getAuthEndpoint();
final URI url = new URI(authEndPoint + "/realms/" + realmName + "/protocol/openid-connect/logout");
LOG.debug("Calling Keycloak");
final HttpClientConnection clientConnection = new HttpClientConnection(url, RequestMethod.GET);
clientConnection.addRequestHeader(AUTHORIZATION_HEADER, req.getHeader(AUTHORIZATION_HEADER));
final int responseCode = clientConnection.readResponseCode();
if (responseCode != HTTP_OK) {
LOG.debug("Error in logout!");
throw new DolphinRuntimeException("Error in logout!");
}
LOG.debug("Logout done");
} catch (final Exception e) {
resp.sendError(SC_INTERNAL_SERVER_ERROR, "Error in logout!");
}
}
use of com.canoo.dp.impl.platform.core.http.HttpClientConnection in project dolphin-platform by canoo.
the class KeycloakSecurity method createDirectConnection.
private HttpClientConnection createDirectConnection(final String realmName) throws URISyntaxException, IOException {
final URI url = new URI(authEndpoint + "/auth/realms/" + realmName + "/protocol/openid-connect/token");
final HttpClientConnection clientConnection = new HttpClientConnection(url, RequestMethod.POST);
clientConnection.addRequestHeader(CONTENT_TYPE_HEADER, FORM_MIME_TYPE);
return clientConnection;
}
use of com.canoo.dp.impl.platform.core.http.HttpClientConnection in project dolphin-platform by canoo.
the class KeycloakTokenServlet method doPost.
@Override
protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
try {
LOG.debug("open-id endpoint called");
final String realmName = Optional.ofNullable(req.getHeader(REALM_NAME_HEADER)).orElse(configuration.getRealmName());
final String appName = Optional.ofNullable(req.getHeader(APPLICATION_NAME_HEADER)).orElse(configuration.getApplicationName());
final String authEndPoint = configuration.getAuthEndpoint();
final String content = ConnectionUtils.readUTF8Content(req.getInputStream()) + "&client_id=" + appName;
LOG.debug("Calling Keycloak");
final URI url = new URI(authEndPoint + "/realms/" + realmName + "/protocol/openid-connect/token");
final HttpClientConnection clientConnection = new HttpClientConnection(url, RequestMethod.POST);
clientConnection.addRequestHeader(CONTENT_TYPE_HEADER, FORM_MIME_TYPE);
clientConnection.addRequestHeader(CHARSET_HEADER, CHARSET);
clientConnection.writeRequestContent(content);
final int responseCode = clientConnection.readResponseCode();
if (responseCode == SC_HTTP_UNAUTHORIZED) {
LOG.debug("Invalid login!");
throw new DolphinRuntimeException("Invalid login!");
}
LOG.debug("sending auth token to client");
final byte[] responseContent = clientConnection.readResponseContent();
ConnectionUtils.writeContent(resp.getOutputStream(), responseContent);
} catch (final Exception e) {
LOG.error("Error in security token handling", e);
resp.sendError(SC_HTTP_UNAUTHORIZED, "Can not authorize");
}
}
use of com.canoo.dp.impl.platform.core.http.HttpClientConnection in project dolphin-platform by canoo.
the class KeycloakSecurity method createServerProxyConnection.
private HttpClientConnection createServerProxyConnection(final String realmName, final String appName) throws URISyntaxException, IOException {
final URI url = new URI(authEndpoint);
final HttpClientConnection clientConnection = new HttpClientConnection(url, RequestMethod.POST);
clientConnection.addRequestHeader(CONTENT_TYPE_HEADER, TEXT_MIME_TYPE);
if (realmName != null && !realmName.isEmpty()) {
clientConnection.addRequestHeader(REALM_NAME_HEADER, realmName);
}
if (appName != null && !appName.isEmpty()) {
clientConnection.addRequestHeader(APPLICATION_NAME_HEADER, appName);
}
return clientConnection;
}
use of com.canoo.dp.impl.platform.core.http.HttpClientConnection in project dolphin-platform by canoo.
the class HttpClientImpl method request.
@Override
public HttpCallRequestBuilder request(final URI url, final RequestMethod method) {
try {
Assert.requireNonNull(url, "url");
Assert.requireNonNull(method, "method");
final HttpClientConnection clientConnection = new HttpClientConnection(httpURLConnectionFactory, url, method);
return new HttpCallRequestBuilderImpl(clientConnection, gson, requestHandlers, responseHandlers, configuration);
} catch (final IOException e) {
throw new DolphinRuntimeException("HTTP error", e);
}
}
Aggregations