diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
new file mode 100644
index 0000000..816031f
--- /dev/null
+++ b/.github/workflows/build.yaml
@@ -0,0 +1,24 @@
+name: Java CI
+
+on: [push]
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - name: Set up JDK 11
+ uses: actions/setup-java@v3
+ with:
+ java-version: '11'
+ distribution: 'adopt'
+ cache: maven
+ - name: Build with Maven
+ run: mvn --batch-mode --update-snapshots package
+ - name: Run the Maven verify phase
+ run: mvn --batch-mode --update-snapshots verify
+ - run: mkdir staging && cp target/*.jar staging
+ - uses: actions/upload-artifact@v3
+ with:
+ name: Package
+ path: staging
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 714493c..bb78120 100644
--- a/pom.xml
+++ b/pom.xml
@@ -42,6 +42,7 @@
scm:git:git://github.com/SIMBAChain/libsimba4j-platform.git
scm:git:ssh://github.com:SIMBAChain/libsimba4j-platform.git
https://github.com/SIMBAChain/libsimba4j-platform
+ HEAD
@@ -110,13 +111,26 @@
dotenv-java
2.2.0
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.3.1
+ test
+
+
+
+ org.apache.maven.plugins
+ maven-release-plugin
+ 3.0.0-M6
+
org.apache.maven.plugins
maven-surefire-plugin
- 2.7.2
+ 2.22.0
${project.basedir}
@@ -181,6 +195,13 @@
true
+
+ maven-release-plugin
+ 3.0.0-M6
+
+ [ci skip]
+
+
diff --git a/src/main/java/com/simbachain/auth/azure/AzConfig.java b/src/main/java/com/simbachain/auth/azure/AzConfig.java
deleted file mode 100644
index 3241b1f..0000000
--- a/src/main/java/com/simbachain/auth/azure/AzConfig.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (c) 2022 SIMBA Chain Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package com.simbachain.auth.azure;
-
-import com.simbachain.auth.AccessTokenProvider;
-import com.simbachain.auth.AuthConfig;
-
-/**
- * Azure config that uses OAuth.
- */
-public class AzConfig extends AuthConfig {
-
- public enum Flow {
- USER_PASSWORD, CLIENT_CREDENTIAL
- }
-
- private static String DEFAULT_SERVER = "https://login.microsoftonline.com";
-
- private final String tenantId;
- private final String appId;
- private final Flow flow;
- private final String server;
-
- public AzConfig(String clientId,
- String clientSecret,
- String tenantId,
- String appId,
- Flow flow,
- String server,
- boolean writeToFile) {
- super(clientId, clientSecret, writeToFile);
- this.tenantId = tenantId;
- this.appId = appId;
- this.flow = flow;
- this.server = server;
- }
-
- public AzConfig(String clientId,
- String clientSecret,
- String tenantId,
- String appId,
- Flow flow, boolean writeToFile) {
- this(clientId, clientSecret, tenantId, appId, flow, DEFAULT_SERVER, writeToFile);
- }
-
- public AzConfig(String clientId,
- String clientSecret,
- String tenantId,
- String appId,
- Flow flow) {
- this(clientId, clientSecret, tenantId, appId, flow, DEFAULT_SERVER, false);
- }
-
- public String getTenantId() {
- return tenantId;
- }
-
- public String getServer() {
- return server;
- }
-
- public String getAppId() {
- return appId;
- }
-
- @Override
- public AccessTokenProvider getTokenProvider() {
- if (flow == Flow.CLIENT_CREDENTIAL) {
- return new AzCredentialAccessTokenProvider(this);
- } else {
- return new AzUserAccessTokenProvider(this);
- }
- }
-}
diff --git a/src/main/java/com/simbachain/auth/azure/AzCredentialAccessTokenProvider.java b/src/main/java/com/simbachain/auth/azure/AzCredentialAccessTokenProvider.java
deleted file mode 100644
index f6e3932..0000000
--- a/src/main/java/com/simbachain/auth/azure/AzCredentialAccessTokenProvider.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (c) 2022 SIMBA Chain Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package com.simbachain.auth.azure;
-
-import java.util.Collections;
-import java.util.concurrent.CompletableFuture;
-
-import com.microsoft.aad.msal4j.ClientCredentialFactory;
-import com.microsoft.aad.msal4j.ClientCredentialParameters;
-import com.microsoft.aad.msal4j.ConfidentialClientApplication;
-import com.microsoft.aad.msal4j.IAuthenticationResult;
-import com.simbachain.SimbaException;
-import com.simbachain.auth.AccessToken;
-import com.simbachain.auth.AccessTokenProvider;
-import com.simbachain.auth.FileAccessToken;
-
-/**
- * Implementation of AccessTokenProvider that talks to Azure.
- */
-public class AzCredentialAccessTokenProvider implements AccessTokenProvider {
-
- private final AzConfig credentials;
- private final AccessToken token;
-
- public AzCredentialAccessTokenProvider(AzConfig credentials) {
- this.credentials = credentials;
- if(this.credentials.isWriteToFile()) {
- this.token = new FileAccessToken(String.format(".%s", this.credentials.getClientId()));
- } else {
- this.token = new AccessToken();
- }
- }
-
- public AccessToken getToken() throws SimbaException {
-
- String server = credentials.getServer();
- if (!server.endsWith("/")) {
- server += "/";
- }
-
- try {
- long now = System.currentTimeMillis();
- if (now >= this.token.getExpiry()) {
- this.token.invalidate();
- }
- if (!this.token.isValid()) {
- ConfidentialClientApplication app = ConfidentialClientApplication.builder(
- credentials.getClientId(),
- ClientCredentialFactory.createFromSecret(credentials.getClientSecret()))
- .authority(
- String.format(
- "%s%s",
- server,
- credentials.getTenantId()))
- .build();
-
- String scope = String.format("%s/.default", credentials.getAppId());
- ClientCredentialParameters clientCredentialParam
- = ClientCredentialParameters.builder(Collections.singleton(scope))
- .build();
- CompletableFuture future = app.acquireToken(
- clientCredentialParam);
- IAuthenticationResult result = future.get();
- long expiry = result.expiresOnDate()
- .getTime();
- this.token.refresh(result.accessToken(), "Bearer", expiry - 5000);
- }
- return this.token;
-
- } catch (Exception e) {
- throw new SimbaException(e.getMessage(), SimbaException.SimbaError.AUTHENTICATION_ERROR,
- e);
- }
- }
-
-}
diff --git a/src/main/java/com/simbachain/auth/azure/AzUserAccessTokenProvider.java b/src/main/java/com/simbachain/auth/azure/AzUserAccessTokenProvider.java
deleted file mode 100644
index 280eb03..0000000
--- a/src/main/java/com/simbachain/auth/azure/AzUserAccessTokenProvider.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (c) 2022 SIMBA Chain Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package com.simbachain.auth.azure;
-
-import java.util.Collections;
-import java.util.concurrent.CompletableFuture;
-
-import com.microsoft.aad.msal4j.IAuthenticationResult;
-import com.microsoft.aad.msal4j.PublicClientApplication;
-import com.microsoft.aad.msal4j.UserNamePasswordParameters;
-import com.simbachain.SimbaException;
-import com.simbachain.auth.AccessToken;
-import com.simbachain.auth.AccessTokenProvider;
-import com.simbachain.auth.FileAccessToken;
-
-/**
- * Implementation of AccessTokenProvider that talks to Azure.
- */
-public class AzUserAccessTokenProvider implements AccessTokenProvider {
-
- private final AzConfig credentials;
- private final AccessToken token;
-
- public AzUserAccessTokenProvider(AzConfig credentials) {
- this.credentials = credentials;
- if (this.credentials.isWriteToFile()) {
- this.token = new FileAccessToken(String.format(".%s", this.credentials.getClientId()));
- } else {
- this.token = new AccessToken();
- }
- }
-
- public AccessToken getToken() throws SimbaException {
-
- String server = credentials.getServer();
- if (!server.endsWith("/")) {
- server += "/";
- }
-
- try {
- long now = System.currentTimeMillis();
- if (now >= this.token.getExpiry()) {
- this.token.invalidate();
- }
- if (!this.token.isValid()) {
- PublicClientApplication pca = PublicClientApplication.builder(
- credentials.getAppId())
- .authority(
- String.format("%s%s",
- server,
- credentials.getTenantId()))
- .build();
-
- String scope = String.format("api://%s/scaas.access", credentials.getAppId());
- UserNamePasswordParameters parameters = UserNamePasswordParameters.builder(
- Collections.singleton(scope), credentials.getClientId(),
- credentials.getClientSecret()
- .toCharArray())
- .build();
- CompletableFuture future = pca.acquireToken(parameters);
- IAuthenticationResult result = future.get();
- long expiry = result.expiresOnDate()
- .getTime();
- this.token.refresh(result.accessToken(), "Bearer", expiry - 5000);
- }
- return this.token;
-
- } catch (Exception e) {
- throw new SimbaException(e.getMessage(), SimbaException.SimbaError.AUTHENTICATION_ERROR,
- e);
- }
- }
-
-}
diff --git a/src/test/java/com/simbachain/simba/test/AzCredentialExample.java b/src/test/java/com/simbachain/simba/test/AzCredentialExample.java
deleted file mode 100644
index 7d35ef1..0000000
--- a/src/test/java/com/simbachain/simba/test/AzCredentialExample.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (c) 2021 SIMBA Chain Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package com.simbachain.simba.test;
-
-import com.simbachain.SimbaException;
-import com.simbachain.auth.azure.AzConfig;
-import com.simbachain.simba.platform.AppConfig;
-import com.simbachain.simba.platform.ContractService;
-import com.simbachain.simba.platform.management.BlockchainIdentities;
-import com.simbachain.simba.platform.management.OrganisationConfig;
-import com.simbachain.simba.platform.management.OrganisationService;
-import io.github.cdimascio.dotenv.Dotenv;
-
-/**
- *
- */
-public class AzCredentialExample {
-
- public static void main(String[] args) throws SimbaException {
- Dotenv dotenv = Dotenv.load();
-
- String tenant_id = dotenv.get("TENANT_ID");
- String client_id = dotenv.get("CLIENT_ID");
- String client_secret = dotenv.get("CLIENT_SECRET");
- String appId = dotenv.get("APP_ID");
- String host = dotenv.get("HOST");
- String org = dotenv.get("ORG");
- String contract = "supplychain_1614267039";
-
- System.out.println("========= CREDENTIAL LOGIN ===========");
- AzConfig authConfig = new AzConfig(client_id, client_secret, tenant_id, appId, AzConfig.Flow.CLIENT_CREDENTIAL, true);
- AppConfig appConfig = new AppConfig("neo-supplychain", org, authConfig);
- ContractService simba = new ContractService(host, contract, appConfig);
- simba.init();
- System.out.println(simba.getMetadata());
- System.out.println(simba.whoami());
- BlockchainIdentities ids = simba.getIdentities();
- System.out.println(ids.getWallet().getIdentities("ethereum", "Quorum"));
- System.out.println(simba.getTransactionCount("Quorum"));
-
- System.out.println("========= USER/PASSWORD LOGIN ===========");
- AzConfig userConfig = new AzConfig(dotenv.get("USER_EMAIL"), dotenv.get("USER_PASSWORD"),
- tenant_id, appId, AzConfig.Flow.USER_PASSWORD, false);
- OrganisationService orgService = new OrganisationService(
- host, new OrganisationConfig(org, userConfig));
- System.out.println(orgService.whoami());
- ContractService simba1 = orgService.newContractService("test", "game-1155");
- System.out.println(simba1.getMetadata());
- }
-}
diff --git a/src/test/java/com/simbachain/simba/test/ClientCompileDeployExample.java b/src/test/java/com/simbachain/simba/test/ClientCompileDeployExample.java
deleted file mode 100644
index ec2a37d..0000000
--- a/src/test/java/com/simbachain/simba/test/ClientCompileDeployExample.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright (c) 2021 SIMBA Chain Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package com.simbachain.simba.test;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-
-import com.simbachain.auth.azure.AzConfig;
-import com.simbachain.simba.CallResponse;
-import com.simbachain.simba.JsonData;
-import com.simbachain.simba.PagedResult;
-import com.simbachain.simba.platform.ContractService;
-import com.simbachain.simba.platform.management.Application;
-import com.simbachain.simba.platform.management.ContractArtifact;
-import com.simbachain.simba.platform.management.ContractDesign;
-import com.simbachain.simba.platform.management.DeployedContract;
-import com.simbachain.simba.platform.management.DeploymentSpec;
-import com.simbachain.simba.platform.management.OrganisationConfig;
-import com.simbachain.simba.platform.management.OrganisationService;
-import com.simbachain.wallet.FileWallet;
-import com.simbachain.wallet.Wallet;
-import io.github.cdimascio.dotenv.Dotenv;
-
-/**
- *
- */
-public class ClientCompileDeployExample {
-
- public static void main(String[] args)
- throws IOException, ExecutionException, InterruptedException {
- Dotenv dotenv = Dotenv.load();
-
- String tenant_id = dotenv.get("TENANT_ID");
- String client_id = dotenv.get("CLIENT_ID");
- String client_secret = dotenv.get("CLIENT_SECRET");
- String appId = dotenv.get("APP_ID");
- String host = dotenv.get("HOST");
- String org = dotenv.get("ORG");
- String clientAddress = dotenv.get("PUBLIC_ADDRESS");
-
- System.out.println("========= CREDENTIAL LOGIN ===========");
- AzConfig config = new AzConfig(client_id, client_secret, tenant_id, appId,
- AzConfig.Flow.CLIENT_CREDENTIAL);
- OrganisationConfig orgConfig = new OrganisationConfig(org, config);
- OrganisationService orgService = new OrganisationService(
- host, orgConfig);
- InputStream in = ClientCompileDeployExample.class.getResourceAsStream("/supply.sol");
-
- String apiName = "supply_" + System.currentTimeMillis();
- ContractDesign design = orgService.compileContract(in, apiName, "sasa");
- System.out.println(design);
- ContractArtifact artifact = orgService.createArtifact(design.getId());
-
- PagedResult apps = orgService.getApplications();
- List extends Application> results = apps.getResults();
- for (Application result : results) {
- System.out.println(result.getName());
- }
-
- DeploymentSpec spec = new DeploymentSpec();
- spec.setApiName(apiName);
- spec.setBlockchain("Quorum");
- spec.setStorage("azure");
- spec.setAppName("neo-supplychain");
-
- Wallet wallet = new FileWallet("./wallets", "pk-test");
- wallet.loadOrCreatePrivateKeyWallet("s3cr3t",
- dotenv.get("PRIVATE_KEY"));
- orgService.setWallet(wallet);
-
- Future future = orgService.deployContract(artifact.getId(), spec);
- DeployedContract contract = future.get();
- System.out.println(contract);
-
- ContractService contractService = orgService.newContractService("neo-supplychain", apiName);
-
-
- JsonData supplyData = JsonData.with("price", 120)
- .and("dateTime", System.currentTimeMillis())
- .and("supplier", JsonData.with("__Supplier", "Supplier3.32"))
- .and("purchaser", JsonData.with("__Supplier", "Supplier2.11"))
- .and("part", JsonData.with("__Part", "Part542"));
-
- Map headers = new HashMap<>();
- headers.put(ContractService.Headers.HTTP_HEADER_SENDER.getValue(), clientAddress);
- long nonce = contractService.getTransactionCount("Quorum", clientAddress);
- headers.put(ContractService.Headers.HTTP_HEADER_NONCE.getValue(), Long.toString(nonce + 1));
-
- CallResponse ret = contractService.callMethod("supply", supplyData, headers);
- System.out.println("Got back response: " + ret);
- }
-}
diff --git a/src/test/java/com/simbachain/simba/test/CompileDeployExample.java b/src/test/java/com/simbachain/simba/test/TestCompileDeploy.java
similarity index 92%
rename from src/test/java/com/simbachain/simba/test/CompileDeployExample.java
rename to src/test/java/com/simbachain/simba/test/TestCompileDeploy.java
index 0b4072c..f8a3feb 100644
--- a/src/test/java/com/simbachain/simba/test/CompileDeployExample.java
+++ b/src/test/java/com/simbachain/simba/test/TestCompileDeploy.java
@@ -28,7 +28,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
-import com.simbachain.auth.azure.AzConfig;
+import com.simbachain.auth.blocks.BlocksConfig;
import com.simbachain.simba.CallResponse;
import com.simbachain.simba.JsonData;
import com.simbachain.simba.PagedResult;
@@ -43,31 +43,33 @@
import com.simbachain.simba.platform.management.OrganisationService;
import com.simbachain.simba.platform.management.Storage;
import io.github.cdimascio.dotenv.Dotenv;
+import org.junit.jupiter.api.Test;
/**
*
*/
-public class CompileDeployExample {
+public class TestCompileDeploy {
- public static void main(String[] args)
+ @Test
+ public void testCompileDeploy()
throws IOException, ExecutionException, InterruptedException {
- Dotenv dotenv = Dotenv.load();
-
- String tenant_id = dotenv.get("TENANT_ID");
+ Dotenv dotenv = Dotenv.configure().ignoreIfMissing().load();
+
+
String client_id = dotenv.get("CLIENT_ID");
String client_secret = dotenv.get("CLIENT_SECRET");
- String appId = dotenv.get("APP_ID");
+ String tokenurl = dotenv.get("TOKEN_URL");
String host = dotenv.get("HOST");
String org = dotenv.get("ORG");
- System.out.println("========= CREDENTIAL LOGIN ===========");
- AzConfig config = new AzConfig(client_id, client_secret, tenant_id, appId,
- AzConfig.Flow.CLIENT_CREDENTIAL);
- OrganisationConfig orgConfig = new OrganisationConfig(org, config);
+ System.out.println("========= OAuth2 Client Credential Login ===========");
+ BlocksConfig authConfig = new BlocksConfig(client_id, client_secret, tokenurl);
+
+ OrganisationConfig orgConfig = new OrganisationConfig(org, authConfig);
OrganisationService orgService = new OrganisationService(
host, orgConfig);
- InputStream in = CompileDeployExample.class.getResourceAsStream("/supply.sol");
+ InputStream in = TestCompileDeploy.class.getResourceAsStream("/supply.sol");
String apiName = "supply_" + System.currentTimeMillis();
ContractDesign design = orgService.compileContract(in, apiName, "sasa");
diff --git a/src/test/java/com/simbachain/simba/test/KeyCloakCredentialExample.java b/src/test/java/com/simbachain/simba/test/TestKeyCloakCredential.java
similarity index 84%
rename from src/test/java/com/simbachain/simba/test/KeyCloakCredentialExample.java
rename to src/test/java/com/simbachain/simba/test/TestKeyCloakCredential.java
index a963b1f..d8c3090 100644
--- a/src/test/java/com/simbachain/simba/test/KeyCloakCredentialExample.java
+++ b/src/test/java/com/simbachain/simba/test/TestKeyCloakCredential.java
@@ -31,20 +31,22 @@
import com.simbachain.simba.platform.management.AuthenticatedUser;
import com.simbachain.simba.platform.management.BlockchainIdentities;
import io.github.cdimascio.dotenv.Dotenv;
+import org.junit.jupiter.api.Test;
/**
*
*/
-public class KeyCloakCredentialExample
+public class TestKeyCloakCredential
{
- public static void main(String[] args) throws SimbaException {
- Dotenv dotenv = Dotenv.load();
- String clientId = dotenv.get("CLIENT_ID");
- String clientSecret = dotenv.get("CLIENT_SECRET");
- String host = dotenv.get("HOST");
- String authHost = dotenv.get("AUTH_HOST");
- String realm = dotenv.get("REALM");
- String org = dotenv.get("ORG");
+ @Test
+ public void testKeycloakCredentials() throws SimbaException {
+ Dotenv dotenv = Dotenv.configure().ignoreIfMissing().load();
+ String clientId = dotenv.get("KC_CLIENT_ID");
+ String clientSecret = dotenv.get("KC_CLIENT_SECRET");
+ String host = dotenv.get("KC_HOST");
+ String authHost = dotenv.get("KC_AUTH_HOST");
+ String realm = dotenv.get("KC_REALM");
+ String org = dotenv.get("KC_ORG");
String app = "MountainApp";
String contract = "mountainapi";
diff --git a/src/test/java/com/simbachain/simba/test/OAuth2CredentialExample.java b/src/test/java/com/simbachain/simba/test/TestOAuth2Credential.java
similarity index 88%
rename from src/test/java/com/simbachain/simba/test/OAuth2CredentialExample.java
rename to src/test/java/com/simbachain/simba/test/TestOAuth2Credential.java
index b2d4d55..1e3e98b 100644
--- a/src/test/java/com/simbachain/simba/test/OAuth2CredentialExample.java
+++ b/src/test/java/com/simbachain/simba/test/TestOAuth2Credential.java
@@ -28,14 +28,16 @@
import com.simbachain.simba.platform.management.OrganisationConfig;
import com.simbachain.simba.platform.management.OrganisationService;
import io.github.cdimascio.dotenv.Dotenv;
+import org.junit.jupiter.api.Test;
/**
* Obtain a set of client ID and Secrets from Blocks
*/
-public class OAuth2CredentialExample {
+public class TestOAuth2Credential {
- public static void main(String[] args) throws SimbaException {
- Dotenv dotenv = Dotenv.load();
+ @Test
+ public void testOAuth2Credentials() throws SimbaException {
+ Dotenv dotenv = Dotenv.configure().ignoreIfMissing().load();
String client_id = dotenv.get("CLIENT_ID");
String client_secret = dotenv.get("CLIENT_SECRET");
@@ -43,7 +45,7 @@ public static void main(String[] args) throws SimbaException {
String host = dotenv.get("HOST");
String org = dotenv.get("ORG");
- System.out.println("========= USER/PASSWORD LOGIN ===========");
+ System.out.println("========= OAuth2 Client Credential Login ===========");
BlocksConfig authConfig = new BlocksConfig(client_id, client_secret, tokenurl);
OrganisationService orgService = new OrganisationService(
host, new OrganisationConfig(org, authConfig));