在Laravel 5.4中将LDAP连接到现有的LDAP系统,可以按照以下步骤进行操作:
'providers' => [
'users' => [
'driver' => 'ldap',
'model' => App\User::class,
'connection' => 'ldap',
],
],
'connections' => [
'ldap' => [
'driver' => 'adldap',
'model' => App\User::class,
'rules' => [
Adldap\Laravel\Validation\Rules\DenyTrashed::class,
],
'identifiers' => [
'ldap' => Adldap\Laravel\Auth\NoDatabaseUserProvider::class,
],
'database' => [
'model' => App\User::class,
'sync_passwords' => false,
'sync_attributes' => [],
],
],
],
'connections' => [
'default' => [
'auto_connect' => env('LDAP_AUTO_CONNECT', true),
'connection' => Adldap\Connections\Ldap::class,
'schema' => Adldap\Schemas\ActiveDirectory::class,
'connection_settings' => [
'account_prefix' => env('LDAP_ACCOUNT_PREFIX', ''),
'account_suffix' => env('LDAP_ACCOUNT_SUFFIX', ''),
'domain_controllers' => explode(' ', env('LDAP_DOMAIN_CONTROLLERS', 'ldap.example.com')),
'port' => env('LDAP_PORT', 389),
'timeout' => env('LDAP_TIMEOUT', 5),
'base_dn' => env('LDAP_BASE_DN', 'dc=example,dc=com'),
'username' => env('LDAP_USERNAME', 'admin'),
'password' => env('LDAP_PASSWORD', 'password'),
],
],
],
LDAP_AUTO_CONNECT=true
LDAP_ACCOUNT_PREFIX=
LDAP_ACCOUNT_SUFFIX=
LDAP_DOMAIN_CONTROLLERS=ldap.example.com
LDAP_PORT=389
LDAP_TIMEOUT=5
LDAP_BASE_DN=dc=example,dc=com
LDAP_USERNAME=admin
LDAP_PASSWORD=password
namespace App;
use Adldap\Laravel\Traits\HasLdapUser;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasLdapUser;
// ...
}
public function login(Request $request)
{
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials)) {
// 认证成功
return redirect()->intended('dashboard');
} else {
// 认证失败
return redirect()->back()->withErrors(['email' => '认证失败']);
}
}
以上步骤完成后,就可以在Laravel 5.4中将LDAP连接到现有的LDAP系统了。请注意,以上步骤仅提供了基本的LDAP连接和认证功能,具体的业务逻辑和功能需根据实际需求进行开发和扩展。
推荐的腾讯云相关产品:腾讯云LDAP身份认证服务(https://cloud.tencent.com/product/ldap)
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云