Skip to content

Commit a5267e6

Browse files
committed
Adding BindAuthenticator2 from jenkins@95b0281f5ff1641b43ee2239ee469001b3fba016; ought to have been moved in jenkinsci/jenkins@9b4cd99 or jenkinsci/jenkins@32cba8f
1 parent 8cbfd53 commit a5267e6

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
package org.acegisecurity.providers.ldap.authenticator;
25+
26+
import org.acegisecurity.ldap.InitialDirContextFactory;
27+
import org.acegisecurity.userdetails.ldap.LdapUserDetails;
28+
29+
import java.util.logging.Logger;
30+
import java.util.logging.Level;
31+
32+
/**
33+
* {@link BindAuthenticator} with improved diagnostics.
34+
*
35+
* @author Kohsuke Kawaguchi
36+
*/
37+
public class BindAuthenticator2 extends BindAuthenticator {
38+
/**
39+
* If we ever had a successful authentication,
40+
*/
41+
private boolean hadSuccessfulAuthentication;
42+
43+
public BindAuthenticator2(InitialDirContextFactory initialDirContextFactory) {
44+
super(initialDirContextFactory);
45+
}
46+
47+
@Override
48+
public LdapUserDetails authenticate(String username, String password) {
49+
LdapUserDetails user = super.authenticate(username, password);
50+
hadSuccessfulAuthentication = true;
51+
return user;
52+
}
53+
54+
@Override
55+
void handleBindException(String userDn, String username, Throwable cause) {
56+
LOGGER.log(hadSuccessfulAuthentication? Level.FINE : Level.WARNING,
57+
"Failed to bind to LDAP: userDn"+userDn+" username="+username,cause);
58+
super.handleBindException(userDn, username, cause);
59+
}
60+
61+
private static final Logger LOGGER = Logger.getLogger(BindAuthenticator2.class.getName());
62+
}

0 commit comments

Comments
 (0)