2525import org .wso2 .carbon .identity .branding .preference .management .core .exception .BrandingPreferenceMgtClientException ;
2626import org .wso2 .carbon .identity .branding .preference .management .core .exception .BrandingPreferenceMgtException ;
2727import org .wso2 .carbon .identity .branding .preference .management .core .model .BrandingPreference ;
28- import org .wso2 .carbon .identity .core .ServiceURLBuilder ;
2928import org .wso2 .carbon .identity .core .URLBuilderException ;
3029import org .wso2 .carbon .identity .core .context .model .Flow ;
3130import org .wso2 .carbon .identity .flow .execution .engine .listener .AbstractFlowExecutionListener ;
3736import static org .wso2 .carbon .identity .branding .preference .management .core .constant .BrandingPreferenceMgtConstants .BRANDING_URLS ;
3837import static org .wso2 .carbon .identity .branding .preference .management .core .constant .BrandingPreferenceMgtConstants .DEFAULT_LOCALE ;
3938import static org .wso2 .carbon .identity .branding .preference .management .core .constant .BrandingPreferenceMgtConstants .ORGANIZATION_TYPE ;
39+ import static org .wso2 .carbon .identity .branding .preference .management .core .util .BrandingPreferenceMgtUtils .DEFAULT_REGISTRATION_PORTAL_URL ;
40+ import static org .wso2 .carbon .identity .branding .preference .management .core .util .BrandingPreferenceMgtUtils .REGISTRATION ;
41+ import static org .wso2 .carbon .identity .branding .preference .management .core .util .BrandingPreferenceMgtUtils .buildDefaultPortalUrl ;
4042
4143/**
4244 * This class is responsible for injecting the portal URL during flow execution.
@@ -46,8 +48,6 @@ public class PortalURLResolver extends AbstractFlowExecutionListener {
4648 private static final Log LOG = LogFactory .getLog (PortalURLResolver .class );
4749 private final BrandingPreferenceManagerImpl brandingPreferenceManager ;
4850 public static final String SELF_SIGN_UP_URL = "selfSignUpURL" ;
49- public static final String DEFAULT_REGISTRATION_PORTAL_URL = "/authenticationendpoint/register.do" ;
50- public static final String REGISTRATION = "REGISTRATION" ;
5151
5252 public PortalURLResolver (BrandingPreferenceManagerImpl brandingPreferenceManager ) {
5353
@@ -75,10 +75,11 @@ public boolean isEnabled() {
7575 @ Override
7676 public boolean doPreExecute (FlowExecutionContext context ) {
7777
78+ String flowType = context .getFlowType ();
79+ if (StringUtils .isNotBlank (context .getPortalUrl ())) {
80+ return true ;
81+ }
7882 try {
79- if (StringUtils .isNotBlank (context .getPortalUrl ())) {
80- return true ;
81- }
8283 String applicationId = context .getApplicationId ();
8384 String tenantDomain = context .getTenantDomain ();
8485 String type = StringUtils .isBlank (applicationId ) ? ORGANIZATION_TYPE : APPLICATION_TYPE ;
@@ -90,27 +91,26 @@ public boolean doPreExecute(FlowExecutionContext context) {
9091 Map <String , Object > prefMap = (Map <String , Object >) preference .getPreference ();
9192 Map <String , String > urlMap = (Map <String , String >) prefMap .get (BRANDING_URLS );
9293
93- if (REGISTRATION .equals ( context . getFlowType ()) || Flow .Name .USER_REGISTRATION .toString ().
94- equalsIgnoreCase (context . getFlowType () )) {
94+ if (REGISTRATION .equalsIgnoreCase ( flowType ) || Flow .Name .USER_REGISTRATION .name ().
95+ equalsIgnoreCase (flowType )) {
9596 String signUpUrl = (urlMap != null ) ? urlMap .get (SELF_SIGN_UP_URL ) : null ;
96-
9797 if (StringUtils .isNotBlank (signUpUrl )) {
9898 context .setPortalUrl (signUpUrl );
9999 } else {
100100 logMissingSelfSignupUrl (context );
101- context .setPortalUrl (buildDefaultRegistrationUrl ( ));
101+ context .setPortalUrl (buildDefaultPortalUrl ( context . getApplicationId (), flowType ));
102102 }
103103 }
104104 }
105105 if (StringUtils .isBlank (context .getPortalUrl ())) {
106106 logMissingSelfSignupUrl (context );
107- context .setPortalUrl (buildDefaultRegistrationUrl ( ));
107+ context .setPortalUrl (buildDefaultPortalUrl ( context . getApplicationId (), flowType ));
108108 }
109109 return true ;
110110 } catch (BrandingPreferenceMgtClientException e ) {
111111 logMissingSelfSignupUrl (context );
112112 try {
113- context .setPortalUrl (buildDefaultRegistrationUrl ( ));
113+ context .setPortalUrl (buildDefaultPortalUrl ( context . getApplicationId (), flowType ));
114114 } catch (URLBuilderException ex ) {
115115 LOG .error ("Failed to build default registration URL for tenant: " + context .getTenantDomain (), ex );
116116 return false ;
@@ -130,12 +130,4 @@ private static void logMissingSelfSignupUrl(FlowExecutionContext context) {
130130 LOG .debug ("Self sign-up URL not configured for tenant: " + context .getTenantDomain () + ". Using default URL: "
131131 + DEFAULT_REGISTRATION_PORTAL_URL );
132132 }
133-
134- private String buildDefaultRegistrationUrl () throws URLBuilderException {
135-
136- return ServiceURLBuilder .create ()
137- .addPath (DEFAULT_REGISTRATION_PORTAL_URL )
138- .build ()
139- .getAbsolutePublicURL ();
140- }
141133}
0 commit comments