use of io.micronaut.http.uri.UriBuilder in project micronaut-core by micronaut-projects.
the class DefaultHttpClient method resolveRedirectURI.
/**
* @param parentRequest The parent request
* @param request The redirect location request
* @param <I> The input type
* @return A {@link Publisher} with the resolved URI
*/
protected <I> Publisher<URI> resolveRedirectURI(io.micronaut.http.HttpRequest<?> parentRequest, io.micronaut.http.HttpRequest<I> request) {
URI requestURI = request.getUri();
if (requestURI.getScheme() != null) {
// if the request URI includes a scheme then it is fully qualified so use the direct server
return Flux.just(requestURI);
} else {
if (parentRequest == null || parentRequest.getUri().getHost() == null) {
return resolveURI(request, false);
} else {
URI parentURI = parentRequest.getUri();
UriBuilder uriBuilder = UriBuilder.of(requestURI).scheme(parentURI.getScheme()).userInfo(parentURI.getUserInfo()).host(parentURI.getHost()).port(parentURI.getPort());
return Flux.just(uriBuilder.build());
}
}
}
use of io.micronaut.http.uri.UriBuilder in project micronaut-core by micronaut-projects.
the class NettyClientHttpRequest method decodeParameters.
private NettyHttpParameters decodeParameters(URI uri) {
QueryStringDecoder queryStringDecoder = createDecoder(uri);
return new NettyHttpParameters(queryStringDecoder.parameters(), ConversionService.SHARED, (name, value) -> {
UriBuilder newUri = UriBuilder.of(getUri());
newUri.replaceQueryParam(name.toString(), value.toArray());
this.uri(newUri.build());
});
}
use of io.micronaut.http.uri.UriBuilder in project micronaut-core by micronaut-projects.
the class HttpToHttpsRedirectHandler method channelRead.
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof HttpRequest && ctx.pipeline().get(SslHandler.class) == null) {
HttpRequest<?> request = (HttpRequest<?>) msg;
UriBuilder uriBuilder = UriBuilder.of(hostResolver.resolve(request));
uriBuilder.scheme("https");
int port = sslConfiguration.getPort();
if (port == 443) {
uriBuilder.port(-1);
} else {
uriBuilder.port(port);
}
uriBuilder.path(request.getPath());
MutableHttpResponse<?> response = HttpResponse.permanentRedirect(uriBuilder.build()).header(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
io.netty.handler.codec.http.HttpResponse nettyResponse = NettyHttpResponseBuilder.toHttpResponse(response);
ctx.writeAndFlush(nettyResponse);
} else {
ctx.fireChannelRead(msg);
}
}
use of io.micronaut.http.uri.UriBuilder in project micronaut-security by micronaut-projects.
the class DefaultAuthorizationRedirectHandler method expandedUri.
/**
* @param baseUrl Base Url
* @param queryParams Query Parameters
* @return The Expanded URI
*/
protected String expandedUri(@NonNull String baseUrl, @NonNull Map<String, Object> queryParams) {
UriBuilder builder = UriBuilder.of(baseUrl);
queryParams.entrySet().stream().filter(entry -> entry.getValue() != null).forEach(entry -> builder.queryParam(entry.getKey(), entry.getValue()));
return builder.toString();
}
use of io.micronaut.http.uri.UriBuilder in project micronaut-starter by micronaut-projects.
the class GitHubRedirectService method constructOAuthRedirectUrl.
/**
* Creates redirect URI to github oauth auhtorise in order to receive the user access code.
*
* @param requestInfo origin request info
* @return URI to github oauth authorise
*/
protected URI constructOAuthRedirectUrl(RequestInfo requestInfo) {
try {
UriBuilder uriBuilder = UriBuilder.of(requestInfo.getServerURL()).path(requestInfo.getPath());
requestInfo.getParameters().forEachValue(uriBuilder::queryParam);
URI redirectUri = uriBuilder.build();
return UriBuilder.of(githubOAuthUrl).queryParam("scope", "user,repo").queryParam("client_id", gitHubConfiguration.getClientId()).queryParam("redirect_uri", redirectUri.toString()).queryParam("state", UUID.randomUUID().toString()).build();
} catch (Exception e) {
String msg = "Failed to construct redirect URI using request " + requestInfo + " to GiHub OAuth: " + e.getMessage();
LOG.error(msg, e);
throw new RuntimeException(msg);
}
}
Aggregations