2
2
3
3
namespace Adldap \Laravel \Commands ;
4
4
5
+ use UnexpectedValueException ;
5
6
use Adldap \Models \User ;
6
7
use Adldap \Laravel \Facades \Resolver ;
7
8
use Adldap \Laravel \Events \Importing ;
@@ -65,9 +66,11 @@ public function handle()
65
66
}
66
67
67
68
/**
68
- * Retrieves an eloquent user by their credentials .
69
+ * Retrieves an eloquent user by their GUID or their username .
69
70
*
70
71
* @return Model|null
72
+ *
73
+ * @throws UnexpectedValueException
71
74
*/
72
75
protected function findUser ()
73
76
{
@@ -85,11 +88,11 @@ protected function findUser()
85
88
return $ query ->where (
86
89
Resolver::getDatabaseIdColumn (),
87
90
'= ' ,
88
- $ this ->user -> getConvertedGuid ()
91
+ $ this ->getObjectGuid ()
89
92
)->orWhere (
90
93
Resolver::getDatabaseUsernameColumn (),
91
94
'= ' ,
92
- $ this ->user -> getFirstAttribute (Resolver:: getLdapDiscoveryAttribute () )
95
+ $ this ->getUsername ( )
93
96
)->first ();
94
97
}
95
98
@@ -127,6 +130,48 @@ protected function sync(Model $model)
127
130
}
128
131
}
129
132
133
+ /**
134
+ * Returns the LDAP users configured username.
135
+ *
136
+ * @return string
137
+ */
138
+ protected function getUsername ()
139
+ {
140
+ $ attribute = Resolver::getLdapDiscoveryAttribute ();
141
+
142
+ $ username = $ this ->user ->getFirstAttribute ($ attribute );
143
+
144
+ if (trim ($ username ) == false ) {
145
+ throw new UnexpectedValueException (
146
+ "Unable to locate a user without a {$ attribute }"
147
+ );
148
+ }
149
+
150
+ return $ username ;
151
+ }
152
+
153
+ /**
154
+ * Returns the LDAP users object GUID.
155
+ *
156
+ * @return string
157
+ *
158
+ * @throws UnexpectedValueException
159
+ */
160
+ protected function getObjectGuid ()
161
+ {
162
+ $ guid = $ this ->user ->getConvertedGuid ();
163
+
164
+ if (trim ($ guid ) == false ) {
165
+ $ attribute = $ this ->user ->getSchema ()->objectGuid ();
166
+
167
+ throw new UnexpectedValueException (
168
+ "Unable to locate a user without a {$ attribute }"
169
+ );
170
+ }
171
+
172
+ return $ guid ;
173
+ }
174
+
130
175
/**
131
176
* Determines if the given handler value is a class that contains the 'handle' method.
132
177
*
0 commit comments