Skip to content

Commit

Permalink
Add thymeleaf security extensions and Security test if OAuth2 client is
Browse files Browse the repository at this point in the history
selected

Closes gh-1542
  • Loading branch information
mhalbritter committed Jul 30, 2024
1 parent 722e50d commit 40e9ea3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* @author Stephane Nicoll
* @author Eddú Meléndez
* @author Kazuki Shimizu
* @author Moritz Halbritter
*/
@ProjectGenerationConfiguration
public class DependencyProjectGenerationConfiguration {
Expand All @@ -67,6 +68,12 @@ public SpringSecurityTestBuildCustomizer securityTestBuildCustomizer() {
return new SpringSecurityTestBuildCustomizer();
}

@Bean
@ConditionalOnRequestedDependency("oauth2-client")
SpringSecurityTestBuildCustomizer oauth2ClientTestBuildCustomizer() {
return new SpringSecurityTestBuildCustomizer();
}

@Bean
@ConditionalOnRequestedDependency("security")
public SpringSecurityRSocketBuildCustomizer securityRSocketBuildCustomizer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
* A {@link BuildCustomizer} for Thymeleaf.
*
* @author Stephane Nicoll
* @author Moritz Halbritter
*/
public class ThymeleafBuildCustomizer implements BuildCustomizer<Build> {

@Override
public void customize(Build build) {
if (build.dependencies().has("security")) {
if (build.dependencies().has("security") || build.dependencies().has("oauth2-client")) {
build.dependencies()
.add("thymeleaf-extras-spring-security",
Dependency.withCoordinates("org.thymeleaf.extras", "thymeleaf-extras-springsecurity6"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* Tests for {@link SpringSecurityTestBuildCustomizer}.
*
* @author Stephane Nicoll
* @author Moritz Halbritter
*/
class SpringSecurityTestBuildCustomizerTests extends AbstractExtensionTests {

Expand All @@ -39,6 +40,15 @@ void securityTestIsAddedWithSecurity() {
.hasDependenciesSize(3);
}

@Test
void securityTestIsAddedWithOAuth2Client() {
ProjectRequest request = createProjectRequest("oauth2-client");
assertThat(mavenPom(request)).hasDependency(Dependency.createSpringBootStarter("oauth2-client"))
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST))
.hasDependency(springSecurityTest())
.hasDependenciesSize(3);
}

@Test
void securityTestIsNotAddedWithoutSpringSecurity() {
ProjectRequest request = createProjectRequest("web");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* Tests for {@link ThymeleafBuildCustomizer}.
*
* @author Stephane Nicoll
* @author Moritz Halbritter
*/
class ThymeleafBuildCustomizerTests extends AbstractExtensionTests {

Expand All @@ -39,6 +40,15 @@ void thymeleafWithSpringSecurityAndSpringBootAddsExtrasDependency() {
"thymeleaf-extras-springsecurity6"));
}

@Test
void thymeleafWithOAuth2ClientAndSpringBootAddsExtrasDependency() {
ProjectRequest projectRequest = createProjectRequest("thymeleaf", "oauth2-client");
assertThat(mavenPom(projectRequest)).hasDependency(Dependency.createSpringBootStarter("thymeleaf"))
.hasDependency(Dependency.createSpringBootStarter("oauth2-client"))
.hasDependency(Dependency.withId("thymeleaf-extras-spring-security", "org.thymeleaf.extras",
"thymeleaf-extras-springsecurity6"));
}

@Test
void thymeleafWithoutSpringSecurityDoesNotAddExtrasDependency() {
assertThat(mavenPom(createProjectRequest("thymeleaf", "web")))
Expand Down

0 comments on commit 40e9ea3

Please sign in to comment.