Overview
ディレクトリ サーバーのユーザー名とパスワードを使用して、LDAP(Lightweight Directory Access Protocol)サーバーで認証できます。
Tip
PLAIN 認証
The authentication mechanism is named PLAIN
instead of LDAP
because the driver authenticates by using the PLAIN
Simple Authentication and Security Layer (SASL) defined in RFC-4616.
LDAP 認証の指定
このセクションの例では、接続文字列または MongoCredential
クラスを使用して LDAP
認証を指定する方法を示します。 以下のプレースホルダー値を置き換えます。
<LDAP username>
: LDAPユーザー名。<password>
: LDAP パスワード。<hostname>
: MongoDBデプロイのネットワーク アドレスで、クライアントからアクセスできます。<port>
: MongoDBデプロイのポート番号。 このパラメーターを省略すると、ドライバーはデフォルトのポート番号(27017
)を使用します。
Connection StringMongoCredentialこの認証メカニズムを指定するための手順とサンプルコードについては、以下の [0 タブまたは タブを選択してください。
接続文字列を使用して LDAP
認証メカニズムを指定するには、次の手順に従います。
authMechanism
URL パラメータに値PLAIN
を割り当てます(任意)
authSource
URLパラメータに値$external
を割り当てます
注意
PLAIN
メカニズムを指定する場合、 authSource
を$external
以外の値に割り当てることはできません。
次のコードでは、 接続文字列で認証メカニズムを指定します。
val connectionString = ConnectionString("<LDAP username>:<password>@<hostname>:<port>/?authSource=$external&authMechanism=PLAIN") val mongoClient = MongoClient.create(connectionString)
MongoCredential
クラスを使用して LDAP
認証メカニズムを指定するには、次の例に示すように createPlainCredential()
メソッドを使用します。
val credential = MongoCredential.createPlainCredential("<LDAP username>", "$external", "<password>".toCharArray()) val settings = MongoClientSettings.builder() .applyToClusterSettings { builder -> builder.hosts(listOf(ServerAddress("<hostname>", <port>))) } .credential(credential) .build() val mongoClient = MongoClient.create(settings)
詳細情報
MongoDBへの認証の詳細については、 MongoDB Serverマニュアルの 認証 を参照してください。
Kotlin Syncドライバーを使用して MongoClient
オブジェクトを作成する方法について詳しくは、「MongoClient の作成」ガイドを参照してください。
API ドキュメント
Kotlin Syncドライバーでアプリケーションを認証するためのクラスとメソッドの詳細については、次のAPIドキュメントを参照してください。