List of usage examples for java.net PasswordAuthentication PasswordAuthentication
public PasswordAuthentication(String userName, char[] password)
From source file:org.owasp.proxy.Main.java
private static HttpRequestHandler configureAuthentication(HttpRequestHandler rh, final Configuration config) { if (config.authUser != null) { if (config.authPassword == null) { System.err.println("authPassword must be provided!"); System.exit(1);//from w ww . ja va 2s . c o m } Authenticator.setDefault(new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(config.authUser, config.authPassword.toCharArray()); } }); return new AuthenticatingHttpRequestHandler(rh); } else { return rh; } }
From source file:com.tremolosecurity.provisioning.sharepoint.SharePointGroups.java
@Override public PasswordAuthentication getPasswordAuthentication() { return (new PasswordAuthentication(username, password)); }
From source file:com.cladonia.xngreditor.URLUtilities.java
public static InputStream open(URL url) throws IOException { // System.out.println( "URLUtilities.open( "+url+")"); InputStream stream = null;/*from w ww . j a v a2s .c o m*/ String password = URLUtilities.getPassword(url); String username = URLUtilities.getUsername(url); String protocol = url.getProtocol(); if (protocol.equals("http") || protocol.equals("https")) { try { DefaultAuthenticator authenticator = Main.getDefaultAuthenticator(); URL newURL = new URL(URLUtilities.toString(url)); if (authenticator != null && password != null && username != null) { authenticator.setPasswordAuthentication( new PasswordAuthentication(username, password.toCharArray())); } stream = newURL.openStream(); if (authenticator != null && password != null && username != null) { authenticator.setPasswordAuthentication(null); } } catch (Exception e) { // System.out.println( "Could not use normal http connection, because of:\n"+e.getMessage()); // try it with webdav WebdavResource webdav = createWebdavResource(toString(url), username, password); stream = webdav.getMethodData(toString(url)); webdav.close(); } } else if (protocol.equals("ftp")) { FTPClient client = null; String host = url.getHost(); try { // System.out.println( "Connecting to: "+host+" ..."); client = new FTPClient(); client.connect(host); // System.out.println( "Connected."); // After connection attempt, you should check the reply code to verify // success. int reply = client.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { // System.out.println( "Could not connect."); client.disconnect(); throw new IOException("FTP Server \"" + host + "\" refused connection."); } // System.out.println( "Logging in using: "+username+", "+password+" ..."); if (!client.login(username, password)) { // System.out.println( "Could not log in."); // TODO bring up login dialog? client.disconnect(); throw new IOException("Could not login to FTP Server \"" + host + "\"."); } // System.out.println( "Logged in."); client.setFileType(FTP.BINARY_FILE_TYPE); client.enterLocalPassiveMode(); // System.out.println( "Opening file \""+url.getFile()+"\" ..."); stream = client.retrieveFileStream(url.getFile()); // System.out.println( "File opened."); // System.out.println( "Disconnecting ..."); client.disconnect(); // System.out.println( "Disconnected."); } catch (IOException e) { if (client.isConnected()) { try { client.disconnect(); } catch (IOException f) { // do nothing e.printStackTrace(); } } throw new IOException("Could not connect to FTP Server \"" + host + "\"."); } } else if (protocol.equals("file")) { stream = url.openStream(); } else { //unknown protocol but try anyways try { stream = url.openStream(); } catch (IOException ioe) { throw new IOException("The \"" + protocol + "\" protocol is not supported."); } } return stream; }
From source file:org.apache.cxf.cwiki.SiteExporter.java
public static void main(String[] args) throws Exception { Authenticator.setDefault(new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(userName, password.toCharArray()); }// w w w .j a va2s . c o m }); ListIterator<String> it = Arrays.asList(args).listIterator(); List<String> files = new ArrayList<String>(); boolean forceAll = false; int maxThreads = -1; while (it.hasNext()) { String s = it.next(); if ("-debug".equals(s)) { debug = true; } else if ("-user".equals(s)) { userName = it.next(); } else if ("-password".equals(s)) { password = it.next(); } else if ("-d".equals(s)) { rootOutputDir = new File(it.next()); } else if ("-force".equals(s)) { forceAll = true; } else if ("-svn".equals(s)) { svn = true; } else if ("-commit".equals(s)) { commit = true; } else if ("-maxThreads".equals(s)) { maxThreads = Integer.parseInt(it.next()); } else if (s != null && s.length() > 0) { files.add(s); } } List<SiteExporter> exporters = new ArrayList<SiteExporter>(); for (String file : files) { exporters.add(new SiteExporter(file, forceAll)); } List<SiteExporter> modified = new ArrayList<SiteExporter>(); for (SiteExporter exporter : exporters) { if (exporter.initialize()) { modified.add(exporter); } } // render stuff only if needed if (!modified.isEmpty()) { setSiteExporters(exporters); if (maxThreads <= 0) { maxThreads = modified.size(); } ExecutorService executor = Executors.newFixedThreadPool(maxThreads, new ThreadFactory() { public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setDaemon(true); return t; } }); List<Future<?>> futures = new ArrayList<Future<?>>(modified.size()); for (SiteExporter exporter : modified) { futures.add(executor.submit(exporter)); } for (Future<?> t : futures) { t.get(); } } if (commit) { File file = FileUtils.createTempFile("svncommit", "txt"); FileWriter writer = new FileWriter(file); writer.write(svnCommitMessage.toString()); writer.close(); callSvn(rootOutputDir, "commit", "-F", file.getAbsolutePath(), rootOutputDir.getAbsolutePath()); svnCommitMessage.setLength(0); } }
From source file:org.tupelo_schneck.electric.Options.java
private void readAndProcessPassword() throws IOException { System.err.print("Please enter password for username '" + username + "': "); password = Options.reader.readLine(); Authenticator.setDefault(new Authenticator() { @Override/*from ww w . j av a2 s. c om*/ protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password.toCharArray()); } }); }
From source file:com.clustercontrol.agent.Agent.java
@Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password.toCharArray()); }
From source file:org.ramadda.repository.Repository.java
/** * _more_/*from www . j a v a2 s. co m*/ */ private void initProxy() { //First try the local ramadda properties //The default value is the system property String proxyHost = getProperty(PROP_PROXY_HOST, getProperty("http.proxyHost", (String) null)); String proxyPort = getProperty(PROP_PROXY_PORT, getProperty("http.proxyPort", "8080")); final String proxyUser = getProperty(PROP_PROXY_USER, (String) null); final String proxyPass = getProperty(PROP_PROXY_PASSWORD, (String) null); httpClient = new HttpClient(); if (proxyHost != null) { getLogManager().logInfoAndPrint("Setting proxy server to:" + proxyHost + ":" + proxyPort); System.setProperty("http.proxyHost", proxyHost); System.setProperty("http.proxyPort", proxyPort); System.setProperty("ftp.proxyHost", proxyHost); System.setProperty("ftp.proxyPort", proxyPort); httpClient.getHostConfiguration().setProxy(proxyHost, Integer.parseInt(proxyPort)); // Just if proxy has authentication credentials if (proxyUser != null) { getLogManager().logInfoAndPrint("Setting proxy user to:" + proxyUser); httpClient.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials(proxyUser, proxyPass); httpClient.getState().setProxyCredentials( new AuthScope(proxyHost, Integer.parseInt(proxyPort), AuthScope.ANY_REALM), defaultcreds); Authenticator.setDefault(new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(proxyUser, proxyPass.toCharArray()); } }); } } }
From source file:in.andres.kandroid.kanboard.KanboardAPI.java
public KanboardAPI(String serverURL, final String username, final String password) throws IOException { Authenticator.setDefault(new Authenticator() { @Override/*ww w . ja va 2 s.co m*/ protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password.toCharArray()); } }); serverURL = serverURL.trim(); String tmpURL = serverURL; if (!serverURL.endsWith("jsonrpc.php")) { if (!serverURL.endsWith("/")) tmpURL += "/"; tmpURL += "jsonrpc.php"; } kanboardURL = new URL(tmpURL); Log.i(Constants.TAG, String.format("Host uses %s", kanboardURL.getProtocol())); // threadPoolExecutor = new ThreadPoolExecutor(12, 12, 20, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(256)); threadPoolExecutor = (ThreadPoolExecutor) AsyncTask.THREAD_POOL_EXECUTOR; threadPoolExecutor.setCorePoolSize(12); threadPoolExecutor.setMaximumPoolSize(12); }
From source file:tvbrowser.TVBrowser.java
/** * Updates the proxy settings./*from ww w . j av a2s .co m*/ */ public static void updateProxySettings() { String httpHost = "", httpPort = "", httpUser = "", httpPassword = ""; if (Settings.propHttpProxyUseProxy.getBoolean()) { httpHost = Settings.propHttpProxyHost.getString(); httpPort = Settings.propHttpProxyPort.getString(); if (Settings.propHttpProxyAuthentifyAtProxy.getBoolean()) { httpUser = Settings.propHttpProxyUser.getString(); httpPassword = Settings.propHttpProxyPassword.getString(); if (httpPassword == null) { httpPassword = ""; } final String user = httpUser; final String pw = httpPassword; Authenticator.setDefault(new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(user, pw.toCharArray()); } }); } } System.setProperty("http.proxyHost", httpHost); System.setProperty("http.proxyPort", httpPort); System.setProperty("http.proxyUser", httpUser); System.setProperty("http.proxyPassword", httpPassword); System.setProperty("https.proxyHost", httpHost); }
From source file:org.apache.tools.ant.taskdefs.optional.net2.FTP2.java
@Nullable private static PasswordAuthentication getPasswordAuthentication(String host, int port, @Nullable String defaultUserId, @Nullable String defaultPassword, RequestorType requestorType) { if (defaultUserId != null) { if (defaultPassword == null) throw new BuildException("Password missing"); return new PasswordAuthentication(defaultUserId, defaultPassword.toCharArray()); }/*from w w w .jav a 2 s. c o m*/ InetAddress addr; try { addr = InetAddress.getByName(host); } catch (UnknownHostException uhe) { throw new BuildException(uhe); } return Authenticator.requestPasswordAuthentication(host, // host addr, // addr port, // port "ftp", // protocol "FTP", // prompt null, // scheme null, // url requestorType // reqType ); }