Skip to content

Refactoring Test Code to Reduce Duplication of Mock Object Creation for Issue#14768 #15256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 137 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
a831ec9
Merged changes from Example 1: Avoid duplicate creation of mocks in A…
gzhao9 Jun 25, 2024
ee231a5
Merged changes from Example 2: Avoid duplicate creation of mocks in o…
gzhao9 Jun 25, 2024
33df5b0
Merged changes from Example 3: Avoid duplicate creation of mocks in C…
gzhao9 Jun 25, 2024
17e09f9
Merged changes from Example 4: Avoid duplicate creation of mocks in E…
gzhao9 Jun 25, 2024
e16ce57
Use AuthenticationFailureHandler instead of @ControllerAdvice
marcusdacoregio Jun 26, 2024
dd74722
Merge branch '6.3.x'
marcusdacoregio Jun 26, 2024
e3d642c
Add Task to Verify Branch Version Matches the Project Version
marcusdacoregio Jun 26, 2024
87e3c23
Merge branch '5.8.x' into 6.2.x
marcusdacoregio Jun 27, 2024
09909d1
Merge branch '6.2.x' into 6.3.x
marcusdacoregio Jun 27, 2024
8c6658d
Merge branch '6.3.x'
marcusdacoregio Jun 27, 2024
1135ad5
Skip checkExpectedBranchVersion task on PR Build workflow
marcusdacoregio Jun 28, 2024
24f573d
Merge branch '5.8.x' into 6.2.x
marcusdacoregio Jun 28, 2024
675eda1
Merge branch '6.2.x' into 6.3.x
marcusdacoregio Jun 28, 2024
ff0eead
Merge branch '6.3.x'
marcusdacoregio Jun 28, 2024
ef85ed5
Bump org.junit:junit-bom from 5.10.2 to 5.10.3
dependabot[bot] Jun 28, 2024
71906b3
Bump org.junit:junit-bom from 5.10.2 to 5.10.3
dependabot[bot] Jun 28, 2024
694bc03
Bump org.junit:junit-bom from 5.10.2 to 5.10.3
dependabot[bot] Jun 28, 2024
f91ca1b
Merge branch '6.2.x' into 6.3.x
github-actions[bot] Jun 28, 2024
a458889
Merge branch '6.3.x'
github-actions[bot] Jun 28, 2024
779030b
Document the role of CredentialsContainer
marcusdacoregio Jun 28, 2024
462ce1e
Merge branch '5.8.x' into 6.2.x
marcusdacoregio Jun 28, 2024
113e72f
Merge branch '6.2.x' into 6.3.x
marcusdacoregio Jun 28, 2024
8572764
Merge branch '6.3.x'
marcusdacoregio Jun 28, 2024
260411a
Bump antora from 3.2.0-alpha.4 to 3.2.0-alpha.5 in /docs
dependabot[bot] Jul 1, 2024
1f572a5
Merge branch '6.2.x' into 6.3.x
github-actions[bot] Jul 1, 2024
d880aa9
Merge branch '6.3.x'
github-actions[bot] Jul 1, 2024
e646f10
Bump antora from 3.2.0-alpha.4 to 3.2.0-alpha.5 in /docs
dependabot[bot] Jul 1, 2024
37c6e21
Merge branch '6.3.x'
github-actions[bot] Jul 1, 2024
d16f265
Bump antora from 3.2.0-alpha.4 to 3.2.0-alpha.5 in /docs
dependabot[bot] Jul 1, 2024
97e6ac7
Bump antora from 3.2.0-alpha.4 to 3.2.0-alpha.5 in /docs
dependabot[bot] Jul 1, 2024
523080c
Merge branch '5.8.x' into 6.2.x
github-actions[bot] Jul 1, 2024
133eb89
Merge branch '6.3.x'
github-actions[bot] Jul 1, 2024
98cf8a8
Merge branch '6.2.x' into 6.3.x
github-actions[bot] Jul 1, 2024
f564385
Bump org.skyscreamer:jsonassert from 1.5.1 to 1.5.3
dependabot[bot] Jul 1, 2024
7ea7749
Merge branch '6.3.x'
github-actions[bot] Jul 1, 2024
bddc10d
Merge branch '6.2.x' into 6.3.x
github-actions[bot] Jul 1, 2024
d159a2e
Bump org.skyscreamer:jsonassert from 1.5.1 to 1.5.3
dependabot[bot] Jul 1, 2024
7b416d8
Bump org.skyscreamer:jsonassert from 1.5.1 to 1.5.3
dependabot[bot] Jul 1, 2024
a7a8494
Merge branch '6.3.x'
github-actions[bot] Jul 1, 2024
9189916
Bump org.skyscreamer:jsonassert from 1.5.1 to 1.5.3
dependabot[bot] Jul 1, 2024
4fc22a4
Merge branch '6.2.x' into 6.3.x
github-actions[bot] Jul 1, 2024
e076a4b
Merge branch '6.3.x'
github-actions[bot] Jul 1, 2024
174435b
Merge branch '5.8.x' into 6.2.x
github-actions[bot] Jul 1, 2024
8917cdb
Improve Performance of IPv4 Check
jzheaux Jul 1, 2024
9f0b2a2
Merge branch '6.3.x'
jzheaux Jul 1, 2024
a9aefaf
Fix malformed list in "Using Method Parameters" documentation
Marcono1234 Jun 29, 2024
e7212b3
Update events.adoc
stefanganzer Jun 30, 2024
ceb278c
Update events.adoc
stefanganzer Jun 30, 2024
4882620
Update architecture.adoc
dboldureanu Jun 28, 2024
99cda31
Update prerequisites documentation
arey Jun 29, 2024
4975254
Merge branch '6.2.x' into 6.3.x
jzheaux Jul 1, 2024
f532807
Merge branch '6.3.x'
jzheaux Jul 1, 2024
850c0a4
Fix Spring Framework Reference Link
jzheaux Jul 2, 2024
1e29003
Add IterableRelyingPartyRegistrationRepository
jzheaux Jul 1, 2024
7b39800
Add CachingRelyingPartyRegistrationRepository
jzheaux Jul 2, 2024
6bd2f1c
Deprecate OpenSamlRelyingPartyRegistration
jzheaux Jul 2, 2024
5b44972
Revert "Disable check-samples temporarily"
marcusdacoregio Jul 2, 2024
207680b
Try check task
marcusdacoregio Jul 2, 2024
773e867
Add ParameterRequestMatcher
jzheaux Jun 22, 2024
a309552
Label superseded dependabot updates as duplicates
marcusdacoregio Jul 3, 2024
cdb8403
Merge branch '5.8.x' into 6.2.x
marcusdacoregio Jul 3, 2024
9486234
Merge branch '6.2.x' into 6.3.x
marcusdacoregio Jul 3, 2024
19cde35
Merge branch '6.3.x'
marcusdacoregio Jul 3, 2024
7e391c3
Bump org-eclipse-jetty from 11.0.21 to 11.0.22
dependabot[bot] Jul 4, 2024
b30a1d4
Merge branch '6.3.x'
github-actions[bot] Jul 4, 2024
298a75e
Bump org-eclipse-jetty from 11.0.21 to 11.0.22
dependabot[bot] Jul 4, 2024
138daec
Bump org-eclipse-jetty from 11.0.21 to 11.0.22
dependabot[bot] Jul 4, 2024
f01ffd1
Merge branch '6.3.x'
github-actions[bot] Jul 4, 2024
3a8c703
Merge branch '6.2.x' into 6.3.x
github-actions[bot] Jul 4, 2024
2bdb57a
Bump org-eclipse-jetty from 9.4.54.v20240208 to 9.4.55.v20240627
dependabot[bot] Jul 4, 2024
a8fe03d
Merge branch '5.8.x' into 6.2.x
github-actions[bot] Jul 4, 2024
3b9a2c3
Merge branch '6.3.x'
github-actions[bot] Jul 4, 2024
cfa7234
Merge branch '6.2.x' into 6.3.x
github-actions[bot] Jul 4, 2024
ba38cda
Bump org-apache-maven-resolver from 1.9.20 to 1.9.21
dependabot[bot] Jul 8, 2024
41f1706
Bump com.github.spullara.mustache.java:compiler from 0.9.13 to 0.9.14
dependabot[bot] Jul 8, 2024
ebb842e
Bump com.fasterxml.jackson:jackson-bom from 2.17.1 to 2.17.2
dependabot[bot] Jul 8, 2024
76f6693
Bump org-apache-maven-resolver from 1.9.20 to 1.9.21
dependabot[bot] Jul 8, 2024
88dc249
Merge branch '6.3.x'
github-actions[bot] Jul 8, 2024
78e56f9
Bump com.github.spullara.mustache.java:compiler from 0.9.13 to 0.9.14
dependabot[bot] Jul 8, 2024
c6017e7
Merge branch '6.3.x'
github-actions[bot] Jul 8, 2024
debfd40
Bump com.fasterxml.jackson:jackson-bom from 2.17.1 to 2.17.2
dependabot[bot] Jul 8, 2024
2e7f61d
Merge branch '6.3.x'
github-actions[bot] Jul 8, 2024
05256da
Bump com.github.spullara.mustache.java:compiler from 0.9.13 to 0.9.14
dependabot[bot] Jul 8, 2024
36f3194
Bump org-apache-maven-resolver from 1.9.20 to 1.9.21
dependabot[bot] Jul 8, 2024
7fceda4
Bump com.github.spullara.mustache.java:compiler from 0.9.13 to 0.9.14
dependabot[bot] Jul 8, 2024
a34e24a
Merge branch '5.8.x' into 6.2.x
github-actions[bot] Jul 8, 2024
f396b4d
Merge branch '6.2.x' into 6.3.x
github-actions[bot] Jul 8, 2024
5496eca
Merge branch '6.3.x'
github-actions[bot] Jul 8, 2024
65c0378
Debug PR event payload
marcusdacoregio Jul 8, 2024
cd404aa
Merge branch '5.8.x' into 6.2.x
marcusdacoregio Jul 8, 2024
fc6acab
Merge branch '6.2.x' into 6.3.x
marcusdacoregio Jul 8, 2024
ce018ff
Merge branch '6.3.x'
marcusdacoregio Jul 8, 2024
148e784
Fix typos and formatting in documentation
Seungpang Jul 3, 2024
f4cbaaa
Fix typos and formatting in documentation
Seungpang Jul 3, 2024
290cee2
Merge branch '6.2.x' into 6.3.x
jzheaux Jul 9, 2024
62c68cb
Merge branch '6.3.x'
jzheaux Jul 9, 2024
527f816
Bump io.micrometer:micrometer-observation from 1.12.7 to 1.12.8
dependabot[bot] Jul 9, 2024
b4f3966
Bump io.micrometer:micrometer-observation from 1.12.7 to 1.12.8
dependabot[bot] Jul 9, 2024
c338791
Merge branch '6.2.x' into 6.3.x
github-actions[bot] Jul 9, 2024
230dae6
Merge branch '6.3.x'
github-actions[bot] Jul 9, 2024
8f850f5
Bump io.micrometer:micrometer-observation from 1.12.7 to 1.12.8
dependabot[bot] Jul 9, 2024
ec4cad6
Merge branch '6.3.x'
github-actions[bot] Jul 9, 2024
01e1813
Remove single quotes from boolean value
marcusdacoregio Jul 9, 2024
90ff253
Merge branch '5.8.x' into 6.2.x
marcusdacoregio Jul 9, 2024
85b679e
Merge branch '6.2.x' into 6.3.x
marcusdacoregio Jul 9, 2024
beff600
Merge branch '6.3.x'
marcusdacoregio Jul 9, 2024
f184d13
Update the OAuth2 jwt and opaque resource server documentation with t…
arey Jul 4, 2024
d6874d9
Fixing URL on README
mateusscheper Jul 2, 2024
5bd4db1
Use javadoc macro
rwinch Jul 9, 2024
5437bf5
Bump io.projectreactor:reactor-bom from 2023.0.7 to 2023.0.8
dependabot[bot] Jul 10, 2024
7e43a42
Bump io.projectreactor:reactor-bom from 2023.0.7 to 2023.0.8
dependabot[bot] Jul 10, 2024
90533d2
Merge branch '6.3.x'
github-actions[bot] Jul 10, 2024
902d60d
Bump io.projectreactor:reactor-bom from 2023.0.7 to 2023.0.8
dependabot[bot] Jul 10, 2024
4a8af6f
Merge branch '6.2.x' into 6.3.x
github-actions[bot] Jul 10, 2024
e59f5a9
Merge branch '6.3.x'
github-actions[bot] Jul 10, 2024
c00197b
Bump io.projectreactor.netty:reactor-netty from 1.0.46 to 1.0.47
dependabot[bot] Jul 10, 2024
3aac1bc
Merge branch '5.8.x' into 6.2.x
github-actions[bot] Jul 10, 2024
4c3a9c6
Merge branch '6.2.x' into 6.3.x
github-actions[bot] Jul 10, 2024
6a88784
Merge branch '6.3.x'
github-actions[bot] Jul 10, 2024
341f58d
Bump io.projectreactor:reactor-bom from 2020.0.45 to 2020.0.46
dependabot[bot] Jul 10, 2024
e95100a
Merge branch '5.8.x' into 6.2.x
github-actions[bot] Jul 10, 2024
21a669c
Merge branch '6.2.x' into 6.3.x
github-actions[bot] Jul 10, 2024
d239806
Merge branch '6.3.x'
github-actions[bot] Jul 10, 2024
9cfc9bb
Use in:title
marcusdacoregio Jul 10, 2024
dff7e83
Merge branch '5.8.x' into 6.2.x
marcusdacoregio Jul 10, 2024
dca1eb0
Merge branch '6.2.x' into 6.3.x
marcusdacoregio Jul 10, 2024
c885cee
Merge branch '6.3.x'
marcusdacoregio Jul 10, 2024
dcf5cc9
Extract EntityDescriptor to AssertingPartyDetails Logic
jzheaux Jul 10, 2024
32e2735
Clarify Valid Metadata Locations
jzheaux Jul 10, 2024
e1fdc61
Merge branch '5.8.x' into 6.2.x
jzheaux Jul 10, 2024
8951b6e
Merge branch '6.2.x' into 6.3.x
jzheaux Jul 10, 2024
161b0f3
Merge branch '6.3.x'
jzheaux Jul 10, 2024
8044395
Merged changes from Example 1: Avoid duplicate creation of mocks in A…
gzhao9 Jun 25, 2024
eeb5f0b
Merged changes from Example 2: Avoid duplicate creation of mocks in o…
gzhao9 Jun 25, 2024
d8c95e4
Merged changes from Example 3: Avoid duplicate creation of mocks in C…
gzhao9 Jun 25, 2024
f482471
Merged changes from Example 4: Avoid duplicate creation of mocks in E…
gzhao9 Jun 25, 2024
c9158cf
Merge branch 'refactor-for-issue#14768' of https://github.com/gzhao9/…
gzhao9 Jul 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions .github/workflows/continuous-integration-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,29 @@ jobs:
java-version: ${{ matrix.java-version }}
test-args: --refresh-dependencies -PforceMavenRepositories=snapshot -PisOverrideVersionCatalog -PtestToolchain=${{ matrix.toolchain }} -PspringFrameworkVersion=6.2.+ -PreactorVersion=2023.0.+ -PspringDataVersion=2024.0.+ --stacktrace
secrets: inherit
# check-samples:
# name: Check Samples
# runs-on: ubuntu-latest
# if: ${{ github.repository_owner == 'spring-projects' }}
# steps:
# - uses: actions/checkout@v4
# - name: Set up gradle
# uses: spring-io/spring-gradle-build-action@v2
# with:
# java-version: 17
# distribution: temurin
# - name: Check samples project
# env:
# LOCAL_REPOSITORY_PATH: ${{ github.workspace }}/build/publications/repos
# SAMPLES_DIR: ../spring-security-samples
# run: |
# # Extract version from gradle.properties
# version=$(cat gradle.properties | grep "version=" | awk -F'=' '{print $2}')
# # Extract samplesBranch from gradle.properties
# samples_branch=$(cat gradle.properties | grep "samplesBranch=" | awk -F'=' '{print $2}')
# ./gradlew publishMavenJavaPublicationToLocalRepository
# ./gradlew cloneRepository -PrepositoryName="spring-projects/spring-security-samples" -Pref="$samples_branch" -PcloneOutputDirectory="$SAMPLES_DIR"
# ./gradlew --project-dir "$SAMPLES_DIR" --init-script spring-security-ci.gradle -PlocalRepositoryPath="$LOCAL_REPOSITORY_PATH" -PspringSecurityVersion="$version" :runAllTests
check-samples:
name: Check Samples
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'spring-projects' }}
steps:
- uses: actions/checkout@v4
- name: Set up gradle
uses: spring-io/spring-gradle-build-action@v2
with:
java-version: 17
distribution: temurin
- name: Check samples project
env:
LOCAL_REPOSITORY_PATH: ${{ github.workspace }}/build/publications/repos
SAMPLES_DIR: ../spring-security-samples
run: |
# Extract version from gradle.properties
version=$(cat gradle.properties | grep "version=" | awk -F'=' '{print $2}')
# Extract samplesBranch from gradle.properties
samples_branch=$(cat gradle.properties | grep "samplesBranch=" | awk -F'=' '{print $2}')
./gradlew publishMavenJavaPublicationToLocalRepository
./gradlew cloneRepository -PrepositoryName="spring-projects/spring-security-samples" -Pref="$samples_branch" -PcloneOutputDirectory="$SAMPLES_DIR"
./gradlew --project-dir "$SAMPLES_DIR" --init-script spring-security-ci.gradle -PlocalRepositoryPath="$LOCAL_REPOSITORY_PATH" -PspringSecurityVersion="$version" check
check-tangles:
name: Check for Package Tangles
runs-on: ubuntu-latest
Expand All @@ -82,21 +82,21 @@ jobs:
./gradlew check s101 -Ps101.licenseId="$STRUCTURE101_LICENSEID" --stacktrace
deploy-artifacts:
name: Deploy Artifacts
needs: [ build, test, check-tangles ]
needs: [ build, test, check-samples, check-tangles ]
uses: spring-io/spring-security-release-tools/.github/workflows/deploy-artifacts.yml@v1
with:
should-deploy-artifacts: ${{ needs.build.outputs.should-deploy-artifacts }}
secrets: inherit
deploy-docs:
name: Deploy Docs
needs: [ build, test, check-tangles ]
needs: [ build, test, check-samples, check-tangles ]
uses: spring-io/spring-security-release-tools/.github/workflows/deploy-docs.yml@v1
with:
should-deploy-docs: ${{ needs.build.outputs.should-deploy-artifacts }}
secrets: inherit
deploy-schema:
name: Deploy Schema
needs: [ build, test, check-tangles ]
needs: [ build, test, check-samples, check-tangles ]
uses: spring-io/spring-security-release-tools/.github/workflows/deploy-schema.yml@v1
with:
should-deploy-schema: ${{ needs.build.outputs.should-deploy-artifacts }}
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/mark-duplicate-dependabot-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Mark Duplicate Dependabot PRs

on:
pull_request:
types: [closed]

jobs:
check_duplicate_prs:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true && github.event.pull_request.user.login == 'dependabot[bot]'
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Extract Dependency Name from PR Title
id: extract
run: |
PR_TITLE="${{ github.event.pull_request.title }}"
DEPENDENCY_NAME=$(echo "$PR_TITLE" | awk -F ' from ' '{print $1}')
echo "dependency_name=$DEPENDENCY_NAME" >> $GITHUB_OUTPUT

- name: Find PRs
id: find_duplicates
env:
DEPENDENCY_NAME: ${{ steps.extract.outputs.dependency_name }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PRS=$(gh pr list --search 'milestone:${{ github.event.pull_request.milestone.title }} is:merged in:title "$DEPENDENCY_NAME"' --json number --jq 'map(.number) | join(",")')
echo "prs=$PRS" >> $GITHUB_OUTPUT

- name: Label Duplicate PRs
if: steps.find_duplicates.outputs.prs != ''
env:
PRS: ${{ steps.find_duplicates.outputs.prs }}
CURRENT_PR_NUMBER: ${{ github.event.pull_request.number }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
for i in ${PRS//,/ }
do
if [ ! $i -eq "$CURRENT_PR_NUMBER" ]; then
echo "Marking PR $i as duplicate"
gh pr edit "$i" --add-label "status: duplicate"
gh pr comment "$i" --body "Duplicate of #$CURRENT_PR_NUMBER"
fi
done
2 changes: 1 addition & 1 deletion .github/workflows/pr-build-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
java-version: '17'
distribution: 'temurin'
- name: Build with Gradle
run: ./gradlew clean build --continue
run: ./gradlew clean build -PskipCheckExpectedBranchVersion --continue
generate-docs:
name: Generate Docs
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Please see our https://github.com/spring-projects/.github/blob/main/CODE_OF_COND
See https://docs.spring.io/spring-security/reference/getting-spring-security.html[Getting Spring Security] for how to obtain Spring Security.

== Documentation
Be sure to read the https://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/[Spring Security Reference].
Be sure to read the https://docs.spring.io/spring-security/reference/[Spring Security Reference].
Extensive JavaDoc for the Spring Security code is also available in the https://docs.spring.io/spring-security/site/docs/current/api/[Spring Security API Documentation].

== Quick Start
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ apply plugin: 's101'
apply plugin: 'io.spring.convention.root'
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'org.springframework.security.versions.verify-dependencies-versions'
apply plugin: 'org.springframework.security.check-expected-branch-version'
apply plugin: 'io.spring.security.release'

group = 'org.springframework.security'
Expand Down
4 changes: 4 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ gradlePlugin {
id = "org.springframework.security.versions.verify-dependencies-versions"
implementationClass = "org.springframework.security.convention.versions.VerifyDependenciesVersionsPlugin"
}
checkExpectedBranchVersion {
id = "org.springframework.security.check-expected-branch-version"
implementationClass = "org.springframework.security.CheckExpectedBranchVersionPlugin"
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.security;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.gradle.api.DefaultTask;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.TaskProvider;

/**
* @author Marcus da Coregio
*/
public class CheckExpectedBranchVersionPlugin implements Plugin<Project> {

@Override
public void apply(Project project) {
TaskProvider<CheckExpectedBranchVersionTask> checkExpectedBranchVersionTask = project.getTasks().register("checkExpectedBranchVersion", CheckExpectedBranchVersionTask.class, (task) -> {
task.setGroup("Build");
task.setDescription("Check if the project version matches the branch version");
});
project.getTasks().named(JavaBasePlugin.CHECK_TASK_NAME, checkTask -> checkTask.dependsOn(checkExpectedBranchVersionTask));
}

public static class CheckExpectedBranchVersionTask extends DefaultTask {

@TaskAction
public void run() throws IOException {
Project project = getProject();
if (project.hasProperty("skipCheckExpectedBranchVersion")) {
return;
}
String version = (String) project.getVersion();
String branchVersion = getBranchVersion(project);
if (!branchVersion.matches("^[0-9]+\\.[0-9]+\\.x$")) {
System.out.println("Branch version does not match *.x, ignoring");
return;
}
if (!versionsMatch(version, branchVersion)) {
throw new IllegalStateException(String.format("Project version [%s] does not match branch version [%s]. " +
"Please verify that the branch contains the right version.", version, branchVersion));
}
}

private static String getBranchVersion(Project project) throws IOException {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
project.exec((exec) -> {
exec.commandLine("git", "symbolic-ref", "--short", "HEAD");
exec.setErrorOutput(System.err);
exec.setStandardOutput(baos);
});
return baos.toString();
}
}

private boolean versionsMatch(String projectVersion, String branchVersion) {
String[] projectVersionParts = projectVersion.split("\\.");
String[] branchVersionParts = branchVersion.split("\\.");
if (projectVersionParts.length < 2 || branchVersionParts.length < 2) {
return false;
}
return projectVersionParts[0].equals(branchVersionParts[0]) && projectVersionParts[1].equals(branchVersionParts[1]);
}

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,8 +18,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;

import jakarta.servlet.http.HttpServletRequest;

Expand Down Expand Up @@ -60,6 +58,7 @@
import org.springframework.security.web.csrf.CsrfTokenRepository;
import org.springframework.security.web.util.matcher.AndRequestMatcher;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.security.web.util.matcher.ParameterRequestMatcher;
import org.springframework.security.web.util.matcher.RequestMatcher;

/**
Expand Down Expand Up @@ -508,23 +507,6 @@ public boolean matches(HttpServletRequest request) {

}

private static class ParameterRequestMatcher implements RequestMatcher {

Predicate<String> test = Objects::nonNull;

String name;

ParameterRequestMatcher(String name) {
this.name = name;
}

@Override
public boolean matches(HttpServletRequest request) {
return this.test.test(request.getParameter(this.name));
}

}

private static class Saml2RelyingPartyInitiatedLogoutFilter extends LogoutFilter {

Saml2RelyingPartyInitiatedLogoutFilter(LogoutSuccessHandler logoutSuccessHandler, LogoutHandler... handlers) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,8 +18,6 @@

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;

import jakarta.servlet.http.HttpServletRequest;
import org.w3c.dom.Element;
Expand All @@ -44,6 +42,7 @@
import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler;
import org.springframework.security.web.util.matcher.AndRequestMatcher;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.security.web.util.matcher.ParameterRequestMatcher;
import org.springframework.security.web.util.matcher.RequestMatcher;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
Expand Down Expand Up @@ -228,23 +227,6 @@ BeanDefinition getLogoutFilter() {
return this.logoutFilter;
}

private static class ParameterRequestMatcher implements RequestMatcher {

Predicate<String> test = Objects::nonNull;

String name;

ParameterRequestMatcher(String name) {
this.name = name;
}

@Override
public boolean matches(HttpServletRequest request) {
return this.test.test(request.getParameter(this.name));
}

}

public static class Saml2RequestMatcher implements RequestMatcher {

private SecurityContextHolderStrategy securityContextHolderStrategy = SecurityContextHolder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ public void beforeWhenMockAuthorizationManagerThenCheckAndReturnedObject() throw

@Test
public void afterWhenMockSecurityContextHolderStrategyThenUses() throws Throwable {
SecurityContextHolderStrategy strategy = mock(SecurityContextHolderStrategy.class);
Authentication authentication = TestAuthentication.authenticatedUser();
given(strategy.getContext()).willReturn(new SecurityContextImpl(authentication));
SecurityContextHolderStrategy strategy = MockSecurityContextHolderStrategy.getmock(new SecurityContextImpl(authentication));
MethodInvocation invocation = mock(MethodInvocation.class);
AuthorizationManager<MethodInvocationResult> authorizationManager = AuthenticatedAuthorizationManager
.authenticated();
Expand All @@ -98,10 +97,9 @@ public void afterWhenMockSecurityContextHolderStrategyThenUses() throws Throwabl
// gh-12877
@Test
public void afterWhenStaticSecurityContextHolderStrategyAfterConstructorThenUses() throws Throwable {
SecurityContextHolderStrategy strategy = mock(SecurityContextHolderStrategy.class);
Authentication authentication = new TestingAuthenticationToken("john", "password",
AuthorityUtils.createAuthorityList("authority"));
given(strategy.getContext()).willReturn(new SecurityContextImpl(authentication));
SecurityContextHolderStrategy strategy = MockSecurityContextHolderStrategy.getmock(new SecurityContextImpl(authentication));
MethodInvocation invocation = mock(MethodInvocation.class);
AuthorizationManager<MethodInvocationResult> authorizationManager = AuthenticatedAuthorizationManager
.authenticated();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ public void beforeWhenMockAuthorizationManagerThenCheck() throws Throwable {

@Test
public void beforeWhenMockSecurityContextHolderStrategyThenUses() throws Throwable {
SecurityContextHolderStrategy strategy = mock(SecurityContextHolderStrategy.class);
Authentication authentication = new TestingAuthenticationToken("user", "password",
AuthorityUtils.createAuthorityList("authority"));
given(strategy.getContext()).willReturn(new SecurityContextImpl(authentication));
SecurityContextHolderStrategy strategy = MockSecurityContextHolderStrategy.getmock(new SecurityContextImpl(authentication));
MethodInvocation invocation = mock(MethodInvocation.class);
AuthorizationManager<MethodInvocation> authorizationManager = AuthenticatedAuthorizationManager.authenticated();
AuthorizationManagerBeforeMethodInterceptor advice = new AuthorizationManagerBeforeMethodInterceptor(
Expand All @@ -93,10 +92,10 @@ public void beforeWhenMockSecurityContextHolderStrategyThenUses() throws Throwab
// gh-12877
@Test
public void beforeWhenStaticSecurityContextHolderStrategyAfterConstructorThenUses() throws Throwable {
SecurityContextHolderStrategy strategy = mock(SecurityContextHolderStrategy.class);

Authentication authentication = new TestingAuthenticationToken("john", "password",
AuthorityUtils.createAuthorityList("authority"));
given(strategy.getContext()).willReturn(new SecurityContextImpl(authentication));
SecurityContextHolderStrategy strategy = MockSecurityContextHolderStrategy.getmock(new SecurityContextImpl(authentication));
MethodInvocation invocation = mock(MethodInvocation.class);
AuthorizationManager<MethodInvocation> authorizationManager = AuthenticatedAuthorizationManager.authenticated();
AuthorizationManagerBeforeMethodInterceptor advice = new AuthorizationManagerBeforeMethodInterceptor(
Expand Down
Loading