List of usage examples for org.apache.http.auth AUTH WWW_AUTH_RESP
String WWW_AUTH_RESP
To view the source code for org.apache.http.auth AUTH WWW_AUTH_RESP.
Click Source Link
From source file:com.ibm.streamsx.topology.internal.streaminganalytics.RestUtils.java
public static void checkInstanceStatus(CloseableHttpClient httpClient, JsonObject service) throws ClientProtocolException, IOException { final String serviceName = jstring(service, "name"); final JsonObject credentials = service.getAsJsonObject("credentials"); String url = getStatusURL(credentials); String apiKey = getAPIKey(credentials); HttpGet getStatus = new HttpGet(url); getStatus.addHeader(AUTH.WWW_AUTH_RESP, apiKey); JsonObject jsonResponse = getGsonResponse(httpClient, getStatus); RemoteContext.REMOTE_LOGGER.info("Streaming Analytics service (" + serviceName + "): instance status response:" + jsonResponse.toString()); if (!"true".equals(jstring(jsonResponse, "enabled"))) throw new IllegalStateException("Service is not enabled!"); if (!"running".equals(jstring(jsonResponse, "status"))) throw new IllegalStateException("Service is not running!"); }
From source file:edu.northwestern.cbits.purple_robot_manager.http.BasicAuthTokenExtractor.java
public String extract(final HttpRequest request) throws HttpException { String auth = null;/*from w w w . j a v a2 s. c om*/ final Header h = request.getFirstHeader(AUTH.WWW_AUTH_RESP); if (h != null) { final String s = h.getValue(); if (s != null) { auth = s.trim(); } } if (auth != null) { final int i = auth.indexOf(' '); if (i == -1) { throw new ProtocolException("Invalid Authorization header: " + auth); } final String authscheme = auth.substring(0, i); if (authscheme.equalsIgnoreCase("basic")) { final String s = auth.substring(i + 1).trim(); try { final byte[] credsRaw = EncodingUtils.getAsciiBytes(s); final BinaryDecoder codec = new Base64(); auth = EncodingUtils.getAsciiString(codec.decode(credsRaw)); } catch (final DecoderException ex) { throw new ProtocolException("Malformed BASIC credentials"); } } } return auth; }
From source file:org.apache.hadoop.gateway.filter.BasicAuthChallengeFilter.java
private static UsernamePasswordCredentials createValidatedCredentials(HttpServletRequest request) { UsernamePasswordCredentials credentials = null; String basicAuthResponse = request.getHeader(AUTH.WWW_AUTH_RESP); if (basicAuthResponse != null) { String[] parts = basicAuthResponse.split(" "); if (parts.length == 2) { String usernamePassword = new String(Base64.decodeBase64(parts[1])); parts = usernamePassword.split(":"); if (parts.length == 2) { String username = parts[0]; String password = parts[1]; if (username.length() > 0 && password.length() > 0) { credentials = new UsernamePasswordCredentials(username, password); }/*from w ww . j ava2 s . com*/ } } //System.out.println( basicAuthResponse ); } return credentials; }
From source file:org.callimachusproject.client.HttpAuthenticator.java
public void generateAuthResponse(final HttpRoute route, final HttpRequest request, final HttpContext context) throws HttpException, IOException { if (!request.containsHeader(AUTH.WWW_AUTH_RESP)) { final AuthState targetAuthState = this.getTargetAuthState(context); if (this.log.isDebugEnabled()) { this.log.debug("Target auth state: " + targetAuthState.getState()); }// ww w . j a v a 2s. co m this.generateAuthResponse(request, targetAuthState, context); } if (!request.containsHeader(AUTH.PROXY_AUTH_RESP) && !route.isTunnelled()) { final AuthState proxyAuthState = this.getProxyAuthState(context); if (this.log.isDebugEnabled()) { this.log.debug("Proxy auth state: " + proxyAuthState.getState()); } this.generateAuthResponse(request, proxyAuthState, context); } }
From source file:nl.esciencecenter.octopus.webservice.mac.MacScheme.java
/** * Generates normalized request string and encrypt is using a secret key * * @return MAC Authentication header/*from w w w . jav a 2 s . c om*/ * @throws AuthenticationException when signature generation fails */ public Header authenticate(Credentials credentials, HttpRequest request, HttpContext context) throws AuthenticationException { String id = credentials.getUserPrincipal().getName(); String key = credentials.getPassword(); Long timestamp = getTimestamp(); String nonce = getNonce(); String data = getNormalizedRequestString((HttpUriRequest) request, nonce, timestamp); String request_mac = calculateRFC2104HMAC(data, key, getAlgorithm(credentials)); return new BasicHeader(AUTH.WWW_AUTH_RESP, headerValue(id, timestamp, nonce, request_mac)); }
From source file:com.ibm.streamsx.topology.internal.streaminganalytics.RestUtils.java
/** * Submit an application bundle to execute as a job. */// www. j a va 2 s .co m public static JsonObject postJob(CloseableHttpClient httpClient, JsonObject service, File bundle, JsonObject jobConfigOverlay) throws ClientProtocolException, IOException { final String serviceName = jstring(service, "name"); final JsonObject credentials = service.getAsJsonObject("credentials"); String url = getJobSubmitURL(credentials, bundle); HttpPost postJobWithConfig = new HttpPost(url); postJobWithConfig.addHeader("accept", ContentType.APPLICATION_JSON.getMimeType()); postJobWithConfig.addHeader(AUTH.WWW_AUTH_RESP, getAPIKey(credentials)); FileBody bundleBody = new FileBody(bundle, ContentType.APPLICATION_OCTET_STREAM); StringBody configBody = new StringBody(jobConfigOverlay.toString(), ContentType.APPLICATION_JSON); HttpEntity reqEntity = MultipartEntityBuilder.create().addPart("sab", bundleBody) .addPart(DeployKeys.JOB_CONFIG_OVERLAYS, configBody).build(); postJobWithConfig.setEntity(reqEntity); JsonObject jsonResponse = getGsonResponse(httpClient, postJobWithConfig); RemoteContext.REMOTE_LOGGER.info("Streaming Analytics service (" + serviceName + "): submit job response:" + jsonResponse.toString()); return jsonResponse; }
From source file:com.androidquery.test.NTLMScheme.java
public Header authenticate(final Credentials credentials, final HttpRequest request) throws AuthenticationException { NTCredentials ntcredentials = null;//from w ww.j ava 2 s . com try { ntcredentials = (NTCredentials) credentials; } catch (ClassCastException e) { throw new InvalidCredentialsException( "Credentials cannot be used for NTLM authentication: " + credentials.getClass().getName()); } String response = null; if (this.state == State.CHALLENGE_RECEIVED || this.state == State.FAILED) { response = this.engine.generateType1Msg(ntcredentials.getDomain(), ntcredentials.getWorkstation()); this.state = State.MSG_TYPE1_GENERATED; } else if (this.state == State.MSG_TYPE2_RECEVIED) { response = this.engine.generateType3Msg(ntcredentials.getUserName(), ntcredentials.getPassword(), ntcredentials.getDomain(), ntcredentials.getWorkstation(), this.challenge); this.state = State.MSG_TYPE3_GENERATED; } else { throw new AuthenticationException("Unexpected state: " + this.state); } CharArrayBuffer buffer = new CharArrayBuffer(32); if (isProxy()) { buffer.append(AUTH.PROXY_AUTH_RESP); } else { buffer.append(AUTH.WWW_AUTH_RESP); } buffer.append(": NTLM "); buffer.append(response); return new BufferedHeader(buffer); }
From source file:com.microsoft.live.ApiRequest.java
/** * Constructs a new instance of a Header that contains the * @param accessToken to construct inside the Authorization header * @return a new instance of a Header that contains the Authorization access_token *//*w w w.ja v a 2 s .c o m*/ private static Header createAuthroizationHeader(LiveConnectSession session) { assert session != null; String accessToken = session.getAccessToken(); assert !TextUtils.isEmpty(accessToken); String tokenType = OAuth.TokenType.BEARER.toString().toLowerCase(Locale.US); String value = TextUtils.join(" ", new String[] { tokenType, accessToken }); return new BasicHeader(AUTH.WWW_AUTH_RESP, value); }
From source file:com.soundcloud.playerapi.OAuth2Scheme.java
static String extractToken(HttpRequest r) { return (r == null) ? null : extractToken(r.getFirstHeader(AUTH.WWW_AUTH_RESP)); }
From source file:com.ibm.streamsx.rest.StreamingAnalyticsConnection.java
/** * Cancels a job that has been submitted to IBM Streaming Analytcis service * * @param jobId//from w w w . ja va 2 s.c o m * string indicating the job id to be canceled * @return boolean indicating * <ul> * <li>true - if job is cancelled</li> * <li>false - if the job still exists</li> * </ul> * @throws IOException */ public boolean cancelJob(String jobId) throws IOException { boolean rc = false; String sReturn = ""; String deleteJob = jobsPath + "?job_id=" + jobId; Request request = Request.Delete(deleteJob).addHeader(AUTH.WWW_AUTH_RESP, apiKey).useExpectContinue(); Response response = executor.execute(request); HttpResponse hResponse = response.returnResponse(); int rcResponse = hResponse.getStatusLine().getStatusCode(); if (HttpStatus.SC_OK == rcResponse) { sReturn = EntityUtils.toString(hResponse.getEntity()); rc = true; } else { rc = false; } traceLog.finest("Request: [" + deleteJob + "]"); traceLog.finest(rcResponse + ": " + sReturn); return rc; }