List of usage examples for java.net PasswordAuthentication PasswordAuthentication
public PasswordAuthentication(String userName, char[] password)
From source file:org.phenotips.internal.ProxyAuthenticator.java
@Override public void onEvent(Event event, Object source, Object data) { final String proxyUser = System.getProperty("http.proxyUser"); final String proxyPassword = System.getProperty("http.proxyPassword"); if (StringUtils.isNoneBlank(proxyUser, proxyPassword)) { Authenticator.setDefault(new Authenticator() { @Override//from w ww. j av a 2s . c o m public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(proxyUser, proxyPassword.toCharArray()); } }); } }
From source file:org.openintents.lib.DeliciousApiHelper.java
public DeliciousApiHelper(String api, String user, String passwd) { this.mAPI = api; this.mUser = user; this.mPasswd = passwd; //init the authentication Authenticator.setDefault(new Authenticator() { @Override/*from w w w . ja v a 2 s. co m*/ protected PasswordAuthentication getPasswordAuthentication() { System.out.printf("url=%s, host=%s, ip=%s, port=%s%n", getRequestingURL(), getRequestingHost(), getRequestingSite(), getRequestingPort()); return new PasswordAuthentication(DeliciousApiHelper.this.mUser, DeliciousApiHelper.this.mPasswd.toCharArray()); } }); }
From source file:com.pras.conn._HttpConHandler.java
private Proxy getProxy() { /**/*from w ww . j a v a 2 s . co m*/ * Connect through a Proxy */ Authenticator.setDefault(new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(PROXY_USER, PROXY_PASS.toCharArray()); } }); return new Proxy(Type.HTTP, new InetSocketAddress(PROXY_URL, PROXY_PORT)); // return Proxy.NO_PROXY; }
From source file:com.adito.server.ProxyAuthenticator.java
public PasswordAuthentication getPasswordAuthentication() { if (log.isInfoEnabled()) log.info("Requesting " + getRequestingProtocol() + " proxy authentication for " + getRequestingSite() + " (" + getRequestingHost() + ":" + getRequestingPort() + "), prompt = " + getRequestingPrompt()); String user = null;/* www .j a v a 2 s .co m*/ String pass = null; try { PropertyClass contextConfiguration = ContextHolder.getContext().getConfig(); if (getRequestingProtocol().startsWith("SOCKS")) { user = contextConfiguration.retrieveProperty(new ContextKey("proxies.socksProxyUser")); pass = contextConfiguration.retrieveProperty(new ContextKey("proxies.socksProxyPassword")); } else { user = contextConfiguration.retrieveProperty(new ContextKey("proxies.http.proxyUser")); pass = contextConfiguration.retrieveProperty(new ContextKey("proxies.http.proxyPassword")); } } catch (Exception e) { log.error("Failed to get proxy authentication details."); return null; } return new PasswordAuthentication(user, pass.toCharArray()); }
From source file:org.droidparts.http.worker.HttpURLConnectionWorker.java
@Override public void authenticateBasic(String user, String password, AuthScope scope) { passAuth = new PasswordAuthentication(user, password.toCharArray()); authScope = scope;//from w ww . ja va 2 s. co m }
From source file:com.varaneckas.hawkscope.util.ModularAuthenticator.java
/** * Loads proxy configuration//from ww w . ja v a2s . c om * * @param cfg configuration */ public void loadProxyAuth(final Configuration cfg) { if (cfg.isHttpProxyInUse() && cfg.isHttpProxyAuthInUse()) { log.debug("Loading proxy authentication data"); getInstance().proxyAuth = new PasswordAuthentication(cfg.getHttpProxyAuthUsername(), cfg.getHttpProxyAuthPassword().toCharArray()); } else { log.debug("Proxy authentication is disabled"); proxyAuth = null; } }
From source file:com.cloudera.recordservice.tests.ClusterConfiguration.java
/** * This method sends a get request to CM using the given URL. The return value * of that request is returned in the method in string form. *//*from w w w . j a v a2 s . co m*/ public String clusterGetRequest(URL url) throws IOException { Authenticator.setDefault(new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username_, password_.toCharArray()); } }); StringBuilder ret = new StringBuilder(); BufferedReader br = null; try { URLConnection cc = url.openConnection(); br = new BufferedReader(new InputStreamReader(cc.getInputStream())); String line; while ((line = br.readLine()) != null) { ret.append(line); } } finally { if (br != null) { br.close(); } } return ret.toString(); }
From source file:com.googlecode.gmail4j.auth.GmailHttpAuthenticator.java
@Override protected PasswordAuthentication getPasswordAuthentication() { if (log.isDebugEnabled()) { log.debug("Password authentication request: " + getRequestingPrompt()); }/*from w w w. j a v a 2 s .c o m*/ if (getRequestorType().equals(RequestorType.PROXY) && proxyCredentials != null) { log.debug("Proxy request detected, returning proxy credentials"); return new PasswordAuthentication(proxyCredentials.getUsername(), proxyCredentials.getPasword()); } if ("mail.google.com".equals(getRequestingHost())) { log.debug("Gmail request detected, returning login credentials"); return new PasswordAuthentication(credentials.getUsername(), credentials.getPasword()); } log.debug("Unknown authentication request, will return nothing"); return null; }
From source file:de.stadtrallye.rallyesoft.net.AuthProvider.java
public Authenticator getAuthenticator() { return new Authenticator() { @Override/* w w w. j a v a 2 s . c o m*/ protected PasswordAuthentication getPasswordAuthentication() { String realm = getRequestingPrompt(); if (realm.equals(Authentication.USER_AUTH)) { Log.i(THIS, "Using Fallback-UserAuthentication"); return new PasswordAuthentication(userAuth.getHttpUser(groupID), userAuth.password.toCharArray()); } else if (realm.equals(Authentication.GROUP_AUTH)) { Log.i(THIS, "Using Fallback-GroupAuthentication"); return new PasswordAuthentication(String.valueOf(groupID), groupPassword.toCharArray()); } else { return null; } } }; }
From source file:de.rallye.test.GroupsTest.java
@Test public void testLogin() throws IOException { Authenticator.setDefault(new Authenticator() { @Override//from ww w . j a v a 2 s.c o m protected PasswordAuthentication getPasswordAuthentication() { String realm = getRequestingPrompt(); assertEquals("Should be right Realm", "RallyeNewUser", realm); return new PasswordAuthentication(String.valueOf(1), "test".toCharArray()); } }); URL url = new URL("http://127.0.0.1:10111/groups/1"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("PUT"); conn.setDoOutput(true); conn.addRequestProperty("Content-Type", "application/json"); // conn.setFixedLengthStreamingMode(post.length); conn.getOutputStream().write(MockDataAdapter.validLogin.getBytes()); int code = conn.getResponseCode(); Authenticator.setDefault(null); try { assertEquals("Code should be 200", 200, code); } catch (AssertionError e) { System.err.println("This is the content:"); List<String> contents = IOUtils.readLines((InputStream) conn.getContent()); for (String line : contents) System.err.println(line); throw e; } }