List of usage examples for org.apache.http.auth AuthScope getRealm
public String getRealm()
From source file:ucar.unidata.util.AccountManager.java
/** * _more_// w w w .j av a2s .c o m * * @param scope _more_ * * @return _more_ */ public Credentials getCredentialsnew(AuthScope scope) { //String host, int port, boolean proxy String host = scope.getHost(); int port = scope.getPort(); String realm = scope.getRealm(); // public Credentials getCredentials(AuthScheme scheme, String host, // int port, boolean proxy) // throws InvalidCredentialsException { if (scope == null) { throw new IllegalArgumentException("Null scope"); } /* //TODO: check if the scheme in the auth is rfc26217 if ( !(scheme instanceof RFC2617Scheme)) { throw new InvalidCredentialsException( "Unsupported authentication scheme: " + scheme.getSchemeName()); } */ String key = host + realm; // System.err.println ("got auth call " + key); UserInfo userInfo = getUserNamePassword(key, "The server " + host + ":" + port + " requires a username/password"); if (userInfo == null) { return null; } return new UsernamePasswordCredentials(userInfo.getUserId(), userInfo.getPassword()); }
From source file:ucar.unidata.util.AccountManager.java
/** * Do the authentication//from www . j a v a 2 s .c o m * @param scope authscope * * @return Null if the user presses cancel. Else return the credentials * */ public Credentials getCredentials(AuthScope scope) { //TODO: What should this do? if (scope == null) { throw new IllegalArgumentException("Authentication scope may not be null"); } if (currentCredentials == null) { String host = scope.getHost(); int port = scope.getPort(); String key = host + ":" + port + ":" + scope.getRealm(); // System.err.println ("got auth call " + key); UserInfo userInfo = getUserNamePassword(key, "The server " + host + ":" + port + " requires a username/password"); if (userInfo == null) { return null; } currentCredentials = new UsernamePasswordCredentials(userInfo.getUserId(), userInfo.getPassword()); } return currentCredentials; }
From source file:org.jets3t.apps.uploader.Uploader.java
/** * Implementation method for the CredentialsProvider interface. * <p>// w w w.j ava 2s . c o m * 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(AuthScope scope) { if (scope == null || scope.getScheme() == null) { return null; } Credentials credentials = mCredentialProvider.getCredentials(scope); if (credentials != null) { return credentials; } try { if (scope.getScheme().equals("ntlm")) { //if (authscheme instanceof NTLMScheme) { AuthenticationDialog pwDialog = new AuthenticationDialog(ownerFrame, "Authentication Required", "<html>Host <b>" + scope.getHost() + ":" + scope.getPort() + "</b> requires Windows authentication</html>", true); pwDialog.setVisible(true); if (pwDialog.getUser().length() > 0) { credentials = new NTCredentials(pwDialog.getUser(), pwDialog.getPassword(), scope.getHost(), pwDialog.getDomain()); } pwDialog.dispose(); } else if (scope.getScheme().equals("basic") || scope.getScheme().equals("digest")) { //if (authscheme instanceof RFC2617Scheme) { AuthenticationDialog pwDialog = new AuthenticationDialog(ownerFrame, "Authentication Required", "<html><center>Host <b>" + scope.getHost() + ":" + scope.getPort() + "</b>" + " requires authentication for the realm:<br><b>" + scope.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 IllegalArgumentException("Unsupported authentication scheme: " + scope.getScheme()); } if (credentials != null) { mCredentialProvider.setCredentials(scope, credentials); } return credentials; } catch (Exception e) { throw new IllegalArgumentException(e.getMessage(), e); } }
From source file:org.jets3t.apps.cockpit.Cockpit.java
/** * Implementation method for the CredentialsProvider interface. * <p>// w ww.j av a2 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(AuthScope scope) { if (scope == null || scope.getScheme() == null) { return null; } Credentials credentials = mCredentialProvider.getCredentials(scope); if (credentials != null) { return credentials; } try { if (scope.getScheme().equals("ntlm")) { //if (authscheme instanceof NTLMScheme) { AuthenticationDialog pwDialog = new AuthenticationDialog(ownerFrame, "Authentication Required", "<html>Host <b>" + scope.getHost() + ":" + scope.getPort() + "</b> requires Windows authentication</html>", true); pwDialog.setVisible(true); if (pwDialog.getUser().length() > 0) { credentials = new NTCredentials(pwDialog.getUser(), pwDialog.getPassword(), scope.getHost(), pwDialog.getDomain()); } pwDialog.dispose(); } else if (scope.getScheme().equals("basic") || scope.getScheme().equals("digest")) { //if (authscheme instanceof RFC2617Scheme) { AuthenticationDialog pwDialog = new AuthenticationDialog(ownerFrame, "Authentication Required", "<html><center>Host <b>" + scope.getHost() + ":" + scope.getPort() + "</b>" + " requires authentication for the realm:<br><b>" + scope.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 IllegalArgumentException("Unsupported authentication scheme: " + scope.getScheme()); } if (credentials != null) { mCredentialProvider.setCredentials(scope, credentials); } return credentials; } catch (Exception e) { throw new IllegalArgumentException(e.getMessage(), e); } }
From source file:org.jets3t.apps.cockpitlite.CockpitLite.java
/** * Implementation method for the CredentialsProvider interface. * <p>//from ww w .ja v a 2 s. co m * 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(AuthScope scope) { if (scope == null || scope.getScheme() == null) { return null; } Credentials credentials = mCredentialProvider.getCredentials(scope); if (credentials != null) { return credentials; } try { if (scope.getScheme().equals("ntlm")) { AuthenticationDialog pwDialog = new AuthenticationDialog(ownerFrame, "Authentication Required", "<html>Host <b>" + scope.getHost() + ":" + scope.getPort() + "</b> requires Windows authentication</html>", true); pwDialog.setVisible(true); if (pwDialog.getUser().length() > 0) { credentials = new NTCredentials(pwDialog.getUser(), pwDialog.getPassword(), scope.getHost(), pwDialog.getDomain()); } pwDialog.dispose(); } else if (scope.getScheme().equals("basic") || scope.getScheme().equals("digest")) { //authscheme instanceof RFC2617Scheme AuthenticationDialog pwDialog = new AuthenticationDialog(ownerFrame, "Authentication Required", "<html><center>Host <b>" + scope.getHost() + ":" + scope.getPort() + "</b>" + " requires authentication for the realm:<br><b>" + scope.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 InvalidCredentialsException("Unsupported authentication scheme: " + scope.getScheme()); } if (credentials != null) { mCredentialProvider.setCredentials(scope, credentials); } return credentials; } catch (Exception e) { throw new IllegalArgumentException(e.getMessage(), e); } }