Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add userId extraction support during self registration. #7314

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -211,8 +212,14 @@
request.getRequestDispatcher("error.jsp").forward(request, response);
}
}

String userId = (String) request.getAttribute("userId");
%>

<% if (isDetailedResponseEnabled && StringUtils.isNotBlank(userId)) { %>
<input type="hidden" id="userId" name="userId" value="<%= Encode.forHtmlAttribute(userId) %>" />
<% } %>

<%-- 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 @@ -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 --%>
<jsp:directive.include file="includes/localize.jsp"/>
Expand All @@ -59,6 +63,7 @@
<jsp:directive.include file="includes/branding-preferences.jsp"/>

<%
Log log = LogFactory.getLog(this.getClass());
String ERROR_MESSAGE = "errorMsg";
String ERROR_CODE = "errorCode";
boolean error = IdentityManagementEndpointUtil.getBooleanValue(request.getAttribute("error"));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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())) {
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
<param-value>{{ downtime_banner.enabled }}</param-value>
</context-param>
{% endif %}
{% if identity_mgt.user_self_registration.enable_detailed_api_response is defined %}
<context-param>
<param-name>isSelfRegistrationDetailedApiResponseEnabled</param-name>
<param-value>{{ identity_mgt.user_self_registration.enable_detailed_api_response }}</param-value>
</context-param>
{% endif %}
<!-- *************** End of Global configurations ********************** -->
<!-- End of Custom Page configurations -->
<context-param>
Expand Down
Loading