Skip to content

Commit f99a73a

Browse files
Refactor isMultiAuthAvailable method to include current authenticator check
1 parent df19234 commit f99a73a

File tree

11 files changed

+111
-285
lines changed

11 files changed

+111
-285
lines changed

identity-apps-core/apps/authentication-portal/src/main/webapp/emailOtp.jsp

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<%--
2-
~ Copyright (c) 2021-2025, WSO2 LLC. (https://www.wso2.com).
2+
~ Copyright (c) 2021-2026, WSO2 LLC. (https://www.wso2.com).
33
~
44
~ WSO2 LLC. licenses this file to you under the Apache License,
55
~ Version 2.0 (the "License"); you may not use this file except
@@ -28,6 +28,7 @@
2828

2929
<%@ include file="includes/localize.jsp" %>
3030
<%@ include file="includes/init-url.jsp" %>
31+
<%@ include file="util/authenticator-utils.jsp" %>
3132

3233
<%
3334
// Add the email-otp screen to the list to retrieve text branding customizations.
@@ -37,33 +38,6 @@
3738
<%-- Branding Preferences --%>
3839
<jsp:directive.include file="includes/branding-preferences.jsp"/>
3940

40-
<%!
41-
private boolean isMultiAuthAvailable(String multiOptionURI) {
42-
43-
boolean isMultiAuthAvailable = true;
44-
if (multiOptionURI == null || multiOptionURI.equals("null")) {
45-
isMultiAuthAvailable = false;
46-
} else {
47-
int authenticatorIndex = multiOptionURI.indexOf("authenticators=");
48-
if (authenticatorIndex == -1) {
49-
isMultiAuthAvailable = false;
50-
} else {
51-
String authenticators = multiOptionURI.substring(authenticatorIndex + 15);
52-
int authLastIndex = authenticators.indexOf("&") != -1 ? authenticators.indexOf("&") : authenticators.length();
53-
authenticators = authenticators.substring(0, authLastIndex);
54-
List<String> authList = Arrays.asList(authenticators.split("%3B"));
55-
if (authList.size() < 2) {
56-
isMultiAuthAvailable = false;
57-
}
58-
else if (authList.size() == 2 && authList.contains("backup-code-authenticator%3ALOCAL")) {
59-
isMultiAuthAvailable = false;
60-
}
61-
}
62-
}
63-
return isMultiAuthAvailable;
64-
}
65-
%>
66-
6741
<%
6842
request.getSession().invalidate();
6943
String queryString = request.getQueryString();
@@ -305,7 +279,7 @@
305279
<%
306280
String multiOptionURI = request.getParameter("multiOptionURI");
307281
if (multiOptionURI != null && AuthenticationEndpointUtil.isValidMultiOptionURI(multiOptionURI) &&
308-
isMultiAuthAvailable(multiOptionURI)) {
282+
isMultiAuthAvailable(multiOptionURI, request.getParameter("authenticators"))) {
309283
%>
310284
<a class="ui primary basic button link-button" id="goBackLink"
311285
href='<%=Encode.forHtmlAttribute(multiOptionURI)%>'>

identity-apps-core/apps/authentication-portal/src/main/webapp/enableTOTP.jsp

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<%@ taglib prefix="layout" uri="org.wso2.identity.apps.taglibs.layout.controller" %>
3131
<%@ include file="includes/localize.jsp" %>
3232
<jsp:directive.include file="includes/init-url.jsp"/>
33+
<%@ include file="util/authenticator-utils.jsp" %>
3334

3435
<%-- Branding Preferences --%>
3536
<jsp:directive.include file="includes/branding-preferences.jsp"/>
@@ -60,33 +61,6 @@
6061
}
6162
%>
6263

63-
<%!
64-
private boolean isMultiAuthAvailable(String multiOptionURI) {
65-
66-
boolean isMultiAuthAvailable = true;
67-
if (multiOptionURI == null || multiOptionURI.equals("null")) {
68-
isMultiAuthAvailable = false;
69-
} else {
70-
int authenticatorIndex = multiOptionURI.indexOf("authenticators=");
71-
if (authenticatorIndex == -1) {
72-
isMultiAuthAvailable = false;
73-
} else {
74-
String authenticators = multiOptionURI.substring(authenticatorIndex + 15);
75-
int authLastIndex = authenticators.indexOf("&") != -1 ? authenticators.indexOf("&") : authenticators.length();
76-
authenticators = authenticators.substring(0, authLastIndex);
77-
List<String> authList = Arrays.asList(authenticators.split("%3B"));
78-
if (authList.size() < 2) {
79-
isMultiAuthAvailable = false;
80-
}
81-
else if (authList.size() == 2 && authList.contains("backup-code-authenticator%3ALOCAL")) {
82-
isMultiAuthAvailable = false;
83-
}
84-
}
85-
}
86-
return isMultiAuthAvailable;
87-
}
88-
%>
89-
9064
<% request.setAttribute("pageName", "enable-totp"); %>
9165

9266
<html lang="en-US">
@@ -222,7 +196,7 @@
222196
String multiOptionURI = request.getParameter("multiOptionURI");
223197
if (multiOptionURI != null &&
224198
AuthenticationEndpointUtil.isValidMultiOptionURI(multiOptionURI) &&
225-
isMultiAuthAvailable(multiOptionURI)) {
199+
isMultiAuthAvailable(multiOptionURI, request.getParameter("authenticators"))) {
226200
%>
227201
<a
228202
class="ui primary basic button link-button"

identity-apps-core/apps/authentication-portal/src/main/webapp/fido2-auth.jsp

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<%--
2-
~ Copyright (c) 2019-2025, WSO2 LLC. (https://www.wso2.com).
2+
~ Copyright (c) 2019-2026, WSO2 LLC. (https://www.wso2.com).
33
~
44
~ WSO2 LLC. licenses this file to you under the Apache License,
55
~ Version 2.0 (the "License"); you may not use this file except
@@ -31,32 +31,7 @@
3131

3232
<%@include file="includes/localize.jsp" %>
3333
<%@include file="includes/init-url.jsp" %>
34-
35-
<%!
36-
private boolean isMultiAuthAvailable(String multiOptionURI) {
37-
38-
boolean isMultiAuthAvailable = true;
39-
if (multiOptionURI == null || multiOptionURI.equals("null")) {
40-
isMultiAuthAvailable = false;
41-
} else {
42-
int authenticatorIndex = multiOptionURI.indexOf("authenticators=");
43-
if (authenticatorIndex == -1) {
44-
isMultiAuthAvailable = false;
45-
} else {
46-
String authenticators = multiOptionURI.substring(authenticatorIndex + 15);
47-
int authLastIndex = authenticators.indexOf("&") != -1 ? authenticators.indexOf("&") : authenticators.length();
48-
authenticators = authenticators.substring(0, authLastIndex);
49-
List<String> authList = Arrays.asList(authenticators.split("%3B"));
50-
if (authList.size() < 2) {
51-
isMultiAuthAvailable = false;
52-
} else if (authList.size() == 2 && authList.contains("backup-code-authenticator%3ALOCAL")) {
53-
isMultiAuthAvailable = false;
54-
}
55-
}
56-
}
57-
return isMultiAuthAvailable;
58-
}
59-
%>
34+
<%@include file="util/authenticator-utils.jsp" %>
6035

6136
<%
6237
String authRequest = Encode.forJavaScriptBlock(request.getParameter("data"));
@@ -181,7 +156,7 @@
181156
<%
182157
String multiOptionURI = Encode.forJava(request.getParameter("multiOptionURI"));
183158
if (multiOptionURI != null && AuthenticationEndpointUtil.isValidMultiOptionURI(multiOptionURI) &&
184-
isMultiAuthAvailable(multiOptionURI)) {
159+
isMultiAuthAvailable(multiOptionURI, request.getParameter("authenticators"))) {
185160
%>
186161
<div class="text-center mt-1">
187162
<a

identity-apps-core/apps/authentication-portal/src/main/webapp/fido2-identifierfirst.jsp

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<%--
2-
~ Copyright (c) 2023-2025, WSO2 LLC. (https://www.wso2.com).
2+
~ Copyright (c) 2023-2026, WSO2 LLC. (https://www.wso2.com).
33
~
44
~ WSO2 LLC. licenses this file to you under the Apache License,
55
~ Version 2.0 (the "License"); you may not use this file except
@@ -31,32 +31,7 @@
3131

3232
<%@include file="includes/localize.jsp" %>
3333
<%@include file="includes/init-url.jsp" %>
34-
35-
<%!
36-
private boolean isMultiAuthAvailable(String multiOptionURI) {
37-
38-
boolean isMultiAuthAvailable = true;
39-
if (multiOptionURI == null || multiOptionURI.equals("null")) {
40-
isMultiAuthAvailable = false;
41-
} else {
42-
int authenticatorIndex = multiOptionURI.indexOf("authenticators=");
43-
if (authenticatorIndex == -1) {
44-
isMultiAuthAvailable = false;
45-
} else {
46-
String authenticators = multiOptionURI.substring(authenticatorIndex + 15);
47-
int authLastIndex = authenticators.indexOf("&") != -1 ? authenticators.indexOf("&") : authenticators.length();
48-
authenticators = authenticators.substring(0, authLastIndex);
49-
List<String> authList = Arrays.asList(authenticators.split("%3B"));
50-
if (authList.size() < 2) {
51-
isMultiAuthAvailable = false;
52-
} else if (authList.size() == 2 && authList.contains("backup-code-authenticator%3ALOCAL")) {
53-
isMultiAuthAvailable = false;
54-
}
55-
}
56-
}
57-
return isMultiAuthAvailable;
58-
}
59-
%>
34+
<%@include file="util/authenticator-utils.jsp" %>
6035

6136
<%
6237
Map data = ((AuthenticationRequestWrapper) request).getAuthParams();
@@ -179,7 +154,7 @@
179154
<%
180155
String multiOptionURI = request.getParameter("multiOptionURI");
181156
if (multiOptionURI != null && AuthenticationEndpointUtil.isValidMultiOptionURI(multiOptionURI) &&
182-
isMultiAuthAvailable(multiOptionURI)) {
157+
isMultiAuthAvailable(multiOptionURI, request.getParameter("authenticators"))) {
183158
%>
184159
<a
185160
class="ui primary basic button link-button"

identity-apps-core/apps/authentication-portal/src/main/webapp/identifierauth.jsp

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<%--
2-
~ Copyright (c) 2021-2025, WSO2 LLC. (https://www.wso2.com).
2+
~ Copyright (c) 2021-2026, WSO2 LLC. (https://www.wso2.com).
33
~
44
~ WSO2 LLC. licenses this file to you under the Apache License,
55
~ Version 2.0 (the "License"); you may not use this file except
@@ -42,33 +42,7 @@
4242
<%@ page import="org.json.JSONObject" %>
4343

4444
<jsp:directive.include file="includes/init-loginform-action-url.jsp"/>
45-
46-
<%!
47-
private boolean isMultiAuthAvailable(String multiOptionURI) {
48-
49-
boolean isMultiAuthAvailable = true;
50-
if (multiOptionURI == null || multiOptionURI.equals("null")) {
51-
isMultiAuthAvailable = false;
52-
} else {
53-
int authenticatorIndex = multiOptionURI.indexOf("authenticators=");
54-
if (authenticatorIndex == -1) {
55-
isMultiAuthAvailable = false;
56-
} else {
57-
String authenticators = multiOptionURI.substring(authenticatorIndex + 15);
58-
int authLastIndex = authenticators.indexOf("&") != -1 ? authenticators.indexOf("&") : authenticators.length();
59-
authenticators = authenticators.substring(0, authLastIndex);
60-
List<String> authList = Arrays.asList(authenticators.split("%3B"));
61-
if (authList.size() < 2) {
62-
isMultiAuthAvailable = false;
63-
}
64-
else if (authList.size() == 2 && authList.contains("backup-code-authenticator%3ALOCAL")) {
65-
isMultiAuthAvailable = false;
66-
}
67-
}
68-
}
69-
return isMultiAuthAvailable;
70-
}
71-
%>
45+
<%@ include file="util/authenticator-utils.jsp" %>
7246

7347
<%
7448
String emailUsernameEnable = application.getInitParameter("EnableEmailUserName");

identity-apps-core/apps/authentication-portal/src/main/webapp/pushAuth.jsp

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<%--
2-
~ Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
2+
~ Copyright (c) 2025-2026, WSO2 LLC. (https://www.wso2.com).
33
~
44
~ WSO2 LLC. licenses this file to you under the Apache License,
55
~ Version 2.0 (the "License"); you may not use this file except
@@ -34,6 +34,7 @@
3434

3535
<%@ include file="includes/localize.jsp" %>
3636
<%@ include file="includes/init-url.jsp" %>
37+
<%@ include file="util/authenticator-utils.jsp" %>
3738

3839
<%
3940
// Add the push-auth screen to the list to retrieve text branding customizations.
@@ -216,7 +217,7 @@
216217

217218
<%
218219
String multiOptionURI = request.getParameter("multiOptionURI");
219-
if (isMultiAuthAvailable(multiOptionURI) && AuthenticationEndpointUtil.isValidMultiOptionURI(multiOptionURI)) {
220+
if (multiOptionURI != null && AuthenticationEndpointUtil.isValidMultiOptionURI(multiOptionURI) && isMultiAuthAvailable(multiOptionURI, request.getParameter("authenticators"))) {
220221
%>
221222
<div class="ui divider hidden"></div>
222223
<a
@@ -346,32 +347,5 @@
346347
347348
</script>
348349

349-
<%!
350-
private boolean isMultiAuthAvailable(String multiOptionURI) {
351-
352-
boolean isMultiAuthAvailable = true;
353-
if (multiOptionURI == null || multiOptionURI.equals("null")) {
354-
isMultiAuthAvailable = false;
355-
} else {
356-
int authenticatorIndex = multiOptionURI.indexOf("authenticators=");
357-
if (authenticatorIndex == -1) {
358-
isMultiAuthAvailable = false;
359-
} else {
360-
String authenticators = multiOptionURI.substring(authenticatorIndex + 15);
361-
int authLastIndex = authenticators.indexOf("&") != -1 ? authenticators.indexOf("&") : authenticators.length();
362-
authenticators = authenticators.substring(0, authLastIndex);
363-
List<String> authList = Arrays.asList(authenticators.split("%3B"));
364-
if (authList.size() < 2) {
365-
isMultiAuthAvailable = false;
366-
}
367-
else if (authList.size() == 2 && authList.contains("backup-code-authenticator%3ALOCAL")) {
368-
isMultiAuthAvailable = false;
369-
}
370-
}
371-
}
372-
return isMultiAuthAvailable;
373-
}
374-
%>
375-
376350
</body>
377351
</html>

identity-apps-core/apps/authentication-portal/src/main/webapp/pushDeviceEnrollConsent.jsp

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<%--
2-
~ Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
2+
~ Copyright (c) 2025-2026, WSO2 LLC. (https://www.wso2.com).
33
~
44
~ WSO2 LLC. licenses this file to you under the Apache License,
55
~ Version 2.0 (the "License"); you may not use this file except
@@ -34,36 +34,11 @@
3434

3535
<%@ include file="includes/localize.jsp" %>
3636
<%@ include file="includes/init-url.jsp" %>
37+
<%@ include file="util/authenticator-utils.jsp" %>
3738

3839
<%-- Branding Preferences --%>
3940
<jsp:directive.include file="includes/branding-preferences.jsp"/>
4041

41-
<%!
42-
private boolean isMultiAuthAvailable(String multiOptionURI) {
43-
44-
boolean isMultiAuthAvailable = true;
45-
if (multiOptionURI == null || multiOptionURI.equals("null")) {
46-
isMultiAuthAvailable = false;
47-
} else {
48-
int authenticatorIndex = multiOptionURI.indexOf("authenticators=");
49-
if (authenticatorIndex == -1) {
50-
isMultiAuthAvailable = false;
51-
} else {
52-
String authenticators = multiOptionURI.substring(authenticatorIndex + 15);
53-
int authLastIndex = authenticators.indexOf("&") != -1 ? authenticators.indexOf("&") : authenticators.length();
54-
authenticators = authenticators.substring(0, authLastIndex);
55-
List<String> authList = Arrays.asList(authenticators.split("%3B"));
56-
if (authList.size() < 2) {
57-
isMultiAuthAvailable = false;
58-
} else if (authList.size() == 2 && authList.contains("backup-code-authenticator%3ALOCAL")) {
59-
isMultiAuthAvailable = false;
60-
}
61-
}
62-
}
63-
return isMultiAuthAvailable;
64-
}
65-
%>
66-
6742
<%
6843
request.getSession().invalidate();
6944
String queryString = request.getQueryString();
@@ -164,7 +139,7 @@
164139
</button>
165140
<%
166141
String multiOptionURI = request.getParameter("multiOptionURI");
167-
if (isMultiAuthAvailable(multiOptionURI) && AuthenticationEndpointUtil.isSchemeSafeURL(multiOptionURI)) {
142+
if (multiOptionURI != null && AuthenticationEndpointUtil.isSchemeSafeURL(multiOptionURI) && isMultiAuthAvailable(multiOptionURI, request.getParameter("authenticators"))) {
168143
%>
169144
<div class="ui divider hidden"></div>
170145
<a

0 commit comments

Comments
 (0)