@@ -33,30 +33,40 @@ of this software and associated documentation files (the "Software"), to deal
33
33
import com .thoughtworks .xstream .io .HierarchicalStreamReader ;
34
34
import com .thoughtworks .xstream .io .HierarchicalStreamWriter ;
35
35
import hudson .Extension ;
36
- import hudson .ProxyConfiguration ;
37
- import hudson .Util ;
38
36
import hudson .model .Descriptor ;
37
+ import hudson .model .listeners .ItemListener ;
39
38
import hudson .model .User ;
39
+ import hudson .ProxyConfiguration ;
40
40
import hudson .security .GroupDetails ;
41
41
import hudson .security .SecurityRealm ;
42
42
import hudson .security .UserMayOrMayNotExistException ;
43
43
import hudson .tasks .Mailer ;
44
+ import hudson .Util ;
45
+ import java .io .IOException ;
46
+ import java .lang .reflect .InvocationTargetException ;
47
+ import java .lang .reflect .Method ;
48
+ import java .net .InetSocketAddress ;
49
+ import java .net .Proxy ;
50
+ import java .util .HashSet ;
51
+ import java .util .logging .Level ;
52
+ import java .util .logging .Logger ;
53
+ import java .util .Set ;
44
54
import jenkins .model .Jenkins ;
45
55
import org .acegisecurity .Authentication ;
46
56
import org .acegisecurity .AuthenticationException ;
47
57
import org .acegisecurity .AuthenticationManager ;
48
58
import org .acegisecurity .BadCredentialsException ;
49
59
import org .acegisecurity .context .SecurityContextHolder ;
60
+ import org .acegisecurity .providers .UsernamePasswordAuthenticationToken ;
50
61
import org .acegisecurity .userdetails .UserDetails ;
51
62
import org .acegisecurity .userdetails .UserDetailsService ;
52
63
import org .acegisecurity .userdetails .UsernameNotFoundException ;
53
- import org .acegisecurity .providers .UsernamePasswordAuthenticationToken ;
54
64
import org .apache .commons .httpclient .URIException ;
55
- import org .apache .http .HttpEntity ;
56
- import org .apache .http .HttpHost ;
57
65
import org .apache .http .client .methods .HttpPost ;
58
66
import org .apache .http .client .methods .HttpUriRequest ;
59
67
import org .apache .http .conn .params .ConnRoutePNames ;
68
+ import org .apache .http .HttpEntity ;
69
+ import org .apache .http .HttpHost ;
60
70
import org .apache .http .impl .client .DefaultHttpClient ;
61
71
import org .apache .http .util .EntityUtils ;
62
72
import org .jfree .util .Log ;
@@ -72,17 +82,6 @@ of this software and associated documentation files (the "Software"), to deal
72
82
import org .springframework .dao .DataAccessException ;
73
83
import org .springframework .dao .DataRetrievalFailureException ;
74
84
75
- import java .io .IOException ;
76
- import java .lang .reflect .InvocationTargetException ;
77
- import java .lang .reflect .Method ;
78
- import java .net .InetSocketAddress ;
79
- import java .net .Proxy ;
80
- import java .util .HashSet ;
81
- import java .util .Set ;
82
- import java .util .logging .Logger ;
83
-
84
- import static java .util .logging .Level .*;
85
-
86
85
/**
87
86
*
88
87
* Implementation of the AbstractPasswordBasedSecurityRealm that uses github
@@ -479,7 +478,7 @@ private void fireAuthenticated(UserDetails details) {
479
478
} catch (IllegalAccessException e ) {
480
479
throw (Error )new IllegalAccessError (e .getMessage ()).initCause (e );
481
480
} catch (InvocationTargetException e ) {
482
- LOGGER .log (WARNING , "Failed to invoke fireAuthenticated" , e );
481
+ LOGGER .log (Level . WARNING , "Failed to invoke fireAuthenticated" , e );
483
482
}
484
483
}
485
484
@@ -663,6 +662,31 @@ public GroupDetails loadGroupByGroupname(String groupName)
663
662
}
664
663
}
665
664
665
+ /*
666
+ Migrate settings from 0.20 to 0.21+
667
+ */
668
+ @ Extension
669
+ public static final class Migrator extends ItemListener {
670
+ @ SuppressWarnings ("deprecation" )
671
+ @ Override
672
+ public void onLoaded () {
673
+ try {
674
+ Jenkins instance = Jenkins .getInstance ();
675
+ if (instance .getSecurityRealm () instanceof GithubSecurityRealm ) {
676
+ GithubSecurityRealm myRealm = (GithubSecurityRealm ) instance .getSecurityRealm ();
677
+ if (myRealm .getOauthScopes () == null ) {
678
+ GithubSecurityRealm newRealm = new GithubSecurityRealm (myRealm .getGithubWebUri (), myRealm .getGithubApiUri (), myRealm .getClientID (), myRealm .getClientSecret ());
679
+ instance .setSecurityRealm (newRealm );
680
+ instance .save ();
681
+ }
682
+ }
683
+ }
684
+ catch (IOException e ) {
685
+ LOGGER .log (Level .WARNING , "could not migrate GithubSecurityRealm" , e );
686
+ }
687
+ }
688
+ }
689
+
666
690
/**
667
691
* Logger for debugging purposes.
668
692
*/
0 commit comments