Skip to content

Commit 0f57bc5

Browse files
authored
Revert "Add IBroker implementation for MSALRuntime (#563)" (#588)
This reverts commit aacb439.
1 parent aacb439 commit 0f57bc5

File tree

7 files changed

+65
-339
lines changed

7 files changed

+65
-339
lines changed

msal4j-brokers/pom.xml

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.microsoft.azure</groupId>
77
<artifactId>msal4j-brokers</artifactId>
8-
<version>1.0.0-beta</version>
8+
<version>0.0.1</version>
99
<packaging>jar</packaging>
1010
<name>msal4j-brokers</name>
1111
<description>
@@ -26,39 +26,18 @@
2626
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2727
</properties>
2828
<dependencies>
29+
<!-- https://mvnrepository.com/artifact/com.microsoft.azure/msal4j -->
2930
<dependency>
3031
<groupId>com.microsoft.azure</groupId>
3132
<artifactId>msal4j</artifactId>
32-
<version>1.13.4</version>
33-
</dependency>
34-
<dependency>
35-
<groupId>com.microsoft.azure</groupId>
36-
<artifactId>javamsalruntime</artifactId>
37-
<version>0.13.4</version>
33+
<version>1.13.2</version>
3834
</dependency>
3935
<dependency>
4036
<groupId>org.projectlombok</groupId>
4137
<artifactId>lombok</artifactId>
4238
<version>1.18.6</version>
4339
<scope>provided</scope>
4440
</dependency>
45-
<dependency>
46-
<groupId>org.testng</groupId>
47-
<artifactId>testng</artifactId>
48-
<version>7.1.0</version>
49-
<scope>test</scope>
50-
</dependency>
51-
<dependency>
52-
<groupId>org.slf4j</groupId>
53-
<artifactId>slf4j-api</artifactId>
54-
<version>1.7.36</version>
55-
</dependency>
56-
<dependency>
57-
<groupId>ch.qos.logback</groupId>
58-
<artifactId>logback-classic</artifactId>
59-
<version>1.2.3</version>
60-
<scope>test</scope>
61-
</dependency>
6241
</dependencies>
6342

6443
<!-- force https -->
@@ -81,6 +60,7 @@
8160
</pluginRepository>
8261
</pluginRepositories>
8362
<build>
63+
<sourceDirectory>${project.build.directory}/delombok</sourceDirectory>
8464
<plugins>
8565
<plugin>
8666
<groupId>org.projectlombok</groupId>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.microsoft.aad.msal4jbrokers;
2+
3+
import com.microsoft.aad.msal4j.*;
4+
import lombok.extern.slf4j.Slf4j;
5+
6+
import java.util.concurrent.CompletableFuture;
7+
8+
@Slf4j
9+
public class MSALRuntimeBroker implements IBroker {
10+
11+
@Override
12+
public IAuthenticationResult acquireToken(PublicClientApplication application, SilentParameters requestParameters) {
13+
log.debug("Should not call this API if msal runtime init failed");
14+
throw new MsalClientException("Broker implementation missing", "missing_broker");
15+
}
16+
17+
@Override
18+
public IAuthenticationResult acquireToken(PublicClientApplication application, InteractiveRequestParameters requestParameters) {
19+
throw new MsalClientException("Broker implementation missing", "missing_broker");
20+
}
21+
22+
@Override
23+
public IAuthenticationResult acquireToken(PublicClientApplication application, UserNamePasswordParameters requestParameters) {
24+
throw new MsalClientException("Broker implementation missing", "missing_broker");
25+
}
26+
27+
@Override
28+
public CompletableFuture removeAccount(IAccount account) {
29+
throw new MsalClientException("Broker implementation missing", "missing_broker");
30+
}
31+
}

msal4j-brokers/src/main/java/com/microsoft/aad/msal4jbrokers/MsalRuntimeBroker.java

Lines changed: 0 additions & 179 deletions
This file was deleted.

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/AuthenticationErrorCode.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,9 @@ public class AuthenticationErrorCode {
115115
* A JWT parsing failure, indicating the JWT provided to MSAL is of invalid format.
116116
*/
117117
public final static String INVALID_JWT = "invalid_jwt";
118-
119118
/**
120119
* Indicates that a Broker implementation is missing from the device, such as when an app developer
121120
* does not include one of our broker packages as a dependency in their project, or otherwise cannot
122-
* be accessed by MSAL Java
123-
*/
121+
* be accessed by MSAL Java*/
124122
public final static String MISSING_BROKER = "missing_broker";
125-
126-
/**
127-
* Indicates an error from the MSAL Java/MSALRuntime interop layer used by the Java Brokers package,
128-
* and will generally just be forwarding an error message from the interop layer or MSALRuntime itself
129-
*/
130-
public final static String MSALRUNTIME_INTEROP_ERROR = "interop_package_error";
131-
132-
/**
133-
* Indicates an error in the MSAL Java Brokers package
134-
*/
135-
public final static String MSALJAVA_BROKERS_ERROR = "brokers_package_error";
136123
}

msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/IBroker.java

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,80 +3,58 @@
33

44
package com.microsoft.aad.msal4j;
55

6-
import com.nimbusds.jwt.JWTParser;
7-
8-
import java.net.URL;
6+
import java.util.Set;
97
import java.util.concurrent.CompletableFuture;
108

119
/**
1210
* Used to define the basic set of methods that all Brokers must implement
1311
*
14-
* All methods are marked as default so they can be referenced by MSAL Java without an implementation,
15-
* and most will simply throw an exception if not overridden by an IBroker implementation
12+
* All methods are so they can be referenced by MSAL Java without an implementation, and by default simply throw an
13+
* exception saying that a broker implementation is missing
1614
*/
1715
public interface IBroker {
1816

17+
/**
18+
* checks if a IBroker implementation exists
19+
*/
20+
21+
default boolean isAvailable(){
22+
return false;
23+
}
1924
/**
2025
* Acquire a token silently, i.e. without direct user interaction
2126
*
2227
* This may be accomplished by returning tokens from a token cache, using cached refresh tokens to get new tokens,
2328
* or via any authentication flow where a user is not prompted to enter credentials
29+
*
30+
* @param requestParameters MsalRequest object which contains everything needed for the broker implementation to make a request
31+
* @return IBroker implementations will return an AuthenticationResult object
2432
*/
25-
default CompletableFuture<IAuthenticationResult> acquireToken(PublicClientApplication application, SilentParameters requestParameters) {
33+
default IAuthenticationResult acquireToken(PublicClientApplication application, SilentParameters requestParameters) {
2634
throw new MsalClientException("Broker implementation missing", AuthenticationErrorCode.MISSING_BROKER);
2735
}
2836

2937
/**
3038
* Acquire a token interactively, by prompting users to enter their credentials in some way
39+
*
40+
* @param requestParameters MsalRequest object which contains everything needed for the broker implementation to make a request
41+
* @return IBroker implementations will return an AuthenticationResult object
3142
*/
32-
default CompletableFuture<IAuthenticationResult> acquireToken(PublicClientApplication application, InteractiveRequestParameters parameters) {
43+
default IAuthenticationResult acquireToken(PublicClientApplication application, InteractiveRequestParameters requestParameters) {
3344
throw new MsalClientException("Broker implementation missing", AuthenticationErrorCode.MISSING_BROKER);
3445
}
3546

3647
/**
3748
* Acquire a token silently, i.e. without direct user interaction, using username/password authentication
49+
*
50+
* @param requestParameters MsalRequest object which contains everything needed for the broker implementation to make a request
51+
* @return IBroker implementations will return an AuthenticationResult object
3852
*/
39-
default CompletableFuture<IAuthenticationResult> acquireToken(PublicClientApplication application, UserNamePasswordParameters parameters) {
53+
default IAuthenticationResult acquireToken(PublicClientApplication application, UserNamePasswordParameters requestParameters) {
4054
throw new MsalClientException("Broker implementation missing", AuthenticationErrorCode.MISSING_BROKER);
4155
}
4256

43-
default void removeAccount(PublicClientApplication application, IAccount account) throws MsalClientException {
57+
default CompletableFuture removeAccount(IAccount account) {
4458
throw new MsalClientException("Broker implementation missing", AuthenticationErrorCode.MISSING_BROKER);
4559
}
46-
47-
default boolean isBrokerAvailable() {
48-
throw new MsalClientException("Broker implementation missing", AuthenticationErrorCode.MISSING_BROKER);
49-
}
50-
51-
/**
52-
* MSAL Java's AuthenticationResult requires several package-private classes that a broker implementation can't access,
53-
* so this helper method can be used to create AuthenticationResults from within the MSAL Java package
54-
*/
55-
default IAuthenticationResult parseBrokerAuthResult(String authority, String idToken, String accessToken,
56-
String accountId, String clientInfo,
57-
long accessTokenExpirationTime) {
58-
59-
AuthenticationResult.AuthenticationResultBuilder builder = AuthenticationResult.builder();
60-
61-
try {
62-
if (idToken != null) {
63-
builder.idToken(idToken);
64-
if (accountId!= null) {
65-
String idTokenJson =
66-
JWTParser.parse(idToken).getParsedParts()[1].decodeToString();
67-
//TODO: need to figure out if 'policy' field is relevant for brokers
68-
builder.accountCacheEntity(AccountCacheEntity.create(clientInfo,
69-
Authority.createAuthority(new URL(authority)), JsonHelper.convertJsonToObject(idTokenJson,
70-
IdToken.class), null));
71-
}
72-
}
73-
if (accessToken != null) {
74-
builder.accessToken(accessToken);
75-
builder.expiresOn(accessTokenExpirationTime);
76-
}
77-
} catch (Exception e) {
78-
throw new MsalClientException(String.format("Exception when converting broker result to MSAL Java AuthenticationResult: %s", e.getMessage()), AuthenticationErrorCode.MSALJAVA_BROKERS_ERROR);
79-
}
80-
return builder.build();
81-
}
8260
}

0 commit comments

Comments
 (0)