Skip to content

Commit d31d867

Browse files
committed
Fix error codes and login processing url
1 parent cde3de3 commit d31d867

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public SecurityFilterChain filterChain(
6060
.authenticationProvider(authTokenDTOAuthenticationProvider)
6161
.addFilterBefore(new WebEidMobileAuthInitFilter("/auth/mobile/init", "/auth/mobile/login", challengeNonceGenerator), UsernamePasswordAuthenticationFilter.class)
6262
.addFilterBefore(new WebEidChallengeNonceFilter("/auth/challenge", challengeNonceGenerator), UsernamePasswordAuthenticationFilter.class)
63-
.addFilterBefore(new WebEidLoginPageGeneratingFilter("/auth/mobile/login"), UsernamePasswordAuthenticationFilter.class)
63+
.addFilterBefore(new WebEidLoginPageGeneratingFilter("/auth/mobile/login", "/auth/login"), UsernamePasswordAuthenticationFilter.class)
6464
.addFilterBefore(new WebEidAjaxLoginProcessingFilter("/auth/login", authConfig.getAuthenticationManager()), UsernamePasswordAuthenticationFilter.class)
6565
.logout(l -> l.logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler()))
6666
.headers(h -> h.frameOptions(HeadersConfigurer.FrameOptionsConfig::sameOrigin))

example/src/main/java/eu/webeid/example/security/ui/WebEidLoginPageGeneratingFilter.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,26 @@ public final class WebEidLoginPageGeneratingFilter extends OncePerRequestFilter
5454
import { showErrorMessage } from "/js/errors.js";
5555
(function () {
5656
const frag = location.hash ? location.hash.substring(1) : "";
57-
if (!frag) { showErrorMessage({ code: "MISSING_PAYLOAD", message: "Missing payload" }); return; }
57+
if (!frag) { showErrorMessage({ code: "UNKNOWN_ERROR", message: "Missing authentication payload" }); return; }
5858
5959
let payload;
6060
try { payload = JSON.parse(atob(frag)); } catch (e) {
6161
console.error("Failed to parse payload", e);
62-
showErrorMessage({ code: "BAD_PAYLOAD", message: "Failed to parse mobile payload" });
62+
showErrorMessage({ code: "UNKNOWN_ERROR", message: "Failed to parse authentication payload" });
6363
return;
6464
}
6565
6666
if (payload["error"]) {
6767
showErrorMessage({
68-
code: payload["code"] ?? "MOPP_ERROR",
69-
message: payload["message"] ?? "Authentication failed in mobile app"
68+
code: payload["code"] ?? "UNKNOWN_ERROR",
69+
message: payload["message"] ?? "Authentication failed"
7070
});
7171
return;
7272
}
7373
74-
const authToken = payload["auth-token"] ?? payload;
74+
const authToken = payload["auth-token"];
7575
76-
fetch("/auth/login", {
76+
fetch("%s", {
7777
method: "POST",
7878
headers: {
7979
"Content-Type": "application/json",
@@ -86,20 +86,20 @@ public final class WebEidLoginPageGeneratingFilter extends OncePerRequestFilter
8686
if (!r.ok) throw new Error("HTTP " + r.status);
8787
window.location.replace("/welcome");
8888
})
89-
.catch(e => {
90-
console.error("Login failed", e);
91-
showErrorMessage({ code: "LOGIN_FAILED", message: e.message });
89+
.catch(error => {
90+
showErrorMessage(error);
9291
});
9392
})();
9493
</script>
95-
Signing you in…
9694
</body>
9795
</html>
9896
""";
9997
private final RequestMatcher requestMatcher;
98+
private final String loginProcessingPath;
10099

101-
public WebEidLoginPageGeneratingFilter(String path) {
100+
public WebEidLoginPageGeneratingFilter(String path, String loginProcessingPath) {
102101
this.requestMatcher = PathPatternRequestMatcher.withDefaults().matcher(HttpMethod.GET, path);
102+
this.loginProcessingPath = loginProcessingPath;
103103
}
104104

105105
@Override
@@ -124,6 +124,7 @@ protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull Ht
124124
private String generateHtml(CsrfToken csrf) {
125125
return String.format(
126126
LOGIN_PAGE_HTML,
127+
loginProcessingPath,
127128
csrf != null ? csrf.getHeaderName() : "X-CSRF-TOKEN",
128129
csrf != null ? csrf.getToken() : ""
129130
);

0 commit comments

Comments
 (0)