Skip to content

Remove the SecurityListener.fireAuthenticated reflection hack #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ of this software and associated documentation files (the "Software"), to deal
import hudson.tasks.Mailer;
import hudson.util.Secret;
import jenkins.model.Jenkins;
import jenkins.security.SecurityListener;
import org.acegisecurity.Authentication;
import org.acegisecurity.AuthenticationException;
import org.acegisecurity.AuthenticationManager;
Expand Down Expand Up @@ -79,14 +80,11 @@ of this software and associated documentation files (the "Software"), to deal
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
Expand Down Expand Up @@ -392,7 +390,7 @@ public HttpResponse doFinishLogin(StaplerRequest request)
}
}

fireAuthenticated(new GithubOAuthUserDetails(self.getLogin(), auth.getAuthorities()));
SecurityListener.fireAuthenticated(new GithubOAuthUserDetails(self.getLogin(), auth.getAuthorities()));
} else {
Log.info("Github did not return an access token.");
}
Expand Down Expand Up @@ -429,25 +427,6 @@ private String getAccessToken(@Nonnull String code) throws IOException {
return null;
}

/**
* Calls {@code SecurityListener.fireAuthenticated()} but through reflection to avoid
* hard dependency on non-LTS core version.
* TODO delete in 1.569+
*/
private void fireAuthenticated(UserDetails details) {
try {
Class<?> c = Class.forName("jenkins.security.SecurityListener");
Method m = c.getMethod("fireAuthenticated", UserDetails.class);
m.invoke(null,details);
} catch (ClassNotFoundException | NoSuchMethodException e) {
// running with old core
} catch (IllegalAccessException e) {
throw (Error)new IllegalAccessError(e.getMessage()).initCause(e);
} catch (InvocationTargetException e) {
LOGGER.log(Level.WARNING, "Failed to invoke fireAuthenticated", e);
}
}

/**
* Returns the proxy to be used when connecting to the given URI.
*/
Expand Down