List of usage examples for java.net PasswordAuthentication getUserName
public String getUserName()
From source file:org.apache.ws.scout.registry.BusinessQueryManagerV3Impl.java
/** * Get the Auth Token from the registry *// w ww . j a va 2 s . c o m * @param connection * @param ireg * @return auth token * @throws JAXRException */ private AuthToken getAuthToken(ConnectionImpl connection, IRegistryV3 ireg) throws JAXRException { Set creds = connection.getCredentials(); Iterator it = creds.iterator(); String username = "", pwd = ""; while (it.hasNext()) { PasswordAuthentication pass = (PasswordAuthentication) it.next(); username = pass.getUserName(); pwd = new String(pass.getPassword()); } if (AuthTokenV3Singleton.getToken(username) != null) { return (AuthToken) AuthTokenV3Singleton.getToken(username); } AuthToken token = null; try { token = ireg.getAuthToken(username, pwd); } catch (Exception e) { throw new JAXRException(e); } AuthTokenV3Singleton.addAuthToken(username, token); return token; }
From source file:org.globus.cog.abstraction.impl.file.webdav.FileResourceImpl.java
/** * Create the davClient and authenticate with the resource. serviceContact * should be in the form of a url// w ww . j a va 2 s .c o m */ public void start() throws IllegalHostException, InvalidSecurityContextException, FileResourceException { ServiceContact serviceContact = getAndCheckServiceContact(); try { SecurityContext securityContext = getOrCreateSecurityContext("WebDAV", serviceContact); String contact = getServiceContact().getContact().toString(); if (!contact.startsWith("http")) { contact = "http://" + contact; } HttpURL hrl = new HttpURL(contact); PasswordAuthentication credentials = getCredentialsAsPasswordAuthentication(securityContext); String username = credentials.getUserName(); String password = String.valueOf(credentials.getPassword()); hrl.setUserinfo(username, password); davClient = new WebdavResource(hrl); setStarted(true); } catch (URIException ue) { throw new IllegalHostException("Error connecting to the WebDAV server at " + serviceContact, ue); } catch (Exception e) { throw new IrrecoverableResourceException(e); } }
From source file:org.talend.core.nexus.HttpClientTransport.java
private IProxySelectorProvider addProxy(final DefaultHttpClient httpClient, URI requestURI) { IProxySelectorProvider proxySelectorProvider = null; try {//from w ww . j a v a 2 s .co m if (Boolean.valueOf( System.getProperty(PROP_PROXY_HTTP_CLIENT_USE_DEFAULT_SETTINGS, Boolean.FALSE.toString()))) { return proxySelectorProvider; } final List<Proxy> proxyList = TalendProxySelector.getInstance().getDefaultProxySelector() .select(requestURI); Proxy usedProxy = null; if (proxyList != null && !proxyList.isEmpty()) { usedProxy = proxyList.get(0); } if (usedProxy != null) { if (Type.DIRECT.equals(usedProxy.type())) { return proxySelectorProvider; } final Proxy finalProxy = usedProxy; InetSocketAddress address = (InetSocketAddress) finalProxy.address(); String proxyServer = address.getHostName(); int proxyPort = address.getPort(); PasswordAuthentication proxyAuthentication = Authenticator.requestPasswordAuthentication( proxyServer, address.getAddress(), proxyPort, "Http Proxy", "Http proxy authentication", null); if (proxyAuthentication != null) { String proxyUser = proxyAuthentication.getUserName(); if (StringUtils.isNotBlank(proxyUser)) { String proxyPassword = ""; char[] passwordChars = proxyAuthentication.getPassword(); if (passwordChars != null) { proxyPassword = new String(passwordChars); } httpClient.getCredentialsProvider().setCredentials(new AuthScope(proxyServer, proxyPort), new UsernamePasswordCredentials(proxyUser, proxyPassword)); } } HttpHost proxyHost = new HttpHost(proxyServer, proxyPort); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxyHost); proxySelectorProvider = createProxySelectorProvider(); } return proxySelectorProvider; } finally { if (proxySelectorProvider != null) { TalendProxySelector.getInstance().addProxySelectorProvider(proxySelectorProvider); } } }