@@ -43,7 +43,7 @@ class Import
4343 */
4444 public function __construct (User $ user , Model $ model , array $ credentials = [])
4545 {
46- $ this ->user = $ user ;
46+ $ this ->user = $ this -> transformUsername ( $ user) ;
4747 $ this ->model = $ model ;
4848 $ this ->credentials = $ credentials ;
4949 }
@@ -113,12 +113,7 @@ protected function findByCredentials()
113113 */
114114 protected function sync (Model $ model )
115115 {
116- $ toSync = Config::get ('ldap_auth.sync_attributes ' , [
117- 'email ' => 'userprincipalname ' ,
118- 'name ' => 'cn ' ,
119- ]);
120-
121- foreach ($ toSync as $ modelField => $ ldapField ) {
116+ foreach ($ this ->getLdapSyncAttributes () as $ modelField => $ ldapField ) {
122117 // If the field is a loaded class and contains a `handle()` method,
123118 // we need to construct the attribute handler.
124119 if ($ this ->isHandler ($ ldapField )) {
@@ -138,6 +133,24 @@ protected function sync(Model $model)
138133 }
139134 }
140135
136+ /**
137+ * Transforms the username of the given user to avoid case sensitivity issues.
138+ *
139+ * We want to transform the username on the user model so it persists through attribute handlers.
140+ *
141+ * @param User $user
142+ *
143+ * @return User
144+ */
145+ protected function transformUsername (User $ user )
146+ {
147+ $ attribute = $ this ->getLdapDiscoveryUsername ();
148+
149+ $ user ->setFirstAttribute ($ attribute , strtolower ($ user ->getFirstAttribute ($ attribute )));
150+
151+ return $ user ;
152+ }
153+
141154 /**
142155 * Determines if the given handler value is a class that contains the 'handle' method.
143156 *
@@ -147,8 +160,29 @@ protected function sync(Model $model)
147160 */
148161 protected function isHandler ($ handler )
149162 {
150- return is_string ($ handler ) &&
151- class_exists ($ handler ) &&
152- method_exists ($ handler , 'handle ' );
163+ return is_string ($ handler ) && class_exists ($ handler ) && method_exists ($ handler , 'handle ' );
164+ }
165+
166+ /**
167+ * Returns the configured LDAP sync attributes.
168+ *
169+ * @return array
170+ */
171+ protected function getLdapSyncAttributes ()
172+ {
173+ return Config::get ('ldap_auth.sync_attributes ' , [
174+ 'email ' => 'userprincipalname ' ,
175+ 'name ' => 'cn ' ,
176+ ]);
177+ }
178+
179+ /**
180+ * Returns the configured LDAP discovery username attribute.
181+ *
182+ * @return string
183+ */
184+ protected function getLdapDiscoveryUsername ()
185+ {
186+ return Config::get ('ldap_auth.usernames.ldap.discover ' , 'userprincipalname ' );
153187 }
154188}
0 commit comments