List of usage examples for org.apache.commons.httpclient NTCredentials NTCredentials
public NTCredentials(String paramString1, String paramString2, String paramString3, String paramString4)
From source file:com.discursive.jccook.httpclient.NTLMAuthExample.java
public static void main(String[] args) throws HttpException, IOException { HttpClient client = new HttpClient(); // Set credentials on the client Credentials credentials = new NTCredentials("testuser", "crazypass", "tobrien.discursive.com", "DOMAIN"); client.getState().setCredentials(null, null, credentials); String url = "http://webmail.domain.biz/exchange/"; HttpMethod method = new GetMethod(url); client.executeMethod(method);// ww w . j a v a 2 s . c o m String response = method.getResponseBodyAsString(); System.out.println(response); method.releaseConnection(); }
From source file:com.eviware.soapui.impl.wsdl.submit.filters.WsdlRequestCredentialsProvider.java
public Credentials getCredentials(final AuthScheme authscheme, final String host, int port, boolean proxy) throws CredentialsNotAvailableException { if (checkedCredentials) throw new CredentialsNotAvailableException("Missing valid credentials"); if (authscheme == null) { return null; }//from w ww .j av a 2s. c om try { String password = wsdlRequest.getPassword(); if (password == null) password = ""; if (authscheme instanceof NTLMScheme) { logger.info(host + ":" + port + " requires Windows authentication"); return new NTCredentials(wsdlRequest.getUsername(), password, host, wsdlRequest.getDomain()); } else if (authscheme instanceof RFC2617Scheme) { logger.info(host + ":" + port + " requires authentication with the realm '" + authscheme.getRealm() + "'"); return new UsernamePasswordCredentials(wsdlRequest.getUsername(), password); } else { throw new CredentialsNotAvailableException( "Unsupported authentication scheme: " + authscheme.getSchemeName()); } } catch (IOException e) { throw new CredentialsNotAvailableException(e.getMessage(), e); } finally { checkedCredentials = true; } }
From source file:com.jaspersoft.studio.server.util.HttpUtils31.java
public static void setupProxy(HttpClient c, URL arg2, HostConfiguration config) { IProxyService proxyService = getProxyService(); if (proxyService == null) return;/*from ww w .j a v a 2s.c om*/ IProxyData[] proxyDataForHost; try { proxyDataForHost = proxyService.select(arg2.toURI()); for (IProxyData data : proxyDataForHost) { if (data.isRequiresAuthentication()) { String userId = data.getUserId(); Credentials proxyCred = new UsernamePasswordCredentials(userId, data.getPassword()); // if the username is in the form "user\domain" // then use NTCredentials instead. int domainIndex = userId.indexOf("\\"); if (domainIndex > 0) { String domain = userId.substring(0, domainIndex); if (userId.length() > domainIndex + 1) { String user = userId.substring(domainIndex + 1); proxyCred = new NTCredentials(user, data.getPassword(), data.getHost(), domain); } } c.getState().setProxyCredentials(AuthScope.ANY, proxyCred); } config.setProxy(data.getHost(), data.getPort()); } // Close the service and close the service tracker proxyService = null; } catch (URISyntaxException e) { e.printStackTrace(); } }
From source file:com.liferay.portlet.webproxy.authenticator.LiferayBridgeAuthenticator.java
@Override public Credentials getCredentials(RenderRequest request) throws ResourceException { PortletPreferences preferences = request.getPreferences(); String configAuthentication = preferences.getValue("authentication", "none"); String configAuthenticationUsername = getUserName(request, preferences.getValue("authenticationUsername", null)); String configAuthenticationPassword = getPassword(request, preferences.getValue("authenticationPassword", null)); String configAuthenticationHost = preferences.getValue("authenticationHost", null); String configAuthenticationDomain = preferences.getValue("authenticationDomain", null); if (configAuthentication != null && configAuthentication.trim().length() > 0) { if ("ntlm".equalsIgnoreCase(configAuthentication)) { return new NTCredentials(configAuthenticationUsername, configAuthenticationPassword, configAuthenticationHost, configAuthenticationDomain); } else if ("basic".equalsIgnoreCase(configAuthentication)) { return new UsernamePasswordCredentials(configAuthenticationUsername, configAuthenticationPassword); } else if ("none".equalsIgnoreCase(configAuthentication)) { return null; } else {/*from w w w.j a v a 2s .co m*/ throw new PortletBridgeException("error.configAuthentication"); } } return null; }
From source file:fr.gouv.finances.dgfip.xemelios.common.NetAccess.java
public static HttpClient getHttpClient(PropertiesExpansion applicationProperties) throws DataConfigurationException { String proxyHost = applicationProperties.getProperty(Constants.SYS_PROP_PROXY_SERVER); String proxyPort = applicationProperties.getProperty(Constants.SYS_PROP_PROXY_PORT); String proxyUser = applicationProperties.getProperty(Constants.SYS_PROP_PROXY_USER); String sTmp = applicationProperties.getProperty(Constants.SYS_PROP_PROXY_PASSWD); String proxyPasswd = sTmp != null ? Scramble.unScramblePassword(sTmp) : null; int intProxyPort = 0; if (proxyPort != null) { try {//from w ww. ja v a 2 s . co m intProxyPort = Integer.parseInt(proxyPort); } catch (NumberFormatException nfEx) { throw new DataConfigurationException(proxyPort + " n'est pas un numro de port valide."); } } String domainName = applicationProperties.getProperty(Constants.SYS_PROP_PROXY_DOMAIN); HttpClient client = new HttpClient(); //client.getParams().setAuthenticationPreemptive(true); // check use of this HostConfiguration hc = new HostConfiguration(); if (proxyHost != null) { hc.setProxy(proxyHost, intProxyPort); client.setHostConfiguration(hc); } if (proxyUser != null) { Credentials creds = null; if (domainName != null && domainName.length() > 0) { String hostName = "127.0.0.1"; try { InetAddress ip = InetAddress.getByName("127.0.0.1"); hostName = ip.getHostName(); } catch (Exception ex) { logger.error("", ex); } creds = new NTCredentials(proxyUser, proxyPasswd, hostName, domainName); } else { creds = new UsernamePasswordCredentials(proxyUser, proxyPasswd); } client.getState().setProxyCredentials(AuthScope.ANY, creds); // client.getState().setProxyCredentials(AuthScope.ANY,new UsernamePasswordCredentials(proxyUser,proxyPasswd)); } return client; }
From source file:com.twinsoft.convertigo.engine.enums.AuthenticationMode.java
public boolean setCredentials(HttpState httpState, String user, String password, String host, String domain) { if (httpState == null) return false; if (host == null) return false; AuthScope authScope = new AuthScope(host, AuthScope.ANY_PORT, AuthScope.ANY_REALM); Credentials credentials = null;/*from w w w .j ava2 s .c o m*/ int type = getType(); try { switch (type) { case 0: // Anonymous credentials = ac; break; case 1: // Basic credentials = new UsernamePasswordCredentials(user, password); break; case 2: // NTLM credentials = new NTCredentials(user, password, host, domain); break; default: // None case -1: break; } Credentials curCred = httpState.getCredentials(authScope); int needChange = compare(curCred, credentials); switch (needChange) { case -1: httpState.setCredentials(authScope, null); Engine.logEngine.debug("(AuthenticationMode) credentials cleared"); break; case 1: httpState.setCredentials(authScope, credentials); Engine.logEngine.debug("(AuthenticationMode) " + name() + " credentials: " + user + ": ******"); break; case 0: Engine.logEngine.debug("(AuthenticationMode) reusing credentials"); break; } return needChange != 0; } catch (Exception e) { Engine.logEngine.error("Unable to set " + name() + " credentials for user", e); return false; } }
From source file:com.globalsight.everest.webapp.applet.util.AuthenticationPrompter.java
/** * Returns the appropriate credentials for authentication. This method * may be called many times, but the username,password entered the first * time is re-used so the user is not prompted multiple times if the connection * isn't kept alive./*from w w w. ja v a 2 s .co m*/ * * @param authscheme * @param host * @param port * @param proxy * @return Credentials * @exception CredentialsNotAvailableException */ public Credentials getCredentials(final AuthScheme authscheme, final String host, int port, boolean proxy) throws CredentialsNotAvailableException { if (authscheme == null) { System.out.println("----No Proxy Authentication Required."); return null; } try { if (authscheme instanceof NTLMScheme) { System.out.println("----" + host + ":" + port + " requires Windows authentication"); if (m_askForAuth) askForAuthentication(); return new NTCredentials(m_username, m_password, host, m_domain); } else if (authscheme instanceof RFC2617Scheme) { System.out.println("----" + host + ":" + port + " requires authentication with the realm '" + authscheme.getRealm() + "'"); if (m_askForAuth) askForAuthentication(); return new UsernamePasswordCredentials(m_username, m_password); } else { throw new CredentialsNotAvailableException( "Unsupported authentication scheme: " + authscheme.getSchemeName()); } } catch (Exception e) { throw new CredentialsNotAvailableException(e.getMessage(), e); } }
From source file:com.apatar.core.ApatarHttpClient.java
private String sendHttpQuery(HttpMethod method) throws HttpException, IOException { HttpClient client = new HttpClient(); HostConfiguration hostConfig = client.getHostConfiguration(); if (isUseProxy) { hostConfig.setProxy(host, port); if (userName != null && !userName.equals("")) { client.getState().setProxyCredentials(AuthScope.ANY, new NTCredentials(userName, password, "", "")); }// ww w .j av a2 s .com } client.executeMethod(method); return method.getResponseBodyAsString(); }
From source file:com.eviware.soapui.impl.wsdl.support.http.ProxyUtils.java
public static HostConfiguration initProxySettings(Settings settings, HttpState httpState, HostConfiguration hostConfiguration, String urlString, PropertyExpansionContext context) { boolean enabled = proxyEnabled; // check system properties first String proxyHost = System.getProperty("http.proxyHost"); String proxyPort = System.getProperty("http.proxyPort"); if (proxyHost == null && enabled) proxyHost = PropertyExpander.expandProperties(context, settings.getString(ProxySettings.HOST, "")); if (proxyPort == null && proxyHost != null && enabled) proxyPort = PropertyExpander.expandProperties(context, settings.getString(ProxySettings.PORT, "")); if (!StringUtils.isNullOrEmpty(proxyHost) && !StringUtils.isNullOrEmpty(proxyPort)) { // check excludes String[] excludes = PropertyExpander .expandProperties(context, settings.getString(ProxySettings.EXCLUDES, "")).split(","); try {/*from w ww .jav a 2 s . co m*/ URL url = new URL(urlString); if (!excludes(excludes, url.getHost(), url.getPort())) { hostConfiguration.setProxy(proxyHost, Integer.parseInt(proxyPort)); String proxyUsername = PropertyExpander.expandProperties(context, settings.getString(ProxySettings.USERNAME, null)); String proxyPassword = PropertyExpander.expandProperties(context, settings.getString(ProxySettings.PASSWORD, null)); if (proxyUsername != null && proxyPassword != null) { Credentials proxyCreds = new UsernamePasswordCredentials(proxyUsername, proxyPassword == null ? "" : proxyPassword); // check for nt-username int ix = proxyUsername.indexOf('\\'); if (ix > 0) { String domain = proxyUsername.substring(0, ix); if (proxyUsername.length() > ix + 1) { String user = proxyUsername.substring(ix + 1); proxyCreds = new NTCredentials(user, proxyPassword, proxyHost, domain); } } httpState.setProxyCredentials(AuthScope.ANY, proxyCreds); } } } catch (MalformedURLException e) { SoapUI.logError(e); } } return hostConfiguration; }
From source file:com.intellij.tasks.impl.BaseRepositoryImpl.java
@Nullable private static Credentials getCredentials(String login, String password, String host) { int domainIndex = login.indexOf("\\"); if (domainIndex > 0) { // if the username is in the form "user\domain" // then use NTCredentials instead of UsernamePasswordCredentials String domain = login.substring(0, domainIndex); if (login.length() > domainIndex + 1) { String user = login.substring(domainIndex + 1); return new NTCredentials(user, password, host, domain); } else {/*www .jav a 2s. co m*/ return null; } } else { return new UsernamePasswordCredentials(login, password); } }