List of usage examples for org.apache.http.auth AuthScope ANY
AuthScope ANY
To view the source code for org.apache.http.auth AuthScope ANY.
Click Source Link
From source file:ch.admin.hermes.etl.load.SharePointRESTClient.java
/** * @throws IOException/* w ww .jav a 2 s .c o m*/ */ private void init(String remote, String user, String pass) throws IOException { this.remote = (remote != null) ? remote : this.remote; this.user = (user != null) ? user : this.user; this.pass = (pass != null) ? pass : this.pass; client = getHttpClient(); // localhost und domain nicht setzen, gibt Probleme mit https:// NTCredentials creds = new NTCredentials(this.user, this.pass, "", ""); client.getCredentialsProvider().setCredentials(AuthScope.ANY, creds); List<String> authpref = new ArrayList<String>(); authpref.add(AuthPolicy.NTLM); client.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref); // FormDigestValue holen try { js = factory.getEngineByName("JavaScript"); js.eval("function getId(rc) { print(rc); return(rc.d.GetContextWebInformation.FormDigestValue); }"); String out = post("/_api/contextinfo", null); js.eval("var rc = " + out + ";"); Object rc = js.get("rc"); xRequestDigest = (String) ((Invocable) js).invokeFunction("getId", rc); } catch (NoSuchMethodException e) { throw new IOException(e); } catch (ScriptException e) { throw new IOException(e); } }
From source file:com.fourspaces.couchdb.Session.java
/** * Constructor for obtaining a Session with an HTTP-AUTH username/password * and (optionally) a secure connection This isn't supported by CouchDB - * you need a proxy in front to use this * * @param host - hostname/*ww w .j a va 2 s . co m*/ * @param port - port to use * @param user - username * @param pass - password * @param usesAuth * @param secure - use an SSL connection? */ public Session(String host, int port, String user, String pass, boolean usesAuth, boolean secure) { this.host = host; this.port = port; this.user = user; this.pass = pass; this.usesAuth = usesAuth; this.secure = secure; PlainConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory(); LayeredConnectionSocketFactory sslsf = SSLConnectionSocketFactory.getSocketFactory(); Registry<ConnectionSocketFactory> r = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", plainsf).register("https", sslsf).build(); this.connManager = new PoolingHttpClientConnectionManager(r); this.requestConfig = RequestConfig.custom().setConnectTimeout(15 * 1000).setSocketTimeout((30 * 1000)) .setAuthenticationEnabled(usesAuth).build(); this.httpContext = HttpClientContext.create(); if (user != null) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, pass)); this.httpContext.setCredentialsProvider(credsProvider); } this.httpClient = createHttpClient(); }
From source file:com.jobaline.uiautomation.framework.selenium.phantomJsThreeHourTimeoutFix.HttpCommandExecutor.java
public HttpCommandExecutor(Map<String, CommandInfo> additionalCommands, URL addressOfRemoteServer) { try {//from w ww . j av a 2 s .co m remoteServer = addressOfRemoteServer == null ? new URL(System.getProperty("webdriver.remote.server", "http://localhost:4444/wd/hub")) : addressOfRemoteServer; } catch (MalformedURLException e) { throw new WebDriverException(e); } HttpParams params = new BasicHttpParams(); // Use the JRE default for the socket linger timeout. params.setParameter(CoreConnectionPNames.SO_LINGER, -1); HttpClientParams.setRedirecting(params, false); synchronized (HttpCommandExecutor.class) { if (httpClientFactory == null) { httpClientFactory = new HttpClientFactory(); } } client = httpClientFactory.getHttpClient(); // PATCH start // HttpClientFactory has a hardcoded timeout of three hours. // This class is intended to be used only for phantomjs which runs locally so the timeouts will be set to a low value BasicHttpParams paramsPatched = (BasicHttpParams) client.getParams(); paramsPatched.setIntParameter("http.connection.timeout", 90000); // 1 minute an a half paramsPatched.setIntParameter("http.socket.timeout", 90000); // 1 minute an a half ((DefaultHttpClient) client).setParams(params); // PATCH end if (addressOfRemoteServer != null && addressOfRemoteServer.getUserInfo() != null) { // Use HTTP Basic auth UsernamePasswordCredentials credentials = new UsernamePasswordCredentials( addressOfRemoteServer.getUserInfo()); ((DefaultHttpClient) client).getCredentialsProvider().setCredentials(AuthScope.ANY, credentials); } // Some machines claim "localhost.localdomain" is the same as "localhost". // This assumption is not always true. String host = remoteServer.getHost().replace(".localdomain", ""); targetHost = new HttpHost(host, remoteServer.getPort(), remoteServer.getProtocol()); ImmutableMap.Builder<String, CommandInfo> builder = ImmutableMap.builder(); for (Map.Entry<String, CommandInfo> entry : additionalCommands.entrySet()) { builder.put(entry.getKey(), entry.getValue()); } builder.put(GET_ALL_SESSIONS, get("/sessions")).put(NEW_SESSION, post("/session")) .put(GET_CAPABILITIES, get("/session/:sessionId")).put(QUIT, delete("/session/:sessionId")) .put(GET_CURRENT_WINDOW_HANDLE, get("/session/:sessionId/window_handle")) .put(GET_WINDOW_HANDLES, get("/session/:sessionId/window_handles")) .put(GET, post("/session/:sessionId/url")) // The Alert API is still experimental and should not be used. .put(GET_ALERT, get("/session/:sessionId/alert")) .put(DISMISS_ALERT, post("/session/:sessionId/dismiss_alert")) .put(ACCEPT_ALERT, post("/session/:sessionId/accept_alert")) .put(GET_ALERT_TEXT, get("/session/:sessionId/alert_text")) .put(SET_ALERT_VALUE, post("/session/:sessionId/alert_text")) .put(GO_FORWARD, post("/session/:sessionId/forward")).put(GO_BACK, post("/session/:sessionId/back")) .put(REFRESH, post("/session/:sessionId/refresh")) .put(EXECUTE_SCRIPT, post("/session/:sessionId/execute")) .put(EXECUTE_ASYNC_SCRIPT, post("/session/:sessionId/execute_async")) .put(GET_CURRENT_URL, get("/session/:sessionId/url")) .put(GET_TITLE, get("/session/:sessionId/title")) .put(GET_PAGE_SOURCE, get("/session/:sessionId/source")) .put(SCREENSHOT, get("/session/:sessionId/screenshot")) .put(FIND_ELEMENT, post("/session/:sessionId/element")) .put(FIND_ELEMENTS, post("/session/:sessionId/elements")) .put(GET_ACTIVE_ELEMENT, post("/session/:sessionId/element/active")) .put(FIND_CHILD_ELEMENT, post("/session/:sessionId/element/:id/element")) .put(FIND_CHILD_ELEMENTS, post("/session/:sessionId/element/:id/elements")) .put(CLICK_ELEMENT, post("/session/:sessionId/element/:id/click")) .put(CLEAR_ELEMENT, post("/session/:sessionId/element/:id/clear")) .put(SUBMIT_ELEMENT, post("/session/:sessionId/element/:id/submit")) .put(GET_ELEMENT_TEXT, get("/session/:sessionId/element/:id/text")) .put(SEND_KEYS_TO_ELEMENT, post("/session/:sessionId/element/:id/value")) .put(UPLOAD_FILE, post("/session/:sessionId/file")) .put(GET_ELEMENT_VALUE, get("/session/:sessionId/element/:id/value")) .put(GET_ELEMENT_TAG_NAME, get("/session/:sessionId/element/:id/name")) .put(IS_ELEMENT_SELECTED, get("/session/:sessionId/element/:id/selected")) .put(IS_ELEMENT_ENABLED, get("/session/:sessionId/element/:id/enabled")) .put(IS_ELEMENT_DISPLAYED, get("/session/:sessionId/element/:id/displayed")) .put(HOVER_OVER_ELEMENT, post("/session/:sessionId/element/:id/hover")) .put(GET_ELEMENT_LOCATION, get("/session/:sessionId/element/:id/location")) .put(GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW, get("/session/:sessionId/element/:id/location_in_view")) .put(GET_ELEMENT_SIZE, get("/session/:sessionId/element/:id/size")) .put(GET_ELEMENT_ATTRIBUTE, get("/session/:sessionId/element/:id/attribute/:name")) .put(ELEMENT_EQUALS, get("/session/:sessionId/element/:id/equals/:other")) .put(GET_ALL_COOKIES, get("/session/:sessionId/cookie")) .put(ADD_COOKIE, post("/session/:sessionId/cookie")) .put(DELETE_ALL_COOKIES, delete("/session/:sessionId/cookie")) .put(DELETE_COOKIE, delete("/session/:sessionId/cookie/:name")) .put(SWITCH_TO_FRAME, post("/session/:sessionId/frame")) .put(SWITCH_TO_PARENT_FRAME, post("/session/:sessionId/frame/parent")) .put(SWITCH_TO_WINDOW, post("/session/:sessionId/window")) .put(GET_WINDOW_SIZE, get("/session/:sessionId/window/:windowHandle/size")) .put(GET_WINDOW_POSITION, get("/session/:sessionId/window/:windowHandle/position")) .put(SET_WINDOW_SIZE, post("/session/:sessionId/window/:windowHandle/size")) .put(SET_WINDOW_POSITION, post("/session/:sessionId/window/:windowHandle/position")) .put(MAXIMIZE_WINDOW, post("/session/:sessionId/window/:windowHandle/maximize")) .put(CLOSE, delete("/session/:sessionId/window")) .put(DRAG_ELEMENT, post("/session/:sessionId/element/:id/drag")) .put(GET_ELEMENT_VALUE_OF_CSS_PROPERTY, get("/session/:sessionId/element/:id/css/:propertyName")) .put(IMPLICITLY_WAIT, post("/session/:sessionId/timeouts/implicit_wait")) .put(SET_SCRIPT_TIMEOUT, post("/session/:sessionId/timeouts/async_script")) .put(SET_TIMEOUT, post("/session/:sessionId/timeouts")) .put(EXECUTE_SQL, post("/session/:sessionId/execute_sql")) .put(GET_LOCATION, get("/session/:sessionId/location")) .put(SET_LOCATION, post("/session/:sessionId/location")) .put(GET_APP_CACHE_STATUS, get("/session/:sessionId/application_cache/status")) .put(IS_BROWSER_ONLINE, get("/session/:sessionId/browser_connection")) .put(SET_BROWSER_ONLINE, post("/session/:sessionId/browser_connection")) .put(SWITCH_TO_CONTEXT, post("/session/:sessionId/context")) .put(GET_CURRENT_CONTEXT_HANDLE, get("/session/:sessionId/context")) .put(GET_CONTEXT_HANDLES, get("/session/:sessionId/contexts")) // TODO (user): Would it be better to combine this command with // GET_LOCAL_STORAGE_SIZE? .put(GET_LOCAL_STORAGE_ITEM, get("/session/:sessionId/local_storage/key/:key")) .put(REMOVE_LOCAL_STORAGE_ITEM, delete("/session/:sessionId/local_storage/key/:key")) .put(GET_LOCAL_STORAGE_KEYS, get("/session/:sessionId/local_storage")) .put(SET_LOCAL_STORAGE_ITEM, post("/session/:sessionId/local_storage")) .put(CLEAR_LOCAL_STORAGE, delete("/session/:sessionId/local_storage")) .put(GET_LOCAL_STORAGE_SIZE, get("/session/:sessionId/local_storage/size")) // TODO (user): Would it be better to combine this command with // GET_SESSION_STORAGE_SIZE? .put(GET_SESSION_STORAGE_ITEM, get("/session/:sessionId/session_storage/key/:key")) .put(REMOVE_SESSION_STORAGE_ITEM, delete("/session/:sessionId/session_storage/key/:key")) .put(GET_SESSION_STORAGE_KEYS, get("/session/:sessionId/session_storage")) .put(SET_SESSION_STORAGE_ITEM, post("/session/:sessionId/session_storage")) .put(CLEAR_SESSION_STORAGE, delete("/session/:sessionId/session_storage")) .put(GET_SESSION_STORAGE_SIZE, get("/session/:sessionId/session_storage/size")) .put(GET_SCREEN_ORIENTATION, get("/session/:sessionId/orientation")) .put(SET_SCREEN_ORIENTATION, post("/session/:sessionId/orientation")) // Interactions-related commands. .put(CLICK, post("/session/:sessionId/click")) .put(DOUBLE_CLICK, post("/session/:sessionId/doubleclick")) .put(MOUSE_DOWN, post("/session/:sessionId/buttondown")) .put(MOUSE_UP, post("/session/:sessionId/buttonup")) .put(MOVE_TO, post("/session/:sessionId/moveto")) .put(SEND_KEYS_TO_ACTIVE_ELEMENT, post("/session/:sessionId/keys")) // IME related commands. .put(IME_GET_AVAILABLE_ENGINES, get("/session/:sessionId/ime/available_engines")) .put(IME_GET_ACTIVE_ENGINE, get("/session/:sessionId/ime/active_engine")) .put(IME_IS_ACTIVATED, get("/session/:sessionId/ime/activated")) .put(IME_DEACTIVATE, post("/session/:sessionId/ime/deactivate")) .put(IME_ACTIVATE_ENGINE, post("/session/:sessionId/ime/activate")) // Advanced Touch API commands // TODO(berrada): Refactor single tap with mouse click. .put(TOUCH_SINGLE_TAP, post("/session/:sessionId/touch/click")) .put(TOUCH_DOWN, post("/session/:sessionId/touch/down")) .put(TOUCH_UP, post("/session/:sessionId/touch/up")) .put(TOUCH_MOVE, post("/session/:sessionId/touch/move")) .put(TOUCH_SCROLL, post("/session/:sessionId/touch/scroll")) .put(TOUCH_DOUBLE_TAP, post("/session/:sessionId/touch/doubleclick")) .put(TOUCH_LONG_PRESS, post("/session/:sessionId/touch/longclick")) .put(TOUCH_FLICK, post("/session/:sessionId/touch/flick")) .put(GET_LOG, post("/session/:sessionId/log")) .put(GET_AVAILABLE_LOG_TYPES, get("/session/:sessionId/log/types")) .put(STATUS, get("/status")); nameToUrl = builder.build(); }
From source file:org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory.java
private SolrHttpClientBuilder initHttpClientBuilder(SolrHttpClientBuilder builder) { final String basicAuthUser = defaultParams.get(HttpClientUtil.PROP_BASIC_AUTH_USER); final String basicAuthPass = defaultParams.get(HttpClientUtil.PROP_BASIC_AUTH_PASS); if (basicAuthUser == null || basicAuthPass == null) { throw new IllegalArgumentException( "username & password must be specified with " + getClass().getName()); }//from ww w . j a va2 s . c o m builder.setDefaultCredentialsProvider(new CredentialsProviderProvider() { @Override public CredentialsProvider getCredentialsProvider() { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(basicAuthUser, basicAuthPass)); return credsProvider; } }); HttpClientUtil.addRequestInterceptor(requestInterceptor); return builder; }
From source file:org.apache.axis2.transport.http.impl.httpclient4.HTTPProxyConfigurator.java
/** * Configure HTTP Proxy settings of commons-httpclient HostConfiguration. * Proxy settings can be get from axis2.xml, Java proxy settings or can be * override through property in message context. * <p/>//from w w w .ja v a 2 s .c om * HTTP Proxy setting element format: <parameter name="Proxy"> * <Configuration> <ProxyHost>example.org</ProxyHost> * <ProxyPort>3128</ProxyPort> <ProxyUser>EXAMPLE/John</ProxyUser> * <ProxyPassword>password</ProxyPassword> <Configuration> <parameter> * * @param messageContext * in message context for * @param httpClient * instance * @throws org.apache.axis2.AxisFault * if Proxy settings are invalid */ public static void configure(MessageContext messageContext, AbstractHttpClient httpClient) throws AxisFault { Credentials proxyCredentials = null; String proxyHost = null; String nonProxyHosts = null; Integer proxyPort = -1; String proxyUser = null; String proxyPassword = null; // Getting configuration values from Axis2.xml Parameter proxySettingsFromAxisConfig = messageContext.getConfigurationContext().getAxisConfiguration() .getParameter(HTTPTransportConstants.ATTR_PROXY); if (proxySettingsFromAxisConfig != null) { OMElement proxyConfiguration = getProxyConfigurationElement(proxySettingsFromAxisConfig); proxyHost = getProxyHost(proxyConfiguration); proxyPort = getProxyPort(proxyConfiguration); proxyUser = getProxyUser(proxyConfiguration); proxyPassword = getProxyPassword(proxyConfiguration); if (proxyUser != null) { if (proxyPassword == null) { proxyPassword = ""; } proxyCredentials = new UsernamePasswordCredentials(proxyUser, proxyPassword); int proxyUserDomainIndex = proxyUser.indexOf("\\"); if (proxyUserDomainIndex > 0) { String domain = proxyUser.substring(0, proxyUserDomainIndex); if (proxyUser.length() > proxyUserDomainIndex + 1) { String user = proxyUser.substring(proxyUserDomainIndex + 1); proxyCredentials = new NTCredentials(user, proxyPassword, proxyHost, domain); } } } } // If there is runtime proxy settings, these settings will override // settings from axis2.xml HttpTransportProperties.ProxyProperties proxyProperties = (HttpTransportProperties.ProxyProperties) messageContext .getProperty(HTTPConstants.PROXY); if (proxyProperties != null) { String proxyHostProp = proxyProperties.getProxyHostName(); if (proxyHostProp == null || proxyHostProp.length() <= 0) { throw new AxisFault("HTTP Proxy host is not available. Host is a MUST parameter"); } else { proxyHost = proxyHostProp; } proxyPort = proxyProperties.getProxyPort(); // Overriding credentials String userName = proxyProperties.getUserName(); String password = proxyProperties.getPassWord(); String domain = proxyProperties.getDomain(); if (userName != null && password != null && domain != null) { proxyCredentials = new NTCredentials(userName, password, proxyHost, domain); } else if (userName != null && domain == null) { proxyCredentials = new UsernamePasswordCredentials(userName, password); } } // Overriding proxy settings if proxy is available from JVM settings String host = System.getProperty(HTTPTransportConstants.HTTP_PROXY_HOST); if (host != null) { proxyHost = host; } String port = System.getProperty(HTTPTransportConstants.HTTP_PROXY_PORT); if (port != null) { proxyPort = Integer.parseInt(port); } if (proxyCredentials != null) { // TODO : Set preemptive authentication, but its not recommended in HC 4 httpClient.getParams().setParameter(ClientPNames.HANDLE_AUTHENTICATION, true); httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, proxyCredentials); HttpHost proxy = new HttpHost(proxyHost, proxyPort); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } }
From source file:org.openremote.controller.protocol.isy99.Isy99Command.java
@Override public void send() { String url = formWriteCommandUrl(); log.debug("send(): URL is " + url); DefaultHttpClient client = new DefaultHttpClient(); if (username != null && !username.equals("")) { CredentialsProvider cred = new BasicCredentialsProvider(); cred.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); client.setCredentialsProvider(cred); }/* w w w . j ava 2s . c om*/ try { HttpGet req = new HttpGet(url); HttpResponse response = client.execute(req); int responseStatusCode = response.getStatusLine().getStatusCode(); if (responseStatusCode != 200) { log.error("send(): response status code was " + responseStatusCode); } else { StatusReader.setLocalStatus(address, command, commandParam); } } catch (IOException e) { log.error("send(): IOException: address: " + address + "command: " + command, e); } }
From source file:com.cisco.ukidcv.ucsd.http.UcsdHttpConnection.java
/** * Set basic http authentication for this connection * * @param username//from w w w .j a va 2s. co m * Username * @param password * Password */ public void setAuth(String username, String password) { Credentials authCreds = new UsernamePasswordCredentials(username, password); this.httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, authCreds); }