Skip to content

Commit

Permalink
Merge pull request #15
Browse files Browse the repository at this point in the history
Conflicts:
	src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java
  • Loading branch information
kohsuke committed Jul 3, 2014
2 parents 3722fa2 + b40fb3d commit e9bbe78
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ of this software and associated documentation files (the "Software"), to deal
import org.acegisecurity.userdetails.UserDetails;
import org.acegisecurity.userdetails.UserDetailsService;
import org.acegisecurity.userdetails.UsernameNotFoundException;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.jfree.util.Log;
Expand Down Expand Up @@ -355,7 +358,11 @@ public HttpResponse doFinishLogin(StaplerRequest request)
+ "/login/oauth/access_token?" + "client_id=" + clientID + "&"
+ "client_secret=" + clientSecret + "&" + "code=" + code);

DefaultHttpClient httpclient = new DefaultHttpClient();
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpHost proxy = getProxy(githubWebUri);
if (proxy != null) {
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}

org.apache.http.HttpResponse response = httpclient.execute(httpost);

Expand Down Expand Up @@ -414,7 +421,26 @@ private void fireAuthenticated(UserDetails details) {
}
}

private String extractToken(String content) {
/**
* Returns the proxy to be used when connecting to the given URI.
*/
private HttpHost getProxy(String uri) {
String prefix = uri.startsWith("https") ? "https" : "http";
String proxyHost = System.getProperty(prefix + ".proxyHost");
if (StringUtils.isBlank(proxyHost)) {
return null;
}

String proxyPortStr = System.getProperty(prefix + ".proxyPort");
if (StringUtils.isBlank(proxyPortStr)) {
return new HttpHost(proxyHost);
} else {
int proxyPort = Integer.parseInt(proxyPortStr);
return new HttpHost(proxyHost, proxyPort);
}
}

private String extractToken(String content) {

String parts[] = content.split("&");

Expand Down

0 comments on commit e9bbe78

Please sign in to comment.