Skip to content

Commit adc03ce

Browse files
authored
Merge pull request #162 from fbelzunc/JENKINS-70492
[JENKINS-70492] Only trigger SecurityListener on real authentication username/password
2 parents 842daef + 3c104ea commit adc03ce

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

src/main/java/hudson/plugins/active_directory/ActiveDirectoryAuthenticationProvider.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import hudson.security.GroupDetails;
4444
import hudson.security.SecurityRealm;
4545
import hudson.security.UserMayOrMayNotExistException;
46-
import jenkins.security.SecurityListener;
4746
import org.acegisecurity.AuthenticationException;
4847
import org.acegisecurity.BadCredentialsException;
4948
import org.acegisecurity.GrantedAuthority;
@@ -253,15 +252,13 @@ protected UserDetails retrieveUser(final String username,final UsernamePassword
253252

254253
LOGGER.log(Level.FINE, "Login successful: {0} dn={1}", new Object[] {username, dn});
255254

256-
UserDetails userDetails = new ActiveDirectoryUserDetail(
255+
return new ActiveDirectoryUserDetail(
257256
username, "redacted",
258257
!isAccountDisabled(usr),
259258
true, true, true,
260259
groups.toArray(new GrantedAuthority[0]),
261260
getFullName(usr), getEmailAddress(usr), getTelephoneNumber(usr)
262261
).updateUserInfo();
263-
SecurityListener.fireAuthenticated(userDetails);
264-
return userDetails;
265262
} finally {
266263
col.disposeAll();
267264
COM4J.removeListener(col);

src/main/java/hudson/plugins/active_directory/ActiveDirectorySecurityRealm.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import hudson.util.ListBoxModel;
4040
import hudson.util.Secret;
4141
import jenkins.model.Jenkins;
42+
import jenkins.security.SecurityListener;
4243
import org.acegisecurity.AuthenticationException;
4344
import org.acegisecurity.BadCredentialsException;
4445
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
@@ -891,7 +892,9 @@ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundEx
891892

892893
@Override
893894
protected UserDetails authenticate(String username, String password) throws AuthenticationException {
894-
return getAuthenticationProvider().retrieveUser(username,new UsernamePasswordAuthenticationToken(username,password));
895+
UserDetails userDetails = getAuthenticationProvider().retrieveUser(username,new UsernamePasswordAuthenticationToken(username,password));
896+
SecurityListener.fireAuthenticated(userDetails);
897+
return userDetails;
895898
}
896899

897900
private static final Logger LOGGER = Logger.getLogger(ActiveDirectorySecurityRealm.class.getName());

src/main/java/hudson/plugins/active_directory/ActiveDirectoryUnixAuthenticationProvider.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838
import javax.naming.NameNotFoundException;
3939

40-
import jenkins.security.SecurityListener;
4140
import org.acegisecurity.AuthenticationException;
4241
import org.acegisecurity.AuthenticationServiceException;
4342
import org.acegisecurity.BadCredentialsException;
@@ -221,9 +220,7 @@ protected UserDetails retrieveUser(final String username, final UsernamePassword
221220

222221
for (ActiveDirectoryDomain domain : domains) {
223222
try {
224-
UserDetails userDetails = retrieveUser(username, authentication, domain);
225-
SecurityListener.fireAuthenticated(userDetails);
226-
return userDetails;
223+
return retrieveUser(username, authentication, domain);
227224
} catch (NamingException ne) {
228225
if (userMatchesInternalDatabaseUser(username)) {
229226
LOGGER.log(Level.WARNING, String.format("Looking into Jenkins Internal Users Database for user %s", username));
@@ -235,9 +232,7 @@ protected UserDetails retrieveUser(final String username, final UsernamePassword
235232
}
236233
if (hudsonPrivateSecurityRealm.isPasswordCorrect(password)) {
237234
LOGGER.log(Level.INFO, String.format("Falling back into the internal user %s", username));
238-
UserDetails userDetails = new ActiveDirectoryUserDetail(username, "redacted", true, true, true, true, hudsonPrivateSecurityRealm.getAuthorities(), internalUser.getDisplayName(), "", "");
239-
SecurityListener.fireAuthenticated(userDetails);
240-
return userDetails;
235+
return new ActiveDirectoryUserDetail(username, "redacted", true, true, true, true, hudsonPrivateSecurityRealm.getAuthorities(), internalUser.getDisplayName(), "", "");
241236
} else {
242237
LOGGER.log(Level.WARNING, String.format("Credential exception trying to authenticate against %s domain", domain.getName()), ne);
243238
errors.add(new MultiCauseUserMayOrMayNotExistException("We can't tell if the user exists or not: " + username, notFound));

0 commit comments

Comments
 (0)