Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 433fb71

Browse files
author
Isaiah Williams
authored
Updating to latest version (#21)
1 parent a6ec760 commit 433fb71

154 files changed

Lines changed: 440 additions & 897 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
# Partner Center Java SDK Samples
1+
# Partner Center SDK for Java Samples
22

3-
[![Build Status](https://dev.azure.com/isaiahwilliams/community/_apis/build/status/partner-center-java-samples/partner-center-java-samples%20CI?branchName=master)](https://dev.azure.com/isaiahwilliams/community/_build/latest?definitionId=15&branchName=master)
3+
[![Build Status](https://dev.azure.com/isaiahwilliams/public/_apis/build/status/partner-center-java-samples?branchName=master)](https://dev.azure.com/isaiahwilliams/public/_build/latest?definitionId=27&branchName=master)
44

5-
This repository contains samples for the Partner Center Java SDK.
5+
This repository contains samples for the Partner Center SDK for Java.
66

77
## Samples List
88

99
| Sample Name | Description |
1010
|-------------|-------------|
1111
| [SDK Samples](sdk/README.md) | Console application that demonstrates each scenario the Partner Center Java SDK is capable of performing.|
12-
| [Secure App Model](secure-app-model/README.md) | A set of projects that demonstrate how a Control Panel Vendor (CPV) and a Cloud Solution Provider (CSP) should implement the Secure App Model. |
12+
| [Secure Application Model](secure-app-model/README.md) | A set of projects that demonstrate how a Control Panel Vendor (CPV) and a Cloud Solution Provider (CSP) should implement the Secure Application Model. |
1313

1414
## Reporting Security Issues
1515

SECURITY.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Security
2+
3+
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [many more](https://opensource.microsoft.com/).
4+
5+
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets Microsoft's [definition](https://docs.microsoft.com/previous-versions/tn-archive/cc751383(v=technet.10)) of a security vulnerability, please report it to us as described below.
6+
7+
## Reporting Security Issues
8+
9+
**Please do not report security vulnerabilities through public GitHub issues.** Instead, please report them to the Microsoft Security Response Center at [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://technet.microsoft.com/security/dn606155).
10+
11+
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
12+
13+
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
14+
15+
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
16+
* Full paths of source file(s) related to the manifestation of the issue
17+
* The location of the affected source code (tag/branch/commit or direct URL)
18+
* Any special configuration required to reproduce the issue
19+
* Step-by-step instructions to reproduce the issue
20+
* Proof-of-concept or exploit code (if possible)
21+
* Impact of the issue, including how an attacker might exploit the issue
22+
23+
This information will help us triage your report more quickly.
24+
25+
## Preferred Languages
26+
27+
We prefer all communications to be in English.
28+
29+
## Policy
30+
31+
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/msrc/cvd).

azure-pipelines.yml

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,63 @@
1+
strategy:
2+
matrix:
3+
linux:
4+
imageName: 'ubuntu-latest'
5+
mac:
6+
imageName: 'macOS-latest'
7+
windows:
8+
imageName: 'windows-latest'
9+
10+
pool:
11+
vmImage: $(imageName)
12+
113
trigger:
214
- master
315

4-
pool:
5-
vmImage: 'ubuntu-latest'
16+
variables:
17+
LoggingOptions: '-Dorg.slf4j.simpleLogger.defaultLogLevel=error -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn'
618

719
steps:
820
- task: Maven@3
21+
displayName: 'Build SDK samples'
922
inputs:
1023
mavenPomFile: 'sdk/pom.xml'
11-
mavenOptions: '-Xmx3072m'
12-
javaHomeOption: 'JDKVersion'
13-
jdkVersionOption: '1.8'
14-
jdkArchitectureOption: 'x64'
15-
publishJUnitResults: true
16-
testResultsFiles: '**/surefire-reports/TEST-*.xml'
1724
goals: 'package'
25+
options: '-DpackageOutputDirectory=$(Build.ArtifactStagingDirectory)" -am'
26+
mavenOptions: '$(LoggingOptions)'
27+
publishJUnitResults: true
28+
testResultsFiles: '**/surefire-reports/TEST-*.xml'
29+
findBugsRunAnalysis: true
1830

1931
- task: Maven@3
32+
displayName: 'Build secure application model CPV sample'
2033
inputs:
2134
mavenPomFile: 'secure-app-model/keyvault/cpvsample/pom.xml'
22-
mavenOptions: '-Xmx3072m'
23-
javaHomeOption: 'JDKVersion'
24-
jdkVersionOption: '1.8'
25-
jdkArchitectureOption: 'x64'
26-
publishJUnitResults: true
27-
testResultsFiles: '**/surefire-reports/TEST-*.xml'
2835
goals: 'package'
36+
options: '-DpackageOutputDirectory=$(Build.ArtifactStagingDirectory)" -am'
37+
mavenOptions: '$(LoggingOptions)'
38+
publishJUnitResults: true
39+
testResultsFiles: '**/surefire-reports/TEST-*.xml'
40+
findBugsRunAnalysis: true
2941

3042
- task: Maven@3
43+
displayName: 'Build secure application model CSP sample'
3144
inputs:
3245
mavenPomFile: 'secure-app-model/keyvault/cspsample/pom.xml'
33-
mavenOptions: '-Xmx3072m'
34-
javaHomeOption: 'JDKVersion'
35-
jdkVersionOption: '1.8'
36-
jdkArchitectureOption: 'x64'
37-
publishJUnitResults: true
38-
testResultsFiles: '**/surefire-reports/TEST-*.xml'
3946
goals: 'package'
47+
options: '-DpackageOutputDirectory=$(Build.ArtifactStagingDirectory)" -am'
48+
mavenOptions: '$(LoggingOptions)'
49+
publishJUnitResults: true
50+
testResultsFiles: '**/surefire-reports/TEST-*.xml'
51+
findBugsRunAnalysis: true
4052

4153
- task: Maven@3
54+
displayName: 'Build secure application model partner consent sample'
4255
inputs:
4356
mavenPomFile: 'secure-app-model/keyvault/partnerconsent/pom.xml'
44-
mavenOptions: '-Xmx3072m'
45-
javaHomeOption: 'JDKVersion'
46-
jdkVersionOption: '1.8'
47-
jdkArchitectureOption: 'x64'
48-
publishJUnitResults: true
49-
testResultsFiles: '**/surefire-reports/TEST-*.xml'
5057
goals: 'package'
51-
58+
options: '-DpackageOutputDirectory=$(Build.ArtifactStagingDirectory)" -am'
59+
mavenOptions: '$(LoggingOptions)'
60+
publishJUnitResults: true
61+
testResultsFiles: '**/surefire-reports/TEST-*.xml'
62+
findBugsRunAnalysis: true
63+

sdk/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.microsoft.store</groupId>
55
<artifactId>partnercenter-samples</artifactId>
6-
<version>1.13.6</version>
6+
<version>1.14.1</version>
77
<packaging>jar</packaging>
88
<name>Samples</name>
99
<url>http://maven.apache.org</url>
@@ -14,7 +14,7 @@
1414
<dependency>
1515
<groupId>com.microsoft.store</groupId>
1616
<artifactId>partnercenter</artifactId>
17-
<version>1.13.6</version>
17+
<version>1.14.1</version>
1818
</dependency>
1919
</dependencies>
2020
<build>
@@ -29,8 +29,8 @@
2929
<artifactId>maven-compiler-plugin</artifactId>
3030
<version>3.8.0</version>
3131
<configuration>
32-
<source>1.7</source>
33-
<target>1.7</target>
32+
<source>1.8</source>
33+
<target>1.8</target>
3434
</configuration>
3535
</plugin>
3636
</plugins>
Lines changed: 62 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
1-
// -----------------------------------------------------------------------
2-
// <copyright file="AadUserLoginHandler.java" company="Microsoft">
3-
// Copyright (c) Microsoft Corporation. All rights reserved.
4-
// </copyright>
5-
// -----------------------------------------------------------------------
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See the LICENSE file in the project root for full license information.
63

74
package com.microsoft.store.partnercenter.samples;
85

96
import java.io.IOException;
10-
import java.net.URI;
11-
import java.net.URISyntaxException;
12-
import java.time.Instant;
13-
import java.util.concurrent.ExecutionException;
14-
import java.util.concurrent.ExecutorService;
15-
import java.util.concurrent.Executors;
16-
17-
import com.microsoft.aad.adal4j.AdalErrorCode;
18-
import com.microsoft.aad.adal4j.AuthenticationContext;
19-
import com.microsoft.aad.adal4j.AuthenticationException;
20-
import com.microsoft.aad.adal4j.AuthenticationResult;
21-
import com.microsoft.aad.adal4j.DeviceCode;
7+
import java.util.Collections;
8+
import java.util.concurrent.CompletableFuture;
9+
import java.util.function.Consumer;
10+
11+
import com.microsoft.aad.msal4j.DeviceCode;
12+
import com.microsoft.aad.msal4j.DeviceCodeFlowParameters;
13+
import com.microsoft.aad.msal4j.IAuthenticationResult;
14+
import com.microsoft.aad.msal4j.PublicClientApplication;
2215
import com.microsoft.store.partnercenter.AuthenticationToken;
2316
import com.microsoft.store.partnercenter.IAadLoginHandler;
24-
import com.microsoft.store.partnercenter.exception.PartnerException;
2517
import com.microsoft.store.partnercenter.samples.configuration.ConfigurationHolder;
2618

2719
import org.joda.time.DateTime;
@@ -37,122 +29,69 @@ public class AadUserLoginHandler
3729
@Override
3830
public AuthenticationToken authenticate()
3931
{
40-
AuthenticationContext context = null;
41-
AuthenticationResult result = null;
42-
Instant expiresOn;
43-
DeviceCode deviceCode;
44-
ExecutorService service = null;
45-
46-
// read AAD configuration
47-
String authority =
48-
ConfigurationHolder.getInstance().getConfiguration().getPartnerServiceSettings().get( "AuthenticationAuthorityEndpoint" );
49-
String commonDomain =
50-
ConfigurationHolder.getInstance().getConfiguration().getPartnerServiceSettings().get( "CommonDomain" );
51-
String resourceUrl =
52-
ConfigurationHolder.getInstance().getConfiguration().getUserAuthentication().get( "ResourceUrl" );
53-
String clientId =
54-
ConfigurationHolder.getInstance().getConfiguration().getUserAuthentication().get( "ClientId" );
32+
CompletableFuture<IAuthenticationResult> future;
33+
Consumer<DeviceCode> deviceCodeConsumer;
34+
IAuthenticationResult authResult = null;
35+
PublicClientApplication app;
36+
String authority;
37+
String clientId;
38+
String scope;
5539

5640
try
5741
{
58-
URI addAuthority = new URI( authority ).resolve( new URI( commonDomain ) );
59-
60-
service = Executors.newFixedThreadPool( 1 );
61-
context = new AuthenticationContext( addAuthority.toString(), false, service );
62-
63-
deviceCode = context.acquireDeviceCode(clientId, resourceUrl, null).get();
64-
expiresOn = Instant.now().plusSeconds(deviceCode.getExpiresIn());
65-
66-
System.out.println(deviceCode.getMessage());
67-
68-
result = SendTokenRequest(context, deviceCode, expiresOn);
69-
}
70-
catch (ExecutionException ex)
71-
{
72-
ex.printStackTrace();
73-
}
74-
catch(IOException e)
75-
{
76-
e.printStackTrace();
77-
}
78-
catch ( URISyntaxException e )
79-
{
80-
e.printStackTrace();
81-
}
82-
catch ( InterruptedException e )
83-
{
84-
e.printStackTrace();
85-
}
86-
87-
finally
88-
{
89-
service.shutdown();
90-
}
91-
92-
if ( result == null )
93-
{
94-
throw new NullPointerException( "authentication result was null" );
95-
}
96-
97-
return new AuthenticationToken( result.getAccessToken(), new DateTime( result.getExpiresOnDate() ) );
98-
}
99-
100-
private AuthenticationResult SendTokenRequest(AuthenticationContext context, DeviceCode deviceCode, Instant expiresOn)
101-
{
102-
AuthenticationResult result = null;
103-
long duration;
104-
105-
duration = expiresOn.getEpochSecond() - Instant.now().getEpochSecond();
106-
107-
while(duration > 0)
108-
{
109-
try
110-
{
111-
result = context.acquireTokenByDeviceCode(deviceCode, null).get();
112-
break;
113-
}
114-
catch(AuthenticationException ex)
115-
{
116-
if(ex.getErrorCode() != AdalErrorCode.AUTHORIZATION_PENDING)
117-
{
118-
throw ex;
119-
}
120-
}
121-
catch (ExecutionException ex)
122-
{
123-
if(ex.getCause() instanceof AuthenticationException)
124-
{
125-
if(((AuthenticationException)ex.getCause()).getErrorCode() != AdalErrorCode.AUTHORIZATION_PENDING)
126-
{
127-
ex.printStackTrace();
128-
}
129-
}
130-
else
42+
authority = ConfigurationHolder
43+
.getInstance()
44+
.getConfiguration()
45+
.getPartnerServiceSettings()
46+
.get("AuthenticationAuthorityEndpoint");
47+
48+
clientId = ConfigurationHolder
49+
.getInstance()
50+
.getConfiguration()
51+
.getUserAuthentication()
52+
.get("ClientId");
53+
54+
scope = ConfigurationHolder
55+
.getInstance()
56+
.getConfiguration()
57+
.getUserAuthentication()
58+
.get("Scope");
59+
60+
app = PublicClientApplication.builder(clientId)
61+
.authority(authority + "/common")
62+
.build();
63+
64+
deviceCodeConsumer = (DeviceCode deviceCode) -> {
65+
System.out.println(deviceCode.message());
66+
};
67+
68+
future = app.acquireToken(
69+
DeviceCodeFlowParameters.builder(
70+
Collections.singleton(scope),
71+
deviceCodeConsumer)
72+
.build());
73+
74+
future.handle((result, ex) -> {
75+
if(ex != null)
13176
{
13277
ex.printStackTrace();
13378
}
134-
}
135-
catch (InterruptedException ex)
136-
{
137-
ex.printStackTrace();
138-
}
139-
140-
try
141-
{
142-
Thread.sleep(deviceCode.getInterval() * 1000);
143-
}
144-
catch(InterruptedException ex)
79+
80+
return result;
81+
});
82+
83+
authResult = future.join();
84+
85+
if ( authResult == null )
14586
{
87+
throw new NullPointerException( "authentication result was null" );
14688
}
147-
148-
duration = expiresOn.getEpochSecond() - Instant.now().getEpochSecond();
14989
}
150-
151-
if(result == null)
90+
catch(IOException ex)
15291
{
153-
throw new PartnerException("Verification code expired before contacting the server.");
92+
ex.printStackTrace();
15493
}
15594

156-
return result;
95+
return new AuthenticationToken(authResult.accessToken(), new DateTime(authResult.expiresOnDate()));
15796
}
15897
}

sdk/src/main/java/com/microsoft/store/partnercenter/samples/AggregatePartnerScenario.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
// -----------------------------------------------------------------------
2-
// <copyright file="AggregatePartnerScenario.java" company="Microsoft">
3-
// Copyright (c) Microsoft Corporation. All rights reserved.
4-
// </copyright>
5-
// -----------------------------------------------------------------------
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See the LICENSE file in the project root for full license information.
63

74
package com.microsoft.store.partnercenter.samples;
85

0 commit comments

Comments
 (0)