List of usage examples for java.net Authenticator setDefault
public static synchronized void setDefault(Authenticator a)
From source file:guiTool.Helper.java
public static String readUrl(String urlString, final String userid, final String password) throws Exception { BufferedReader reader = null; StringBuilder buffer = null;//from w w w .j a v a 2s . c om try { URL url = new URL(urlString); Authenticator.setDefault(new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(userid, password.toCharArray()); } }); InputStreamReader s = new InputStreamReader(url.openStream()); // System.out.println("getEncoding " + s.getEncoding()); reader = new BufferedReader(s); buffer = new StringBuilder(); int read; char[] chars = new char[1024]; while ((read = reader.read(chars)) != -1) { buffer.append(chars, 0, read); } } catch (Exception e) { System.out.println("Exception " + e.getMessage()); // JOptionPane.showMessageDialog(null, "The server or your internet connection could be down.", "connection test", JOptionPane.ERROR_MESSAGE); } finally { if (reader != null) { reader.close(); } } return buffer.toString(); }
From source file:org.opentravel.schemacompiler.repository.impl.NTLMSystemCredentialsProviderTest.java
@BeforeClass public static void beforeTest() { Authenticator.setDefault(testAuthenticator); }
From source file:net.orpiske.ssps.sdm.utils.net.ProxyHelper.java
private static void setupAuth() { boolean auth = config.getBoolean("proxy.auth.required", false); if (auth) {//from w w w . j a va2 s. c o m String user = config.getString("proxy.auth.user"); String password = config.getString("proxy.auth.password"); Authenticator.setDefault(getAuth(user, password)); } }
From source file:org.opf_labs.fmts.droid.ForegCmd.java
static void downloadSigFile() { // To make java.net.URL cope with an authenticating proxy. // Apache HTTPClient does this automatically, but we're not using that here at the moment. String proxyUser = System.getProperty("http.proxyUser"); if (proxyUser != null) { Authenticator.setDefault(new ProxyAuth(proxyUser, System.getProperty("http.proxyPassword"))); }// w w w. j a v a 2 s . com SigFile sigFile = SigFileUtils.getLatestSigFile(); try { SigFileUtils.writeSigFileToOutputStream(sigFile, new FileOutputStream("signaturefile.xml")); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.orange.clara.pivotaltrackermirror.util.ProxyUtil.java
private static void loadAuthenticator() { if (authenticatorIsLoaded) { return;// w w w.j av a2s .c o m } authenticatorIsLoaded = true; Authenticator authenticator = new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return (new PasswordAuthentication(PROXY_USER, PROXY_PASSWD.toCharArray())); } }; Authenticator.setDefault(authenticator); }
From source file:de.stadtrallye.rallyesoft.net.retrofit.RetroFactory.java
@Deprecated public static void setFallbackAuthentication(AuthProvider authProvider) { Authenticator.setDefault(authProvider.getAuthenticator()); }
From source file:net.sf.jabref.JabRefMain.java
private static void start(String[] args) { JabRefPreferences preferences = JabRefPreferences.getInstance(); ProxyPreferences proxyPreferences = ProxyPreferences.loadFromPreferences(preferences); ProxyRegisterer.register(proxyPreferences); if (proxyPreferences.isUseProxy() && proxyPreferences.isUseAuthentication()) { Authenticator.setDefault(new ProxyAuthenticator()); }/*from ww w.j av a 2 s. c om*/ Globals.startBackgroundTasks(); Globals.prefs = preferences; Localization.setLanguage(preferences.get(JabRefPreferences.LANGUAGE)); Globals.prefs.setLanguageDependentDefaultValues(); // Update which fields should be treated as numeric, based on preferences: InternalBibtexFields.setNumericFields(Globals.prefs.getStringList(JabRefPreferences.NUMERIC_FIELDS)); /* Build list of Import and Export formats */ Globals.IMPORT_FORMAT_READER.resetImportFormats(); CustomEntryTypesManager.loadCustomEntryTypes(preferences); ExportFormats.initAllExports(Globals.prefs.customExports.getCustomExportFormats(Globals.prefs)); // Read list(s) of journal names and abbreviations Globals.journalAbbreviationLoader = new JournalAbbreviationLoader(); // Check for running JabRef RemotePreferences remotePreferences = new RemotePreferences(Globals.prefs); if (remotePreferences.useRemoteServer()) { Globals.REMOTE_LISTENER.open(new JabRefMessageHandler(), remotePreferences.getPort()); if (!Globals.REMOTE_LISTENER.isOpen()) { // we are not alone, there is already a server out there, try to contact already running JabRef: if (RemoteListenerClient.sendToActiveJabRefInstance(args, remotePreferences.getPort())) { // We have successfully sent our command line options through the socket to another JabRef instance. // So we assume it's all taken care of, and quit. LOGGER.info( Localization.lang("Arguments passed on to running JabRef instance. Shutting down.")); JabRefExecutorService.INSTANCE.shutdownEverything(); return; } } // we are alone, we start the server Globals.REMOTE_LISTENER.start(); } // override used newline character with the one stored in the preferences // The preferences return the system newline character sequence as default Globals.NEWLINE = Globals.prefs.get(JabRefPreferences.NEWLINE); // Process arguments ArgumentProcessor argumentProcessor = new ArgumentProcessor(args, ArgumentProcessor.Mode.INITIAL_START); // See if we should shut down now if (argumentProcessor.shouldShutDown()) { JabRefExecutorService.INSTANCE.shutdownEverything(); return; } // If not, start GUI SwingUtilities.invokeLater( () -> new JabRefGUI(argumentProcessor.getParserResults(), argumentProcessor.isBlank())); }
From source file:com.varaneckas.hawkscope.util.ModularAuthenticator.java
/** * Registers this authenticator in JVM//from w ww.j ava 2 s. c o m */ public static void register() { Authenticator.setDefault(getInstance()); getInstance().loadProxyAuth(ConfigurationFactory.getConfigurationFactory().getConfiguration()); }
From source file:org.restheart.test.performance.AbstractPT.java
public void prepare() { Authenticator.setDefault(new Authenticator() { @Override/* w w w . j a v a2 s . c o m*/ protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(id, pwd.toCharArray()); } }); Configuration conf; StringBuilder ymlSB = new StringBuilder(); if (mongoUri != null) { ymlSB.append(Configuration.MONGO_URI_KEY).append(": ").append(mongoUri).append("\n"); } Yaml yaml = new Yaml(); Map<String, Object> configuration = (Map<String, Object>) yaml.load(ymlSB.toString()); try { MongoDBClientSingleton.init(new Configuration(configuration, true)); } catch (ConfigurationException ex) { System.out.println(ex.getMessage() + ", exiting..."); System.exit(-1); } httpExecutor = Executor.newInstance(); // for perf test better to disable the restheart security if (url != null && id != null && pwd != null) { String host = "127.0.0.1"; int port = 8080; String scheme = "http"; try { URI uri = new URI(url); host = uri.getHost(); port = uri.getPort(); scheme = uri.getScheme(); } catch (URISyntaxException ex) { Logger.getLogger(LoadPutPT.class.getName()).log(Level.SEVERE, null, ex); } httpExecutor.authPreemptive(new HttpHost(host, port, scheme)).auth(new HttpHost(host), id, pwd); } }
From source file:com.opoopress.maven.plugins.plugin.downloader.ProgressURLDownloader.java
private void configureProxyAuthentication() { if (System.getProperty("http.proxyUser") != null) { Authenticator.setDefault(new SystemPropertiesProxyAuthenticator()); }//from www . ja v a 2 s.com }