public URI toUri() { return URI.create(toString()); }
public URI toUri() { return URI.create(toString()); }
public URL toUrl() { try { return new URL(toString()); } catch (MalformedURLException e) { throw new IllegalArgumentException(e); } }
public URL toUrl() { try { return new URL(toString()); } catch (MalformedURLException e) { throw new IllegalArgumentException(e); } }
public static String getContextURL() { return createContextURLBuilder().toString(); }
public static String buildUrl(String baseUrl, String... pathElements) { final URLBuilder url = new URLBuilder(baseUrl); for (String element : pathElements) { url.path(element); } return url.toString(); }
/** * Return an absolute URL under the context path. * * @param path Path * @return absolute URL */ public static String getContextURL(String path) { return createContextURLBuilder().path(path).toString(); }
public static String buildUrl(String baseUrl, String... pathElements) { final URLBuilder url = new URLBuilder(baseUrl); for (String element : pathElements) { url.addPath(element); } return url.toString(); }
/** * Initiate an IDVKey authentication for a user * * @param serviceId Website serviceId * @param redirectUrl URL that the user's browser should be redirected to after he's performed the authentication. * @param cancelUrl URL that the user's browser should be redirected to if he cancelled the authentication. * @return Operation result. This will contain the URL you should redirect your user's browser to. * ({@link OperationResult#getRedirectUrl()}), and an operation id that you will use to verify that the user has completed * authentication successfully ({@link OperationResult#getOpId()}) * @throws IOException If error occurred performing the operation */ public OperationResult authenticateUser(@NotNull String serviceId, @NotNull URL redirectUrl, URL cancelUrl) throws IOException { String url = new URLBuilder("api/idvkey/authenticate").add("serviceId", serviceId).add("redirectUrl", redirectUrl.toString()).add("cancelUrl", cancelUrl.toString()).toString(); final String jsonOpRes = post(url, null); return jsonMapper.readValue(jsonOpRes, OperationResult.class); }
private void init(String serverUrl, String keyId, SigningKey signingKey, SignatureVerificationKey signatureVerificationKey, int timeout) { this.serverUrl = serverUrl; // Create HTTP Client with REST security interceptor final HCInterceptor hcInterceptor = new HCInterceptor(new JCECryptoEngine(), null); HttpClientBuilder httpClientBuilder = hcInterceptor.createClientBuilder(); RequestConfig.Builder requestBuilder = RequestConfig.custom().setConnectTimeout(timeout) .setConnectionRequestTimeout(timeout).setSocketTimeout(timeout); httpClientBuilder.setDefaultRequestConfig(requestBuilder.build()); BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); // This is used to used to adjust http timestamps in case client has the wrong time final TimeAsHttpContentTimeSync timeSync = new TimeAsHttpContentTimeSync(new URLBuilder(serverUrl).addPath("/public/time").toString()); credentialsProvider.setCredentials(ANY, new RestAuthCredential(keyId, signingKey, signatureVerificationKey, DigestAlgorithm.SHA256, timeSync)); httpClient = httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider).build(); }
/** * Request for a user to approve an operation using IDVKey * * @param serviceId serviceId * @param userRef User ref * @param redirectUrl URL to redirect browser once the operation has been handled by the user (or if it expired). * @param cancelUrl URL to redirect browser if the user wants to cancel the operation. * @param approvalRequest Approval request details @return Operation results * @throws IOException If an error occurs while performing the operation * @return operation result */ @SuppressWarnings("ConstantConditions") public OperationResult requestApproval(@NotNull String serviceId, @NotNull String userRef, @NotNull URL redirectUrl, @NotNull URL cancelUrl, @NotNull ApprovalRequest approvalRequest) throws IOException { if (approvalRequest == null) { throw new IllegalArgumentException("approval request missing"); } else if (StringUtils.isBlank(approvalRequest.getTitle())) { throw new IllegalArgumentException("approval title missing"); } else if (StringUtils.isBlank(approvalRequest.getText())) { throw new IllegalArgumentException("approval text missing"); } final String json = postJson(new URLBuilder("api/idvkey/approve").add("serviceId", serviceId) .add("redirectUrl", redirectUrl.toString()).add("cancelUrl", cancelUrl.toString()).add("userRef", userRef).toString(), approvalRequest); return jsonMapper.readValue(json, OperationResult.class); }
public void download() throws HttpException { String url = buildUrl().param("limit", limit).param("offset", offset).toString(); String json = parent.getClient().getHttpHelper().httpGet(url); JsonHelper jsonHelper = parent.getClient().getJsonHelper(); parseJson(json, jsonHelper); }