8989import jenkins .model .Jenkins ;
9090import jenkins .security .QueueItemAuthenticatorConfiguration ;
9191
92- import org .acegisecurity .Authentication ;
93- import org .acegisecurity .context .SecurityContext ;
94- import org .acegisecurity .context .SecurityContextHolder ;
95- import org .acegisecurity . providers .UsernamePasswordAuthenticationToken ;
92+ import org .springframework . security . core .Authentication ;
93+ import org .springframework . security . core .context .SecurityContext ;
94+ import org .springframework . security . core .context .SecurityContextHolder ;
95+ import org .springframework . security . authentication .UsernamePasswordAuthenticationToken ;
9696import org .apache .commons .lang .StringUtils ;
9797import org .jenkinsci .plugins .workflow .DirectArtifactManagerFactory ;
9898import org .junit .After ;
@@ -1026,11 +1026,9 @@ public void testPermission() throws Exception {
10261026 assertEquals (src .getName (), ca .getProjectName ());
10271027
10281028 // Build should succeed when run as joe.
1029- Map <String , Authentication > authMap = new HashMap <>();
1030- authMap .put (dest .getFullName (), User .getById ("joe" , true ).impersonate ());
10311029 QueueItemAuthenticatorConfiguration .get ().getAuthenticators ().clear ();
10321030 QueueItemAuthenticatorConfiguration .get ().getAuthenticators ().add (
1033- new MockQueueItemAuthenticator (authMap )
1031+ new MockQueueItemAuthenticator (). authenticate ( dest . getFullName (), User . getById ( "joe" , true ). impersonate2 () )
10341032 );
10351033 rule .assertBuildStatusSuccess (dest .scheduleBuild2 (0 ));
10361034 }
@@ -1074,7 +1072,7 @@ public void testPermissionWhenParameterized() throws Exception {
10741072 rule .assertBuildStatusSuccess (b );
10751073 // Build step should fail for a job not accessible to all authenticated users,
10761074 // even when accessible to the user starting the job, as in this case:
1077- SecurityContext old = ACL .impersonate (
1075+ SecurityContext old = ACL .impersonate2 (
10781076 new UsernamePasswordAuthenticationToken ("joe" ,"joe" ));
10791077 try {
10801078 b = p .scheduleBuild2 (0 , new Cause .UserIdCause (),
@@ -1678,10 +1676,10 @@ public void testCopyArtifactPermissionProperty() throws Exception {
16781676
16791677 // test permissions
16801678 // not all user can access projects.
1681- assertFalse (copiee .getACL ().hasPermission (test1 .impersonate (), Item .READ ));
1682- assertFalse (copier .getACL ().hasPermission (test1 .impersonate (), Item .READ ));
1683- assertFalse (matrixCopiee .getACL ().hasPermission (test1 .impersonate (), Item .READ ));
1684- assertFalse (matrixCopier .getACL ().hasPermission (test1 .impersonate (), Item .READ ));
1679+ assertFalse (copiee .getACL ().hasPermission2 (test1 .impersonate2 (), Item .READ ));
1680+ assertFalse (copier .getACL ().hasPermission2 (test1 .impersonate2 (), Item .READ ));
1681+ assertFalse (matrixCopiee .getACL ().hasPermission2 (test1 .impersonate2 (), Item .READ ));
1682+ assertFalse (matrixCopier .getACL ().hasPermission2 (test1 .impersonate2 (), Item .READ ));
16851683
16861684 // prepare an artifact
16871685 rule .assertBuildStatusSuccess (copiee .scheduleBuild2 (0 ));
@@ -2093,15 +2091,15 @@ public void testCliCannotBypassPermission() throws Exception {
20932091 }
20942092
20952093 private static class TestQueueItemAuthenticator extends jenkins .security .QueueItemAuthenticator {
2096- private final transient org . acegisecurity . Authentication auth ;
2094+ private final transient Authentication auth ;
20972095
2098- public TestQueueItemAuthenticator (org . acegisecurity . Authentication auth ) {
2096+ public TestQueueItemAuthenticator (Authentication auth ) {
20992097 this .auth = auth ;
21002098 }
21012099
21022100 @ Override
21032101 @ edu .umd .cs .findbugs .annotations .CheckForNull
2104- public org . acegisecurity . Authentication authenticate (Queue .Item item ) {
2102+ public Authentication authenticate2 (Queue .Item item ) {
21052103 return auth ;
21062104 }
21072105
@@ -2146,20 +2144,20 @@ public void testQueueItemAuthenticator() throws Exception {
21462144 auth .grant (Item .READ ).onItems (copier ).to (test1 ,test2 );
21472145
21482146 // test permissions
2149- assertTrue (copiee .getACL ().hasPermission (admin .impersonate (), Item .READ ));
2150- assertTrue (copiee .getACL ().hasPermission (test1 .impersonate (), Item .READ ));
2151- assertFalse (copiee .getACL ().hasPermission (test2 .impersonate (), Item .READ ));
2147+ assertTrue (copiee .getACL ().hasPermission2 (admin .impersonate2 (), Item .READ ));
2148+ assertTrue (copiee .getACL ().hasPermission2 (test1 .impersonate2 (), Item .READ ));
2149+ assertFalse (copiee .getACL ().hasPermission2 (test2 .impersonate2 (), Item .READ ));
21522150
2153- assertTrue (copier .getACL ().hasPermission (admin .impersonate (), Item .BUILD ));
2154- assertTrue (copier .getACL ().hasPermission (test1 .impersonate (), Item .BUILD ));
2155- assertTrue (copier .getACL ().hasPermission (test2 .impersonate (), Item .BUILD ));
2156- assertTrue (copier .getACL ().hasPermission (Jenkins .ANONYMOUS , Item .BUILD ));
2151+ assertTrue (copier .getACL ().hasPermission2 (admin .impersonate2 (), Item .BUILD ));
2152+ assertTrue (copier .getACL ().hasPermission2 (test1 .impersonate2 (), Item .BUILD ));
2153+ assertTrue (copier .getACL ().hasPermission2 (test2 .impersonate2 (), Item .BUILD ));
2154+ assertTrue (copier .getACL ().hasPermission2 (Jenkins .ANONYMOUS2 , Item .BUILD ));
21572155
21582156 // Computer.BUILD is required since Jenkins 1.521.
2159- assertTrue (rule .jenkins .getACL ().hasPermission (admin .impersonate (), Computer .BUILD ));
2160- assertTrue (rule .jenkins .getACL ().hasPermission (test1 .impersonate (), Computer .BUILD ));
2161- assertTrue (rule .jenkins .getACL ().hasPermission (test2 .impersonate (), Computer .BUILD ));
2162- assertTrue (rule .jenkins .getACL ().hasPermission (Jenkins .ANONYMOUS , Computer .BUILD ));
2157+ assertTrue (rule .jenkins .getACL ().hasPermission2 (admin .impersonate2 (), Computer .BUILD ));
2158+ assertTrue (rule .jenkins .getACL ().hasPermission2 (test1 .impersonate2 (), Computer .BUILD ));
2159+ assertTrue (rule .jenkins .getACL ().hasPermission2 (test2 .impersonate2 (), Computer .BUILD ));
2160+ assertTrue (rule .jenkins .getACL ().hasPermission2 (Jenkins .ANONYMOUS2 , Computer .BUILD ));
21632161
21642162 // prepare an artifact
21652163 rule .assertBuildStatusSuccess (copiee .scheduleBuild2 (0 ));
@@ -2174,7 +2172,7 @@ public void testQueueItemAuthenticator() throws Exception {
21742172 {
21752173 QueueItemAuthenticatorConfiguration .get ().getAuthenticators ().clear ();
21762174 QueueItemAuthenticatorConfiguration .get ().getAuthenticators ().add (
2177- new TestQueueItemAuthenticator (admin .impersonate ())
2175+ new TestQueueItemAuthenticator (admin .impersonate2 ())
21782176 );
21792177 rule .assertBuildStatus (Result .SUCCESS , copier .scheduleBuild2 (0 ).get (TIMEOUT , TimeUnit .SECONDS ));
21802178 }
@@ -2184,7 +2182,7 @@ public void testQueueItemAuthenticator() throws Exception {
21842182 {
21852183 QueueItemAuthenticatorConfiguration .get ().getAuthenticators ().clear ();
21862184 QueueItemAuthenticatorConfiguration .get ().getAuthenticators ().add (
2187- new TestQueueItemAuthenticator (test1 .impersonate ())
2185+ new TestQueueItemAuthenticator (test1 .impersonate2 ())
21882186 );
21892187 rule .assertBuildStatus (Result .SUCCESS , copier .scheduleBuild2 (0 ).get (TIMEOUT , TimeUnit .SECONDS ));
21902188 }
@@ -2194,7 +2192,7 @@ public void testQueueItemAuthenticator() throws Exception {
21942192 {
21952193 QueueItemAuthenticatorConfiguration .get ().getAuthenticators ().clear ();
21962194 QueueItemAuthenticatorConfiguration .get ().getAuthenticators ().add (
2197- new TestQueueItemAuthenticator (test2 .impersonate ())
2195+ new TestQueueItemAuthenticator (test2 .impersonate2 ())
21982196 );
21992197 rule .assertBuildStatus (Result .FAILURE , copier .scheduleBuild2 (0 ).get (TIMEOUT , TimeUnit .SECONDS ));
22002198 }
@@ -2204,7 +2202,7 @@ public void testQueueItemAuthenticator() throws Exception {
22042202 {
22052203 QueueItemAuthenticatorConfiguration .get ().getAuthenticators ().clear ();
22062204 QueueItemAuthenticatorConfiguration .get ().getAuthenticators ().add (
2207- new TestQueueItemAuthenticator (Jenkins .ANONYMOUS )
2205+ new TestQueueItemAuthenticator (Jenkins .ANONYMOUS2 )
22082206 );
22092207 rule .assertBuildStatus (Result .FAILURE , copier .scheduleBuild2 (0 ).get (TIMEOUT , TimeUnit .SECONDS ));
22102208 }
@@ -2482,11 +2480,9 @@ public void artifactsPermissionWithAuthSuccess() throws Exception {
24822480 true
24832481 ));
24842482
2485- Map <String , Authentication > authMap = new HashMap <>();
2486- authMap .put (dest .getFullName (), User .getById ("joe" , true ).impersonate ());
24872483 QueueItemAuthenticatorConfiguration .get ().getAuthenticators ().clear ();
24882484 QueueItemAuthenticatorConfiguration .get ().getAuthenticators ().add (
2489- new MockQueueItemAuthenticator (authMap )
2485+ new MockQueueItemAuthenticator (). authenticate ( dest . getFullName (), User . getById ( "joe" , true ). impersonate2 () )
24902486 );
24912487 rule .assertBuildStatusSuccess (dest .scheduleBuild2 (0 ));
24922488 }
@@ -2520,11 +2516,9 @@ public void artifactsPermissionWithAuthFailure() throws Exception {
25202516 true
25212517 ));
25222518
2523- Map <String , Authentication > authMap = new HashMap <>();
2524- authMap .put (dest .getFullName (), User .getById ("joe" , true ).impersonate ());
25252519 QueueItemAuthenticatorConfiguration .get ().getAuthenticators ().clear ();
25262520 QueueItemAuthenticatorConfiguration .get ().getAuthenticators ().add (
2527- new MockQueueItemAuthenticator (authMap )
2521+ new MockQueueItemAuthenticator (). authenticate ( dest . getFullName (), User . getById ( "joe" , true ). impersonate2 () )
25282522 );
25292523 rule .assertBuildStatus (Result .FAILURE , dest .scheduleBuild2 (0 ));
25302524 }
0 commit comments