Skip to content

Commit

Permalink
Merge pull request #7027 from DilshanSenarath/issue-21352
Browse files Browse the repository at this point in the history
Enhance the performance of the JSP pages
  • Loading branch information
DilshanSenarath authored Oct 24, 2024
2 parents c5a512a + 905abd6 commit a4883fc
Show file tree
Hide file tree
Showing 34 changed files with 237 additions and 101 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-ligers-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wso2is/identity-apps-core": patch
---

Enhance the performance of the JSP pages
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,14 @@
--%>

<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="org.owasp.encoder.Encode" %>
<%@ page import="org.wso2.carbon.identity.application.authentication.endpoint.util.AuthenticationEndpointUtil" %>
<%@ page import="org.wso2.carbon.identity.application.authentication.endpoint.util.EncodedControl" %>
<%@ page import="org.wso2.carbon.identity.application.authentication.endpoint.util.Constants" %>
<%@ page import="org.wso2.carbon.identity.challenge.questions.ui.IdentityManagementAdminClient" %>
<%@ page import="org.wso2.carbon.identity.challenge.questions.recovery.model.ChallengeQuestion" %>
<%@ page import="org.wso2.carbon.utils.ServerConstants" %>
<%@ page import="org.wso2.carbon.CarbonConstants" %>
<%@ page import="java.nio.charset.StandardCharsets" %>
<%@ page import="java.util.ResourceBundle" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.io.File" %>
<%@ taglib prefix="layout" uri="org.wso2.identity.apps.taglibs.layout.controller" %>
<%@ include file="includes/localize.jsp" %>

<%-- Include tenant context --%>
<jsp:directive.include file="includes/init-url.jsp"/>
Expand All @@ -42,9 +33,6 @@
<jsp:directive.include file="includes/branding-preferences.jsp"/>

<%
String BUNDLE = "org.wso2.carbon.identity.application.authentication.endpoint.i18n.Resources";
ResourceBundle resourceBundle = ResourceBundle.getBundle(BUNDLE, request.getLocale(), new
EncodedControl(StandardCharsets.UTF_8.toString()));
String urlData = request.getParameter("data");
// Extract the challenge questions from the request and add them into an array
String[] questionSets = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
<%@ page import="org.apache.commons.text.StringEscapeUtils" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="layout" uri="org.wso2.identity.apps.taglibs.layout.controller" %>
<%@ include file="includes/localize.jsp" %>

<%-- Include tenant context --%>
<jsp:directive.include file="includes/init-url.jsp"/>

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

<%@include file="includes/localize.jsp" %>

<%-- Data for the layout from the page --%>
<%
layoutData.put("isResponsePage", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
<%@ include file="includes/localize.jsp" %>
<%@ include file="includes/init-url.jsp" %>

<%
// Add the email-otp screen to the list to retrieve text branding customizations.
screenNames.add("email-otp");
%>

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@
String poweredByLogoURL = "";
String productWhiteLogoAlt = "WSO2 Identity Server Logo White Variation";
boolean enableDefaultPreLoader = true;
String[] screenNames = {"common", "login", "email-otp", "sms-otp", "email-otp", "totp"};
final String BRANDING_PREFERENCE_CACHE_KEY = "BrandingPreferenceCache";
final String BRANDING_TEXT_PREFERENCE_CACHE_KEY = "BrandingTextPreferenceCache";
// Constants used to create full custom layout name
String PREFIX_FOR_CUSTOM_LAYOUT_NAME = "custom";
Expand Down Expand Up @@ -423,8 +425,18 @@
}
BrandingPreferenceRetrievalClient brandingPreferenceRetrievalClient = new BrandingPreferenceRetrievalClient();
JSONObject brandingPreferenceResponse = brandingPreferenceRetrievalClient.getPreference(tenantRequestingPreferences,
JSONObject brandingPreferenceResponse = null;
Object cachedBrandingPreferenceResponse = request.getAttribute(BRANDING_PREFERENCE_CACHE_KEY);
if (cachedBrandingPreferenceResponse != null && cachedBrandingPreferenceResponse instanceof BrandingPreferenceRetrievalClientException) {
throw (BrandingPreferenceRetrievalClientException) cachedBrandingPreferenceResponse;
} else {
brandingPreferenceResponse = (JSONObject) cachedBrandingPreferenceResponse;
}
if (brandingPreferenceResponse == null) {
brandingPreferenceResponse = brandingPreferenceRetrievalClient.getPreference(tenantRequestingPreferences,
preferenceResourceType, applicationRequestingPreferences, DEFAULT_RESOURCE_LOCALE);
request.setAttribute(BRANDING_PREFERENCE_CACHE_KEY, brandingPreferenceResponse);
}
if (brandingPreferenceResponse.has(PREFERENCE_KEY)) {
brandingPreference = brandingPreferenceResponse.getJSONObject(PREFERENCE_KEY);
Expand All @@ -450,13 +462,20 @@
if (isBrandingEnabledInTenantPreferences) {
// Custom Text
for (String screenName : screenNames) {
JSONObject customTextPreferenceResponse = brandingPreferenceRetrievalClient.getCustomTextPreference(
tenantRequestingPreferences,
preferenceResourceType,
applicationRequestingPreferences,
screenName,
locale
);
StringBuilder textBrandingCacheKey = new StringBuilder(BRANDING_TEXT_PREFERENCE_CACHE_KEY);
textBrandingCacheKey.append("-");
textBrandingCacheKey.append(screenName);
JSONObject customTextPreferenceResponse = (JSONObject) request.getAttribute(textBrandingCacheKey.toString());
if (customTextPreferenceResponse == null) {
customTextPreferenceResponse = brandingPreferenceRetrievalClient.getCustomTextPreference(
tenantRequestingPreferences,
preferenceResourceType,
applicationRequestingPreferences,
screenName,
locale
);
request.setAttribute(textBrandingCacheKey.toString(), customTextPreferenceResponse);
}
// Merge the preferences for the current screen into the customText object
if (customTextPreferenceResponse.has(PREFERENCE_KEY)) {
Expand Down Expand Up @@ -646,6 +665,7 @@
} catch (BrandingPreferenceRetrievalClientException e) {
// Exception is ignored and the variable will use the fallbacks.
// TODO: Move the duplicated logic to a common place.
request.setAttribute(BRANDING_PREFERENCE_CACHE_KEY, e);
} finally {
// Set fallbacks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
<%-- Include tenant context --%>
<jsp:directive.include file="./init-url.jsp"/>

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

<%-- Localization --%>
<jsp:directive.include file="./localize.jsp" />

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

<%
if (!StringUtils.isBlank(cookiePolicyURL)) {
%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
String uiLocaleFromURL = request.getParameter("ui_locales");
String localeFromCookie = null;
String BUNDLE = "org.wso2.carbon.identity.application.authentication.endpoint.i18n.Resources";
// List of screen names for retrieving text branding customizations.
List<String> screenNames = new ArrayList<>();
screenNames.add("common");
// Map to store default supported language codes.
// TODO: Use this map to generate the `language-switcher.jsp`.
Map<String, String> supportedLanguages = new HashMap<>();
Expand Down Expand Up @@ -230,7 +234,7 @@
String COUNTRY_PLACEHOLDER = "{{country}}";
String LOCALE_PLACEHOLDER = "{{locale}}";
if (transformedLink.contains(LANGUAGE_PLACEHOLDER) || transformedLink.contains(COUNTRY_PLACEHOLDER) || transformedLink.contains(LOCALE_PLACEHOLDER)) {
if (transformedLink.contains(LANGUAGE_PLACEHOLDER) || transformedLink.contains(COUNTRY_PLACEHOLDER) || transformedLink.contains(LOCALE_PLACEHOLDER)) {
transformedLink = transformedLink
.replace("{{lang}}", langCode)
.replace("{{country}}", countryCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
<%-- Include tenant context --%>
<jsp:directive.include file="init-url.jsp"/>

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

<%-- Localization --%>
<jsp:directive.include file="localize.jsp" />

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

<%-- Cookie Consent Banner --%>
<%
if (config.getServletContext().getResource("extensions/cookie-consent-banner.jsp") != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<%-- Include tenant context --%>
<jsp:directive.include file="init-url.jsp"/>

<%-- Localization --%>
<jsp:directive.include file="localize.jsp" />

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<%-- Include tenant context --%>
<jsp:directive.include file="init-url.jsp"/>

<%-- Localization --%>
<jsp:directive.include file="localize.jsp" />

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

Expand Down Expand Up @@ -1128,7 +1131,7 @@
.tabs.resource-tabs>.ui.menu .item.active {
border-bottom-color: var(--asg-colors-primary-main);
color: var(--asg-colors-primary-main);
}
}
.tabs.resource-tabs>.ui.menu:not(.secondary) .item.active {
border-bottom-color: var(--asg-colors-primary-main);
Expand All @@ -1142,7 +1145,7 @@
color: var(--asg-colors-primary-main);
}
/*-----------------------------
Step Indicator
Step Indicator
------------------------------*/
.steps .step.active {
Expand Down Expand Up @@ -1208,25 +1211,25 @@
color: var(--asg-colors-primary-main) !important;
box-shadow: inset 0 0 0 1px var(--asg-colors-primary-main) !important;
filter: brightness(0.85);
}
}
.ui.basic.primary.button:focus,.ui.basic.primary.buttons .button:focus {
background: 0 0!important;
box-shadow: inset 0 0 0 1px var(--asg-colors-primary-main) !important;
color: var(--asg-colors-primary-main) !important
}
.ui.basic.primary.active.button,.ui.basic.primary.buttons .active.button {
background: 0 0!important;
box-shadow: inset 0 0 0 1px var(--asg-colors-primary-main) !important;
color: var(--asg-colors-primary-main) !important
}
.ui.basic.primary.button:active,.ui.basic.primary.buttons .button:active {
box-shadow: inset 0 0 0 1px var(--asg-colors-primary-main) !important;
color: var(--asg-colors-primary-main) !important
}
/* Link Button:Hover */
.ui.button.basic.link-button,.ui.button.basic.link-button.primary {
box-shadow: none!important
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
<%-- Include tenant context --%>
<jsp:directive.include file="includes/init-url.jsp"/>

<%
// Add the login screen to the list to retrieve text branding customizations.
screenNames.add("login");
%>

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

Expand Down Expand Up @@ -170,7 +175,7 @@
boolean hasLocalLoginOptions = false;
boolean isBackChannelBasicAuth = false;
List<String> localAuthenticatorNames = new ArrayList<String>();
List<String> registeredLocalAuthenticators = Arrays.asList(
List<String> registeredLocalAuthenticators = Arrays.asList(
BACKUP_CODE_AUTHENTICATOR, TOTP_AUTHENTICATOR, EMAIL_OTP_AUTHENTICATOR,
MAGIC_LINK_AUTHENTICATOR,SMS_OTP_AUTHENTICATOR,OPEN_ID_AUTHENTICATOR,
IDENTIFIER_EXECUTOR,JWT_BASIC_AUTHENTICATOR,BASIC_AUTHENTICATOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
// The `request` object contains the tenantDomain, which can be directly provided to the init-url.jsp code.
%>

<%-- Localization --%>
<jsp:directive.include file="includes/localize.jsp" />

<%-- Include tenant context --%>
<jsp:directive.include file="includes/init-url.jsp"/>

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

<%-- Localization --%>
<jsp:directive.include file="includes/localize.jsp" />

<%!
<%!
private static final String AUTHENTICATION_ENDPOINT = "/authenticationendpoint";
private static final String CONSOLE_APP_NAME = "Console";
%>
Expand Down Expand Up @@ -205,7 +205,7 @@
box-shadow: 0 0 0 1px transparent;
top: 0;
left: 0;
}
}
.trifacta-pre-loader {
margin-top: 41px;
Expand Down Expand Up @@ -524,8 +524,8 @@
</g>
</svg>
</div>
<%
} else {
<%
} else {
if (!StringUtils.startsWith(logoURL, "http")) {
logoURL = ServiceURLBuilder.create().addPath(AUTHENTICATION_ENDPOINT + "/" + logoURL).build().getAbsolutePublicURL();
}
Expand All @@ -536,7 +536,7 @@
<div class="ui loader"></div>
</div>
</div>
<% } %>
<% } %>
</div>
<p class="message-description">
<a class="primary-color-btn button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
<%@ include file="includes/localize.jsp" %>
<%@ include file="includes/init-url.jsp" %>

<%
// Add the sms-otp screen to the list to retrieve text branding customizations.
screenNames.add("sms-otp");
%>

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<%@ include file="includes/localize.jsp" %>
<jsp:directive.include file="includes/init-url.jsp"/>

<%
// Add the totp screen to the list to retrieve text branding customizations.
screenNames.add("totp");
%>

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
<%-- Include tenant context --%>
<jsp:directive.include file="tenant-resolve.jsp"/>

<%
// Add the email-link-expiry screen to the list to retrieve text branding customizations.
screenNames.add("email-link-expiry");
%>

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

Expand Down
Loading

0 comments on commit a4883fc

Please sign in to comment.