מחלקה Java.net.Authenticator ב-Java

מחלקת Authenticator משמשת במקרים שבהם נדרש אימות כדי לבקר בכתובת URL כלשהי. ברגע שידוע שנדרש אימות, הוא מבקש מהמשתמש לעשות זאת או משתמש בשם משתמש וסיסמה מקודדים. 
כדי להשתמש בכיתה זו יש לבצע את השלבים הבאים- 
 


  1. צור מחלקה שמרחיבה את המאמת. בואו נקרא לזה customAuth.
  2. עוקף את שיטת getPasswordAuthentication()‎. שיטה זו מכילה מספר שיטות לקבלת הפרטים של הישות המבקשת לאימות. כל השיטות הללו יידונו בפירוט בהמשך.
  3. הגדר את תת-המחלקה החדשה שנוצרה כמאמת ברירת המחדל לשימוש כאשר שרת http מבקש אימות עם שיטת setDefault(Authenticator a) של המחלקה Authenticator.
      setDefault(Authenticator a) : מגדיר את המאמת לשימוש כאשר שרת HTTP דורש אימות. 
       
  Syntax :   public static void setDefault(Authenticator a) throws SecurityException   Parameter :   a : authenticator to be set as default   Throws :   SecurityException : if security manager doesn't allow setting default authenticator 

  1.  
  2. requestPasswordAuthentication() : מבקש מהמאמת הרשום במערכת סיסמה. מחזירה שם משתמש/סיסמה או null אם לא נמצא.
     
  Syntax :    public static PasswordAuthentication requestPasswordAuthentication( InetAddress addr int port String protocol String prompt String scheme)   Parameter :   addr : Inet address of the site asking for authentication port : port of requesting site protocol : protocol used for connection prompt : message for the user scheme : authentication scheme   Throws :   SecurityException : if security manager doesn't allow setting password authentication. 

  1. שיטה עמוסה נוספת שניתן להשתמש בה במצבים בהם ניתן להשתמש בשם מארח אם inetaddress אינו זמין. 
     
  Syntax :    public static PasswordAuthentication requestPasswordAuthentication( String host InetAddress addr int port String protocol String prompt String scheme)   Parameter :   host : hostname of the site asking for authentication addr : Inet address of the site asking for authentication port : port of requesting site protocol : protocol used for connection prompt : message for the user scheme : authentication scheme   Throws :   SecurityException : if security manager doesn't allow setting password authentication. 

  1. שיטה עמוסה נוספת שניתן להשתמש בה אם כתובת האתר של האתר המבקש אימות ידועה רק ולא כתובת ה-Inetaddress ושם המארח. 
     
  Syntax :    public static PasswordAuthentication requestPasswordAuthentication( String host InetAddress addr int port String protocol String prompt URL url String scheme)   Parameter :   host : hostname of the site asking for authentication addr : Inet address of the site asking for authentication port : port of requesting site protocol : protocol used for connection prompt : message for the user url : URL of the site requesting authentication scheme : authentication scheme   Throws :   SecurityException : if security manager doesn't allow setting password authentication. 

  1.  
  2. getRequestingHost() : מחזירה את שם המארח של האתר המבקש אימות. 
     
  Syntax : protected final String getRequestingHost()   

  1.  
  2. getRequestingSite() : מחזירה את ה-inetaddress של האתר המבקש אימות. 
     
  Syntax : protected final InetAddress getRequestingSite()   

  1.  
  2. getRequestingPort() : מחזיר את יציאת החיבור. 
     
  Syntax : protected final int getRequestingPort()   

  1.  
  2. getRequestingProtocol() : מחזיר את הפרוטוקול המבקש את החיבור. 
     
  Syntax : protected final String getRequestingProtocol()   

  1.  
  2. getRequestingPrompt() : מחזירה את ההודעה שהתבקשת על ידי המבקש. 
     
  Syntax : protected final String getRequestingPrompt()   

  1.  
  2. getRequestingScheme() : מחזירה את התוכנית של האתר המבקש. 
     
  Syntax : protected final String getRequestingScheme()   

  1.  
  2. getPasswordAuthentication() : שיטה זו נקראת כאשר נדרש אימות סיסמה. כל מחלקות המשנה חייבות לעקוף שיטה זו מכיוון ששיטת ברירת המחדל תמיד מחזירה null. 
     
  Syntax : protected PasswordAuthentication getPasswordAuthentication()   

  1.  
  2. getRequestingURL() : מחזירה את כתובת האתר של המבקש. 
     
  Syntax : protected final URL getRequestingURL()   

  1.  
  2. getRequestorType() : חוזר אם המבקש הוא פרוקסי או שרת. 
     
  Syntax : protected Authenticator.RequestorType getRequestorType()   

  1.  
צור חידון