List of usage examples for org.apache.commons.httpclient.auth AuthScheme getRealm
public abstract String getRealm();
From source file:org.eurocarbdb.application.glycoworkbench.plugin.s3.Cockpit.java
/** * Implementation method for the CredentialsProvider interface. * <p>//from w w w. ja v a 2 s .c om * Based on sample code: * <a href="http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/src/examples/InteractiveAuthenticationExample.java?view=markup">InteractiveAuthenticationExample</a> * */ public Credentials getCredentials(AuthScheme authscheme, String host, int port, boolean proxy) throws CredentialsNotAvailableException { if (authscheme == null) { return null; } try { Credentials credentials = null; if (authscheme instanceof NTLMScheme) { AuthenticationDialog pwDialog = new AuthenticationDialog(ownerFrame, "Authentication Required", "<html>Host <b>" + host + ":" + port + "</b> requires Windows authentication</html>", true); pwDialog.setVisible(true); if (pwDialog.getUser().length() > 0) { credentials = new NTCredentials(pwDialog.getUser(), pwDialog.getPassword(), host, pwDialog.getDomain()); } pwDialog.dispose(); } else if (authscheme instanceof RFC2617Scheme) { AuthenticationDialog pwDialog = new AuthenticationDialog(ownerFrame, "Authentication Required", "<html><center>Host <b>" + host + ":" + port + "</b>" + " requires authentication for the realm:<br><b>" + authscheme.getRealm() + "</b></center></html>", false); pwDialog.setVisible(true); if (pwDialog.getUser().length() > 0) { credentials = new UsernamePasswordCredentials(pwDialog.getUser(), pwDialog.getPassword()); } pwDialog.dispose(); } else { throw new CredentialsNotAvailableException( "Unsupported authentication scheme: " + authscheme.getSchemeName()); } return credentials; } catch (IOException e) { throw new CredentialsNotAvailableException(e.getMessage(), e); } }
From source file:org.jets3t.apps.synchronize.CommandLineCredentialsProvider.java
/** * Implementation method for the CredentialsProvider interface. * <p>//from w w w .j av a 2s . c om * Based on sample code: * <a href="http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/src/examples/InteractiveAuthenticationExample.java?view=markup">InteractiveAuthenticationExample</a> * */ public Credentials getCredentials(AuthScheme authscheme, String host, int port, boolean proxy) throws CredentialsNotAvailableException { if (authscheme == null) { return null; } try { Credentials credentials = null; BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); if (authscheme instanceof NTLMScheme) { System.out.println("Proxy Authentication Required -- " + "Host " + host + ":" + port + " requires Windows authentication"); System.out.print("Username: "); String username = inputReader.readLine(); System.out.print("Password: "); String password = inputReader.readLine(); System.out.print("Domain: "); String domain = inputReader.readLine(); credentials = new NTCredentials(username, password, host, domain); } else if (authscheme instanceof RFC2617Scheme) { System.out.println("Proxy Authentication Required -- " + "Host " + host + ":" + port + " requires authentication for the realm: " + authscheme.getRealm()); System.out.print("Username: "); String username = inputReader.readLine(); System.out.print("Password: "); String password = inputReader.readLine(); credentials = new UsernamePasswordCredentials(username, password); } else { throw new CredentialsNotAvailableException( "Unsupported authentication scheme: " + authscheme.getSchemeName()); } return credentials; } catch (IOException e) { throw new CredentialsNotAvailableException(e.getMessage(), e); } }
From source file:sernet.springclient.CommonsExecuter.java
@Override void init() {/*from w w w.jav a2 s .c o m*/ /** * Sets the verinice password dialog. */ getHttpClient().getParams().setParameter(CredentialsProvider.PROVIDER, new CredentialsProvider() { @Override public Credentials getCredentials(AuthScheme authScheme, String host, int port, boolean arg3) throws CredentialsNotAvailableException { Authentication auth = AuthDialog.getAuthentication(host + ", Port: " + port, authScheme.getRealm()); return new UsernamePasswordCredentials(auth.getUser(), auth.getPassword()); } }); }