Skip to content

A free open source IT asset/license management system

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

Fabian Grutschus5becb93e6c54
diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php
index 988534a6ac..73a21491d2 100755
--- a/app/Http/Controllers/SettingsController.php
+++ b/app/Http/Controllers/SettingsController.php
@@ -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');
diff --git a/app/Http/Requests/SettingsLdapRequest.php b/app/Http/Requests/SettingsLdapRequest.php
index 8cfef0d995..33da10fd65 100644
--- a/app/Http/Requests/SettingsLdapRequest.php
+++ b/app/Http/Requests/SettingsLdapRequest.php
@@ -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;
diff --git a/app/Models/Setting.php b/app/Models/Setting.php
index 96de9fdfb2..982377c954 100755
--- a/app/Models/Setting.php
+++ b/app/Models/Setting.php
@@ -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);
diff --git a/app/Services/LdapAd.php b/app/Services/LdapAd.php
index fb54771a7e..bd3170e134 100644
--- a/app/Services/LdapAd.php
+++ b/app/Services/LdapAd.php
@@ -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) {
diff --git a/app/Services/LdapAdConfiguration.php b/app/Services/LdapAdConfiguration.php
index d25679faaa..638dc450a5 100644
--- a/app/Services/LdapAdConfiguration.php
+++ b/app/Services/LdapAdConfiguration.php
@@ -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.
diff --git a/database/migrations/2020_02_04_172100_add_ad_append_domain_settings.php b/database/migrations/2020_02_04_172100_add_ad_append_domain_settings.php
new file mode 100644
index 0000000000..4fce7f4558
--- /dev/null
+++ b/database/migrations/2020_02_04_172100_add_ad_append_domain_settings.php
@@ -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');
+ });
+ }
+}
diff --git a/resources/lang/de/admin/settings/general.php b/resources/lang/de/admin/settings/general.php
index 7a5eacd983..9b8392ef15 100644
--- a/resources/lang/de/admin/settings/general.php
+++ b/resources/lang/de/admin/settings/general.php
@@ -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 „[email protected]“' ,
'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',
diff --git a/resources/lang/en/admin/settings/general.php b/resources/lang/en/admin/settings/general.php
index 27decf49da..2048f2df16 100644
--- a/resources/lang/en/admin/settings/general.php
+++ b/resources/lang/en/admin/settings/general.php
@@ -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 "[email protected]", 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',
diff --git a/resources/views/settings/ldap.blade.php b/resources/views/settings/ldap.blade.php
index af7cbe84f4..6dd094eb04 100644
--- a/resources/views/settings/ldap.blade.php
+++ b/resources/views/settings/ldap.blade.php
@@ -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',