Skip to content

Commit 53e6004

Browse files
authored
1.6.2 release (#269)
* 1.6.2 release
1 parent a60641b commit 53e6004

File tree

19 files changed

+270
-100
lines changed

19 files changed

+270
-100
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Quick links:
1616
The library supports the following Java environments:
1717
- Java 8 (or higher)
1818

19-
Current version - 1.6.1
19+
Current version - 1.6.2
2020

2121
You can find the changes for each version in the [change log](https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/master/changelog.txt).
2222

@@ -28,13 +28,13 @@ Find [the latest package in the Maven repository](https://mvnrepository.com/arti
2828
<dependency>
2929
<groupId>com.microsoft.azure</groupId>
3030
<artifactId>msal4j</artifactId>
31-
<version>1.6.1</version>
31+
<version>1.6.2</version>
3232
</dependency>
3333
```
3434
### Gradle
3535

3636
```
37-
compile group: 'com.microsoft.azure', name: 'msal4j', version: '1.6.1'
37+
compile group: 'com.microsoft.azure', name: 'msal4j', version: '1.6.2'
3838
```
3939

4040
## Usage

changelog.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Version 1.6.2
2+
=============
3+
- Fix for "NullPointerException during accessing B2C authority aliases"
4+
- Adding extraScopesToConsent parameter to AuthorizationRequestUrlParameters builder.
5+
Can be used to request the end user to consent upfront,
6+
in addition to scopes which the application is requesting access to.
7+
18
Version 1.6.1
29
=============
310
- Compatibility with json-smart [1.3.1 - 2.3]

pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.microsoft.azure</groupId>
55
<artifactId>msal4j</artifactId>
6-
<version>1.6.1</version>
6+
<version>1.6.2</version>
77
<packaging>jar</packaging>
88
<name>msal4j</name>
99
<description>
@@ -55,7 +55,6 @@
5555
<version>2.10.1</version>
5656
</dependency>
5757

58-
5958
<!-- test dependencies -->
6059
<dependency>
6160
<groupId>org.apache.commons</groupId>

src/integrationtest/java/com.microsoft.aad.msal4j/DeviceCodeIT.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void DeviceCodeFlowADTest(String environment) throws Exception {
4646
build();
4747

4848
Consumer<DeviceCode> deviceCodeConsumer = (DeviceCode deviceCode) -> {
49-
runAutomatedDeviceCodeFlow(deviceCode, user);
49+
runAutomatedDeviceCodeFlow(deviceCode, user, environment);
5050
};
5151

5252
IAuthenticationResult result = pca.acquireToken(DeviceCodeFlowParameters
@@ -70,7 +70,7 @@ public void DeviceCodeFlowADFSv2019Test(String environment) throws Exception {
7070
build();
7171

7272
Consumer<DeviceCode> deviceCodeConsumer = (DeviceCode deviceCode) -> {
73-
runAutomatedDeviceCodeFlow(deviceCode, user);
73+
runAutomatedDeviceCodeFlow(deviceCode, user, environment);
7474
};
7575

7676
IAuthenticationResult result = pca.acquireToken(DeviceCodeFlowParameters
@@ -83,7 +83,7 @@ public void DeviceCodeFlowADFSv2019Test(String environment) throws Exception {
8383
Assert.assertFalse(Strings.isNullOrEmpty(result.accessToken()));
8484
}
8585

86-
private void runAutomatedDeviceCodeFlow(DeviceCode deviceCode, User user){
86+
private void runAutomatedDeviceCodeFlow(DeviceCode deviceCode, User user, String environment){
8787
boolean isRunningLocally = true;//!Strings.isNullOrEmpty(
8888
//System.getenv(TestConstants.LOCAL_FLAG_ENV_VAR));
8989

@@ -123,6 +123,15 @@ private void runAutomatedDeviceCodeFlow(DeviceCode deviceCode, User user){
123123
} else {
124124
SeleniumExtensions.performADLogin(seleniumDriver, user);
125125
}
126+
127+
if (environment.equals(AzureEnvironment.AZURE) && !isADFS2019) {
128+
//Login flow for azurecloud environment has an extra "Stay signed in?" page after authentication
129+
continueBtn = SeleniumExtensions.waitForElementToBeVisibleAndEnable(
130+
seleniumDriver,
131+
new By.ById(continueButtonId));
132+
continueBtn.click();
133+
}
134+
126135
} catch(Exception e){
127136
if(!isRunningLocally){
128137
SeleniumExtensions.takeScreenShot(seleniumDriver);

src/integrationtest/java/com.microsoft.aad.msal4j/UsernamePasswordIT.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ public void acquireTokenWithUsernamePassword_B2C_CustomAuthority() throws Except
149149
Assert.assertNotNull(result);
150150
Assert.assertNotNull(result.accessToken());
151151
Assert.assertNotNull(result.idToken());
152+
153+
IAccount account = pca.getAccounts().join().iterator().next();
154+
SilentParameters.builder(Collections.singleton(TestConstants.B2C_READ_SCOPE), account);
155+
156+
result = pca.acquireTokenSilently(
157+
SilentParameters.builder(Collections.singleton(TestConstants.B2C_READ_SCOPE), account)
158+
.build())
159+
.get();
160+
161+
Assert.assertNotNull(result);
162+
Assert.assertNotNull(result.accessToken());
163+
Assert.assertNotNull(result.idToken());
152164
}
153165

154166
@Test
@@ -173,5 +185,17 @@ public void acquireTokenWithUsernamePassword_B2C_LoginMicrosoftOnline() throws E
173185
Assert.assertNotNull(result);
174186
Assert.assertNotNull(result.accessToken());
175187
Assert.assertNotNull(result.idToken());
188+
189+
IAccount account = pca.getAccounts().join().iterator().next();
190+
SilentParameters.builder(Collections.singleton(TestConstants.B2C_READ_SCOPE), account);
191+
192+
result = pca.acquireTokenSilently(
193+
SilentParameters.builder(Collections.singleton(TestConstants.B2C_READ_SCOPE), account)
194+
.build())
195+
.get();
196+
197+
Assert.assertNotNull(result);
198+
Assert.assertNotNull(result.accessToken());
199+
Assert.assertNotNull(result.idToken());
176200
}
177201
}

src/main/java/com/microsoft/aad/msal4j/AadInstanceDiscoveryProvider.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static AadInstanceDiscoveryResponse parseInstanceDiscoveryMetadata(String instan
7474
static void cacheInstanceDiscoveryMetadata(String host,
7575
AadInstanceDiscoveryResponse aadInstanceDiscoveryResponse) {
7676

77-
if (aadInstanceDiscoveryResponse.metadata() != null) {
77+
if (aadInstanceDiscoveryResponse != null && aadInstanceDiscoveryResponse.metadata() != null) {
7878
for (InstanceDiscoveryMetadataEntry entry : aadInstanceDiscoveryResponse.metadata()) {
7979
for (String alias: entry.aliases()) {
8080
cache.put(alias, entry);
@@ -83,7 +83,9 @@ static void cacheInstanceDiscoveryMetadata(String host,
8383
}
8484
cache.putIfAbsent(host, InstanceDiscoveryMetadataEntry.builder().
8585
preferredCache(host).
86-
preferredNetwork(host).build());
86+
preferredNetwork(host).
87+
aliases(Collections.singleton(host)).
88+
build());
8789
}
8890

8991
private static String getAuthorizeEndpoint(String host, String tenant) {
@@ -127,11 +129,14 @@ private static void doInstanceDiscoveryAndCache(URL authorityUrl,
127129
MsalRequest msalRequest,
128130
ServiceBundle serviceBundle) {
129131

130-
AadInstanceDiscoveryResponse aadInstanceDiscoveryResponse =
131-
sendInstanceDiscoveryRequest(authorityUrl, msalRequest, serviceBundle);
132+
AadInstanceDiscoveryResponse aadInstanceDiscoveryResponse = null;
132133

133-
if (validateAuthority) {
134-
validate(aadInstanceDiscoveryResponse);
134+
if(msalRequest.application().authenticationAuthority.authorityType.equals(AuthorityType.AAD)) {
135+
aadInstanceDiscoveryResponse = sendInstanceDiscoveryRequest(authorityUrl, msalRequest, serviceBundle);
136+
137+
if (validateAuthority) {
138+
validate(aadInstanceDiscoveryResponse);
139+
}
135140
}
136141

137142
cacheInstanceDiscoveryMetadata(authorityUrl.getAuthority(), aadInstanceDiscoveryResponse);

src/main/java/com/microsoft/aad/msal4j/AcquireTokenByDeviceCodeFlowSupplier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private AuthenticationResult acquireTokenWithDeviceCode(DeviceCode deviceCode,
5858
try {
5959
return acquireTokenByAuthorisationGrantSupplier.execute();
6060
} catch (MsalServiceException ex) {
61-
if (ex.errorCode().equals(AUTHORIZATION_PENDING)) {
61+
if (ex.errorCode() != null && ex.errorCode().equals(AUTHORIZATION_PENDING)) {
6262
TimeUnit.SECONDS.sleep(deviceCode.interval());
6363
} else {
6464
throw ex;

src/main/java/com/microsoft/aad/msal4j/AuthenticationResultSupplier.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ public IAuthenticationResult get() {
7171
String error = StringHelper.EMPTY_STRING;
7272
if (ex instanceof MsalException) {
7373
MsalException exception = ((MsalException) ex);
74-
if(exception.errorCode() != null){
74+
if (exception.errorCode() != null){
7575
apiEvent.setApiErrorCode(exception.errorCode());
7676
}
7777
} else {
78-
if(ex.getCause() != null){
78+
if (ex.getCause() != null){
7979
error = ex.getCause().toString();
8080
}
8181
}
@@ -136,7 +136,7 @@ private void logException(Exception ex) {
136136

137137
if (ex instanceof MsalClientException) {
138138
MsalClientException exception = (MsalClientException) ex;
139-
if (exception.errorCode().equalsIgnoreCase(AuthenticationErrorCode.CACHE_MISS)) {
139+
if (exception.errorCode() != null && exception.errorCode().equalsIgnoreCase(AuthenticationErrorCode.CACHE_MISS)) {
140140
clientApplication.log.debug(logMessage, ex);
141141
return;
142142
}

src/main/java/com/microsoft/aad/msal4j/AuthorizationRequestUrlParameters.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@
1010

1111
import java.net.MalformedURLException;
1212
import java.net.URL;
13-
import java.util.Arrays;
14-
import java.util.Collections;
15-
import java.util.HashMap;
16-
import java.util.List;
17-
import java.util.Map;
18-
import java.util.Set;
19-
import java.util.TreeSet;
13+
import java.util.*;
2014

2115
/**
2216
* Parameters for {@link AbstractClientApplicationBase#getAuthorizationRequestUrl(AuthorizationRequestUrlParameters)}
@@ -62,9 +56,15 @@ private AuthorizationRequestUrlParameters(Builder builder){
6256
requestParameters.put("redirect_uri", Collections.singletonList(this.redirectUri));
6357
this.scopes = builder.scopes;
6458

65-
Set<String> scopesParam = new TreeSet<>(builder.scopes);
6659
String[] commonScopes = AbstractMsalAuthorizationGrant.COMMON_SCOPES_PARAM.split(" ");
67-
scopesParam.addAll(Arrays.asList(commonScopes));
60+
61+
Set<String> scopesParam = new LinkedHashSet<>(Arrays.asList(commonScopes));
62+
63+
scopesParam.addAll(builder.scopes);
64+
65+
if(builder.extraScopesToConsent != null) {
66+
scopesParam.addAll(builder.extraScopesToConsent);
67+
}
6868

6969
this.scopes = scopesParam;
7070
requestParameters.put("scope", Collections.singletonList(String.join(" ", scopesParam)));
@@ -151,6 +151,7 @@ public static class Builder {
151151

152152
private String redirectUri;
153153
private Set<String> scopes;
154+
private Set<String> extraScopesToConsent;
154155
private Set<String> claims;
155156
private String claimsChallenge;
156157
private String codeChallenge;
@@ -188,6 +189,15 @@ public Builder scopes(Set<String> val){
188189
return self();
189190
}
190191

192+
/**
193+
* Scopes that you can request the end user to consent upfront,
194+
* in addition to scopes which the application is requesting access to.
195+
*/
196+
public Builder extraScopesToConsent(Set<String> val){
197+
this.extraScopesToConsent = val;
198+
return self();
199+
}
200+
191201
/**
192202
* In cases where Azure AD tenant admin has enabled conditional access policies, and the
193203
* policy has not been met,{@link MsalServiceException} will contain claims that need be

src/main/java/com/microsoft/aad/msal4j/DefaultHttpClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class DefaultHttpClient implements IHttpClient {
1515

1616
private final Proxy proxy;
1717
private final SSLSocketFactory sslSocketFactory;
18+
public int DEFAULTCONNECTIONTIMEOUT = 3000;
19+
public int DEFAULTREADTIMEOUT = 5000;
1820

1921
DefaultHttpClient(Proxy proxy, SSLSocketFactory sslSocketFactory){
2022
this.proxy = proxy;
@@ -76,6 +78,9 @@ private HttpsURLConnection openConnection(final URL finalURL)
7678
connection.setSSLSocketFactory(sslSocketFactory);
7779
}
7880

81+
connection.setConnectTimeout(DEFAULTCONNECTIONTIMEOUT);
82+
connection.setReadTimeout(DEFAULTREADTIMEOUT);
83+
7984
return connection;
8085
}
8186

0 commit comments

Comments
 (0)