KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > net > Authenticator

java.net
Class Authenticator

java.lang.Object
  extended by java.net.Authenticator
See Also:
Top Examples, Source Code, PasswordAuthentication, setDefault(java.net.Authenticator), getPasswordAuthentication()

public Authenticator()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected PasswordAuthentication getPasswordAuthentication()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected final String getRequestingHost()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected final int getRequestingPort()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected final String getRequestingPrompt()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected final String getRequestingProtocol()
See Also:
URL.getProtocol()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected final String getRequestingScheme()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected final InetAddress getRequestingSite()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected URL getRequestingURL()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected Authenticator.RequestorType getRequestorType()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static PasswordAuthentication requestPasswordAuthentication(String host,
                                                                   InetAddress addr,
                                                                   int port,
                                                                   String protocol,
                                                                   String prompt,
                                                                   String scheme)
See Also:
NetPermission, SecurityManager.checkPermission(java.security.Permission), SecurityException, getRequestingProtocol()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static PasswordAuthentication requestPasswordAuthentication(String host,
                                                                   InetAddress addr,
                                                                   int port,
                                                                   String protocol,
                                                                   String prompt,
                                                                   String scheme,
                                                                   URL url,
                                                                   Authenticator.RequestorType reqType)
See Also:
NetPermission, SecurityManager.checkPermission(java.security.Permission), SecurityException, getRequestingProtocol()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static PasswordAuthentication requestPasswordAuthentication(InetAddress addr,
                                                                   int port,
                                                                   String protocol,
                                                                   String prompt,
                                                                   String scheme)
See Also:
NetPermission, SecurityManager.checkPermission(java.security.Permission), SecurityException, getRequestingProtocol()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void setDefault(Authenticator a)
See Also:
NetPermission, SecurityManager.checkPermission(java.security.Permission), SecurityException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1481]Double authentication problem
By Anonymous on 2005/07/14 03:26:18  Rate
Pay attention here! If you use this class to authenticate, the request will be send twice over the wire. The first request will be denied access by the server, the server's response triggers the default authenticator. The client resubmits the request with the "Authorisation" header added to the request.  
  
  
 Solution to send this authentication immediatelly: 
  
  
 URL url = new URL ( ???http://host/service??? ) ; 
 URLConnection connection = url.openConnection (  ) ; 
 PasswordAuthentication pa = Authenticator.requestPasswordAuthentication (  
   InetAddress.getByName ( connection.getURL (  ) .getHost (  )  ) , 
   connection.getURL (  ) .getPort (  ) , 
   connection.getURL (  ) .getProtocol (  ) , 
 null, 
   "Basic" ) ; 
 StringBuffer buf = new StringBuffer ( pa.getUserName (  )  ) ; 
 buf.append ( ":" ) ; 
 buf.append ( pa.getPassword (  )  ) ; 
 String encoded = new BASE64Encoder (  ) .encode ( buf.toString (  ) .getBytes (  )  ) ;; 
 connection.setRequestProperty  ( "Authorization", "Basic " + encoded ) ;     
  
  
  
 

Popular Tags