Search in sources :

Example 6 with URIBuilder

use of org.apache.http.client.utils.URIBuilder in project helios by spotify.

the class HeliosClient method uri.

private URI uri(final String path, final Multimap<String, String> query) {
    checkArgument(path.startsWith("/"));
    final URIBuilder builder = new URIBuilder().setScheme("http").setHost("helios").setPath(path);
    for (final Map.Entry<String, String> q : query.entries()) {
        builder.addParameter(q.getKey(), q.getValue());
    }
    builder.addParameter("user", user);
    try {
        return builder.build();
    } catch (URISyntaxException e) {
        throw Throwables.propagate(e);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 7 with URIBuilder

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

the class BaseSamlRegisteredServiceAttributeReleasePolicy method getAttributesInternal.

@Override
protected Map<String, Object> getAttributesInternal(final Map<String, Object> attrs, final RegisteredService service) {
    if (service instanceof SamlRegisteredService) {
        final SamlRegisteredService saml = (SamlRegisteredService) service;
        final HttpServletRequest request = WebUtils.getHttpServletRequestFromRequestAttributes();
        if (request == null) {
            LOGGER.warn("Could not locate the request context to process attributes");
            return super.getAttributesInternal(attrs, service);
        }
        String entityId = request.getParameter(SamlProtocolConstants.PARAMETER_ENTITY_ID);
        if (StringUtils.isBlank(entityId)) {
            final String svcParam = request.getParameter(CasProtocolConstants.PARAMETER_SERVICE);
            if (StringUtils.isNotBlank(svcParam)) {
                try {
                    final URIBuilder builder = new URIBuilder(svcParam);
                    entityId = builder.getQueryParams().stream().filter(p -> p.getName().equals(SamlProtocolConstants.PARAMETER_ENTITY_ID)).map(NameValuePair::getValue).findFirst().orElse(StringUtils.EMPTY);
                } catch (final Exception e) {
                    LOGGER.error(e.getMessage());
                }
            }
        }
        final ApplicationContext ctx = ApplicationContextProvider.getApplicationContext();
        if (ctx == null) {
            LOGGER.warn("Could not locate the application context to process attributes");
            return super.getAttributesInternal(attrs, service);
        }
        final SamlRegisteredServiceCachingMetadataResolver resolver = ctx.getBean("defaultSamlRegisteredServiceCachingMetadataResolver", SamlRegisteredServiceCachingMetadataResolver.class);
        final Optional<SamlRegisteredServiceServiceProviderMetadataFacade> facade = SamlRegisteredServiceServiceProviderMetadataFacade.get(resolver, saml, entityId);
        if (facade == null || !facade.isPresent()) {
            LOGGER.warn("Could not locate metadata for [{}] to process attributes", entityId);
            return super.getAttributesInternal(attrs, service);
        }
        final EntityDescriptor input = facade.get().getEntityDescriptor();
        if (input == null) {
            LOGGER.warn("Could not locate entity descriptor for [{}] to process attributes", entityId);
            return super.getAttributesInternal(attrs, service);
        }
        return getAttributesForSamlRegisteredService(attrs, saml, ctx, resolver, facade.get(), input);
    }
    return super.getAttributesInternal(attrs, service);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) ApplicationContext(org.springframework.context.ApplicationContext) SamlRegisteredServiceServiceProviderMetadataFacade(org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade) SamlRegisteredServiceCachingMetadataResolver(org.apereo.cas.support.saml.services.idp.metadata.cache.SamlRegisteredServiceCachingMetadataResolver) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 8 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) Logger(org.slf4j.Logger) URIBuilder(org.apache.http.client.utils.URIBuilder) WSFederationConstants(org.apereo.cas.ws.idp.WSFederationConstants) Service(org.apereo.cas.authentication.principal.Service) LoggerFactory(org.slf4j.LoggerFactory) 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 9 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) Logger(org.slf4j.Logger) URIBuilder(org.apache.http.client.utils.URIBuilder) WSFederationConstants(org.apereo.cas.ws.idp.WSFederationConstants) Service(org.apereo.cas.authentication.principal.Service) LoggerFactory(org.slf4j.LoggerFactory) 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 10 with URIBuilder

use of org.apache.http.client.utils.URIBuilder in project musiccabinet by hakko.

the class AbstractMusicBrainzClient method getURI.

protected URI getURI(String path, List<NameValuePair> params) throws ApplicationException {
    URI uri = null;
    try {
        URIBuilder uriBuilder = new URIBuilder();
        uriBuilder.setScheme(HTTP);
        uriBuilder.setHost(HOST);
        uriBuilder.setPath(path);
        for (NameValuePair param : params) {
            uriBuilder.addParameter(param.getName(), param.getValue());
        }
        uri = uriBuilder.build();
    } catch (URISyntaxException e) {
        throw new ApplicationException("Could not create MusicBrainz URI!", e);
    }
    return uri;
}
Also used : NameValuePair(org.apache.http.NameValuePair) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URIBuilder(org.apache.http.client.utils.URIBuilder)

Aggregations

URIBuilder (org.apache.http.client.utils.URIBuilder)95 URISyntaxException (java.net.URISyntaxException)36 URI (java.net.URI)35 HttpGet (org.apache.http.client.methods.HttpGet)21 IOException (java.io.IOException)19 NameValuePair (org.apache.http.NameValuePair)12 HttpEntity (org.apache.http.HttpEntity)9 NotNull (org.jetbrains.annotations.NotNull)9 Map (java.util.Map)8 HashMap (java.util.HashMap)7 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)7 HttpResponse (org.apache.http.HttpResponse)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 HttpClient (org.apache.http.client.HttpClient)5 Gson (com.google.gson.Gson)4 URL (java.net.URL)4 HttpPost (org.apache.http.client.methods.HttpPost)4 StringEntity (org.apache.http.entity.StringEntity)4 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)4