מחלקה Java.net.Authenticator ב-Java
מחלקת Authenticator משמשת במקרים שבהם נדרש אימות כדי לבקר בכתובת URL כלשהי. ברגע שידוע שנדרש אימות, הוא מבקש מהמשתמש לעשות זאת או משתמש בשם משתמש וסיסמה מקודדים.
כדי להשתמש בכיתה זו יש לבצע את השלבים הבאים-
-
צור מחלקה שמרחיבה את המאמת. בואו נקרא לזה customAuth. - עוקף את שיטת getPasswordAuthentication(). שיטה זו מכילה מספר שיטות לקבלת הפרטים של הישות המבקשת לאימות. כל השיטות הללו יידונו בפירוט בהמשך.
- הגדר את תת-המחלקה החדשה שנוצרה כמאמת ברירת המחדל לשימוש כאשר שרת http מבקש אימות עם שיטת setDefault(Authenticator a) של המחלקה Authenticator.
-
-
שיטה עמוסה נוספת שניתן להשתמש בה במצבים בהם ניתן להשתמש בשם מארח אם inetaddress אינו זמין.
-
שיטה עמוסה נוספת שניתן להשתמש בה אם כתובת האתר של האתר המבקש אימות ידועה רק ולא כתובת ה-Inetaddress ושם המארח.
-
-
-
-
-
-
-
-
-
-
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
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.
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.
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.
getRequestingHost() : מחזירה את שם המארח של האתר המבקש אימות.
Syntax : protected final String getRequestingHost()
getRequestingSite() : מחזירה את ה-inetaddress של האתר המבקש אימות.
Syntax : protected final InetAddress getRequestingSite()
getRequestingPort() : מחזיר את יציאת החיבור.
Syntax : protected final int getRequestingPort()
getRequestingProtocol() : מחזיר את הפרוטוקול המבקש את החיבור.
Syntax : protected final String getRequestingProtocol()
getRequestingPrompt() : מחזירה את ההודעה שהתבקשת על ידי המבקש.
Syntax : protected final String getRequestingPrompt()
getRequestingScheme() : מחזירה את התוכנית של האתר המבקש.
Syntax : protected final String getRequestingScheme()
getPasswordAuthentication() : שיטה זו נקראת כאשר נדרש אימות סיסמה. כל מחלקות המשנה חייבות לעקוף שיטה זו מכיוון ששיטת ברירת המחדל תמיד מחזירה null.
Syntax : protected PasswordAuthentication getPasswordAuthentication()
getRequestingURL() : מחזירה את כתובת האתר של המבקש.
Syntax : protected final URL getRequestingURL()
getRequestorType() : חוזר אם המבקש הוא פרוקסי או שרת.
Syntax : protected Authenticator.RequestorType getRequestorType()
אולי תאהבו
מאמרים למעלה
קטגוריה
-