Added: allow appending of domain name to username when user tries to login (#7790)

This commit is contained in:
Fabian Grutschus 2020-02-04 21:47:49 +01:00 committed by GitHub
parent 56582614b6
commit 5becb93e6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 71 additions and 5 deletions

View file

@ -981,6 +981,7 @@ class SettingsController extends Controller
$setting->ldap_email = $request->input('ldap_email');
$setting->ad_domain = $request->input('ad_domain');
$setting->is_ad = $request->input('is_ad', '0');
$setting->ad_append_domain = $request->input('ad_append_domain', '0');
$setting->ldap_tls = $request->input('ldap_tls', '0');
$setting->ldap_pw_sync = $request->input('ldap_pw_sync', '0');
$setting->custom_forgot_pass_url = $request->input('custom_forgot_pass_url');

View file

@ -33,6 +33,7 @@ class SettingsLdapRequest extends Request
"ldap_lname_field" => 'sometimes|required_if:ldap_enabled,1|nullable',
"ldap_auth_filter_query" => 'sometimes|required_if:ldap_enabled,1|nullable',
"ldap_version" => 'sometimes|required_if:ldap_enabled,1|nullable',
"ad_domain" => 'sometimes|required_if:is_ad,1|nullable',
];
return $rules;

View file

@ -341,7 +341,8 @@ class Setting extends Model
'ldap_tls',
'ldap_pw_sync',
'is_ad',
'ad_domain'
'ad_domain',
'ad_append_domain',
])->first()->getAttributes();
return collect($ldapSettings);

View file

@ -86,6 +86,10 @@ class LdapAd extends LdapAdConfiguration
*/
public function ldapLogin(string $username, string $password): User
{
if ($this->ldapSettings['ad_append_domain']) {
$username .= '@' . $this->ldapSettings['ad_domain'];
}
try {
$this->ldap->auth()->attempt($username, $password);
} catch (Exception $e) {

View file

@ -22,7 +22,15 @@ class LdapAdConfiguration
const LDAP_PORT = 389;
const CONNECTION_TIMEOUT = 5;
const DEFAULT_LDAP_VERSION = 3;
const LDAP_BOOLEAN_SETTINGS = ['ldap_enabled', 'ldap_server_cert_ignore', 'ldap_tls', 'ldap_tls', 'ldap_pw_sync', 'is_ad'];
const LDAP_BOOLEAN_SETTINGS = [
'ldap_enabled',
'ldap_server_cert_ignore',
'ldap_tls',
'ldap_tls',
'ldap_pw_sync',
'is_ad',
'ad_append_domain',
];
/**
* Ldap Settings.

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddAdAppendDomainSettings extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('settings', function (Blueprint $table) {
$table->boolean('ad_append_domain')->nullable(false)->default('0');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('settings', function (Blueprint $table) {
$table->dropColumn('ad_append_domain');
});
}
}

View file

@ -4,6 +4,9 @@ return array(
'ad' => 'Active Directory',
'ad_domain' => 'Active Directory Domäne',
'ad_domain_help' => 'Meistens dieselbe wie die E-Mail Domäne.',
'ad_append_domain_label' => 'Domäne hinzufügen',
'ad_append_domain' => 'Automatisch dem Benutzernamen den Domänennamen anhängen',
'ad_append_domain_help' => 'Benutzer müssen lediglich „username“ schreiben, statt „username@domain.local“' ,
'admin_cc_email' => 'CC Email',
'admin_cc_email_help' => 'Wenn Sie eine Kopie der Rücknahme- / Herausgabe-E-Mails, die an Benutzer gehen auch an zusätzliche E-Mail-Empfänger versenden möchten, geben Sie sie hier ein. Ansonsten lassen Sie dieses Feld leer.',
'is_ad' => 'Dies ist ein Active Directory Server',

View file

@ -4,6 +4,9 @@ return array(
'ad' => 'Active Directory',
'ad_domain' => 'Active Directory domain',
'ad_domain_help' => 'This is sometimes the same as your email domain, but not always.',
'ad_append_domain_label' => 'Append domain name',
'ad_append_domain' => 'Append domain name to username field',
'ad_append_domain_help' => 'User doesn\'t require to write "username@domain.local", they can just type "username".' ,
'admin_cc_email' => 'CC Email',
'admin_cc_email_help' => 'If you would like to send a copy of checkin/checkout emails that are sent to users to an additional email account, enter it here. Otherwise leave this field blank.',
'is_ad' => 'This is an Active Directory server',

View file

@ -92,7 +92,7 @@
{{ trans('admin/settings/general.is_ad') }}
{!! $errors->first('is_ad', '<span class="alert-msg">:message</span>') !!}
</div>
</div>
</div>
<!-- AD Domain -->
<div class="form-group {{ $errors->has('ad_domain') ? 'error' : '' }}">
@ -106,6 +106,19 @@
</div>
</div><!-- AD Domain -->
<!-- AD Append Domain -->
<div class="form-group">
<div class="col-md-3">
{{ Form::label('ad_append_domain', trans('admin/settings/general.ad_append_domain_label')) }}
</div>
<div class="col-md-9">
{{ Form::checkbox('ad_append_domain', '1', Request::old('ad_append_domain', $setting->ad_append_domain),['class' => 'minimal '. $setting->demoMode, $setting->demoMode]) }}
{{ trans('admin/settings/general.ad_append_domain') }}
<p class="help-block">{{ trans('admin/settings/general.ad_append_domain_help') }}</p>
{!! $errors->first('is_ad', '<span class="alert-msg">:message</span>') !!}
</div>
</div>
<!-- LDAP Server -->
<div class="form-group {{ $errors->has('ldap_server') ? 'error' : '' }}">
<div class="col-md-3">
@ -293,7 +306,7 @@
<div class="col-md-9 col-md-offset-3">
<p class="help-block">{{ trans('admin/settings/general.ldap_login_sync_help') }}</p>
</div>
</div>
@endif
@ -368,7 +381,7 @@
headers: {
"X-Requested-With": 'XMLHttpRequest',
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
},
},
data: {},
dataType: 'json',