List of usage examples for org.apache.http.client.utils URIBuilder addParameter
public URIBuilder addParameter(final String param, final String value)
From source file:org.apache.ambari.server.view.HttpImpersonatorImpl.java
/** * Returns the result of the HTTP request by setting the "doAs" impersonation for the query param and username * in @param impersonatorSetting.//ww w. j av a 2s .c o m * @param url URL to request * @param requestType HTTP Request type: GET, PUT, POST, DELETE, etc. * @param impersonatorSetting Setting class with default values for username and doAs param name. * To use different values, call the setters of the object. * @return Return a response as a String */ @Override public String requestURL(String url, String requestType, final ImpersonatorSetting impersonatorSetting) { String result = ""; BufferedReader rd; String line; if (url.toLowerCase().contains(impersonatorSetting.getDoAsParamName().toLowerCase())) { throw new IllegalArgumentException( "URL cannot contain \"" + impersonatorSetting.getDoAsParamName() + "\" parameter"); } try { String username = impersonatorSetting.getUsername(); if (username != null) { URIBuilder builder = new URIBuilder(url); builder.addParameter(impersonatorSetting.getDoAsParamName(), username); url = builder.build().toString(); } HttpURLConnection connection = urlStreamProvider.processURL(url, requestType, (String) null, null); int responseCode = connection.getResponseCode(); InputStream resultInputStream; if (responseCode >= ProxyService.HTTP_ERROR_RANGE_START) { resultInputStream = connection.getErrorStream(); } else { resultInputStream = connection.getInputStream(); } rd = new BufferedReader(new InputStreamReader(resultInputStream)); if (rd != null) { line = rd.readLine(); while (line != null) { result += line; line = rd.readLine(); } rd.close(); } } catch (Exception e) { LOG.error("Exception caught processing impersonator request.", e); } return result; }
From source file:org.mitre.openid.connect.client.service.impl.SignedAuthRequestUrlBuilder.java
@Override public String buildAuthRequestUrl(ServerConfiguration serverConfig, RegisteredClient clientConfig, String redirectUri, String nonce, String state, Map<String, String> options, String loginHint) { // create our signed JWT for the request object JWTClaimsSet.Builder claims = new JWTClaimsSet.Builder(); //set parameters to JwtClaims claims.claim("response_type", "code"); claims.claim("client_id", clientConfig.getClientId()); claims.claim("scope", Joiner.on(" ").join(clientConfig.getScope())); // build our redirect URI claims.claim("redirect_uri", redirectUri); // this comes back in the id token claims.claim("nonce", nonce); // this comes back in the auth request return claims.claim("state", state); // Optional parameters for (Entry<String, String> option : options.entrySet()) { claims.claim(option.getKey(), option.getValue()); }// w w w .ja v a2s . c o m // if there's a login hint, send it if (!Strings.isNullOrEmpty(loginHint)) { claims.claim("login_hint", loginHint); } JWSAlgorithm alg = clientConfig.getRequestObjectSigningAlg(); if (alg == null) { alg = signingAndValidationService.getDefaultSigningAlgorithm(); } SignedJWT jwt = new SignedJWT(new JWSHeader(alg), claims.build()); signingAndValidationService.signJwt(jwt, alg); try { URIBuilder uriBuilder = new URIBuilder(serverConfig.getAuthorizationEndpointUri()); uriBuilder.addParameter("request", jwt.serialize()); // build out the URI return uriBuilder.build().toString(); } catch (URISyntaxException e) { throw new AuthenticationServiceException("Malformed Authorization Endpoint Uri", e); } }
From source file:com.activiti.service.activiti.TaskService.java
public JsonNode getSubTasks(ServerConfig serverConfig, String taskId) { URIBuilder builder = clientUtil.createUriBuilder(HISTORIC_TASK_LIST_URL); builder.addParameter("parentTaskId", taskId); builder.addParameter("size", DEFAULT_SUBTASK_RESULT_SIZE); HttpGet get = new HttpGet(clientUtil.getServerUrl(serverConfig, builder)); return clientUtil.executeRequest(get, serverConfig); }
From source file:org.eclipse.cft.server.core.internal.ssh.SshClientSupport.java
public String getSshCode() { try {// w ww .j a v a 2s .c om URIBuilder builder = new URIBuilder(authorizationUrl + "/oauth/authorize"); //$NON-NLS-1$ builder.addParameter("response_type" //$NON-NLS-1$ , "code"); //$NON-NLS-1$ builder.addParameter("grant_type", //$NON-NLS-1$ "authorization_code"); //$NON-NLS-1$ builder.addParameter("client_id", sshClientId); //$NON-NLS-1$ URI url = new URI(builder.toString()); ResponseEntity<String> response = restTemplate.getForEntity(url, String.class); HttpStatus statusCode = response.getStatusCode(); if (statusCode != HttpStatus.FOUND) { throw new CloudFoundryException(statusCode); } String loc = response.getHeaders().getFirst("Location"); //$NON-NLS-1$ if (loc == null) { throw new CloudOperationException("No 'Location' header in redirect response"); //$NON-NLS-1$ } List<NameValuePair> qparams = URLEncodedUtils.parse(new URI(loc), "utf8"); //$NON-NLS-1$ for (NameValuePair pair : qparams) { String name = pair.getName(); if (name.equals("code")) { //$NON-NLS-1$ return pair.getValue(); } } throw new CloudOperationException("No 'code' param in redirect Location: " + loc); //$NON-NLS-1$ } catch (URISyntaxException e) { throw new CloudOperationException(e); } }
From source file:com.sheepdog.mashmesh.PickupNotification.java
private URI createDynamicMapUri() throws URISyntaxException { URIBuilder uriBuilder = new URIBuilder(DYNAMIC_MAPS_URL); uriBuilder.addParameter("saddr", volunteerUserProfile.getAddress()); uriBuilder.addParameter("daddr", getPatientProfile().getAddress() + " to:" + getAppointmentAddress()); return uriBuilder.build(); }
From source file:com.activiti.service.activiti.AppService.java
public JsonNode getDecisionDefinitionsForDeploymentId(ServerConfig serverConfig, String dmnDeploymentId) { URIBuilder builder = clientUtil.createUriBuilder(DECISION_TABLES_URL); builder.addParameter("deploymentId", dmnDeploymentId); HttpGet get = new HttpGet(clientUtil.getServerUrl(serverConfig, builder)); return clientUtil.executeRequest(get, serverConfig); }
From source file:org.flowable.admin.service.engine.FormInstanceService.java
public JsonNode listFormInstances(ServerConfig serverConfig, Map<String, String[]> parameterMap) { URIBuilder builder = clientUtil.createUriBuilder("form/form-instances"); for (String name : parameterMap.keySet()) { builder.addParameter(name, parameterMap.get(name)[0]); }//from w w w .j a v a 2s. co m HttpGet get = new HttpGet(clientUtil.getServerUrl(serverConfig, builder.toString())); return clientUtil.executeRequest(get, serverConfig); }
From source file:org.jasig.portlet.proxy.service.web.interceptor.ProxyCASAuthenticationPreInterceptor.java
@Override protected void prepareAuthentication(HttpContentRequestImpl contentRequest, PortletRequest portletRequest) { // retrieve the CAS ticket from the UserInfo map @SuppressWarnings("unchecked") Map<String, String> userinfo = (Map<String, String>) portletRequest.getAttribute(PortletRequest.USER_INFO); String ticket = (String) userinfo.get("casProxyTicket"); if (ticket == null) { log.warn(/*from www .j a v a 2 s . c o m*/ "No CAS ticket found in the UserInfo map. Is 'casProxyTicket' user-attribute declared in the portlet configuration?"); return; } log.debug("serviceURL: {}, ticket: {}", this.serviceUrl, ticket); /* contact CAS and validate */ try { // validate the ticket provided by the portal final Assertion assertion = this.ticketValidator.validate(ticket, this.serviceUrl); // get a proxy ticket for the target URL final String proxyTicket = assertion.getPrincipal() .getProxyTicketFor(contentRequest.getProxiedLocation()); if (proxyTicket == null) { log.error("Failed to retrieve proxy ticket for assertion [{}]. Is the PGT still valid?", assertion.toString()); return; } log.trace("returning from proxy ticket request with proxy ticket [{}]", proxyTicket); // update the URL to include the proxy ticket final URIBuilder builder = new URIBuilder(contentRequest.getProxiedLocation()); builder.addParameter("ticket", proxyTicket); String proxiedLocation = builder.build().toString(); log.debug("Set final proxied location to be {}", proxiedLocation); contentRequest.setProxiedLocation(proxiedLocation); } catch (TicketValidationException e) { log.warn("Failed to validate proxy ticket", e); return; } catch (URISyntaxException e) { log.warn("Failed to parse proxy URL", e); return; } }
From source file:com.squid.kraken.v4.auth.ChangePasswordServlet.java
private User getUser(HttpServletRequest request) throws URISyntaxException, ServiceException, ServerUnavailableException, IOException, SSORedirectException { URIBuilder builder = new URIBuilder(privateServerURL + "/rs/user"); builder.addParameter("access_token", request.getParameter("access_token")); HttpGet req = new HttpGet(builder.build()); User user = RequestHelper.processRequest(User.class, request, req); return user;//from w w w .j a v a2s. co m }