Skip to content

Commit 0546f34

Browse files
committed
NFC-109 Conditional mobile authentication security configuration
1 parent a45b481 commit 0546f34

File tree

3 files changed

+74
-46
lines changed

3 files changed

+74
-46
lines changed

example/src/main/java/eu/webeid/example/config/ApplicationConfiguration.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import eu.webeid.example.security.WebEidMobileAuthInitFilter;
2929
import eu.webeid.example.security.ui.WebEidLoginPageGeneratingFilter;
3030
import eu.webeid.security.challenge.ChallengeNonceGenerator;
31+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProperty;
3132
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
3233
import org.springframework.context.annotation.Bean;
3334
import org.springframework.context.annotation.Configuration;
@@ -48,7 +49,8 @@
4849
public class ApplicationConfiguration {
4950

5051
@Bean
51-
public SecurityFilterChain filterChain(
52+
@ConditionalOnBooleanProperty(name = "web-eid-mobile.enabled", matchIfMissing = true)
53+
public SecurityFilterChain webEidPluginAndMobileSecurityFilterChain(
5254
HttpSecurity http,
5355
WebEidAuthenticationProvider webEidAuthenticationProvider,
5456
AuthenticationConfiguration authConfig,
@@ -71,4 +73,27 @@ public SecurityFilterChain filterChain(
7173
.headers(h -> h.frameOptions(HeadersConfigurer.FrameOptionsConfig::sameOrigin))
7274
.build();
7375
}
76+
77+
@Bean
78+
@ConditionalOnBooleanProperty(name = "web-eid-mobile.enabled", havingValue = false)
79+
public SecurityFilterChain webEidPluginOnlySecurityFilterChain(
80+
HttpSecurity http,
81+
WebEidAuthenticationProvider webEidAuthenticationProvider,
82+
AuthenticationConfiguration authConfig,
83+
ChallengeNonceGenerator challengeNonceGenerator
84+
) throws Exception {
85+
return http
86+
.authorizeHttpRequests(auth -> auth
87+
.requestMatchers("/css/**", "/files/**", "/img/**", "/js/**", "/scripts/**").permitAll()
88+
.requestMatchers("/").permitAll()
89+
.anyRequest().authenticated()
90+
)
91+
.authenticationProvider(webEidAuthenticationProvider)
92+
.addFilterBefore(new WebEidChallengeNonceFilter("/auth/challenge", challengeNonceGenerator), UsernamePasswordAuthenticationFilter.class)
93+
.addFilterBefore(new WebEidAjaxLoginProcessingFilter("/auth/login", authConfig.getAuthenticationManager()), UsernamePasswordAuthenticationFilter.class)
94+
.logout(l -> l.logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler()))
95+
.headers(h -> h.frameOptions(HeadersConfigurer.FrameOptionsConfig::sameOrigin))
96+
.build();
97+
}
98+
7499
}

example/src/main/resources/application-dev.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ web-eid-auth-token:
33
use-digi-doc4j-prod-configuration: false
44
local-origin: "https://test.web-eid.eu"
55
web-eid-mobile:
6+
enabled: true
67
base-request-uri: "web-eid-mobile://"
78
request-signing-cert: false

example/src/main/resources/templates/index.html

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ <h4>Table of contents</h4>
6262
<li><a href="#for-developers">For developers</a></li>
6363
</ul>
6464
</li>
65-
<li>
65+
<li th:if="${@environment.getProperty('web-eid-mobile.enabled')}">
6666
<a href="#usage-without-plugin">Usage without Web eID plugin</a>
6767
<ul>
6868
<li><a href="#documentation-mobile">Documentation</a></li>
@@ -427,51 +427,53 @@ <h4 class="accordion-header" id="headingDevelopers">
427427
</div>
428428
</div>
429429

430-
<hr />
431-
<h3><a id="usage-without-plugin"></a>Usage without Web eID plugin</h3>
432-
<p>
433-
The Web eID solution can also be used without installing the Web eID native app and browser
434-
extension. This includes devices like mobile phones, tablets, and some Chromebooks, where the
435-
Web eID plugin cannot currently be installed.
436-
</p>
437-
<p class="text-center p-4">
438-
<button id="webeid-mobile-auth-button" class="btn btn-primary">Authenticate</button>
439-
</p>
440-
441-
<hr />
442-
<div class="accordion accordion-flush" id="accordionMobileInfo">
443-
<div class="accordion-item border-0">
444-
<h4 class="accordion-header" id="headingDocumentationMobile">
445-
<button
446-
class="accordion-button collapsed ps-0"
447-
id="documentation-mobile"
448-
type="button"
449-
data-bs-toggle="collapse"
450-
data-bs-target="#collapseDocumentationMobile"
451-
aria-expanded="false"
452-
aria-controls="collapseDocumentationMobile"
430+
<div th:if="${@environment.getProperty('web-eid-mobile.enabled')}">
431+
<hr />
432+
<h3><a id="usage-without-plugin"></a>Usage without Web eID plugin</h3>
433+
<p>
434+
The Web eID solution can also be used without installing the Web eID native app and browser
435+
extension. This includes devices like mobile phones, tablets, and some Chromebooks, where the
436+
Web eID plugin cannot currently be installed.
437+
</p>
438+
<p class="text-center p-4">
439+
<button id="webeid-mobile-auth-button" class="btn btn-primary">Authenticate</button>
440+
</p>
441+
442+
<hr />
443+
<div class="accordion accordion-flush" id="accordionMobileInfo">
444+
<div class="accordion-item border-0">
445+
<h4 class="accordion-header" id="headingDocumentationMobile">
446+
<button
447+
class="accordion-button collapsed ps-0"
448+
id="documentation-mobile"
449+
type="button"
450+
data-bs-toggle="collapse"
451+
data-bs-target="#collapseDocumentationMobile"
452+
aria-expanded="false"
453+
aria-controls="collapseDocumentationMobile"
454+
>
455+
Documentation
456+
</button>
457+
</h4>
458+
<div
459+
id="collapseDocumentationMobile"
460+
class="accordion-collapse collapse"
461+
aria-labelledby="headingDocumentationMobile"
462+
data-bs-parent="#accordionMobileInfo"
453463
>
454-
Documentation
455-
</button>
456-
</h4>
457-
<div
458-
id="collapseDocumentationMobile"
459-
class="accordion-collapse collapse"
460-
aria-labelledby="headingDocumentationMobile"
461-
data-bs-parent="#accordionMobileInfo"
462-
>
463-
<div class="accordion-body ps-0">
464-
<p>
465-
Technical overview of the solution is available in the project
466-
<a href="https://github.com/web-eid/web-eid-for-mobile-architecture-doc"
467-
>system architecture document</a
468-
>. Overview of authentication token validation implementation in the back end is
469-
available in the <i>web-eid-authtoken-validation-java</i> Java library
470-
<a
471-
href="https://github.com/web-eid/web-eid-authtoken-validation-java#authentication-token-validation"
472-
>README</a
473-
>.
474-
</p>
464+
<div class="accordion-body ps-0">
465+
<p>
466+
Technical overview of the solution is available in the project
467+
<a href="https://github.com/web-eid/web-eid-for-mobile-architecture-doc"
468+
>system architecture document</a
469+
>. Overview of authentication token validation implementation in the back end is
470+
available in the <i>web-eid-authtoken-validation-java</i> Java library
471+
<a
472+
href="https://github.com/web-eid/web-eid-authtoken-validation-java#authentication-token-validation"
473+
>README</a
474+
>.
475+
</p>
476+
</div>
475477
</div>
476478
</div>
477479
</div>

0 commit comments

Comments
 (0)