Skip to content

Commit 8be650d

Browse files
committed
Update Custom Domain opt-in boolean to be opt-in regex pattern.
1 parent 1c75ec4 commit 8be650d

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

libs/SalesforceSDK/src/com/salesforce/androidsdk/app/SalesforceSDKManager.java

+17-10
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import android.webkit.CookieManager;
4949

5050
import androidx.annotation.NonNull;
51+
import androidx.annotation.Nullable;
5152
import androidx.lifecycle.Lifecycle;
5253
import androidx.lifecycle.LifecycleObserver;
5354
import androidx.lifecycle.OnLifecycleEvent;
@@ -100,6 +101,7 @@
100101
import java.util.SortedSet;
101102
import java.util.UUID;
102103
import java.util.concurrent.ConcurrentSkipListSet;
104+
import java.util.regex.Pattern;
103105

104106
/**
105107
* This class serves as an interface to the various
@@ -182,7 +184,7 @@ public class SalesforceSDKManager implements LifecycleObserver {
182184

183185
private boolean useHybridAuthentication = true; // hybrid authentication flows ON by default - but app can opt out by calling setUseHybridAuthentication(false)
184186

185-
private boolean shouldInferCustomDomain = false; // Do not detect use of Custom Domain input from login webview but app can opt in by calling setInferCustomDomain(ture)
187+
private Pattern customDomainInferencePattern;
186188

187189
private Theme theme = Theme.SYSTEM_DEFAULT;
188190
private String appName;
@@ -676,20 +678,25 @@ public synchronized void setUseHybridAuthentication(boolean useHybridAuthenticat
676678
}
677679

678680
/**
679-
* Returns whether the SDK should infer if the user has entered a new login server through
680-
* the "Use Custom Domain" button on the login screen.
681+
* Returns the pattern used to detect the use of "Use Custom Domain" input from login web view.
682+
*
683+
* @return pattern if set or null
681684
*/
682-
public boolean shouldInferCustomDomain() {
683-
return this.shouldInferCustomDomain;
685+
public synchronized Pattern getCustomDomainInferencePattern() {
686+
return customDomainInferencePattern;
684687
}
685688

686689
/**
687-
* Sets whether the SDK should infer if the user has entered a new login server through
688-
* the "Use Custom Domain" button on the login screen.
689-
* @param shouldInferCustomDomain
690+
* Detect use of "Use Custom Domain" input from login web view using the given regex.
691+
* Example for a specific org:
692+
* "^https:\\/\\/mobilesdk\\.my\\.salesforce\\.com\\/\\?startURL=%2Fsetup%2Fsecur%2FRemoteAccessAuthorizationPage\\.apexp"
693+
* For any my domain:
694+
* "^https:\\/\\/[a-zA-Z0-9]+\\.my\\.salesforce\\.com/\\?startURL=%2Fsetup%2Fsecur%2FRemoteAccessAuthorizationPage\\.apexp"
695+
*
696+
* @param pattern regex to use when detecting use of custom domain on login
690697
*/
691-
public synchronized void setShouldInferCustomDomain(boolean shouldInferCustomDomain) {
692-
this.shouldInferCustomDomain = shouldInferCustomDomain;
698+
public synchronized void setCustomDomainInferencePattern(@Nullable Pattern pattern) {
699+
this.customDomainInferencePattern = pattern;
693700
}
694701

695702
/**

libs/SalesforceSDK/src/com/salesforce/androidsdk/ui/OAuthWebviewHelper.java

+5-15
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
import java.util.Map;
101101
import java.util.concurrent.ExecutorService;
102102
import java.util.concurrent.Executors;
103+
import java.util.regex.Pattern;
103104

104105
import okhttp3.Request;
105106
import okhttp3.Response;
@@ -525,7 +526,10 @@ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request
525526
}
526527

527528
// Check if user entered a custom domain
528-
if (SalesforceSDKManager.getInstance().shouldInferCustomDomain() && isNewLoginUrl(uri)) {
529+
String host = uri.getHost();
530+
Pattern customDomainPattern = SalesforceSDKManager.getInstance().getCustomDomainInferencePattern();
531+
if (host != null && !getLoginUrl().contains(host) && customDomainPattern != null
532+
&& customDomainPattern.matcher(uri.toString()).find()) {
529533
try {
530534
String baseUrl = "https://" + uri.getHost();
531535
LoginServerManager serverManager = SalesforceSDKManager.getInstance().getLoginServerManager();
@@ -574,20 +578,6 @@ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request
574578
return authFlowFinished;
575579
}
576580

577-
private boolean isNewLoginUrl(Uri uri) {
578-
String host = uri.getHost();
579-
String query = uri.getQuery();
580-
String path = uri.getPath();
581-
582-
if (host == null || query == null || path == null || getLoginUrl().contains(host)) {
583-
return false;
584-
}
585-
586-
final String myDomainHost = ".my.salesforce.com";
587-
final String loginPath = "startURL=/setup/secur/RemoteAccessAuthorizationPage.apexp";
588-
return host.endsWith(myDomainHost) && query.startsWith(loginPath) && path.equals("/");
589-
}
590-
591581
@Override
592582
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
593583
int primError = error.getPrimaryError();

0 commit comments

Comments
 (0)