41
41
import hudson .model .User ;
42
42
import hudson .security .GroupDetails ;
43
43
import hudson .security .SecurityRealm ;
44
- import hudson .security .UserMayOrMayNotExistException ;
44
+ import hudson .security .UserMayOrMayNotExistException2 ;
45
45
import hudson .tasks .Mailer ;
46
46
import hudson .util .Secret ;
47
+ import jakarta .servlet .http .HttpSession ;
47
48
import java .io .IOException ;
48
49
import java .net .InetSocketAddress ;
49
50
import java .net .MalformedURLException ;
55
56
import java .util .ArrayList ;
56
57
import java .util .List ;
57
58
import java .util .logging .Logger ;
58
- import javax .servlet .http .HttpSession ;
59
59
import jenkins .model .Jenkins ;
60
60
import jenkins .security .SecurityListener ;
61
- import org .acegisecurity .Authentication ;
62
- import org .acegisecurity .AuthenticationException ;
63
- import org .acegisecurity .AuthenticationManager ;
64
- import org .acegisecurity .BadCredentialsException ;
65
- import org .acegisecurity .context .SecurityContextHolder ;
66
- import org .acegisecurity .providers .UsernamePasswordAuthenticationToken ;
67
- import org .acegisecurity .userdetails .UserDetails ;
68
- import org .acegisecurity .userdetails .UserDetailsService ;
69
- import org .acegisecurity .userdetails .UsernameNotFoundException ;
70
61
import org .apache .commons .lang .StringUtils ;
71
62
import org .apache .commons .lang .builder .HashCodeBuilder ;
72
63
import org .apache .http .HttpEntity ;
91
82
import org .kohsuke .stapler .HttpResponse ;
92
83
import org .kohsuke .stapler .HttpResponses ;
93
84
import org .kohsuke .stapler .QueryParameter ;
94
- import org .kohsuke .stapler .StaplerRequest ;
95
- import org .springframework .dao .DataAccessException ;
96
- import org .springframework .dao .DataRetrievalFailureException ;
85
+ import org .kohsuke .stapler .StaplerRequest2 ;
86
+ import org .springframework .security .authentication .AuthenticationManager ;
87
+ import org .springframework .security .authentication .AuthenticationServiceException ;
88
+ import org .springframework .security .authentication .BadCredentialsException ;
89
+ import org .springframework .security .authentication .UsernamePasswordAuthenticationToken ;
90
+ import org .springframework .security .core .Authentication ;
91
+ import org .springframework .security .core .AuthenticationException ;
92
+ import org .springframework .security .core .context .SecurityContextHolder ;
93
+ import org .springframework .security .core .userdetails .UserDetails ;
94
+ import org .springframework .security .core .userdetails .UserDetailsService ;
95
+ import org .springframework .security .core .userdetails .UsernameNotFoundException ;
97
96
98
97
/**
99
98
*
103
102
* This is based on the GitLabSecurityRealm from the gitlab-auth-plugin written
104
103
* by Alex Ackerman.
105
104
*/
106
- public class GitLabSecurityRealm extends SecurityRealm implements UserDetailsService {
105
+ public class GitLabSecurityRealm extends SecurityRealm {
107
106
private String gitlabWebUri ;
108
107
private String gitlabApiUri ;
109
108
private String clientID ;
@@ -266,7 +265,7 @@ public Secret getClientSecret() {
266
265
267
266
// "from" is coming from SecurityRealm/loginLink.jelly
268
267
public HttpResponse doCommenceLogin (
269
- StaplerRequest request , @ QueryParameter String from , @ Header ("Referer" ) final String referer )
268
+ StaplerRequest2 request , @ QueryParameter String from , @ Header ("Referer" ) final String referer )
270
269
throws IOException {
271
270
// 2. Requesting authorization :
272
271
// http://doc.gitlab.com/ce/api/oauth2.html
@@ -298,7 +297,7 @@ public HttpResponse doCommenceLogin(
298
297
gitlabWebUri + "/oauth/authorize?" + URLEncodedUtils .format (parameters , StandardCharsets .UTF_8 ));
299
298
}
300
299
301
- private String buildRedirectUrl (StaplerRequest request ) throws MalformedURLException {
300
+ private String buildRedirectUrl (StaplerRequest2 request ) throws MalformedURLException {
302
301
URL currentUrl = new URL (Jenkins .get ().getRootUrl ());
303
302
304
303
URL redirect_uri = new URL (
@@ -313,7 +312,7 @@ private String buildRedirectUrl(StaplerRequest request) throws MalformedURLExcep
313
312
* This is where the user comes back to at the end of the OpenID redirect
314
313
* ping-pong.
315
314
*/
316
- public HttpResponse doFinishLogin (StaplerRequest request ) throws IOException {
315
+ public HttpResponse doFinishLogin (StaplerRequest2 request ) throws IOException {
317
316
String code = request .getParameter ("code" );
318
317
String state = request .getParameter (STATE_ATTRIBUTE );
319
318
String expectedState = (String ) request .getSession ().getAttribute (STATE_ATTRIBUTE );
@@ -394,7 +393,7 @@ public HttpResponse doFinishLogin(StaplerRequest request) throws IOException {
394
393
new Mailer .UserProperty (auth .getMyself ().getEmail ()));
395
394
}
396
395
}
397
- SecurityListener .fireAuthenticated (new GitLabOAuthUserDetails (self , auth .getAuthorities ()));
396
+ SecurityListener .fireAuthenticated2 (new GitLabOAuthUserDetails (self , auth .getAuthorities ()));
398
397
} catch (GitLabApiException e ) {
399
398
throw new RuntimeException (e );
400
399
}
@@ -489,8 +488,8 @@ public Authentication authenticate(Authentication authentication) throws Authent
489
488
new UserDetailsService () {
490
489
@ Override
491
490
public UserDetails loadUserByUsername (String username )
492
- throws UsernameNotFoundException , DataAccessException {
493
- return GitLabSecurityRealm .this .loadUserByUsername (username );
491
+ throws UsernameNotFoundException {
492
+ return GitLabSecurityRealm .this .loadUserByUsername2 (username );
494
493
}
495
494
});
496
495
}
@@ -501,7 +500,7 @@ public String getLoginUrl() {
501
500
}
502
501
503
502
@ Override
504
- protected String getPostLogOutUrl ( StaplerRequest req , Authentication auth ) {
503
+ protected String getPostLogOutUrl2 ( StaplerRequest2 req , Authentication auth ) {
505
504
// if we just redirect to the root and anonymous does not have Overall read then we will start a login all over
506
505
// again.
507
506
// we are actually anonymous here as the security context has been cleared
@@ -546,16 +545,15 @@ public DescriptorImpl getDescriptor() {
546
545
/**
547
546
* @param username
548
547
* @throws UsernameNotFoundException
549
- * @throws DataAccessException
550
548
*/
551
549
@ Override
552
- public UserDetails loadUserByUsername (String username ) throws UsernameNotFoundException , DataAccessException {
550
+ public UserDetails loadUserByUsername2 (String username ) throws UsernameNotFoundException {
553
551
GitLabAuthenticationToken authToken ;
554
552
if (SecurityContextHolder .getContext ().getAuthentication () instanceof GitLabAuthenticationToken ) {
555
553
authToken = (GitLabAuthenticationToken )
556
554
SecurityContextHolder .getContext ().getAuthentication ();
557
555
} else {
558
- throw new UserMayOrMayNotExistException ("Could not get auth token." );
556
+ throw new UserMayOrMayNotExistException2 ("Could not get auth token." );
559
557
}
560
558
561
559
try {
@@ -572,7 +570,7 @@ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundEx
572
570
573
571
return userDetails ;
574
572
} catch (Error e ) {
575
- throw new DataRetrievalFailureException ("loadUserByUsername (username=" + username + ")" , e );
573
+ throw new AuthenticationServiceException ("loadUserByUsername (username=" + username + ")" , e );
576
574
}
577
575
}
578
576
@@ -604,10 +602,9 @@ public int hashCode() {
604
602
/**
605
603
* @param groupName
606
604
* @throws UsernameNotFoundException
607
- * @throws DataAccessException
608
605
*/
609
606
@ Override
610
- public GroupDetails loadGroupByGroupname (String groupName ) throws UsernameNotFoundException , DataAccessException {
607
+ public GroupDetails loadGroupByGroupname2 (String groupName , boolean fetchMembers ) throws UsernameNotFoundException {
611
608
612
609
GitLabAuthenticationToken authToken =
613
610
(GitLabAuthenticationToken ) SecurityContextHolder .getContext ().getAuthentication ();
0 commit comments