2323import org .apache .commons .logging .LogFactory ;
2424import org .wso2 .carbon .context .PrivilegedCarbonContext ;
2525import 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 ;
2628import org .wso2 .carbon .identity .core .model .IdentityEventListenerConfig ;
2729import org .wso2 .carbon .identity .core .util .IdentityCoreConstants ;
2830import 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 ;
0 commit comments