-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Persistence token cache for Mac & Linux with new MSAL ext #9188
Changes from 49 commits
898a02f
132c01a
3c03443
49acab7
f50d8b7
4e4c467
fca0133
571b44c
e2c5dc3
dd341e7
7cba579
600fc6b
1c53b24
3539779
80bb671
b289411
a83c9ab
52e11f6
5a79873
bfcf3b3
3660848
8c5606a
435a4f2
4ad8ef8
5ac9807
0b48bbb
f8245f0
e8d572a
ed6b013
1472726
1cc8254
6b1e50d
3a16cad
db0eb37
775568f
006b191
eb9c615
abfbea9
233ce5c
a0b1725
77c8a59
7c7045c
ed8e722
09718dd
806539a
066d413
6cc8c1b
d5c4662
0bf3f76
b337b93
4e1d1a0
5b4e878
25d2a63
e3a405d
3dff1f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<parent> | ||
<groupId>com.azure</groupId> | ||
<artifactId>azure-client-sdk-parent</artifactId> | ||
<version>1.7.0</version> <!-- {x-version-update;com.azure:azure-client-sdk-parent;current} --> | ||
<relativePath>../../../pom.client.xml</relativePath> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.azure</groupId> | ||
<artifactId>azure-identity-perf</artifactId> | ||
<version>1.0.0-beta.1</version> <!-- {x-version-update;com.azure:azure-identity-perf;current} --> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.azure</groupId> | ||
<artifactId>azure-identity</artifactId> | ||
<version>1.1.0-beta.4</version> <!-- {x-version-update;com.azure:azure-identity;current} --> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.azure</groupId> | ||
<artifactId>perf-test-core</artifactId> | ||
<version>1.0.0-beta.1</version> <!-- {x-version-update;com.azure:perf-test-core;current} --> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<version>3.2.0</version> <!-- {x-version-update;org.apache.maven.plugins:maven-assembly-plugin;external_dependency} --> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<mainClass> | ||
com.azure.identity.perf.App | ||
</mainClass> | ||
</manifest> | ||
</archive> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.identity.perf; | ||
|
||
import com.azure.perf.test.core.PerfStressProgram; | ||
|
||
/** | ||
* Runs the Identity performance tests. | ||
* | ||
* Test scenarios: | ||
* 1. Read cache from a single process | ||
* 2. Read cache from multiple processes | ||
* 3. Write cache from a single process | ||
* 4. Write cache from multiple processes | ||
* | ||
* <p>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' </p> | ||
* | ||
* <p> 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.</p> | ||
*/ | ||
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ServiceTest<PerfStressOptions> { | ||
private final SharedTokenCacheCredential credential; | ||
|
||
public ReadCache(PerfStressOptions options) { | ||
super(options); | ||
credential = new SharedTokenCacheCredentialBuilder() | ||
.clientId(CLI_CLIENT_ID) | ||
.build(); | ||
} | ||
|
||
// Perform the API call to be tested here | ||
@Override | ||
public void run() { | ||
credential.getToken(ARM_TOKEN_REQUEST_CONTEXT).block(); | ||
} | ||
|
||
@Override | ||
public Mono<Void> runAsync() { | ||
return credential.getToken(ARM_TOKEN_REQUEST_CONTEXT).then(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// 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; | ||
|
||
import java.time.Duration; | ||
|
||
public class WriteCache extends ServiceTest<PerfStressOptions> { | ||
private final SharedTokenCacheCredential credential; | ||
|
||
public WriteCache(PerfStressOptions options) { | ||
super(options); | ||
credential = new SharedTokenCacheCredentialBuilder() | ||
.clientId(CLI_CLIENT_ID) | ||
.tokenRefreshOffset(Duration.ofMinutes(60)) | ||
.build(); | ||
} | ||
|
||
// Perform the API call to be tested here | ||
@Override | ||
public void run() { | ||
credential.getToken(ARM_TOKEN_REQUEST_CONTEXT).block(); | ||
} | ||
|
||
@Override | ||
public Mono<Void> runAsync() { | ||
return credential.getToken(ARM_TOKEN_REQUEST_CONTEXT).then(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.identity.perf.core; | ||
|
||
import com.azure.core.credential.TokenRequestContext; | ||
import com.azure.identity.InteractiveBrowserCredential; | ||
import com.azure.identity.InteractiveBrowserCredentialBuilder; | ||
import com.azure.perf.test.core.PerfStressOptions; | ||
import com.azure.perf.test.core.PerfStressTest; | ||
import reactor.core.publisher.Mono; | ||
|
||
public abstract class ServiceTest<TOptions extends PerfStressOptions> extends PerfStressTest<TOptions> { | ||
protected static final String CLI_CLIENT_ID = "04b07795-8ddb-461a-bbee-02f9e1bf7b46"; | ||
protected static final TokenRequestContext ARM_TOKEN_REQUEST_CONTEXT = new TokenRequestContext() | ||
.addScopes("https://management.azure.com/.default"); | ||
|
||
private InteractiveBrowserCredential interactiveBrowserCredential = new InteractiveBrowserCredentialBuilder() | ||
.port(8765) | ||
.clientId(CLI_CLIENT_ID) | ||
.build(); | ||
|
||
public ServiceTest(TOptions options) { | ||
super(options); | ||
} | ||
|
||
@Override | ||
public Mono<Void> globalSetupAsync() { | ||
// Populate the token cache for tests | ||
return super.globalSetupAsync() | ||
.then(interactiveBrowserCredential.getToken(ARM_TOKEN_REQUEST_CONTEXT)) | ||
.then(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ public class DeviceCodeCredential implements TokenCredential { | |
public Mono<AccessToken> getToken(TokenRequestContext request) { | ||
return Mono.defer(() -> { | ||
if (cachedToken.get() != null) { | ||
return identityClient.authenticateWithUserRefreshToken(request, cachedToken.get()) | ||
return identityClient.authenticateWithMsalAccount(request, cachedToken.get().getAccount()) | ||
.onErrorResume(t -> Mono.empty()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you want this to resume on an error and return an empty Mono? I'd expect the error to be propagated downstream and allow downstream subscribers to do with that error what they will. In There are similar instances in other credentials below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it should be probably be handled downstream - it's out of the scope of this PR but I can see if it can be done with minimal footprint |
||
} else { | ||
return Mono.empty(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need them to be static ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm simply defining it as a constant: https://stackoverflow.com/questions/9639007/defining-constant-string-in-java