Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

LDAP Login Loop and User Import #836

Open
Groganj89 opened this issue Jan 17, 2020 · 3 comments
Open

LDAP Login Loop and User Import #836

Groganj89 opened this issue Jan 17, 2020 · 3 comments
Labels

Comments

@Groganj89
Copy link

Groganj89 commented Jan 17, 2020

  • Laravel Version: 5.8
  • Adldap2-Laravel Version: 6.08
  • PHP Version: 7.1.33
  • LDAP Type:

Description:

Hi There. I have set up ldap on the test app that I created following the guide: https://adldap2.github.io/Adldap2-Laravel/#/auth/installation

Now from what I can gather, I have authenticated with my AD and I have used php artisan adldap:import and it has imported all my users and I can see them in the user table in my MySQL DB. But I am currently having one issue and I also have one question in regards to integration into my main application.

I'll start with my issue. When I try to log in, it loops back to the login screen instead of redirecting to /home. It does not show any errors from what I can see anyway. I would like to get this sorted for a different project.

My question is, the command php artisan adldap:import, can i change where that imports the information to for example anywhere else other than the users table? and can I restrict the information it imports/syncs. For example, can I have it just importing names into say a Hosts table?

Here is my documents for my issue.

Login Controller

'<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/

use AuthenticatesUsers;

/**
 * Where to redirect users after login.
 *
 * @return string
 */
protected $redirectTo = '/home';

/**
* The path to redirect authenticated users to. 
*
 * @return string
*/
public function redirectTo()
{
    return url('/home');
}

/**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct()
{
    $this->middleware('guest')->except('logout');
}

public function username()
{
    return 'userprinciplename';
}

}'

ldap_auth

'<?php

return [
'connection' => 'default',
'provider' => Adldap\Laravel\Auth\DatabaseUserProvider::class,
'model' => App\User::class,
'rules' => [
Adldap\Laravel\Validation\Rules\DenyTrashed::class,
],
'scopes' => [
],
'identifiers' => [
'ldap' => [
'locate_users_by' => 'userprincipalname',
'bind_users_by' => 'distinguishedname',
],
// 'database' => [
// 'guid_column' => 'objectguid',
// 'username_column' => 'username',
// ],
// 'windows' => [
// 'locate_users_by' => 'userprincipalname',
// 'server_key' => 'AUTH_USER',
//],
],

'passwords' => [
    'sync' => false,
    'column' => 'password',
],
'login_fallback' => false,
'sync_attributes' => [
    'username' => 'userprincipalname',
    'name' => 'cn',
],
'logging' => [
    'enabled' => env('LDAP_LOGGING', true),
    'events' => [
        \Adldap\Laravel\Events\Importing::class => \Adldap\Laravel\Listeners\LogImport::class,
        \Adldap\Laravel\Events\Synchronized::class => \Adldap\Laravel\Listeners\LogSynchronized::class,
        \Adldap\Laravel\Events\Synchronizing::class => \Adldap\Laravel\Listeners\LogSynchronizing::class,
        \Adldap\Laravel\Events\Authenticated::class => \Adldap\Laravel\Listeners\LogAuthenticated::class,
        \Adldap\Laravel\Events\Authenticating::class => \Adldap\Laravel\Listeners\LogAuthentication::class,
        \Adldap\Laravel\Events\AuthenticationFailed::class => \Adldap\Laravel\Listeners\LogAuthenticationFailure::class,
        \Adldap\Laravel\Events\AuthenticationRejected::class => \Adldap\Laravel\Listeners\LogAuthenticationRejection::class,
        \Adldap\Laravel\Events\AuthenticationSuccessful::class => \Adldap\Laravel\Listeners\LogAuthenticationSuccess::class,
        \Adldap\Laravel\Events\DiscoveredWithCredentials::class => \Adldap\Laravel\Listeners\LogDiscovery::class,
        \Adldap\Laravel\Events\AuthenticatedWithWindows::class => \Adldap\Laravel\Listeners\LogWindowsAuth::class,
        \Adldap\Laravel\Events\AuthenticatedModelTrashed::class => \Adldap\Laravel\Listeners\LogTrashedModel::class,
    ],
],

];'

ldap.php

'<?php

return [

'logging' => true,

'connections' =>[

    'default' => [

        'auto_connect' => true,

        'connection' => Adldap\Connections\Ldap::class,

        'settings' => [

            'schema' => Adldap\Schemas\ActiveDirectory::class,

            // 'account_prefix' => env('LDAP_ACCOUNT_PREFIX', ''),

            // 'account_suffix' => '@LesarUKLTD.local',

            'hosts' => [
                'HIDDEN FOR OBVIOUS REASONS',
            ],
            'port' => '389',

            'timeout' => 5,

            'base_dn' => 'dc=LesarUKLtd,dc=local',

            'username' => 'sysadmin',
            'password' => HIDDEN FOR OBVIOUS REASONS

            'follow_referrals' => false,

            'use_ssl' => false,
            'use_tls' => false,

        ],

    ],

],

];'

auth.php

'<?php

return [

'defaults' => [
    'guard' => 'web',
    'passwords' => 'users',
],


'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'token',
        'provider' => 'users',
        'hash' => false,
    ],
],

'providers' => [
    'users' => [
        'driver' => 'database',
        'model' => App\User::class,
        'table' => 'users',
    ],
],

// 'users' => [
//    'driver' => 'database',
//    'table' => 'users',
//    ],
// ],

'passwords' => [
    'users' => [
        'provider' => 'users',
        'table' => 'password_resets',
        'expire' => 60,
    ],
],

];'

Sorry if my post has a lot of content, I just want to provide you with as much information as possible.

Thanks in advance.

@stevebauman
Copy link
Member

Hi @Groganj89,

I can definitely help you get up and running - though you have things commented out in your posted code snippets and I'm not sure if this is the true state that your application is running in.

For example in your ldap_auth.php config, the database config option is required but you've commented it out:

// 'database' => [
// 'guid_column' => 'objectguid',
// 'username_column' => 'username',
// ],
// 'windows' => [
// 'locate_users_by' => 'userprincipalname',
// 'server_key' => 'AUTH_USER',
//],

In your ldap.php file:

// 'account_prefix' => env('LDAP_ACCOUNT_PREFIX', ''),

// 'account_suffix' => '@LesarUKLTD.local',

And in your auth.php file you aren't using the ldap driver in your users provider:

'providers' => [
    'users' => [
        'driver' => 'database',
        'model' => App\User::class,
        'table' => 'users',
    ],
],

// 'users' => [
//    'driver' => 'database',
//    'table' => 'users',
//    ],
// ],

Can you clarify this for me?

@Groganj89
Copy link
Author

Hi Steve

Thanks for getting back to me. I can certainly clear these up for you. Basically I was having sync issues, and trying different methods to get that working. Although, I am not entirely sure that it is fully working as it finds 169 users in my AD but only syncs 154 of them.

I have since uncommented the commented section in ldap_auth.php and changed auth.php back to ldap and I am still getting the redirect issue.

@Groganj89
Copy link
Author

Groganj89 commented Jan 17, 2020

Actually, in addition to what I said above, the sync must be working fine, I have just had a look at the logs and the ones it has not synced are groups without principal names which is fine, to be honest. I have a feeling it has nothing to do with my redirect but maybe more towards authentication. From what i understand of the code, if it is not authenticated with the LDAP server / Database then it will not redirect.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants