diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt
index 4b770581f2023..eeb5e4a6adfdb 100644
--- a/eng/versioning/version_client.txt
+++ b/eng/versioning/version_client.txt
@@ -22,6 +22,7 @@ com.azure:azure-cosmos-benchmark;4.0.1-beta.1;4.0.1-beta.1
com.azure:azure-data-appconfiguration;1.1.1;1.2.0-beta.1
com.azure:azure-e2e;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-identity;1.0.5;1.1.0-beta.4
+com.azure:azure-identity-perf;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-messaging-eventhubs;5.0.3;5.1.0-beta.1
com.azure:azure-messaging-eventhubs-checkpointstore-blob;1.0.3;1.1.0-beta.1
com.azure:azure-messaging-servicebus;7.0.0-beta.1;7.0.0-beta.2
diff --git a/sdk/identity/azure-identity-perf/README.md b/sdk/identity/azure-identity-perf/README.md
new file mode 100644
index 0000000000000..73530b2e3b06a
--- /dev/null
+++ b/sdk/identity/azure-identity-perf/README.md
@@ -0,0 +1,32 @@
+# Azure Identity Performance test client library for Java
+
+Represents Performance tests for Azure Identity SDK for Java.
+
+## Getting started
+
+### Prerequisites
+
+- Java Development Kit (JDK) with version 8 or above
+
+### Adding the package to your product
+
+
+## Key concepts
+
+
+## Examples
+
+## Troubleshooting
+
+## Next steps
+
+## Contributing
+
+If you would like to become an active contributor to this project please follow the instructions provided in [Microsoft
+Azure Projects Contribution Guidelines](http://azure.github.io/guidelines.html).
+
+1. Fork it
+1. Create your feature branch (`git checkout -b my-new-feature`)
+1. Commit your changes (`git commit -am 'Add some feature'`)
+1. Push to the branch (`git push origin my-new-feature`)
+1. Create new Pull Request
diff --git a/sdk/identity/azure-identity-perf/pom.xml b/sdk/identity/azure-identity-perf/pom.xml
new file mode 100644
index 0000000000000..a48d02f94172e
--- /dev/null
+++ b/sdk/identity/azure-identity-perf/pom.xml
@@ -0,0 +1,68 @@
+
+
+
To run from command line. Package the project into a jar with dependencies via mvn clean package. + * Then run the program via java -jar 'compiled-jar-with-dependencies-path'
+ * + *To run from IDE, set all the required environment variables in IntelliJ via Run -> EditConfigurations section. + * Then run the App's main method via IDE.
+ */ +public class App { + public static void main(String[] args) { + Class>[] testClasses; + + try { + testClasses = new Class>[] { + Class.forName("com.azure.identity.perf.ReadCache"), + Class.forName("com.azure.identity.perf.WriteCache"), + }; + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + + PerfStressProgram.run(testClasses, args); + } +} diff --git a/sdk/identity/azure-identity-perf/src/main/java/com/azure/identity/perf/ReadCache.java b/sdk/identity/azure-identity-perf/src/main/java/com/azure/identity/perf/ReadCache.java new file mode 100644 index 0000000000000..e3a87ea9fe685 --- /dev/null +++ b/sdk/identity/azure-identity-perf/src/main/java/com/azure/identity/perf/ReadCache.java @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.identity.perf; + +import com.azure.identity.SharedTokenCacheCredential; +import com.azure.identity.SharedTokenCacheCredentialBuilder; +import com.azure.identity.perf.core.ServiceTest; +import com.azure.perf.test.core.PerfStressOptions; +import reactor.core.publisher.Mono; + +public class ReadCache extends ServiceTestcacheFileLocation()
instead of
+ * Gnome keyring on Linux. This is false by default.
+ *
+ * @param allowUnencryptedCache whether to use an unprotected file for cache storage.
+ *
+ * @return An updated instance of this builder with the unprotected token cache setting set as specified.
+ */
+ public AuthorizationCodeCredentialBuilder allowUnencryptedCache(boolean allowUnencryptedCache) {
+ this.identityClientOptions.allowUnencryptedCache(allowUnencryptedCache);
+ return this;
+ }
+
+ /**
+ * Sets whether to enable using the shared token cache. This is disabled by default.
+ *
+ * @param enabled whether to enabled using the shared token cache.
+ *
+ * @return An updated instance of this builder with if the shared token cache enabled specified.
+ */
+ public AuthorizationCodeCredentialBuilder enablePersistentCache(boolean enabled) {
+ this.identityClientOptions.enablePersistentCache(enabled);
+ return this;
+ }
+
/**
* Creates a new {@link AuthorizationCodeCredential} with the current configurations.
*
diff --git a/sdk/identity/azure-identity/src/main/java/com/azure/identity/DeviceCodeCredential.java b/sdk/identity/azure-identity/src/main/java/com/azure/identity/DeviceCodeCredential.java
index dbd820196392f..4e2648ee77e67 100644
--- a/sdk/identity/azure-identity/src/main/java/com/azure/identity/DeviceCodeCredential.java
+++ b/sdk/identity/azure-identity/src/main/java/com/azure/identity/DeviceCodeCredential.java
@@ -48,7 +48,7 @@ public class DeviceCodeCredential implements TokenCredential {
public MonocacheFileLocation()
instead of
+ * Gnome keyring on Linux. This is false by default.
+ *
+ * @param allowUnencryptedCache whether to use an unprotected file for cache storage.
+ *
+ * @return An updated instance of this builder with the unprotected token cache setting set as specified.
+ */
+ public DeviceCodeCredentialBuilder allowUnencryptedCache(boolean allowUnencryptedCache) {
+ this.identityClientOptions.allowUnencryptedCache(allowUnencryptedCache);
+ return this;
+ }
+
+ /**
+ * Sets whether to enable using the shared token cache. This is disabled by default.
+ *
+ * @param enabled whether to enabled using the shared token cache.
+ *
+ * @return An updated instance of this builder with if the shared token cache enabled specified.
+ */
+ public DeviceCodeCredentialBuilder enablePersistentCache(boolean enabled) {
+ this.identityClientOptions.enablePersistentCache(enabled);
+ return this;
+ }
+
/**
* Creates a new {@link DeviceCodeCredential} with the current configurations.
*
diff --git a/sdk/identity/azure-identity/src/main/java/com/azure/identity/IntelliJCredential.java b/sdk/identity/azure-identity/src/main/java/com/azure/identity/IntelliJCredential.java
index ab9baa21176d5..3798a75f793ad 100644
--- a/sdk/identity/azure-identity/src/main/java/com/azure/identity/IntelliJCredential.java
+++ b/sdk/identity/azure-identity/src/main/java/com/azure/identity/IntelliJCredential.java
@@ -72,7 +72,7 @@ class IntelliJCredential implements TokenCredential {
public MonocacheFileLocation()
instead of
+ * Gnome keyring on Linux. This is false by default.
+ *
+ * @param allowUnencryptedCache whether to use an unprotected file for cache storage.
+ *
+ * @return An updated instance of this builder with the unprotected token cache setting set as specified.
+ */
+ public InteractiveBrowserCredentialBuilder allowUnencryptedCache(boolean allowUnencryptedCache) {
+ this.identityClientOptions.allowUnencryptedCache(allowUnencryptedCache);
+ return this;
+ }
+
+ /**
+ * Sets whether to enable using the shared token cache. This is disabled by default.
+ *
+ * @param enabled whether to enabled using the shared token cache.
+ *
+ * @return An updated instance of this builder with if the shared token cache enabled specified.
+ */
+ public InteractiveBrowserCredentialBuilder enablePersistentCache(boolean enabled) {
+ this.identityClientOptions.enablePersistentCache(enabled);
+ return this;
+ }
+
/**
* Creates a new {@link InteractiveBrowserCredential} with the current configurations.
*
diff --git a/sdk/identity/azure-identity/src/main/java/com/azure/identity/SharedTokenCacheCredential.java b/sdk/identity/azure-identity/src/main/java/com/azure/identity/SharedTokenCacheCredential.java
index 8565844826b30..ecf37596b9e31 100644
--- a/sdk/identity/azure-identity/src/main/java/com/azure/identity/SharedTokenCacheCredential.java
+++ b/sdk/identity/azure-identity/src/main/java/com/azure/identity/SharedTokenCacheCredential.java
@@ -7,21 +7,13 @@
import com.azure.core.credential.TokenCredential;
import com.azure.core.credential.TokenRequestContext;
import com.azure.core.util.Configuration;
-import com.azure.core.util.CoreUtils;
+import com.azure.identity.implementation.IdentityClient;
+import com.azure.identity.implementation.IdentityClientBuilder;
import com.azure.identity.implementation.IdentityClientOptions;
-import com.azure.identity.implementation.msalextensions.PersistentTokenCacheAccessAspect;
-import com.microsoft.aad.msal4j.IAccount;
-import com.microsoft.aad.msal4j.IAuthenticationResult;
-import com.microsoft.aad.msal4j.PublicClientApplication;
-import com.microsoft.aad.msal4j.SilentParameters;
+import com.azure.identity.implementation.MsalToken;
import reactor.core.publisher.Mono;
-import java.net.MalformedURLException;
-import java.time.ZoneOffset;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicReference;
/**
* A credential provider that provides token credentials from the MSAL shared token cache.
@@ -32,9 +24,9 @@ public class SharedTokenCacheCredential implements TokenCredential {
private final String username;
private final String clientId;
private final String tenantId;
- private final IdentityClientOptions options;
+ private final AtomicReferencecacheFileLocation()
instead of
+ * Gnome keyring on Linux. This is false by default.
+ *
+ * @param allowUnencryptedCache whether to use an unprotected file for cache storage.
+ *
+ * @return An updated instance of this builder with the unprotected token cache setting set as specified.
+ */
+ public SharedTokenCacheCredentialBuilder allowUnencryptedCache(boolean allowUnencryptedCache) {
+ this.identityClientOptions.allowUnencryptedCache(allowUnencryptedCache);
+ return this;
+ }
+
/**
* Creates a new {@link SharedTokenCacheCredentialBuilder} with the current configurations.
*
* @return a {@link SharedTokenCacheCredentialBuilder} with the current configurations.
*/
public SharedTokenCacheCredential build() {
- return new SharedTokenCacheCredential(username, clientId, tenantId, identityClientOptions);
+ return new SharedTokenCacheCredential(username, clientId, tenantId,
+ identityClientOptions.enablePersistentCache(true));
}
}
diff --git a/sdk/identity/azure-identity/src/main/java/com/azure/identity/UsernamePasswordCredential.java b/sdk/identity/azure-identity/src/main/java/com/azure/identity/UsernamePasswordCredential.java
index 5e40ce3385678..39f63b14913e7 100644
--- a/sdk/identity/azure-identity/src/main/java/com/azure/identity/UsernamePasswordCredential.java
+++ b/sdk/identity/azure-identity/src/main/java/com/azure/identity/UsernamePasswordCredential.java
@@ -56,7 +56,7 @@ public class UsernamePasswordCredential implements TokenCredential {
public MonocacheFileLocation()
instead of
+ * Gnome keyring on Linux. This is false by default.
+ *
+ * @param allowUnencryptedCache whether to use an unprotected file for cache storage.
+ *
+ * @return An updated instance of this builder with the unprotected token cache setting set as specified.
+ */
+ public UsernamePasswordCredentialBuilder allowUnencryptedCache(boolean allowUnencryptedCache) {
+ this.identityClientOptions.allowUnencryptedCache(allowUnencryptedCache);
+ return this;
+ }
+
+ /**
+ * Sets whether to enable using the shared token cache. This is disabled by default.
+ *
+ * @param enabled whether to enabled using the shared token cache.
+ *
+ * @return An updated instance of this builder with if the shared token cache enabled specified.
+ */
+ public UsernamePasswordCredentialBuilder enablePersistentCache(boolean enabled) {
+ this.identityClientOptions.enablePersistentCache(enabled);
+ return this;
+ }
+
/**
* Creates a new {@link UsernamePasswordCredential} with the current configurations.
*
diff --git a/sdk/identity/azure-identity/src/main/java/com/azure/identity/VisualStudioCodeCredential.java b/sdk/identity/azure-identity/src/main/java/com/azure/identity/VisualStudioCodeCredential.java
index 4d1f741d1d775..d7f6ec0e24f7c 100644
--- a/sdk/identity/azure-identity/src/main/java/com/azure/identity/VisualStudioCodeCredential.java
+++ b/sdk/identity/azure-identity/src/main/java/com/azure/identity/VisualStudioCodeCredential.java
@@ -57,7 +57,7 @@ class VisualStudioCodeCredential implements TokenCredential {
public MonocacheFileLocation()
instead of
+ * Gnome keyring on Linux. This is false by default.
+ *
+ * @param allowUnencryptedCache whether to use an unprotected file for cache storage.
+ *
+ * @return The updated identity client options.
+ */
+ public IdentityClientOptions allowUnencryptedCache(boolean allowUnencryptedCache) {
+ this.allowUnencryptedCache = allowUnencryptedCache;
+ return this;
+ }
+
/**
* Specifies the database to extract IntelliJ cached credentials from.
* @param keePassDatabasePath the database to extract intellij credentials from.
@@ -207,6 +264,26 @@ public IdentityClientOptions setIntelliJKeePassDatabasePath(String keePassDataba
}
/**
+ * Gets if the shared token cache is disabled.
+ * @return if the shared token cache is disabled.
+ */
+ public boolean isSharedTokenCacheEnabled() {
+ return this.sharedTokenCacheEnabled;
+ }
+
+ /**
+ * Sets whether to enable using the shared token cache. This is disabled by default.
+ *
+ * @param enabled whether to enable using the shared token cache.
+ *
+ * @return The updated identity client options.
+ */
+ public IdentityClientOptions enablePersistentCache(boolean enabled) {
+ this.sharedTokenCacheEnabled = enabled;
+ return this;
+ }
+
+ /*
* Get the KeePass database path.
* @return the KeePass database path to extract inellij credentials from.
*/
diff --git a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/CacheLock.java b/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/CacheLock.java
deleted file mode 100644
index 9d29e2666e0e1..0000000000000
--- a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/CacheLock.java
+++ /dev/null
@@ -1,154 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-package com.azure.identity.implementation.msalextensions;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.channels.FileChannel;
-import java.nio.channels.FileLock;
-import java.nio.channels.OverlappingFileLockException;
-import java.nio.file.Files;
-import java.util.Random;
-
-/**
- * Cache lock for the persistent shared MSAL token cache
- *
- * Needed to maintain the integrity of the cache if multiple processes are trying to access it at the same time.
- * */
-public class CacheLock {
-
- private int lockfileRetryWait = 100;
- private int lockfileRetryCount = 60000 / lockfileRetryWait;
-
- private File lockFile;
-
- private FileOutputStream fos;
- private FileChannel channel;
- private FileLock lock = null;
-
- private File debugFile;
- private String debugFilename = java.nio.file.Paths.get(
- System.getProperty("user.dir"), "target", "debug").toString();
- private final boolean debugFlag;
-
- /**
- * Default constructor to be used to initialize CacheLock
- *
- * @param lockfileName path of the lock file to be used
- * */
- public CacheLock(String lockfileName) {
- lockFile = new File(lockfileName);
- debugFlag = false;
- }
-
- /**
- * Constructor to be used for debugging purposes
- * Enables printing the actions for each process while using the cache lock
- *
- * @param lockfileName path of the lock file to be used
- * @param id name of the current process so
- * */
- public CacheLock(String lockfileName, String id) {
- lockFile = new File(lockfileName);
- debugFile = new File(debugFilename + id + ".txt");
- debugFlag = true;
- }
-
- /**
- * Tries to obtain the lock by creating a file lock on the provided lockFile
- * If it cannot be obtained right away, it retries lockfileRetryCount = 60000 / lockfileRetryWait times
- *
- * @throws CacheLockNotObtainedException if the lock cannot be obtained after all these tries.
- * */
- public void lock() throws CacheLockNotObtainedException {
- try {
- for (int tryCount = 0; tryCount < lockfileRetryCount; tryCount++) {
-
- if (debugFlag) {
- try {
- fos = new FileOutputStream(debugFile, true);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
-
- if (!lockFile.exists()) { // file doesn't already exist so now you have to make a new one
- if (lockFile.createNewFile()) {
- lockFile.deleteOnExit();
-
- try {
- channel = new RandomAccessFile(lockFile, "rw").getChannel();
- lock = channel.lock();
-
- printToFileIfDebug("Locked!\n");
- return; //success
-
- } catch (OverlappingFileLockException e) {
- printToFileIfDebug("overlap error\n");
- } catch (Exception e) {
- printToFileIfDebug("something else went wrong.. general exception\n");
- }
-
- } else {
- printToFileIfDebug("lockfile already exists\n");
- }
- } else {
- printToFileIfDebug("create new file failed");
- }
-
- printToFileIfDebug("retry\n");
-
- try {
- Random rand = new Random(System.currentTimeMillis());
- int offset = rand.nextInt(10);
- // slight offset in case multiple threads/processes have the same wait time
- Thread.sleep(lockfileRetryWait + offset);
- } catch (InterruptedException ex) {
- printToFileIfDebug("thread sleep issue");
- }
- }
-
- } catch (IOException e) {
- printToFileIfDebug("general exception, not sure what happened here...no retries\n");
- }
-
- throw new CacheLockNotObtainedException("Maximum retries used; could not obtain CacheLock");
- }
-
- /**
- * Tries to unlock the file lock
- *
- * @return true if the file was unlocked, false otherwise
- * */
- public boolean unlock() {
- try {
- lock.release();
- channel.close();
- Files.delete(java.nio.file.Paths.get(lockFile.getPath()));
-
- printToFileIfDebug("unlocked\n");
-
- return true;
- } catch (IOException e) {
- printToFileIfDebug("not unlocked... IOException: " + e.getMessage());
- return false;
- }
- }
-
- /**
- * If debugFlag is true, then this will print logs to the file, otherwise it will do nothing
- */
- private void printToFileIfDebug(String message) {
- if (debugFlag && fos != null) {
- try {
- fos.write(message.getBytes("UTF-8"));
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-}
diff --git a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/CacheLockNotObtainedException.java b/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/CacheLockNotObtainedException.java
deleted file mode 100644
index de36ebf7be389..0000000000000
--- a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/CacheLockNotObtainedException.java
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-package com.azure.identity.implementation.msalextensions;
-
-/**
- * Exception for when the {@link CacheLock} cannot be obtained when trying cacheLock.lock()
- * */
-public class CacheLockNotObtainedException extends RuntimeException {
-
- /**
- * Initializes CacheLockNotObtainedException
- *
- * @param message Error message
- * */
- public CacheLockNotObtainedException(String message) {
- super(message);
- }
-}
diff --git a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/PersistentTokenCacheAccessAspect.java b/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/PersistentTokenCacheAccessAspect.java
deleted file mode 100644
index 74d5377d19c79..0000000000000
--- a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/PersistentTokenCacheAccessAspect.java
+++ /dev/null
@@ -1,87 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-package com.azure.identity.implementation.msalextensions;
-
-import com.azure.core.util.logging.ClientLogger;
-import com.azure.identity.implementation.msalextensions.cachepersister.CachePersister;
-import com.azure.identity.implementation.msalextensions.cachepersister.PlatformNotSupportedException;
-import com.microsoft.aad.msal4j.ITokenCacheAccessAspect;
-import com.microsoft.aad.msal4j.ITokenCacheAccessContext;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-
-/**
- * Access Aspect for accessing the token cache
- * Allows for notifications for the cache before/after access so the lock can be used
- * */
-public class PersistentTokenCacheAccessAspect implements ITokenCacheAccessAspect {
-
- private CachePersister cachePersister;
- private ClientLogger logger;
-
- /**
- * Default constructor, creates a CachePersister object
- *
- * @throws IOException from errors in creating the CachePersister
- * @throws PlatformNotSupportedException from errors in creating the CachePersister
- * */
- public PersistentTokenCacheAccessAspect() throws RuntimeException, PlatformNotSupportedException {
- logger = new ClientLogger(PersistentTokenCacheAccessAspect.class);
-
- cachePersister = new CachePersister.Builder().build();
- }
-
- /**
- * Constructor with a custom CachePersister object
- *
- * @param customCachePersister
- * */
- public PersistentTokenCacheAccessAspect(CachePersister customCachePersister) {
- cachePersister = customCachePersister;
- }
-
- /**
- * Loads token cache to memory using CachePersister - deserialize data in file to Token Cache class
- *
- * @param iTokenCacheAccessContext
- * */
- public void beforeCacheAccess(ITokenCacheAccessContext iTokenCacheAccessContext) {
-
- byte[] bytes = cachePersister.readCache();
- String data;
- try {
- data = new String(bytes, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- data = "";
- }
-
- iTokenCacheAccessContext.tokenCache().deserialize(data);
- }
-
- /**
- * Reads memory and writes to token cache file using CachePersister
- *
- * @param iTokenCacheAccessContext
- * */
- public void afterCacheAccess(ITokenCacheAccessContext iTokenCacheAccessContext) {
-
- if (iTokenCacheAccessContext.hasCacheChanged()) {
- String newData = iTokenCacheAccessContext.tokenCache().serialize();
- try {
- cachePersister.writeCache(newData.getBytes("UTF-8"));
- } catch (UnsupportedEncodingException e) {
- // don't update cache
- logger.error("was not able to write to cache");
- }
- }
- }
-
- /**
- * Wrapper method to delete cache
- * */
- public void deleteCache() {
- cachePersister.deleteCache();
- }
-}
diff --git a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/cachepersister/CachePersister.java b/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/cachepersister/CachePersister.java
deleted file mode 100644
index 42d4ff0e5cb45..0000000000000
--- a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/cachepersister/CachePersister.java
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-package com.azure.identity.implementation.msalextensions.cachepersister;
-
-import com.azure.identity.implementation.msalextensions.cachepersister.windows.WindowsDPAPICacheProtector;
-import com.sun.jna.Platform;
-
-import java.io.IOException;
-
-/**
- * Wrapper class for CacheProtector
- * Determines the type of CacheProtector to use (if possible) and instantiates it
- * Also contains wrapper methods for read, write, and delete cache
- * */
-public final class CachePersister {
-
- private CacheProtectorBase cacheProtector;
-
- /**
- * Default constructor
- * */
- private CachePersister(CacheProtectorBase cacheProtector) {
- this.cacheProtector = cacheProtector;
- }
-
- /**
- * Wrapper method for reading cache
- *
- * @return byte[] of cache contents
- * */
- public byte[] readCache() {
- return cacheProtector.readCache();
- }
-
- /**
- * Wrapper method for writing to the cache
- *
- * @param data Cache contents
- * */
- public void writeCache(byte[] data) {
- cacheProtector.writeCache(data);
- }
-
- public boolean deleteCache() {
- return cacheProtector.deleteCache();
- }
-
- /**
- * Builder for CachePersister class
- * Creates appropriate file paths and account and service names, and calls createCacheProtector
- * */
- public static class Builder {
-
- private String cacheLocation;
- private String lockfileLocation;
-
- /**
- * Default builder based on platform for cache file, and default service and account names
- */
- public Builder() {
-
- // determine platform and create cache file location
- if (Platform.isWindows()) {
- cacheLocation = java.nio.file.Paths.get(System.getProperty("user.home"),
- "AppData", "Local", ".IdentityService", "msal.cache").toString();
- } else {
- cacheLocation = java.nio.file.Paths.get(System.getProperty("user.home"),
- "msal.cache").toString();
- }
- lockfileLocation = cacheLocation + ".lockfile";
-//
-// serviceName = "Microsoft.Developer.IdentityService";
-// accountName = "MSALCache";
- }
-
- /**
- * @return Builder with updated cacheLocation and lockfileLocation
- * */
- public Builder cacheLocation(String cacheLocation) {
- this.cacheLocation = cacheLocation;
- this.lockfileLocation = cacheLocation + ".lockfile";
- return this;
- }
-
- /**
- * @return Builder with updated lockfileLocation
- * */
- public Builder lockfileLocation(String lockfileLocation) {
- this.lockfileLocation = lockfileLocation;
- return this;
- }
-
- /**
- * Builds CachePersister with all the information passed into the Builder
- *
- * @return newly instantiated CachePersister
- * */
- public CachePersister build() throws RuntimeException {
- if (Platform.isWindows()) {
- try {
- return new CachePersister(new WindowsDPAPICacheProtector(cacheLocation, lockfileLocation));
- } catch (IOException e) {
- throw new RuntimeException("IO Exception in creating the WindowsDPAPICacheProtector");
- }
- } else {
- throw new PlatformNotSupportedException("Platform is not supported");
- }
- }
- }
-}
diff --git a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/cachepersister/CacheProtectorBase.java b/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/cachepersister/CacheProtectorBase.java
deleted file mode 100644
index 453043940e0fb..0000000000000
--- a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/cachepersister/CacheProtectorBase.java
+++ /dev/null
@@ -1,128 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-package com.azure.identity.implementation.msalextensions.cachepersister;
-
-import com.azure.core.util.logging.ClientLogger;
-import com.azure.identity.implementation.msalextensions.CacheLock;
-import com.azure.identity.implementation.msalextensions.CacheLockNotObtainedException;
-
-import java.io.IOException;
-
-/**
- * Abstract class for Cache Protectors
- * Provides methods to read and write cache while using a CacheLock
- * */
-public abstract class CacheProtectorBase {
-
- private String lockfileLocation;
- private CacheLock lock;
-
- private ClientLogger logger;
-
- /**
- * Constructor
- * initializes cacheLock
- * */
- public CacheProtectorBase(String lockfileLocation) {
- logger = new ClientLogger(CacheProtectorBase.class);
-
- this.lockfileLocation = lockfileLocation;
- lock = new CacheLock(this.lockfileLocation);
- }
-
- /**
- * Obtains lock and uses unprotect() to read and decrypt contents of the cache
- *
- * @return byte[] contents of cache
- * */
- public byte[] readCache() {
- byte[] contents = null;
-
- try {
- lock.lock();
- } catch (CacheLockNotObtainedException ex) {
- logger.error("readCache() - Issue in locking");
- return contents;
- }
-
- try {
- contents = unprotect();
- } catch (IOException ex) {
- logger.error("readCache() - Issue in reading");
- }
-
- lock.unlock();
- return contents;
- }
-
- /**
- * Obtains lock and uses protect() to read and encrypt contents of the cache
- *
- * @param data data to write to cache
- * */
- public void writeCache(byte[] data) {
-
- try {
- lock.lock();
- } catch (CacheLockNotObtainedException e) {
- logger.error("writeCache() - Issue in locking");
- return;
- }
-
- try {
- protect(data);
- } catch (IOException e) {
- logger.error("writeCache() - Issue in writing");
- }
-
- lock.unlock();
- }
-
- /**
- * Decrypts data from cache
- *
- * @return byte[] of cache contents
- *
- * Overwritten by subclasses; each OS handles differently
- * */
- protected byte[] unprotect() throws IOException {
- byte[] empty = {};
- return empty;
- }
-
- /**
- * Encrypts data and writes to cache
- *
- * @param data
- *
- * Overwritten by subclasses; each OS handles differently
- * */
- protected void protect(byte[] data) throws IOException {
- }
-
- /**
- * Obtains lock and deletes cache using deleteCacheHelper()
- *
- * @return true if cache is deleted, false otherwise
- * */
- public boolean deleteCache() {
- try {
- lock.lock();
- } catch (CacheLockNotObtainedException e) {
- logger.error("deleteCache() - issue in locking");
- return false;
- }
-
- deleteCacheHelper();
- lock.unlock();
-
- return true;
- }
-
- /**
- * Overwritten by subclasses; each OS handles differently
- * */
- protected void deleteCacheHelper() {
- }
-}
diff --git a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/cachepersister/PlatformNotSupportedException.java b/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/cachepersister/PlatformNotSupportedException.java
deleted file mode 100644
index 61bab965a1d5b..0000000000000
--- a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/cachepersister/PlatformNotSupportedException.java
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-package com.azure.identity.implementation.msalextensions.cachepersister;
-
-/**
- * Exception for when the current OS is not supported by {@link CachePersister}
- * so the OS specific DPAPI cannot be used to encrypt the token cache.
- * */
-public class PlatformNotSupportedException extends RuntimeException {
-
- /**
- * Initializes PlatformNotSupportedException
- *
- * @param message Error message
- * */
- public PlatformNotSupportedException(String message) {
- super(message);
- }
-
-}
diff --git a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/cachepersister/windows/WindowsDPAPICacheProtector.java b/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/cachepersister/windows/WindowsDPAPICacheProtector.java
deleted file mode 100644
index 97f3091ad8f39..0000000000000
--- a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/msalextensions/cachepersister/windows/WindowsDPAPICacheProtector.java
+++ /dev/null
@@ -1,95 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-package com.azure.identity.implementation.msalextensions.cachepersister.windows;
-
-import com.azure.identity.implementation.msalextensions.cachepersister.CacheProtectorBase;
-import com.sun.jna.platform.win32.Crypt32Util;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-/**
- * Cache Protector for Windows which uses Windows DPAPI to encrypt the cache
- * */
-public class WindowsDPAPICacheProtector extends CacheProtectorBase {
-
- private final String cacheFilename;
- private File cacheFile;
-
- /**
- * Constructor to initialize WindowsDPAPICacheProtector
- * Calls super constructor to initialize lock
- *
- * @param cacheLocation
- * @param lockfileLocation
- *
- * @throws IOException if cacheFile File isn't created
- * */
- public WindowsDPAPICacheProtector(String cacheLocation, String lockfileLocation) throws IOException {
- super(lockfileLocation);
- cacheFilename = cacheLocation;
- cacheFile = new File(cacheFilename);
-
- makeSureFileExists();
- }
-
- /**
- * Uses DPAPI to read and decrypt cache contents
- *
- * @return byte[] cache contents
- * */
- protected byte[] unprotect() throws IOException {
- makeSureFileExists();
-
- byte[] encryptedBytes = new byte[(int) cacheFile.length()];
-
- try (FileInputStream stream = new FileInputStream(cacheFile)) {
- int read = 0;
- while (read != encryptedBytes.length) {
- read += stream.read(encryptedBytes);
- }
- }
-
- byte[] decryptedBytes = Crypt32Util.cryptUnprotectData(encryptedBytes);
- return decryptedBytes;
- }
-
- /**
- * Uses DPAPI to write and protect cache contents
- *
- * @param data contents to write to cache
- * */
- protected void protect(byte[] data) throws IOException {
- makeSureFileExists();
-
- byte[] encryptedBytes = Crypt32Util.cryptProtectData(data);
-
- try (FileOutputStream stream = new FileOutputStream(cacheFile)) {
- stream.write(encryptedBytes);
- }
- }
-
- /**
- * Make sure file exists - and write " " if it was just created
- * Just a backup in case the cache was deleted
- * */
- private void makeSureFileExists() throws IOException {
- if (!cacheFile.exists()) {
- cacheFile.createNewFile();
- protect(" ".getBytes("UTF-8"));
- }
- }
-
- /**
- * Deletes the cache file if it exists
- * */
- public void deleteCacheHelper() {
- if (cacheFile.exists()) {
- cacheFile.delete();
- }
- }
-
-}
diff --git a/sdk/identity/azure-identity/src/test/java/com/azure/identity/AuthorizationCodeCredentialTest.java b/sdk/identity/azure-identity/src/test/java/com/azure/identity/AuthorizationCodeCredentialTest.java
index 0b9305627739b..b15a28f51478e 100644
--- a/sdk/identity/azure-identity/src/test/java/com/azure/identity/AuthorizationCodeCredentialTest.java
+++ b/sdk/identity/azure-identity/src/test/java/com/azure/identity/AuthorizationCodeCredentialTest.java
@@ -47,7 +47,7 @@ public void testValidAuthorizationCode() throws Exception {
IdentityClient identityClient = PowerMockito.mock(IdentityClient.class);
when(identityClient.authenticateWithAuthorizationCode(eq(request1), eq(authCode1), eq(redirectUri)))
.thenReturn(TestUtils.getMockMsalToken(token1, expiresAt));
- when(identityClient.authenticateWithUserRefreshToken(any(), any()))
+ when(identityClient.authenticateWithMsalAccount(any(), any()))
.thenAnswer(invocation -> {
TokenRequestContext argument = (TokenRequestContext) invocation.getArguments()[0];
if (argument.getScopes().size() == 1 && argument.getScopes().get(0).equals(request2.getScopes().get(0))) {
diff --git a/sdk/identity/azure-identity/src/test/java/com/azure/identity/DefaultAzureCredentialTest.java b/sdk/identity/azure-identity/src/test/java/com/azure/identity/DefaultAzureCredentialTest.java
index 50405f6990b03..a01add160fb3e 100644
--- a/sdk/identity/azure-identity/src/test/java/com/azure/identity/DefaultAzureCredentialTest.java
+++ b/sdk/identity/azure-identity/src/test/java/com/azure/identity/DefaultAzureCredentialTest.java
@@ -25,7 +25,8 @@
@RunWith(PowerMockRunner.class)
@PrepareForTest(fullyQualifiedNames = "com.azure.identity.*")
-@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*"})
+@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.net.ssl.*",
+ "io.netty.handler.ssl.*", "io.netty.buffer.*", "io.netty.channel.*"})
public class DefaultAzureCredentialTest {
private final String tenantId = "contoso.com";
@@ -95,7 +96,7 @@ public void testUseManagedIdentityCredential() throws Exception {
&& expiresAt.getSecond() == accessToken.getExpiresAt().getSecond())
.verifyComplete();
}
-
+
@Test
public void testUseAzureCliCredential() throws Exception {
// setup
@@ -113,6 +114,7 @@ public void testUseAzureCliCredential() throws Exception {
IdentityClient identityClient = PowerMockito.mock(IdentityClient.class);
when(identityClient.authenticateWithAzureCli(request)).thenReturn(TestUtils.getMockAccessToken(token1, expiresAt));
when(identityClient.authenticateToIMDSEndpoint(request)).thenReturn(Mono.empty());
+ when(identityClient.authenticateWithSharedTokenCache(request, null)).thenReturn(Mono.empty());
when(identityClient.authenticateWithIntelliJ(request)).thenReturn(Mono.empty());
when(identityClient.authenticateWithVsCodeCredential(any(), any())).thenReturn(Mono.empty());
PowerMockito.whenNew(IdentityClient.class).withAnyArguments().thenReturn(identityClient);
diff --git a/sdk/identity/azure-identity/src/test/java/com/azure/identity/DeviceCodeCredentialTest.java b/sdk/identity/azure-identity/src/test/java/com/azure/identity/DeviceCodeCredentialTest.java
index 126e3f5f1e667..8660390ff28db 100644
--- a/sdk/identity/azure-identity/src/test/java/com/azure/identity/DeviceCodeCredentialTest.java
+++ b/sdk/identity/azure-identity/src/test/java/com/azure/identity/DeviceCodeCredentialTest.java
@@ -46,7 +46,7 @@ public void testValidDeviceCode() throws Exception {
// mock
IdentityClient identityClient = PowerMockito.mock(IdentityClient.class);
when(identityClient.authenticateWithDeviceCode(eq(request1), eq(consumer))).thenReturn(TestUtils.getMockMsalToken(token1, expiresAt));
- when(identityClient.authenticateWithUserRefreshToken(any(), any()))
+ when(identityClient.authenticateWithMsalAccount(any(), any()))
.thenAnswer(invocation -> {
TokenRequestContext argument = (TokenRequestContext) invocation.getArguments()[0];
if (argument.getScopes().size() == 1 && argument.getScopes().get(0).equals(request2.getScopes().get(0))) {
diff --git a/sdk/identity/azure-identity/src/test/java/com/azure/identity/InteractiveBrowserCredentialTest.java b/sdk/identity/azure-identity/src/test/java/com/azure/identity/InteractiveBrowserCredentialTest.java
index 5f89055c0861a..1b5e1e2a94a8d 100644
--- a/sdk/identity/azure-identity/src/test/java/com/azure/identity/InteractiveBrowserCredentialTest.java
+++ b/sdk/identity/azure-identity/src/test/java/com/azure/identity/InteractiveBrowserCredentialTest.java
@@ -48,7 +48,7 @@ public void testValidInteractive() throws Exception {
// mock
IdentityClient identityClient = PowerMockito.mock(IdentityClient.class);
when(identityClient.authenticateWithBrowserInteraction(eq(request1), eq(port))).thenReturn(TestUtils.getMockMsalToken(token1, expiresAt));
- when(identityClient.authenticateWithUserRefreshToken(any(), any()))
+ when(identityClient.authenticateWithMsalAccount(any(), any()))
.thenAnswer(invocation -> {
TokenRequestContext argument = (TokenRequestContext) invocation.getArguments()[0];
if (argument.getScopes().size() == 1 && argument.getScopes().get(0).equals(request2.getScopes().get(0))) {
diff --git a/sdk/identity/azure-identity/src/test/java/com/azure/identity/UsernamePasswordCredentialTest.java b/sdk/identity/azure-identity/src/test/java/com/azure/identity/UsernamePasswordCredentialTest.java
index b78ef63b8412b..bd75c2307e036 100644
--- a/sdk/identity/azure-identity/src/test/java/com/azure/identity/UsernamePasswordCredentialTest.java
+++ b/sdk/identity/azure-identity/src/test/java/com/azure/identity/UsernamePasswordCredentialTest.java
@@ -47,7 +47,7 @@ public void testValidUserCredential() throws Exception {
// mock
IdentityClient identityClient = PowerMockito.mock(IdentityClient.class);
when(identityClient.authenticateWithUsernamePassword(request1, username, password)).thenReturn(TestUtils.getMockMsalToken(token1, expiresAt));
- when(identityClient.authenticateWithUserRefreshToken(any(), any()))
+ when(identityClient.authenticateWithMsalAccount(any(), any()))
.thenAnswer(invocation -> {
TokenRequestContext argument = (TokenRequestContext) invocation.getArguments()[0];
if (argument.getScopes().size() == 1 && argument.getScopes().get(0).equals(request2.getScopes().get(0))) {
@@ -83,7 +83,7 @@ public void testInvalidUserCredential() throws Exception {
// mock
IdentityClient identityClient = PowerMockito.mock(IdentityClient.class);
when(identityClient.authenticateWithUsernamePassword(request, username, badPassword)).thenThrow(new MsalServiceException("bad credential", "BadCredential"));
- when(identityClient.authenticateWithUserRefreshToken(any(), any()))
+ when(identityClient.authenticateWithMsalAccount(any(), any()))
.thenAnswer(invocation -> Mono.error(new UnsupportedOperationException("nothing cached")));
PowerMockito.whenNew(IdentityClient.class).withAnyArguments().thenReturn(identityClient);
@@ -107,7 +107,7 @@ public void testInvalidParameters() throws Exception {
// mock
IdentityClient identityClient = PowerMockito.mock(IdentityClient.class);
when(identityClient.authenticateWithUsernamePassword(request, username, password)).thenReturn(TestUtils.getMockMsalToken(token1, expiresOn));
- when(identityClient.authenticateWithUserRefreshToken(any(), any()))
+ when(identityClient.authenticateWithMsalAccount(any(), any()))
.thenAnswer(invocation -> Mono.error(new UnsupportedOperationException("nothing cached")));
PowerMockito.whenNew(IdentityClient.class).withAnyArguments().thenReturn(identityClient);
diff --git a/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/IdentityClientIntegrationTests.java b/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/IdentityClientIntegrationTests.java
index aa7fd71b7aef2..72adcc2c2f8d6 100644
--- a/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/IdentityClientIntegrationTests.java
+++ b/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/IdentityClientIntegrationTests.java
@@ -51,7 +51,7 @@ public void deviceCodeCanGetToken() {
Assert.assertNotNull(token.getToken());
Assert.assertNotNull(token.getExpiresAt());
Assert.assertFalse(token.isExpired());
- token = client.authenticateWithUserRefreshToken(new TokenRequestContext().addScopes("https://vault.azure.net/.default"), token).block();
+ token = client.authenticateWithMsalAccount(new TokenRequestContext().addScopes("https://vault.azure.net/.default"), token.getAccount()).block();
Assert.assertNotNull(token);
Assert.assertNotNull(token.getToken());
Assert.assertNotNull(token.getExpiresAt());
@@ -66,7 +66,7 @@ public void browserCanGetToken() {
Assert.assertNotNull(token.getToken());
Assert.assertNotNull(token.getExpiresAt());
Assert.assertFalse(token.isExpired());
- token = client.authenticateWithUserRefreshToken(new TokenRequestContext().addScopes("https://vault.azure.net/.default"), token).block();
+ token = client.authenticateWithMsalAccount(new TokenRequestContext().addScopes("https://vault.azure.net/.default"), token.getAccount()).block();
Assert.assertNotNull(token);
Assert.assertNotNull(token.getToken());
Assert.assertNotNull(token.getExpiresAt());
@@ -81,7 +81,7 @@ public void usernamePasswordCanGetToken() {
Assert.assertNotNull(token.getToken());
Assert.assertNotNull(token.getExpiresAt());
Assert.assertFalse(token.isExpired());
- token = client.authenticateWithUserRefreshToken(new TokenRequestContext().addScopes("https://vault.azure.net/.default"), token).block();
+ token = client.authenticateWithMsalAccount(new TokenRequestContext().addScopes("https://vault.azure.net/.default"), token.getAccount()).block();
Assert.assertNotNull(token);
Assert.assertNotNull(token.getToken());
Assert.assertNotNull(token.getExpiresAt());
@@ -96,7 +96,7 @@ public void authCodeCanGetToken() throws Exception {
Assert.assertNotNull(token.getToken());
Assert.assertNotNull(token.getExpiresAt());
Assert.assertFalse(token.isExpired());
- token = client.authenticateWithUserRefreshToken(new TokenRequestContext().addScopes("https://vault.azure.net/.default"), token).block();
+ token = client.authenticateWithMsalAccount(new TokenRequestContext().addScopes("https://vault.azure.net/.default"), token.getAccount()).block();
Assert.assertNotNull(token);
Assert.assertNotNull(token.getToken());
Assert.assertNotNull(token.getExpiresAt());
diff --git a/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/IdentityClientTests.java b/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/IdentityClientTests.java
index 1e942dbd516f7..72fe05076ecc4 100644
--- a/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/IdentityClientTests.java
+++ b/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/IdentityClientTests.java
@@ -169,7 +169,8 @@ public void testValidDeviceCodeFlow() throws Exception {
mockForDeviceCodeFlow(request, accessToken, expiresOn);
// test
- IdentityClient client = new IdentityClientBuilder().tenantId(tenantId).clientId(clientId).build();
+ IdentityClientOptions options = new IdentityClientOptions();
+ IdentityClient client = new IdentityClientBuilder().tenantId(tenantId).clientId(clientId).identityClientOptions(options).build();
AccessToken token = client.authenticateWithDeviceCode(request, deviceCodeChallenge -> { /* do nothing */ }).block();
Assert.assertEquals(accessToken, token.getToken());
Assert.assertEquals(expiresOn.getSecond(), token.getExpiresAt().getSecond());
@@ -237,7 +238,8 @@ public void testAuthorizationCodeFlow() throws Exception {
mockForAuthorizationCodeFlow(token1, request, expiresAt);
// test
- IdentityClient client = new IdentityClientBuilder().tenantId(tenantId).clientId(clientId).build();
+ IdentityClientOptions options = new IdentityClientOptions();
+ IdentityClient client = new IdentityClientBuilder().tenantId(tenantId).clientId(clientId).identityClientOptions(options).build();
StepVerifier.create(client.authenticateWithAuthorizationCode(request, authCode1, redirectUri))
.expectNextMatches(accessToken -> token1.equals(accessToken.getToken())
&& expiresAt.getSecond() == accessToken.getExpiresAt().getSecond())
@@ -256,8 +258,9 @@ public void testUserRefreshTokenflow() throws Exception {
mockForUserRefreshTokenFlow(token2, request2, expiresAt);
// test
- IdentityClient client = new IdentityClientBuilder().tenantId(tenantId).clientId(clientId).build();
- StepVerifier.create(client.authenticateWithUserRefreshToken(request2, TestUtils.getMockMsalToken(token1, expiresAt).block()))
+ IdentityClientOptions options = new IdentityClientOptions();
+ IdentityClient client = new IdentityClientBuilder().tenantId(tenantId).clientId(clientId).identityClientOptions(options).build();
+ StepVerifier.create(client.authenticateWithMsalAccount(request2, TestUtils.getMockMsalAccount(token1, expiresAt).block()))
.expectNextMatches(accessToken -> token2.equals(accessToken.getToken())
&& expiresAt.getSecond() == accessToken.getExpiresAt().getSecond())
.verifyComplete();
@@ -276,7 +279,8 @@ public void testUsernamePasswordCodeFlow() throws Exception {
mockForUsernamePasswordCodeFlow(token, request, expiresOn);
// test
- IdentityClient client = new IdentityClientBuilder().tenantId(tenantId).clientId(clientId).build();
+ IdentityClientOptions options = new IdentityClientOptions();
+ IdentityClient client = new IdentityClientBuilder().tenantId(tenantId).clientId(clientId).identityClientOptions(options).build();
StepVerifier.create(client.authenticateWithUsernamePassword(request, username, password))
.expectNextMatches(accessToken -> token.equals(accessToken.getToken())
&& expiresOn.getSecond() == accessToken.getExpiresAt().getSecond())
@@ -297,7 +301,8 @@ public void testBrowserAuthenicationCodeFlow() throws Exception {
mocForBrowserAuthenticationCodeFlow();
// test
- IdentityClient client = new IdentityClientBuilder().tenantId(tenantId).clientId(clientId).build();
+ IdentityClientOptions options = new IdentityClientOptions();
+ IdentityClient client = new IdentityClientBuilder().tenantId(tenantId).clientId(clientId).identityClientOptions(options).build();
StepVerifier.create(client.authenticateWithBrowserInteraction(request, 4567))
.expectNextMatches(accessToken -> token.equals(accessToken.getToken())
&& expiresOn.getSecond() == accessToken.getExpiresAt().getSecond())
diff --git a/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/msalextensions/CacheLockTest.java b/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/msalextensions/CacheLockTest.java
deleted file mode 100644
index f28d76a8aef3a..0000000000000
--- a/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/msalextensions/CacheLockTest.java
+++ /dev/null
@@ -1,235 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-package com.azure.identity.implementation.msalextensions;
-
-import com.sun.jna.Platform;
-import org.junit.*;
-
-import java.io.*;
-import java.util.Stack;
-import java.util.stream.Collectors;
-
-public class CacheLockTest {
-
- private static String folder;
- private static String testerFilename;
- private static String lockfile;
-
- @BeforeClass
- public static void setup() {
- // get proper file paths
- String currDir = System.getProperty("user.dir");
- String home = System.getProperty("user.home");
-
- java.nio.file.Path classes = java.nio.file.Paths.get(currDir, "target", "classes");
- java.nio.file.Path tests = java.nio.file.Paths.get(currDir, "target", "test-classes");
-
- testerFilename = java.nio.file.Paths.get(home, "tester.txt").toString();
- lockfile = java.nio.file.Paths.get(home, "testlock.lockfile").toString();
-
- String delimiter = ":";
- if (Platform.isWindows()) {
- delimiter = ";";
- }
- folder = classes.toString() + delimiter + tests;
- }
-
- @Test
- public void tenThreadsWritingToFile() throws IOException {
-
- // make sure tester.json file doesn't already exist
- File tester = new File(testerFilename);
- tester.delete();
-
- // delete the lock file just in case before starting
- File lock = new File(lockfile);
- lock.delete();
-
- FileWriter a = new FileWriter("a", lockfile, testerFilename);
- FileWriter b = new FileWriter("b", lockfile, testerFilename);
- FileWriter c = new FileWriter("c", lockfile, testerFilename);
- FileWriter d = new FileWriter("d", lockfile, testerFilename);
- FileWriter e = new FileWriter("e", lockfile, testerFilename);
- FileWriter f = new FileWriter("f", lockfile, testerFilename);
- FileWriter g = new FileWriter("g", lockfile, testerFilename);
- FileWriter h = new FileWriter("h", lockfile, testerFilename);
- FileWriter i = new FileWriter("i", lockfile, testerFilename);
- FileWriter j = new FileWriter("j", lockfile, testerFilename);
-
- try {
- a.t.join();
- b.t.join();
- c.t.join();
- d.t.join();
- e.t.join();
- f.t.join();
- g.t.join();
- h.t.join();
- i.t.join();
- j.t.join();
- } catch (Exception ex) {
- System.out.printf("Error with threads");
- }
-
- Stack