Skip to content

Commit a9ca5ef

Browse files
jglicktimjajtnord
authored
[JEP-227] Replace Acegi Security with Spring Security & upgrade Spring Framework (#4848)
Replacing Acegi Security with Spring Security Co-authored-by: Tim Jacomb <[email protected]> Co-authored-by: James Nord <[email protected]>
1 parent 748e8b2 commit a9ca5ef

File tree

229 files changed

+5241
-4085
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

229 files changed

+5241
-4085
lines changed

Jenkinsfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ for(j = 0; j < jdks.size(); j++) {
4343
"MAVEN_OPTS=-Xmx1536m -Xms512m"], buildType, jdk) {
4444
// Actually run Maven!
4545
// -Dmaven.repo.local=… tells Maven to create a subdir in the temporary directory for the local Maven repository
46-
def mvnCmd = "mvn -Pdebug -U -Dset.changelist help:evaluate -Dexpression=changelist -Doutput=$changelistF clean install ${runTests ? '-Dmaven.test.failure.ignore' : '-DskipTests'} -V -B -ntp -Dmaven.repo.local=$m2repo -e"
46+
def mvnCmd = "mvn -Pdebug -Pjapicmp -U -Dset.changelist help:evaluate -Dexpression=changelist -Doutput=$changelistF clean install ${runTests ? '-Dmaven.test.failure.ignore' : '-DskipTests'} -V -B -ntp -Dmaven.repo.local=$m2repo -e"
4747

4848
if(isUnix()) {
4949
sh mvnCmd
@@ -69,6 +69,7 @@ for(j = 0; j < jdks.size(); j++) {
6969
allowEmptyArchive: true, // in case we forgot to reincrementalify
7070
fingerprint: true
7171
}
72+
publishHTML([allowMissing: true, alwaysLinkToLastBuild: false, includes: 'japicmp.html', keepAll: false, reportDir: 'core/target/japicmp', reportFiles: 'japicmp.html', reportName: 'API compatibility', reportTitles: 'japicmp report'])
7273
}
7374
}
7475
}

bom/pom.xml

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,18 @@ THE SOFTWARE.
4242
<guavaVersion>11.0.1</guavaVersion>
4343
<slf4jVersion>1.7.30</slf4jVersion>
4444
<stapler.version>1.261</stapler.version>
45-
<spring.version>2.5.6.SEC03</spring.version>
4645
<groovy.version>2.4.12</groovy.version>
4746
</properties>
4847

4948
<dependencyManagement>
5049
<dependencies>
50+
<dependency> <!-- https://docs.spring.io/spring-security/site/docs/5.4.0-M1/reference/html5/#getting-maven-no-boot -->
51+
<groupId>org.springframework.security</groupId>
52+
<artifactId>spring-security-bom</artifactId>
53+
<version>5.4.1</version>
54+
<type>pom</type>
55+
<scope>import</scope>
56+
</dependency>
5157
<dependency>
5258
<groupId>com.github.spotbugs</groupId>
5359
<artifactId>spotbugs-annotations</artifactId>
@@ -418,29 +424,6 @@ THE SOFTWARE.
418424
<version>1.1-beta-11</version>
419425
</dependency>
420426

421-
<!--Spring-->
422-
<dependency>
423-
<groupId>org.springframework</groupId>
424-
<artifactId>spring-webmvc</artifactId>
425-
<version>${spring.version}</version>
426-
</dependency>
427-
<dependency>
428-
<groupId>org.springframework</groupId>
429-
<artifactId>spring-core</artifactId>
430-
<version>${spring.version}</version>
431-
</dependency>
432-
<dependency><!-- Jenkins core doesn't use it but JENKINS-3881 requires us to put it. -->
433-
<groupId>org.springframework</groupId>
434-
<artifactId>spring-aop</artifactId>
435-
<version>${spring.version}</version>
436-
</dependency>
437-
<dependency>
438-
<groupId>org.acegisecurity</groupId>
439-
<artifactId>acegi-security</artifactId>
440-
<version>1.0.7</version>
441-
</dependency>
442-
443-
444427
<!-- Modules -->
445428
<dependency>
446429
<groupId>org.jenkins-ci.modules</groupId>

core/pom.xml

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -387,16 +387,12 @@ THE SOFTWARE.
387387
<artifactId>commons-jexl</artifactId>
388388
</dependency>
389389
<dependency>
390-
<groupId>org.acegisecurity</groupId>
391-
<artifactId>acegi-security</artifactId>
390+
<groupId>org.springframework.security</groupId>
391+
<artifactId>spring-security-web</artifactId>
392392
<exclusions>
393393
<exclusion>
394394
<groupId>org.springframework</groupId>
395-
<artifactId>spring-remoting</artifactId>
396-
</exclusion>
397-
<exclusion>
398-
<groupId>org.springframework</groupId>
399-
<artifactId>spring-support</artifactId>
395+
<artifactId>spring-jcl</artifactId>
400396
</exclusion>
401397
</exclusions>
402398
</dependency>
@@ -414,22 +410,6 @@ THE SOFTWARE.
414410
<groupId>org.fusesource.jansi</groupId>
415411
<artifactId>jansi</artifactId>
416412
</dependency>
417-
<dependency>
418-
<!--
419-
for Grails spring bean builder.
420-
Ideally we should be able to modify BeanBuilder so as not to depend on this.
421-
-->
422-
<groupId>org.springframework</groupId>
423-
<artifactId>spring-webmvc</artifactId>
424-
</dependency>
425-
<dependency>
426-
<groupId>org.springframework</groupId>
427-
<artifactId>spring-core</artifactId>
428-
</dependency>
429-
<dependency><!-- Jenkins core doesn't use it but HUDSON-3811 requires us to put it. -->
430-
<groupId>org.springframework</groupId>
431-
<artifactId>spring-aop</artifactId>
432-
</dependency>
433413
<dependency>
434414
<groupId>org.junit.jupiter</groupId>
435415
<artifactId>junit-jupiter-api</artifactId>
@@ -869,5 +849,41 @@ THE SOFTWARE.
869849
<maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
870850
</properties>
871851
</profile>
852+
<profile>
853+
<id>japicmp</id>
854+
<build>
855+
<plugins>
856+
<plugin>
857+
<groupId>com.github.siom79.japicmp</groupId>
858+
<artifactId>japicmp-maven-plugin</artifactId>
859+
<version>0.14.4-20200728.214757-1</version> <!-- TODO https://github.com/siom79/japicmp/pull/266 -->
860+
<configuration>
861+
<parameter>
862+
<!-- see https://siom79.github.io/japicmp/MavenPlugin.html -->
863+
<oldVersionPattern>\d+[.]\d+</oldVersionPattern>
864+
<!-- <onlyModified>true</onlyModified> -->
865+
<onlyBinaryIncompatible>true</onlyBinaryIncompatible>
866+
</parameter>
867+
<oldClassPathDependencies>
868+
<dependency> <!-- provided, so not visible in flattened artifact -->
869+
<groupId>javax.servlet</groupId>
870+
<artifactId>javax.servlet-api</artifactId>
871+
<version>3.1.0</version>
872+
<scope>provided</scope>
873+
</dependency>
874+
</oldClassPathDependencies>
875+
</configuration>
876+
<executions>
877+
<execution>
878+
<phase>verify</phase>
879+
<goals>
880+
<goal>cmp</goal>
881+
</goals>
882+
</execution>
883+
</executions>
884+
</plugin>
885+
</plugins>
886+
</build>
887+
</profile>
872888
</profiles>
873889
</project>

core/src/main/java/hudson/DependencyRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public DependencyRunner(ProjectRunnable runnable) {
5252
}
5353

5454
public void run() {
55-
try (ACLContext ctx = ACL.as(ACL.SYSTEM)) {
55+
try (ACLContext ctx = ACL.as2(ACL.SYSTEM2)) {
5656
Set<AbstractProject> topLevelProjects = new HashSet<>();
5757
// Get all top-level projects
5858
LOGGER.fine("assembling top level projects");

core/src/main/java/hudson/ExpressionFactory2.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package hudson;
22

3-
import org.acegisecurity.AcegiSecurityException;
43
import org.apache.commons.jelly.JellyContext;
54
import org.apache.commons.jelly.JellyException;
65
import org.apache.commons.jelly.expression.Expression;
@@ -15,6 +14,7 @@
1514
import java.util.logging.Logger;
1615
import org.kohsuke.stapler.Stapler;
1716
import org.kohsuke.stapler.StaplerRequest;
17+
import org.springframework.security.access.AccessDeniedException;
1818

1919
/**
2020
* {@link ExpressionFactory} so that security exception aborts the page rendering.
@@ -72,7 +72,7 @@ public Object evaluate(JellyContext context) {
7272
CURRENT_CONTEXT.set(context);
7373
JexlContext jexlContext = new JellyJexlContext( context );
7474
return expression.evaluate(jexlContext);
75-
} catch (AcegiSecurityException e) {
75+
} catch (AccessDeniedException e) {
7676
// let the security exception pass through
7777
throw e;
7878
} catch (Exception e) {

core/src/main/java/hudson/ExtensionFinder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ public <T> void onProvision(ProvisionInvocation<T> provision) {
578578
// so that we invoke them before derived class one. This isn't specified in JSR-250 but implemented
579579
// this way in Spring and what most developers would expect to happen.
580580

581-
final Set<Class> interfaces = ClassUtils.getAllInterfacesAsSet(instance);
581+
final Set<Class<?>> interfaces = ClassUtils.getAllInterfacesAsSet(instance);
582582

583583
while (c != Object.class) {
584584
Arrays.stream(c.getDeclaredMethods())
@@ -607,7 +607,7 @@ public <T> void onProvision(ProvisionInvocation<T> provision) {
607607
* This allows to introspect metadata for a method which is both declared in parent class and in implemented
608608
* interface(s). {@code interfaces} typically is obtained by {@link ClassUtils#getAllInterfacesAsSet}
609609
*/
610-
Collection<Method> getMethodAndInterfaceDeclarations(Method method, Collection<Class> interfaces) {
610+
Collection<Method> getMethodAndInterfaceDeclarations(Method method, Collection<Class<?>> interfaces) {
611611
final List<Method> methods = new ArrayList<>();
612612
methods.add(method);
613613

core/src/main/java/hudson/Functions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@
145145
import jenkins.model.ModelObjectWithChildren;
146146
import jenkins.model.ModelObjectWithContextMenu;
147147

148-
import org.acegisecurity.AccessDeniedException;
149148
import org.apache.commons.jelly.JellyContext;
150149
import org.apache.commons.jelly.JellyTagException;
151150
import org.apache.commons.jelly.Script;
@@ -174,6 +173,7 @@
174173
import org.kohsuke.accmod.Restricted;
175174
import org.kohsuke.accmod.restrictions.NoExternalUse;
176175
import org.kohsuke.accmod.restrictions.DoNotUse;
176+
import org.springframework.security.access.AccessDeniedException;
177177

178178
/**
179179
* Utility functions used in views.
@@ -1770,7 +1770,7 @@ public static String toCCStatus(Item i) {
17701770
* Checks if the current user is anonymous.
17711771
*/
17721772
public static boolean isAnonymous() {
1773-
return ACL.isAnonymous(Jenkins.getAuthentication());
1773+
return ACL.isAnonymous2(Jenkins.getAuthentication2());
17741774
}
17751775

17761776
/**

core/src/main/java/hudson/PluginManager.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
import jenkins.util.xml.RestrictiveEntityResolver;
7070
import net.sf.json.JSONArray;
7171
import net.sf.json.JSONObject;
72-
import org.acegisecurity.Authentication;
7372
import org.apache.commons.fileupload.FileItem;
7473
import org.apache.commons.fileupload.FileUploadException;
7574
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
@@ -156,6 +155,7 @@
156155

157156
import static hudson.init.InitMilestone.*;
158157
import static java.util.logging.Level.*;
158+
import org.springframework.security.core.Authentication;
159159

160160
/**
161161
* Manages {@link PluginWrapper}s.
@@ -884,7 +884,7 @@ public void dynamicLoad(File arc) throws IOException, InterruptedException, Rest
884884
*/
885885
@Restricted(NoExternalUse.class)
886886
public void dynamicLoad(File arc, boolean removeExisting, @CheckForNull List<PluginWrapper> batch) throws IOException, InterruptedException, RestartRequiredException {
887-
try (ACLContext context = ACL.as(ACL.SYSTEM)) {
887+
try (ACLContext context = ACL.as2(ACL.SYSTEM2)) {
888888
LOGGER.log(FINE, "Attempting to dynamic load {0}", arc);
889889
PluginWrapper p = null;
890890
String sn;
@@ -951,7 +951,7 @@ public void dynamicLoad(File arc, boolean removeExisting, @CheckForNull List<Plu
951951

952952
@Restricted(NoExternalUse.class)
953953
public void start(List<PluginWrapper> plugins) throws Exception {
954-
try (ACLContext context = ACL.as(ACL.SYSTEM)) {
954+
try (ACLContext context = ACL.as2(ACL.SYSTEM2)) {
955955
Map<String, PluginWrapper> pluginsByName = plugins.stream().collect(Collectors.toMap(p -> p.getShortName(), p -> p));
956956

957957
// recalculate dependencies of plugins optionally depending the newly deployed ones.
@@ -1548,7 +1548,7 @@ private List<Future<UpdateCenter.UpdateCenterJob>> install(@NonNull Collection<S
15481548
installJobs.add(updateCenter.addJob(updateCenter.new CompleteBatchJob(batch, start, correlationId)));
15491549
}
15501550

1551-
final Authentication currentAuth = Jenkins.getAuthentication();
1551+
final Authentication currentAuth = Jenkins.getAuthentication2();
15521552

15531553
if (!jenkins.getInstallState().isSetupComplete()) {
15541554
jenkins.setInstallState(InstallState.INITIAL_PLUGINS_INSTALLING);
@@ -1578,7 +1578,7 @@ public void run() {
15781578
}
15791579
updateCenter.persistInstallStatus();
15801580
if(!failures) {
1581-
try (ACLContext acl = ACL.as(currentAuth)) {
1581+
try (ACLContext acl = ACL.as2(currentAuth)) {
15821582
InstallUtil.proceedToNextStateFrom(InstallState.INITIAL_PLUGINS_INSTALLING);
15831583
}
15841584
}

core/src/main/java/hudson/WebAppMain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ public FileAndDescription getHomeDir(ServletContextEvent event) {
434434
}
435435

436436
public void contextDestroyed(ServletContextEvent event) {
437-
try (ACLContext old = ACL.as(ACL.SYSTEM)) {
437+
try (ACLContext old = ACL.as2(ACL.SYSTEM2)) {
438438
Jenkins instance = Jenkins.getInstanceOrNull();
439439
try {
440440
if (instance != null) {

core/src/main/java/hudson/cli/BuildCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ protected int run() throws Exception {
166166
throw new IllegalStateException(msg);
167167
}
168168

169-
Queue.Item item = ParameterizedJobMixIn.scheduleBuild2(job, 0, new CauseAction(new CLICause(Jenkins.getAuthentication().getName())), a);
169+
Queue.Item item = ParameterizedJobMixIn.scheduleBuild2(job, 0, new CauseAction(new CLICause(Jenkins.getAuthentication2().getName())), a);
170170
QueueTaskFuture<? extends Run<?,?>> f = item != null ? (QueueTaskFuture)item.getFuture() : null;
171171

172172
if (wait || sync || follow) {

0 commit comments

Comments
 (0)