3
3
namespace Adldap \Laravel ;
4
4
5
5
use Adldap \Adldap ;
6
+ use Adldap \AdldapException ;
6
7
use Adldap \AdldapInterface ;
7
- use Adldap \Auth \BindException ;
8
8
use Adldap \Connections \Provider ;
9
9
use Adldap \Connections \ConnectionInterface ;
10
- use Adldap \Connections \ConnectionException ;
11
10
use Illuminate \Container \Container ;
12
11
use Illuminate \Support \Facades \Config ;
13
12
use Illuminate \Support \ServiceProvider ;
14
13
15
14
class AdldapServiceProvider extends ServiceProvider
16
15
{
17
16
/**
18
- * We'll defer loading this service provider so our LDAP connection
19
- * isn't instantiated unless requested to speed up our application.
17
+ * We'll defer loading this service provider so our
18
+ * LDAP connection isn't instantiated unless
19
+ * requested to speed up our application.
20
20
*
21
21
* @var bool
22
22
*/
@@ -29,7 +29,7 @@ class AdldapServiceProvider extends ServiceProvider
29
29
*/
30
30
public function boot ()
31
31
{
32
- if (Config:: get ( ' ldap.logging ' )) {
32
+ if ($ this -> isLogging ( )) {
33
33
Adldap::setLogger (logger ());
34
34
}
35
35
@@ -85,12 +85,12 @@ public function provides()
85
85
* If a provider is configured to auto connect,
86
86
* this method will throw a BindException.
87
87
*
88
- * @param Adldap $adldap
88
+ * @param Adldap $ldap
89
89
* @param array $connections
90
90
*
91
91
* @return Adldap
92
92
*/
93
- protected function addProviders (Adldap $ adldap , array $ connections = [])
93
+ protected function addProviders (AdldapInterface $ ldap , array $ connections = [])
94
94
{
95
95
// Go through each connection and construct a Provider.
96
96
foreach ($ connections as $ name => $ config ) {
@@ -100,21 +100,24 @@ protected function addProviders(Adldap $adldap, array $connections = [])
100
100
new $ config ['connection ' ]
101
101
);
102
102
103
+ // If auto connect is enabled, an attempt will be made to bind to
104
+ // the LDAP server with the configured credentials. If this
105
+ // fails then the exception will be logged (if enabled).
103
106
if ($ this ->shouldAutoConnect ($ config )) {
104
107
try {
105
108
$ provider ->connect ();
106
- } catch (BindException $ e ) {
107
- logger ()-> error ( $ e );
108
- } catch ( ConnectionException $ e ) {
109
- logger ()-> error ( $ e );
109
+ } catch (AdldapException $ e ) {
110
+ if ( $ this -> isLogging ()) {
111
+ logger ()-> error ( $ e );
112
+ }
110
113
}
111
114
}
112
115
113
- // Add the provider to the Adldap container.
114
- $ adldap ->addProvider ($ provider , $ name );
116
+ // Add the provider to the LDAP container.
117
+ $ ldap ->addProvider ($ provider , $ name );
115
118
}
116
119
117
- return $ adldap ;
120
+ return $ ldap ;
118
121
}
119
122
120
123
/**
@@ -128,9 +131,9 @@ protected function newAdldap()
128
131
}
129
132
130
133
/**
131
- * Returns a new Provider instance.
134
+ * Returns a new LDAP Provider instance.
132
135
*
133
- * @param array $configuration
136
+ * @param array $configuration
134
137
* @param ConnectionInterface|null $connection
135
138
*
136
139
* @return Provider
@@ -141,7 +144,7 @@ protected function newProvider($configuration = [], ConnectionInterface $connect
141
144
}
142
145
143
146
/**
144
- * Determine if the given settings is configured for auto-connecting .
147
+ * Determines if the given settings has auto connect enabled .
145
148
*
146
149
* @param array $settings
147
150
*
@@ -154,7 +157,17 @@ protected function shouldAutoConnect(array $settings)
154
157
}
155
158
156
159
/**
157
- * Determines if the current application is Lumen.
160
+ * Determines whether logging is enabled.
161
+ *
162
+ * @return bool
163
+ */
164
+ protected function isLogging ()
165
+ {
166
+ return Config::get ('ldap.logging ' , false );
167
+ }
168
+
169
+ /**
170
+ * Determines if the current application is a Lumen instance.
158
171
*
159
172
* @return bool
160
173
*/
0 commit comments