فئة Java.net.Authenticator في جافا
يتم استخدام فئة Authenticator في الحالات التي تكون فيها المصادقة مطلوبة لزيارة بعض عناوين URL. بمجرد معرفة أن المصادقة مطلوبة، فإنه يطالب المستخدم بنفس الشيء أو يستخدم اسم مستخدم وكلمة مرور مرمزة.
لاستخدام هذا الفصل يتم اتباع الخطوات التالية-
-
قم بإنشاء فئة تعمل على توسيع Authenticator. دعونا نسميها customAuth. - تجاوز طريقة getPasswordAuthentication(). تحتوي هذه الطريقة على عدة طرق للحصول على تفاصيل الجهة التي تطلب المصادقة. وستتم مناقشة كل هذه الأساليب بالتفصيل لاحقًا.
- قم بتعيين الفئة الفرعية التي تم إنشاؤها حديثًا كمصدق افتراضي لاستخدامه عندما يطلب خادم http المصادقة باستخدام طريقة setDefault(Authenticator a) لفئة Authenticator.
-
-
طريقة أخرى مثقلة التحميل يمكن استخدامها في المواقف التي يمكن فيها استخدام اسم المضيف في حالة عدم توفر inetaddress.
-
هناك طريقة أخرى مثقلة يمكن استخدامها إذا كان عنوان URL الخاص بالموقع الذي يطلب المصادقة معروفًا فقط وليس inetaddress واسم المضيف.
-
-
-
-
-
-
-
-
-
-
setDefault(الموثق أ): يضبط المصادق الذي سيتم استخدامه عندما يتطلب خادم 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
طلب كلمة المرور () : يطلب من الموثق المسجل في النظام كلمة المرور. إرجاع اسم المستخدم/كلمة المرور أو إرجاع قيمة فارغة إذا لم يتم العثور عليها.
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()
موقع الحصول على الطلب () : يقوم بإرجاع 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()
الحصول على مصادقة كلمة المرور () : يتم استدعاء هذه الطريقة عندما تكون مصادقة كلمة المرور مطلوبة. يجب أن تتجاوز جميع الفئات الفرعية هذه الطريقة لأن الطريقة الافتراضية تُرجع دائمًا قيمة فارغة.
Syntax : protected PasswordAuthentication getPasswordAuthentication()
الحصول على عنوان URL () : يقوم بإرجاع عنوان URL الخاص بالطالب.
Syntax : protected final URL getRequestingURL()
getRequestorType() : يُرجع إذا كان الطالب وكيلًا أو خادمًا.
Syntax : protected Authenticator.RequestorType getRequestorType()
مقالات العلوي
فئة
-