Skip to content

Commit 58a69bf

Browse files
siddhijainfadidurah
andcommitted
Use Broker Content Provider for number match, Fixes AB#3308440 (#2699)
[AB#3308440](https://identitydivision.visualstudio.com/fac9d424-53d2-45c0-91b5-ef6ba7a6bf26/_workitems/edit/3308440) This PR adds constants used by AADAuthenticator module for number match scenarios. --------- Co-authored-by: fadidurah <[email protected]>
1 parent 1d1b331 commit 58a69bf

File tree

5 files changed

+58
-9
lines changed

5 files changed

+58
-9
lines changed

common/src/main/java/com/microsoft/identity/common/adal/internal/AuthenticationConstants.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,16 @@ public static String computeMaxHostBrokerProtocol() {
14751475
*/
14761476
public static final String GET_FLIGHTS_RESULT = "active_flights";
14771477

1478+
/**
1479+
* The Bundle key name of the result of the number match operation.
1480+
*/
1481+
public static final String GET_NUMBER_MATCH_RESULT = "number_match";
1482+
1483+
/**
1484+
* SessionID for the number match operation.
1485+
*/
1486+
public static final String SESSION_ID = "session_id";
1487+
14781488
/**
14791489
* Time out for the AccountManager's remove account operation in broker.
14801490
*/
@@ -1656,6 +1666,7 @@ public enum API {
16561666
BROKER_UPDATE_BRT(BROKER_API_UPDATE_BRT_PATH, BROKER_VERSION_1, null),
16571667
BROKER_SET_FLIGHTS(BROKER_API_SET_FLIGHTS_PATH, BROKER_VERSION_3, null),
16581668
BROKER_GET_FLIGHTS(BROKER_API_GET_FLIGHTS_PATH, BROKER_VERSION_3, null),
1669+
16591670
GET_SSO_TOKEN(GET_SSO_TOKEN_PATH, null, VERSION_7),
16601671
UNKNOWN(null, null, null),
16611672
DEVICE_REGISTRATION_PROTOCOLS(DEVICE_REGISTRATION_PROTOCOLS_PATH, null, null),
@@ -1674,7 +1685,9 @@ public enum API {
16741685
WEBAPPS_GET_SUPPORTED_WEB_APPS_CONTRACTS(WEBAPPS_GET_SUPPORTED_WEB_APPS_CONTRACTS_PATH, null, null),
16751686
WEBAPPS_EXECUTE_WEB_APPS_REQUEST(WEBAPPS_EXECUTE_WEB_APPS_REQUEST_PATH, null, null),
16761687
PROVISION_RESOURCE_ACCOUNT(PROVISION_RESOURCE_ACCOUNT_PATH, null, null),
1677-
GET_AAD_DEVICE_ID(GET_AAD_DEVICE_ID_PATH, null, null);
1688+
GET_AAD_DEVICE_ID(GET_AAD_DEVICE_ID_PATH, null, null),
1689+
BROKER_GET_NUMBER_MATCH(BROKER_API_GET_NUMBER_MATCH_PATH, BROKER_VERSION_3, null);
1690+
16781691

16791692
/**
16801693
* The content provider path that the API exists behind.
@@ -1794,6 +1807,11 @@ public String getMsalVersion(){
17941807
*/
17951808
public static final String BROKER_API_GET_FLIGHTS_PATH = "/brokerApi/getFlights";
17961809

1810+
/**
1811+
* Broker api path constant for getting number match.
1812+
*/
1813+
public static final String BROKER_API_GET_NUMBER_MATCH_PATH = "/brokerApi/getNumberMatch";
1814+
17971815
/**
17981816
* ContentProvider path for retrieving Broker Discovery Metadata.
17991817
*/

common/src/main/java/com/microsoft/identity/common/internal/broker/AuthUxJavaScriptInterface.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import com.google.gson.JsonSyntaxException
2929
import com.google.gson.stream.MalformedJsonException
3030
import com.microsoft.identity.common.adal.internal.AuthenticationConstants
3131
import com.microsoft.identity.common.internal.numberMatch.NumberMatchHelper
32+
import com.microsoft.identity.common.java.opentelemetry.AttributeName
33+
import com.microsoft.identity.common.java.opentelemetry.SpanExtension
3234
import com.microsoft.identity.common.logging.Logger
3335
import java.net.MalformedURLException
3436
import java.net.URL
@@ -115,10 +117,11 @@ class AuthUxJavaScriptInterface {
115117
"Correlation ID during JavaScript Call: [${payloadObject.correlationId}]"
116118
)
117119

118-
119-
// TODO: Leaving these here, as these will be relevant for next WebCP feature
120-
// val actionName = payloadObject.actionName
121-
// val actionComponent = payloadObject.actionComponent
120+
val span = SpanExtension.current()
121+
val actionName = payloadObject.actionName
122+
span.setAttribute(AttributeName.authux_js_action_name.name, actionName)
123+
val actionComponent = payloadObject.actionComponent
124+
span.setAttribute(AttributeName.authux_js_action_component.name, actionComponent)
122125

123126
val parameters = payloadObject.params
124127
if (parameters == null) {
@@ -127,6 +130,9 @@ class AuthUxJavaScriptInterface {
127130
}
128131

129132
val operation = parameters.operation
133+
if (operation != null) {
134+
span.setAttribute(AttributeName.authux_js_operation.name, operation)
135+
}
130136

131137
Logger.info(methodTag, "Function name: [$operation]")
132138

common/src/main/java/com/microsoft/identity/common/internal/broker/ipc/BrokerOperationBundle.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public enum Operation {
7878
BROKER_WEBAPPS_API_GET_SUPPORTED_WEB_APPS_CONTRACTS(API.WEBAPPS_GET_SUPPORTED_WEB_APPS_CONTRACTS, null),
7979
BROKER_WEBAPPS_API_EXECUTE_WEB_APPS_REQUEST(API.WEBAPPS_EXECUTE_WEB_APPS_REQUEST, null),
8080
PROVISION_RESOURCE_ACCOUNT(API.PROVISION_RESOURCE_ACCOUNT, null),
81-
GET_AAD_DEVICE_ID(API.GET_AAD_DEVICE_ID, null);
81+
GET_AAD_DEVICE_ID(API.GET_AAD_DEVICE_ID, null),
82+
BROKER_GET_NUMBER_MATCH(API.BROKER_GET_NUMBER_MATCH, null);
8283

8384
final API mContentApi;
8485
final String mAccountManagerOperation;

common/src/main/java/com/microsoft/identity/common/internal/numberMatch/NumberMatchHelper.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
// THE SOFTWARE.
2323
package com.microsoft.identity.common.internal.numberMatch
2424

25+
import com.microsoft.identity.common.java.opentelemetry.AttributeName
26+
import com.microsoft.identity.common.java.opentelemetry.SpanExtension
2527
import com.microsoft.identity.common.logging.Logger
2628

2729
/**
@@ -41,8 +43,6 @@ class NumberMatchHelper {
4143
companion object {
4244
val TAG = NumberMatchHelper::class.java.simpleName
4345
val numberMatchMap: HashMap<String, String> = HashMap()
44-
const val SESSION_ID_ATTRIBUTE_NAME = "sessionID"
45-
const val NUMBER_MATCH_ATTRIBUTE_NAME = "numberMatch"
4646

4747
/**
4848
* Method to add a key:value pair of sessionID:numberMatch to static hashmap. This hashmap will be accessed
@@ -53,15 +53,19 @@ class NumberMatchHelper {
5353
Logger.info(methodTag,
5454
"Adding entry in NumberMatch hashmap for session ID: $sessionId")
5555

56+
val span = SpanExtension.current()
57+
5658
// If both parameters are non-null, add a new entry to the hashmap
5759
if (sessionId != null && numberMatch != null) {
5860
numberMatchMap[sessionId] = numberMatch
61+
span.setAttribute(AttributeName.stored_number_match_entry.name, true)
5962
}
6063
// If either parameter is null, do nothing
6164
else {
6265
Logger.warn(methodTag,
6366
"Either session ID or number match is null. Nothing to add for number match."
6467
)
68+
span.setAttribute(AttributeName.stored_number_match_entry.name, false)
6569
}
6670
}
6771

common4j/src/main/com/microsoft/identity/common/java/opentelemetry/AttributeName.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,5 +384,25 @@ public enum AttributeName {
384384
* Records the if webview received an SSL error and
385385
* corresponding primary error code.
386386
*/
387-
web_view_ssl_primary_error_code
387+
web_view_ssl_primary_error_code,
388+
389+
/**
390+
* Record action name from Webview JavaScript Payload
391+
*/
392+
authux_js_action_name,
393+
394+
/**
395+
* Record action component from Webview JavaScript Payload
396+
*/
397+
authux_js_action_component,
398+
399+
/**
400+
* Record operation name from Webview JavaScript Payload
401+
*/
402+
authux_js_operation,
403+
404+
/**
405+
* Record whether or not the request stored a number match entry.
406+
*/
407+
stored_number_match_entry
388408
}

0 commit comments

Comments
 (0)