@@ -42,6 +42,7 @@ of this software and associated documentation files (the "Software"), to deal
42
42
import hudson .security .UserMayOrMayNotExistException ;
43
43
import hudson .tasks .Mailer ;
44
44
import hudson .Util ;
45
+ import hudson .util .Secret ;
45
46
import java .io .IOException ;
46
47
import java .lang .reflect .InvocationTargetException ;
47
48
import java .lang .reflect .Method ;
@@ -105,7 +106,7 @@ public class GithubSecurityRealm extends SecurityRealm implements UserDetailsSer
105
106
private String githubWebUri ;
106
107
private String githubApiUri ;
107
108
private String clientID ;
108
- private String clientSecret ;
109
+ private Secret clientSecret ;
109
110
private String oauthScopes ;
110
111
private String [] myScopes ;
111
112
@@ -129,7 +130,7 @@ public GithubSecurityRealm(String githubWebUri,
129
130
this .githubWebUri = Util .fixEmptyAndTrim (githubWebUri );
130
131
this .githubApiUri = Util .fixEmptyAndTrim (githubApiUri );
131
132
this .clientID = Util .fixEmptyAndTrim (clientID );
132
- this . clientSecret = Util .fixEmptyAndTrim (clientSecret );
133
+ setClientSecret ( Util .fixEmptyAndTrim (clientSecret ) );
133
134
this .oauthScopes = Util .fixEmptyAndTrim (oauthScopes );
134
135
}
135
136
@@ -154,7 +155,7 @@ public GithubSecurityRealm(String githubWebUri,
154
155
this .githubWebUri = Util .fixEmptyAndTrim (githubWebUri );
155
156
this .githubApiUri = Util .fixEmptyAndTrim (githubApiUri );
156
157
this .clientID = Util .fixEmptyAndTrim (clientID );
157
- this . clientSecret = Util .fixEmptyAndTrim (clientSecret );
158
+ setClientSecret ( Util .fixEmptyAndTrim (clientSecret ) );
158
159
this .oauthScopes = DEFAULT_OAUTH_SCOPES ;
159
160
}
160
161
@@ -173,7 +174,7 @@ public GithubSecurityRealm(String githubWebUri, String clientID, String clientSe
173
174
this .githubWebUri = Util .fixEmptyAndTrim (githubWebUri );
174
175
this .githubApiUri = determineApiUri (this .githubWebUri );
175
176
this .clientID = Util .fixEmptyAndTrim (clientID );
176
- this . clientSecret = Util .fixEmptyAndTrim (clientSecret );
177
+ setClientSecret ( Util .fixEmptyAndTrim (clientSecret ) );
177
178
this .oauthScopes = DEFAULT_OAUTH_SCOPES ;
178
179
}
179
180
@@ -225,7 +226,7 @@ private void setClientID(String clientID) {
225
226
* @param clientSecret the clientSecret to set
226
227
*/
227
228
private void setClientSecret (String clientSecret ) {
228
- this .clientSecret = clientSecret ;
229
+ this .clientSecret = Secret . fromString ( clientSecret ) ;
229
230
}
230
231
231
232
/**
@@ -286,7 +287,7 @@ public void marshal(Object source, HierarchicalStreamWriter writer,
286
287
writer .endNode ();
287
288
288
289
writer .startNode ("clientSecret" );
289
- writer .setValue (realm .getClientSecret ());
290
+ writer .setValue (realm .getClientSecret (). getEncryptedValue () );
290
291
writer .endNode ();
291
292
292
293
writer .startNode ("oauthScopes" );
@@ -371,7 +372,7 @@ public String getClientID() {
371
372
/**
372
373
* @return the clientSecret
373
374
*/
374
- public String getClientSecret () {
375
+ public Secret getClientSecret () {
375
376
return clientSecret ;
376
377
}
377
378
@@ -382,12 +383,6 @@ public String getOauthScopes() {
382
383
return oauthScopes ;
383
384
}
384
385
385
- // @Override
386
- // public Filter createFilter(FilterConfig filterConfig) {
387
- //
388
- // return new GithubOAuthAuthenticationFilter();
389
- // }
390
-
391
386
public HttpResponse doCommenceLogin (StaplerRequest request , @ Header ("Referer" ) final String referer )
392
387
throws IOException {
393
388
request .getSession ().setAttribute (REFERER_ATTRIBUTE ,referer );
@@ -735,7 +730,7 @@ public void onLoaded() {
735
730
if (instance .getSecurityRealm () instanceof GithubSecurityRealm ) {
736
731
GithubSecurityRealm myRealm = (GithubSecurityRealm ) instance .getSecurityRealm ();
737
732
if (myRealm .getOauthScopes () == null ) {
738
- GithubSecurityRealm newRealm = new GithubSecurityRealm (myRealm .getGithubWebUri (), myRealm .getGithubApiUri (), myRealm .getClientID (), myRealm .getClientSecret ());
733
+ GithubSecurityRealm newRealm = new GithubSecurityRealm (myRealm .getGithubWebUri (), myRealm .getGithubApiUri (), myRealm .getClientID (), myRealm .getClientSecret (). getPlainText () );
739
734
instance .setSecurityRealm (newRealm );
740
735
instance .save ();
741
736
}
0 commit comments