Skip to content
Merged
Show file tree
Hide file tree
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
23 changes: 9 additions & 14 deletions src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ of this software and associated documentation files (the "Software"), to deal
import hudson.security.UserMayOrMayNotExistException;
import hudson.tasks.Mailer;
import hudson.Util;
import hudson.util.Secret;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -105,7 +106,7 @@ public class GithubSecurityRealm extends SecurityRealm implements UserDetailsSer
private String githubWebUri;
private String githubApiUri;
private String clientID;
private String clientSecret;
private Secret clientSecret;
private String oauthScopes;
private String[] myScopes;

Expand All @@ -129,7 +130,7 @@ public GithubSecurityRealm(String githubWebUri,
this.githubWebUri = Util.fixEmptyAndTrim(githubWebUri);
this.githubApiUri = Util.fixEmptyAndTrim(githubApiUri);
this.clientID = Util.fixEmptyAndTrim(clientID);
this.clientSecret = Util.fixEmptyAndTrim(clientSecret);
setClientSecret(Util.fixEmptyAndTrim(clientSecret));
this.oauthScopes = Util.fixEmptyAndTrim(oauthScopes);
}

Expand All @@ -154,7 +155,7 @@ public GithubSecurityRealm(String githubWebUri,
this.githubWebUri = Util.fixEmptyAndTrim(githubWebUri);
this.githubApiUri = Util.fixEmptyAndTrim(githubApiUri);
this.clientID = Util.fixEmptyAndTrim(clientID);
this.clientSecret = Util.fixEmptyAndTrim(clientSecret);
setClientSecret(Util.fixEmptyAndTrim(clientSecret));
this.oauthScopes = DEFAULT_OAUTH_SCOPES;
}

Expand All @@ -173,7 +174,7 @@ public GithubSecurityRealm(String githubWebUri, String clientID, String clientSe
this.githubWebUri = Util.fixEmptyAndTrim(githubWebUri);
this.githubApiUri = determineApiUri(this.githubWebUri);
this.clientID = Util.fixEmptyAndTrim(clientID);
this.clientSecret = Util.fixEmptyAndTrim(clientSecret);
setClientSecret(Util.fixEmptyAndTrim(clientSecret));
this.oauthScopes = DEFAULT_OAUTH_SCOPES;
}

Expand Down Expand Up @@ -225,7 +226,7 @@ private void setClientID(String clientID) {
* @param clientSecret the clientSecret to set
*/
private void setClientSecret(String clientSecret) {
this.clientSecret = clientSecret;
this.clientSecret = Secret.fromString(clientSecret);
}

/**
Expand Down Expand Up @@ -286,7 +287,7 @@ public void marshal(Object source, HierarchicalStreamWriter writer,
writer.endNode();

writer.startNode("clientSecret");
writer.setValue(realm.getClientSecret());
writer.setValue(realm.getClientSecret().getEncryptedValue());
writer.endNode();

writer.startNode("oauthScopes");
Expand Down Expand Up @@ -371,7 +372,7 @@ public String getClientID() {
/**
* @return the clientSecret
*/
public String getClientSecret() {
public Secret getClientSecret() {
return clientSecret;
}

Expand All @@ -382,12 +383,6 @@ public String getOauthScopes() {
return oauthScopes;
}

// @Override
// public Filter createFilter(FilterConfig filterConfig) {
//
// return new GithubOAuthAuthenticationFilter();
// }

public HttpResponse doCommenceLogin(StaplerRequest request, @Header("Referer") final String referer)
throws IOException {
request.getSession().setAttribute(REFERER_ATTRIBUTE,referer);
Expand Down Expand Up @@ -735,7 +730,7 @@ public void onLoaded() {
if(instance.getSecurityRealm() instanceof GithubSecurityRealm) {
GithubSecurityRealm myRealm = (GithubSecurityRealm) instance.getSecurityRealm();
if(myRealm.getOauthScopes() == null) {
GithubSecurityRealm newRealm = new GithubSecurityRealm(myRealm.getGithubWebUri(), myRealm.getGithubApiUri(), myRealm.getClientID(), myRealm.getClientSecret());
GithubSecurityRealm newRealm = new GithubSecurityRealm(myRealm.getGithubWebUri(), myRealm.getGithubApiUri(), myRealm.getClientID(), myRealm.getClientSecret().getPlainText());
instance.setSecurityRealm(newRealm);
instance.save();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ of this software and associated documentation files (the "Software"), to deal

package org.jenkinsci.plugins;

import hudson.util.Secret;
import java.io.IOException;
import junit.framework.TestCase;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jenkinsci.plugins.GithubSecurityRealm.DescriptorImpl;
import org.junit.runner.RunWith;
import org.junit.Test;

public class GithubSecurityRealmTest extends TestCase {
public class GithubSecurityRealmTest extends HudsonTestCase {

@Test
public void testEquals_true() {
Expand Down