From d740fa0680c39d2b8a7f94f8d28d4ed225accafb Mon Sep 17 00:00:00 2001 From: Afra Hussaindeen Date: Fri, 17 Jan 2025 07:19:29 +0530 Subject: [PATCH 1/2] Add userId extraction support during self registration. --- .../webapp/self-registration-complete.jsp | 7 +++++ .../main/webapp/self-registration-process.jsp | 26 ++++++++++++++++++- .../resources/web.xml.j2 | 6 +++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/identity-apps-core/apps/recovery-portal/src/main/webapp/self-registration-complete.jsp b/identity-apps-core/apps/recovery-portal/src/main/webapp/self-registration-complete.jsp index 4a75c054034..9d5196347b9 100644 --- a/identity-apps-core/apps/recovery-portal/src/main/webapp/self-registration-complete.jsp +++ b/identity-apps-core/apps/recovery-portal/src/main/webapp/self-registration-complete.jsp @@ -91,6 +91,7 @@ boolean accountVerification = false; Boolean autoLoginEnabled = false; String emailValue = request.getParameter("http://wso2.org/claims/emailaddress"); + boolean isDetailedResponseEnabled = Boolean.parseBoolean(application.getInitParameter("isSelfRegistrationDetailedApiResponseEnabled")); /** * For SaaS application read from user tenant from parameters. @@ -211,8 +212,14 @@ request.getRequestDispatcher("error.jsp").forward(request, response); } } + + String userId = (String) request.getAttribute("userId"); %> +<% if (isDetailedResponseEnabled && StringUtils.isNotBlank(userId)) { %> + +<% } %> + <%-- Data for the layout from the page --%> <% layoutData.put("isResponsePage", true); diff --git a/identity-apps-core/apps/recovery-portal/src/main/webapp/self-registration-process.jsp b/identity-apps-core/apps/recovery-portal/src/main/webapp/self-registration-process.jsp index 8a2f240ca2d..316a9b92eea 100644 --- a/identity-apps-core/apps/recovery-portal/src/main/webapp/self-registration-process.jsp +++ b/identity-apps-core/apps/recovery-portal/src/main/webapp/self-registration-process.jsp @@ -48,6 +48,10 @@ <%@ page import="org.wso2.carbon.identity.core.util.IdentityUtil" %> <%@ page import="javax.servlet.http.Cookie" %> <%@ page import="org.wso2.carbon.identity.mgt.endpoint.util.client.PreferenceRetrievalClientException" %> +<%@ page import="com.google.gson.Gson" %> +<%@ page import="com.google.gson.JsonObject" %> +<%@ page import="org.apache.commons.logging.Log" %> +<%@ page import="org.apache.commons.logging.LogFactory" %> <%-- Localization --%> @@ -59,6 +63,7 @@ <% + Log log = LogFactory.getLog(this.getClass()); String ERROR_MESSAGE = "errorMsg"; String ERROR_CODE = "errorCode"; boolean error = IdentityManagementEndpointUtil.getBooleanValue(request.getAttribute("error")); @@ -95,6 +100,7 @@ boolean skipSignUpEnableCheck = Boolean.parseBoolean(request.getParameter("skipsignupenablecheck")); String policyURL = privacyPolicyURL; String tenantAwareUsername = ""; + boolean isDetailedResponseEnabled = Boolean.parseBoolean(application.getInitParameter("isSelfRegistrationDetailedApiResponseEnabled")); if (error) { request.setAttribute("error", true); @@ -353,7 +359,22 @@ } SelfRegisterApi selfRegisterApi = new SelfRegisterApi(); - selfRegisterApi.mePostCall(selfUserRegistrationRequest, requestHeaders); + String responseContent = selfRegisterApi.mePostCall(selfUserRegistrationRequest, requestHeaders); + + // Extract userId from response if available + String userId = ""; + if (isDetailedResponseEnabled && StringUtils.isNotBlank(responseContent)) { + try { + Gson gson = new Gson(); + JsonObject jsonResponse = gson.fromJson(responseContent, JsonObject.class); + if (jsonResponse.has("userId")) { + userId = jsonResponse.get("userId").getAsString(); + } + } catch (Exception e) { + log.error("Error extracting userId from successful user registration response", e); + } + } + // Add auto login cookie. if (isAutoLoginEnable && !isSelfRegistrationLockOnCreationEnabled) { if (StringUtils.isNotEmpty(user.getRealm())) { @@ -387,6 +408,9 @@ if (StringUtils.isNotBlank(srtenantDomain)) { request.setAttribute("srtenantDomain", srtenantDomain); } + if (isDetailedResponseEnabled && StringUtils.isNotBlank(userId)) { + request.setAttribute("userId", userId); + } request.setAttribute("sessionDataKey", sessionDataKey); request.getRequestDispatcher("self-registration-complete.jsp").forward(request, response); diff --git a/identity-apps-core/features/org.wso2.identity.apps.recovery.portal.server.feature/resources/web.xml.j2 b/identity-apps-core/features/org.wso2.identity.apps.recovery.portal.server.feature/resources/web.xml.j2 index 3a0920d1991..4185636521d 100644 --- a/identity-apps-core/features/org.wso2.identity.apps.recovery.portal.server.feature/resources/web.xml.j2 +++ b/identity-apps-core/features/org.wso2.identity.apps.recovery.portal.server.feature/resources/web.xml.j2 @@ -66,6 +66,12 @@ {{ downtime_banner.enabled }} {% endif %} + {% if identity_mgt.user_self_registration.enable_detailed_api_response is defined %} + + isSelfRegistrationDetailedApiResponseEnabled + {{ identity_mgt.user_self_registration.enable_detailed_api_response }} + + {% endif %} From df64c8e46741ad83103d1fa8b266846a105572ea Mon Sep 17 00:00:00 2001 From: Afra Hussaindeen Date: Sun, 19 Jan 2025 19:04:39 +0530 Subject: [PATCH 2/2] =?UTF-8?q?Add=20changeset=20=F0=9F=A6=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/modern-emus-shake.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/modern-emus-shake.md diff --git a/.changeset/modern-emus-shake.md b/.changeset/modern-emus-shake.md new file mode 100644 index 00000000000..a63daa1e92c --- /dev/null +++ b/.changeset/modern-emus-shake.md @@ -0,0 +1,5 @@ +--- +"@wso2is/identity-apps-core": patch +--- + +Add userId extraction support during self registration