Java Code Examples for org.apache.http.client.utils.URIBuilder#setFragment()

The following examples show how to use org.apache.http.client.utils.URIBuilder#setFragment() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HTTPUtil.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Remove selected fields from a URI producing a new URI
 *
 * @param uri the uri to convert
 * @param excludes the parts to exclude
 * @return The new URI instance
 */
static URI uriExclude(final URI uri, URIPart... excludes) {
  URIBuilder urib = new URIBuilder();
  EnumSet<URIPart> set = EnumSet.of(excludes[0], excludes);
  for (URIPart part : URIPart.values()) {
    if (set.contains(part))
      continue;
    switch (part) {
      case SCHEME:
        urib.setScheme(uri.getScheme());
        break;
      case USERINFO:
        urib.setUserInfo(uri.getRawUserInfo());
        break;
      case HOST:
        urib.setHost(uri.getHost());
        break;
      case PORT:
        urib.setPort(uri.getPort());
        break;
      case PATH:
        urib.setPath(uri.getPath());
        break;
      case QUERY:
        urib.setCustomQuery(uri.getQuery());
        break;
      case FRAGMENT:
        urib.setFragment(uri.getFragment());
        break;
    }
  }
  try {
    return urib.build();
  } catch (URISyntaxException e) {
    throw new IllegalArgumentException(e.getMessage());
  }
}
 
Example 2
Source File: BuildAuthorizationRequestContextAction.java    From shibboleth-oidc with Apache License 2.0 4 votes vote down vote up
/**
 * Check for none prompt pair.
 *
 * @param client      the client
 * @param authRequest the auth request
 * @return the pair
 */
private Pair<Events, ? extends Object> checkForNonePrompt(final ClientDetailsEntity client,
                                                          final OIDCAuthorizationRequestContext authRequest) {
    log.debug("Prompt contains {}", ConnectRequestParameters.PROMPT_NONE);
    final Authentication auth = SecurityContextHolder.getContext().getAuthentication();

    if (auth != null) {
        log.debug("Authentication context is found for {}. Already logged in; continue without prompt",
                auth.getPrincipal());
        return new Pair(Events.Success, auth);
    }

    log.info("Client requested no prompt");
    if (client != null && authRequest.getRedirectUri() != null) {
        try {
            final String url = redirectResolver.resolveRedirect(authRequest.getRedirectUri(), client);
            log.debug("Initial redirect url resolved for client {} is {}", client.getClientName(), url);

            final URIBuilder uriBuilder = new URIBuilder(url);
            
            if (authRequest.isImplicitResponseType()) {
                log.debug("Request is asking for implicit grant type. Encoding parameters as fragments");
                final StringBuilder builder = new StringBuilder();
                builder.append(ConnectRequestParameters.ERROR)
                       .append('=')
                       .append(ConnectRequestParameters.LOGIN_REQUIRED);

                if (!Strings.isNullOrEmpty(authRequest.getState())) {
                    builder.append('&')
                           .append(ConnectRequestParameters.STATE)
                           .append('=')
                           .append(authRequest.getState());
                }
                uriBuilder.setFragment(builder.toString());
            } else {
                log.debug("Request is asking for code grant type. Encoding parameters as url parameters");
                uriBuilder.addParameter(ConnectRequestParameters.ERROR,
                        ConnectRequestParameters.LOGIN_REQUIRED);
                if (!Strings.isNullOrEmpty(authRequest.getState())) {
                    uriBuilder.addParameter(ConnectRequestParameters.STATE, authRequest.getState());
                }
            }
            log.debug("Resolved redirect url {}", uriBuilder.toString());
            return new Pair<>(Events.Redirect, uriBuilder.toString());

        } catch (final URISyntaxException e) {
            log.error("Can't build redirect URI for prompt=none, sending error instead", e);
        }
    } else {
        log.warn("Access denied. Either client is not found or no redirect uri is specified");

    }
    return new Pair(Events.Failure, null);
}