List of usage examples for com.squareup.okhttp Credentials basic
public static String basic(String userName, String password)
From source file:com.horntell.http.Request.java
private Response doPutRequest(String url, Map<String, Object> params) throws IOException { String credential = Credentials.basic(App.getKey(), App.getSecret()); String json = new JSONObject(params).toString(); RequestBody body = RequestBody.create(JSON, json); com.squareup.okhttp.Request request; request = new com.squareup.okhttp.Request.Builder().url(url).header("Authorization", credential) .addHeader("Accept", "application/vnd.horntell." + App.getVersion() + "+json") .addHeader("Content-Type", "text/json").put(body).build(); com.squareup.okhttp.Response response = client.newCall(request).execute(); return new Response(response); }
From source file:com.ibm.watson.developer_cloud.service.WatsonService.java
License:Open Source License
/** * Sets the username and password.//from w w w . j a v a2s . c o m * * @param username the username * @param password the password */ public void setUsernameAndPassword(String username, String password) { apiKey = Credentials.basic(username, password); }
From source file:com.ibm.watson.developer_cloud.util.BluemixUtils.java
License:Open Source License
/** * Returns the apiKey from the VCAP_SERVICES or null if doesn't exists. If plan is specified, then * only credentials for the given plan will be returned. * //from w ww . j a v a 2 s. c o m * @param serviceName the service name * @param plan the service plan: standard, free or experimental * @return the API key */ public static String getAPIKey(String serviceName, String plan) { if (serviceName == null || serviceName.isEmpty()) return null; final JsonObject services = getVCAPServices(); if (services == null) return null; for (final Entry<String, JsonElement> entry : services.entrySet()) { final String key = entry.getKey(); if (key.startsWith(serviceName)) { final JsonArray servInstances = services.getAsJsonArray(key); for (final JsonElement instance : servInstances) { final JsonObject service = instance.getAsJsonObject(); final String instancePlan = service.get(PLAN).getAsString(); if (plan == null || plan.equalsIgnoreCase(instancePlan)) { final JsonObject credentials = instance.getAsJsonObject().getAsJsonObject(CREDENTIALS); if (serviceName.equalsIgnoreCase(ALCHEMY_API)) { return credentials.get(APIKEY).getAsString(); } else { final String username = credentials.get(USERNAME).getAsString(); final String password = credentials.get(PASSWORD).getAsString(); return Credentials.basic(username, password); } } } } } return null; }
From source file:com.ibm.watson.developer_cloud.util.CredentialUtils.java
License:Open Source License
/** * Returns the apiKey from the VCAP_SERVICES or null if doesn't exists. If plan is specified, then * only credentials for the given plan will be returned. * /*ww w.j a v a 2s . c om*/ * @param serviceName the service name * @param plan the service plan: standard, free or experimental * @return the API key */ public static String getAPIKey(String serviceName, String plan) { if (serviceName == null || serviceName.isEmpty()) return null; final JsonObject services = getVCAPServices(); if (services == null) return getKeyUsingJNDI(serviceName); for (final Entry<String, JsonElement> entry : services.entrySet()) { final String key = entry.getKey(); if (key.startsWith(serviceName)) { final JsonArray servInstances = services.getAsJsonArray(key); for (final JsonElement instance : servInstances) { final JsonObject service = instance.getAsJsonObject(); final String instancePlan = service.get(PLAN).getAsString(); if (plan == null || plan.equalsIgnoreCase(instancePlan)) { final JsonObject credentials = instance.getAsJsonObject().getAsJsonObject(CREDENTIALS); if (serviceName.equalsIgnoreCase(ALCHEMY_API)) { return credentials.get(APIKEY).getAsString(); } else { final String username = credentials.get(USERNAME).getAsString(); final String password = credentials.get(PASSWORD).getAsString(); return Credentials.basic(username, password); } } } } } return null; }
From source file:com.liferay.mobile.android.auth.basic.BasicAuthAutenticator.java
License:Open Source License
@Override public Request authenticate(Proxy proxy, Response response) throws IOException { String credential = Credentials.basic(username, password); return response.request().newBuilder().header(Headers.AUTHORIZATION, credential).build(); }
From source file:com.liferay.mobile.android.auth.basic.BasicAuthentication.java
License:Open Source License
@Override public void authenticate(Request request) { request.getHeaders().put(Headers.AUTHORIZATION, Credentials.basic(username, password)); }
From source file:com.liferay.mobile.sdk.auth.BasicAuthentication.java
License:Open Source License
@Override public Request authenticate(Request request) { return request.newBuilder().header(Headers.AUTHORIZATION, Credentials.basic(username, password)).build(); }
From source file:com.nizlumina.utils.WebUnitMaster.java
License:Open Source License
public void setCredentials(String user, String password) { String credentials = Credentials.basic(user, password); System.out.print("Authorization: " + credentials); mHeaders.put("Authorization", credentials); }
From source file:com.northernwall.hadrian.module.maven.MavenHelper.java
License:Apache License
@Override public List<String> readArtifactVersions(Module module) { List<String> versions = new LinkedList<>(); if (module.getMavenGroupId() != null && !module.getMavenGroupId().isEmpty() && module.getMavenArtifactId() != null && !module.getMavenArtifactId().isEmpty()) { try {//from w ww. j a va 2 s . c o m Request.Builder builder = new Request.Builder(); String mavenRepo = parameters.getString(Const.MAVEN_URL, Const.MAVEN_URL_DEFAULT); String url = mavenRepo + module.getMavenGroupId().replace(".", "/") + "/" + module.getMavenArtifactId() + "/maven-metadata.xml"; builder.url(url); String mavenUsername = parameters.getString(Const.MAVEN_USERNAME, Const.MAVEN_USERNAME_DEFAULT); String mavenPassword = parameters.getString(Const.MAVEN_PASSWORD, Const.MAVEN_PASSWORD_DEFAULT); if (!mavenUsername.equals(Const.MAVEN_USERNAME_DEFAULT)) { String credential = Credentials.basic(mavenUsername, mavenPassword); builder.header("Authorization", credential); } Request request = builder.build(); Response response = client.newCall(request).execute(); try (InputStream inputStream = response.body().byteStream()) { versions = processMavenStream(inputStream); } } catch (Exception ex) { logger.error("Error reading maven version from {} {}, {}", module.getMavenGroupId(), module.getMavenArtifactId(), ex.getMessage()); } } return versions; }
From source file:com.quarterfull.newsAndroid.reader.HttpJsonRequest.java
License:Open Source License
public void setCredentials(final String username, final String password, final String oc_root_path) { if (username != null) credentials = Credentials.basic(username, password); else/* w w w . j ava 2 s. c o m*/ credentials = null; if (oc_root_path != null) { // Add empty path segment to ensure trailing slash oc_root_url = HttpUrl.parse(oc_root_path).newBuilder().addPathSegment("").build(); } }