@@ -67,6 +67,13 @@ public LdapServer(String server) {
6767 this .url = server ;
6868 }
6969
70+ public LdapServer (String server , String username , String password ) {
71+ this (prepareEnv ());
72+ this .url = server ;
73+ this .username = username ;
74+ this .password = password ;
75+ }
76+
7077 public LdapServer (Hashtable <String , String > env ) {
7178 this .env = env ;
7279 }
@@ -134,7 +141,7 @@ public synchronized boolean isWorking() {
134141 * @return the new connection or null
135142 */
136143 private synchronized LdapContext connect () {
137- LOGGER .log (Level .INFO , "Server {0} connecting " , this .url );
144+ LOGGER .log (Level .INFO , "Connecting to LDAP server {0} " , this .toString () );
138145
139146 if (errorTimestamp > 0 && errorTimestamp + interval > System .currentTimeMillis ()) {
140147 LOGGER .log (Level .INFO , "LDAP server {0} is down" , this .url );
@@ -159,7 +166,7 @@ private synchronized LdapContext connect() {
159166 ctx = new InitialLdapContext (env , null );
160167 ctx .reconnect (null );
161168 ctx .setRequestControls (null );
162- LOGGER .log (Level .INFO , "Connected to LDAP server {0}" , env . get ( Context . PROVIDER_URL ));
169+ LOGGER .log (Level .INFO , "Connected to LDAP server {0}" , this . toString ( ));
163170 errorTimestamp = 0 ;
164171 } catch (NamingException ex ) {
165172 LOGGER .log (Level .INFO , "LDAP server {0} is not responding" , env .get (Context .PROVIDER_URL ));
@@ -252,6 +259,20 @@ private static Hashtable<String, String> prepareEnv() {
252259
253260 @ Override
254261 public String toString () {
255- return getUrl ();
262+ StringBuilder sb = new StringBuilder ();
263+
264+ sb .append (getUrl ());
265+
266+ if (getConnectTimeout () > 0 ) {
267+ sb .append (" timeout: " );
268+ sb .append (getConnectTimeout ());
269+ }
270+
271+ if (getUsername () != null && !getUsername ().isEmpty ()) {
272+ sb .append (" username: " );
273+ sb .append (getUsername ());
274+ }
275+
276+ return sb .toString ();
256277 }
257278}
0 commit comments