Skip to content

Commit 4ee25e5

Browse files
committed
Handle pre add user event
1 parent 0cc99eb commit 4ee25e5

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

components/org.wso2.carbon.user.mgt.workflow/src/main/java/org/wso2/carbon/user/mgt/workflow/userstore/UserStoreActionListener.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.apache.commons.logging.LogFactory;
2424
import org.wso2.carbon.context.PrivilegedCarbonContext;
2525
import org.wso2.carbon.identity.core.AbstractIdentityUserOperationEventListener;
26+
import org.wso2.carbon.identity.core.context.IdentityContext;
27+
import org.wso2.carbon.identity.core.context.model.Flow;
2628
import org.wso2.carbon.identity.core.model.IdentityEventListenerConfig;
2729
import org.wso2.carbon.identity.core.util.IdentityCoreConstants;
2830
import org.wso2.carbon.identity.core.util.IdentityUtil;
@@ -100,12 +102,23 @@ public int getExecutionOrderId() {
100102
public boolean doPreAddUser(String userName, Object credential, String[] roleList, Map<String, String> claims,
101103
String profile, UserStoreManager userStoreManager) throws UserStoreException {
102104

103-
if (!isEnable() || isCalledViaIdentityMgtListners()
104-
|| !isEventAssociatedWithWorkflow(UserStoreWFConstants.ADD_USER_EVENT) || isJITProvisioningFlow()
105+
if (!isEnable() || isCalledViaIdentityMgtListners() || isJITProvisioningFlow()
105106
|| UserStoreWFUtils.isAgentUserStore(userStoreManager)) {
106107
return true;
107108
}
108109

110+
Flow flow = IdentityContext.getThreadLocalIdentityContext().getCurrentFlow();
111+
String eventType = UserStoreWFConstants.ADD_USER_EVENT;
112+
if (flow != null && Flow.Name.REGISTER.equals(flow.getName()) &&
113+
Flow.InitiatingPersona.USER.equals(flow.getInitiatingPersona())) {
114+
log.debug("User self registration flow is detected.");
115+
eventType = UserStoreWFConstants.SELF_REGISTER_USER_EVENT;
116+
}
117+
118+
if (!isEventAssociatedWithWorkflow(eventType)) {
119+
return true;
120+
}
121+
109122
if (claims != null && claims.containsKey(CLAIM_MANAGED_ORGANIZATION)) {
110123
// User add workflow is not supported for the shared users.
111124
return true;
@@ -114,7 +127,12 @@ public boolean doPreAddUser(String userName, Object credential, String[] roleLis
114127
validatePassword(credential, userName, roleList, claims, profile, userStoreManager);
115128

116129
try {
117-
AddUserWFRequestHandler addUserWFRequestHandler = new AddUserWFRequestHandler();
130+
AddUserWFRequestHandler addUserWFRequestHandler;
131+
if (UserStoreWFConstants.SELF_REGISTER_USER_EVENT.equals(eventType)) {
132+
addUserWFRequestHandler = new SelfRegisterUserWFRequestHandler();
133+
} else {
134+
addUserWFRequestHandler = new AddUserWFRequestHandler();
135+
}
118136
doPasswordPolicyValidation(userName, credential, userStoreManager, addUserWFRequestHandler);
119137
String domain = userStoreManager.getRealmConfiguration()
120138
.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
@@ -439,7 +457,7 @@ private void doPasswordPolicyValidation(String userName, Object credential, User
439457
// Check if add_user operation is engaged with a workflow or not.
440458
if (!addUserWFRequestHandler.isAssociated()) {
441459
/*
442-
This password policy pattern validation wil be done in later step from governance listeners.
460+
This password policy pattern validation will be done in later step from governance listeners.
443461
So skip this validation in this stage if workflows are not enabled for add user operation.
444462
*/
445463
return;

components/org.wso2.carbon.user.mgt.workflow/src/main/java/org/wso2/carbon/user/mgt/workflow/util/UserStoreWFConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class UserStoreWFConstants {
2727

2828

2929
public static final String ADD_USER_EVENT = "ADD_USER";
30+
public static final String SELF_REGISTER_USER_EVENT = "SELF_REGISTER_USER";
3031
public static final String ADD_ROLE_EVENT = "ADD_ROLE";
3132
public static final String DELETE_USER_EVENT = "DELETE_USER";
3233
public static final String DELETE_ROLE_EVENT = "DELETE_ROLE";

0 commit comments

Comments
 (0)