Skip to content

Commit a137f8a

Browse files
committed
Add Spring Security WebAuthn
This dependency is only selectable for Spring Boot 4.0+, and it automatically adds the Spring Security dependency if not selected already. Closes gh-1891
1 parent 961bcc8 commit a137f8a

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

start-site/src/main/java/io/spring/start/site/extension/dependency/DependencyProjectGenerationConfiguration.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import io.spring.start.site.extension.dependency.springbatch.SpringBatchTestBuildCustomizer;
3434
import io.spring.start.site.extension.dependency.springsecurity.SpringSecurityRSocketBuildCustomizer;
3535
import io.spring.start.site.extension.dependency.springsecurity.SpringSecurityTestBuildCustomizer;
36+
import io.spring.start.site.extension.dependency.springsecurity.SpringSecurityWebAuthnBuildCustomizer;
3637
import io.spring.start.site.extension.dependency.springshell.SpringShellTestBuildCustomizer;
3738
import io.spring.start.site.extension.dependency.thymeleaf.ThymeleafBuildCustomizer;
3839

@@ -80,6 +81,12 @@ public SpringSecurityRSocketBuildCustomizer securityRSocketBuildCustomizer() {
8081
return new SpringSecurityRSocketBuildCustomizer();
8182
}
8283

84+
@Bean
85+
@ConditionalOnRequestedDependency("spring-security-webauthn")
86+
SpringSecurityWebAuthnBuildCustomizer springSecurityWebAuthnBuildCustomizer() {
87+
return new SpringSecurityWebAuthnBuildCustomizer();
88+
}
89+
8390
@Bean
8491
@ConditionalOnRequestedDependency("batch")
8592
public SpringBatchTestBuildCustomizer batchTestBuildCustomizer() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2012 - present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.start.site.extension.dependency.springsecurity;
18+
19+
import io.spring.initializr.generator.buildsystem.Build;
20+
import io.spring.initializr.generator.spring.build.BuildCustomizer;
21+
22+
/**
23+
* A {@link BuildCustomizer} that ensures that Spring Security is added if Spring Security
24+
* WebAuthn is selected.
25+
*
26+
* @author Moritz Halbritter
27+
*/
28+
public class SpringSecurityWebAuthnBuildCustomizer implements BuildCustomizer<Build> {
29+
30+
@Override
31+
public void customize(Build build) {
32+
if (!build.dependencies().has("security")) {
33+
build.dependencies().add("security");
34+
}
35+
}
36+
37+
}

start-site/src/main/resources/application.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,16 @@ initializr:
529529
links:
530530
- rel: reference
531531
href: https://docs.spring.io/spring-boot/{bootVersion}/reference/web/spring-security.html#web.security.oauth2.server
532+
- name: WebAuthn for Spring Security
533+
id: spring-security-webauthn
534+
starter: false
535+
compatibility-range: "4.0.0-M1"
536+
group-id: org.springframework.security
537+
artifact-id: spring-security-webauthn
538+
description: Support for WebAuthn in Spring Security.
539+
links:
540+
- rel: reference
541+
href: https://docs.spring.io/spring-security/reference/servlet/authentication/passkeys.html
532542
- name: Spring LDAP
533543
id: data-ldap
534544
description: Makes it easier to build Spring based applications that use the Lightweight Directory Access Protocol.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2012 - present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.start.site.extension.dependency.springsecurity;
18+
19+
import io.spring.initializr.metadata.Dependency;
20+
import io.spring.initializr.web.project.ProjectRequest;
21+
import io.spring.start.site.SupportedBootVersion;
22+
import io.spring.start.site.extension.AbstractExtensionTests;
23+
import org.junit.jupiter.api.Test;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
27+
/**
28+
* Tests for {@link SpringSecurityWebAuthnBuildCustomizer}.
29+
*
30+
* @author Moritz Halbritter
31+
*/
32+
class SpringSecurityWebAuthnBuildCustomizerTests extends AbstractExtensionTests {
33+
34+
@Test
35+
void shouldDoNothingIfNotSelected() {
36+
ProjectRequest request = createProjectRequest(SupportedBootVersion.V4_0, "web");
37+
Dependency security = getDependency("security");
38+
assertThat(mavenPom(request)).doesNotHaveDependency(security.getGroupId(), security.getArtifactId());
39+
}
40+
41+
@Test
42+
void shouldAddSpringSecurityOnBoot40() {
43+
ProjectRequest request = createProjectRequest(SupportedBootVersion.V4_0, "spring-security-webauthn");
44+
assertThat(mavenPom(request)).hasDependency(getDependency("security"));
45+
}
46+
47+
}

0 commit comments

Comments
 (0)