Search in sources :

Example 46 with URIBuilder

use of org.apache.http.client.utils.URIBuilder in project cas by apereo.

the class WSFederationAuthenticationServiceSelectionStrategy method getRealmAsParameter.

private static Optional<NameValuePair> getRealmAsParameter(final Service service) {
    try {
        final URIBuilder builder = new URIBuilder(service.getId());
        final Optional param = builder.getQueryParams().stream().filter(p -> p.getName().equals(WSFederationConstants.WTREALM)).findFirst();
        return param;
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return Optional.empty();
}
Also used : AuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.AuthenticationServiceSelectionStrategy) Ordered(org.springframework.core.Ordered) Slf4j(lombok.extern.slf4j.Slf4j) URIBuilder(org.apache.http.client.utils.URIBuilder) WSFederationConstants(org.apereo.cas.ws.idp.WSFederationConstants) Service(org.apereo.cas.authentication.principal.Service) Optional(java.util.Optional) NameValuePair(org.apache.http.NameValuePair) ServiceFactory(org.apereo.cas.authentication.principal.ServiceFactory) Optional(java.util.Optional) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 47 with URIBuilder

use of org.apache.http.client.utils.URIBuilder in project cas by apereo.

the class WSFederationAuthenticationServiceSelectionStrategy method getReplyAsParameter.

private static Optional<NameValuePair> getReplyAsParameter(final Service service) {
    try {
        final URIBuilder builder = new URIBuilder(service.getId());
        final Optional param = builder.getQueryParams().stream().filter(p -> p.getName().equals(WSFederationConstants.WREPLY)).findFirst();
        return param;
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return Optional.empty();
}
Also used : AuthenticationServiceSelectionStrategy(org.apereo.cas.authentication.AuthenticationServiceSelectionStrategy) Ordered(org.springframework.core.Ordered) Slf4j(lombok.extern.slf4j.Slf4j) URIBuilder(org.apache.http.client.utils.URIBuilder) WSFederationConstants(org.apereo.cas.ws.idp.WSFederationConstants) Service(org.apereo.cas.authentication.principal.Service) Optional(java.util.Optional) NameValuePair(org.apache.http.NameValuePair) ServiceFactory(org.apereo.cas.authentication.principal.ServiceFactory) Optional(java.util.Optional) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 48 with URIBuilder

use of org.apache.http.client.utils.URIBuilder in project blueocean-plugin by jenkinsci.

the class BitbucketServerApi method getBranch.

@Override
@CheckForNull
public BbBranch getBranch(@Nonnull String orgId, @Nonnull String repoSlug, @Nonnull String branch) {
    try {
        URIBuilder uriBuilder = new URIBuilder(String.format("%s/%s/repos/%s/branches/", baseUrl + "projects", orgId, repoSlug));
        uriBuilder.addParameter("filterText", branch);
        BbServerPage<BbServerBranch> branches = om.readValue(request.get(uriBuilder.build().toString()).getContent(), new TypeReference<BbServerPage<BbServerBranch>>() {
        });
        String expectedId = "refs/heads/" + branch;
        for (BbServerBranch b : branches.getValues()) {
            if (b.getId().equals(expectedId)) {
                return b;
            }
        }
        return null;
    } catch (IOException | URISyntaxException e) {
        throw handleException(e);
    }
}
Also used : BbServerPage(io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerPage) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URIBuilder(org.apache.http.client.utils.URIBuilder) BbServerBranch(io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.model.BbServerBranch) CheckForNull(javax.annotation.CheckForNull)

Example 49 with URIBuilder

use of org.apache.http.client.utils.URIBuilder in project opennms by OpenNMS.

the class HttpCollector method buildUri.

private static URI buildUri(final HttpCollectorAgent collectorAgent) throws URISyntaxException {
    HashMap<String, String> substitutions = new HashMap<String, String>();
    substitutions.put("ipaddr", InetAddressUtils.str(collectorAgent.getAgent().getAddress()));
    substitutions.put("nodeid", Integer.toString(collectorAgent.getAgent().getNodeId()));
    final URIBuilder ub = new URIBuilder();
    ub.setScheme(collectorAgent.getUriDef().getUrl().getScheme());
    ub.setHost(substituteKeywords(substitutions, collectorAgent.getUriDef().getUrl().getHost(), "getHost"));
    ub.setPort(collectorAgent.getPort());
    ub.setPath(substituteKeywords(substitutions, collectorAgent.getUriDef().getUrl().getPath(), "getURL"));
    final String query = substituteKeywords(substitutions, collectorAgent.getUriDef().getUrl().getQuery().orElse(null), "getQuery");
    if (query != null) {
        final List<NameValuePair> params = URLEncodedUtils.parse(query, StandardCharsets.UTF_8);
        ub.setParameters(params);
    }
    ub.setFragment(substituteKeywords(substitutions, collectorAgent.getUriDef().getUrl().getFragment().orElse(null), "getFragment"));
    return ub.build();
}
Also used : NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HashMap(java.util.HashMap) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 50 with URIBuilder

use of org.apache.http.client.utils.URIBuilder in project cas by apereo.

the class OAuth20AuthorizeEndpointController method buildCallbackUrlResponseType.

/**
     * Build callback url response type string.
     *
     * @param authentication the authentication
     * @param service        the service
     * @param redirectUri    the redirect uri
     * @param accessToken    the access token
     * @param params         the params
     * @return the string
     * @throws Exception the exception
     */
protected String buildCallbackUrlResponseType(final Authentication authentication, final Service service, final String redirectUri, final AccessToken accessToken, final List<NameValuePair> params) throws Exception {
    final String state = authentication.getAttributes().get(OAuthConstants.STATE).toString();
    final String nonce = authentication.getAttributes().get(OAuthConstants.NONCE).toString();
    final URIBuilder builder = new URIBuilder(redirectUri);
    final StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(OAuthConstants.ACCESS_TOKEN).append('=').append(accessToken.getId()).append('&').append(OAuthConstants.TOKEN_TYPE).append('=').append(OAuthConstants.TOKEN_TYPE_BEARER).append('&').append(OAuthConstants.EXPIRES_IN).append('=').append(casProperties.getTicket().getTgt().getTimeToKillInSeconds());
    params.forEach(p -> stringBuilder.append('&').append(p.getName()).append('=').append(p.getValue()));
    if (StringUtils.isNotBlank(state)) {
        stringBuilder.append('&').append(OAuthConstants.STATE).append('=').append(EncodingUtils.urlEncode(state));
    }
    if (StringUtils.isNotBlank(nonce)) {
        stringBuilder.append('&').append(OAuthConstants.NONCE).append('=').append(EncodingUtils.urlEncode(nonce));
    }
    builder.setFragment(stringBuilder.toString());
    final String url = builder.toString();
    return url;
}
Also used : URIBuilder(org.apache.http.client.utils.URIBuilder)

Aggregations

URIBuilder (org.apache.http.client.utils.URIBuilder)107 URISyntaxException (java.net.URISyntaxException)42 URI (java.net.URI)37 HttpGet (org.apache.http.client.methods.HttpGet)22 IOException (java.io.IOException)21 NameValuePair (org.apache.http.NameValuePair)13 HttpEntity (org.apache.http.HttpEntity)10 NotNull (org.jetbrains.annotations.NotNull)9 Map (java.util.Map)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 HttpResponse (org.apache.http.HttpResponse)7 List (java.util.List)6 HttpClient (org.apache.http.client.HttpClient)5 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)5 Gson (com.google.gson.Gson)4 URL (java.net.URL)4 RequestConfig (org.apache.http.client.config.RequestConfig)4 HttpPost (org.apache.http.client.methods.HttpPost)4