Skip to content

Commit

Permalink
java: Adjust example to be more suitable towards test users
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanCoding committed May 14, 2024
1 parent 033f319 commit dc6898c
Showing 1 changed file with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
package de.gdata.vaasexample;

import de.gdata.vaas.ClientCredentialsGrantAuthenticator;
import de.gdata.vaas.Vaas;
import de.gdata.vaas.VaasConfig;
import de.gdata.vaas.*;
import de.gdata.vaas.messages.VerdictRequestAttributes;

import java.net.URI;
import java.nio.file.Path;

public class Main {
public static void main(String[] args) throws Exception {
var clientId = getenv("CLIENT_ID");
var clientSecret = getenv("CLIENT_SECRET");
// Either set CLIENT_ID & CLIENT_SECRET or alternatively VAAS_USER_NAME and VAAS_PASSWORD
var clientId = System.getenv("CLIENT_ID");
var clientSecret = System.getenv("CLIENT_SECRET");
var userName = System.getenv("VAAS_USER_NAME");
var password = System.getenv("VAAS_PASSWORD");
var scanPath = getenv("SCAN_PATH");
var tokenUrl = System.getenv("TOKEN_URL");
if (tokenUrl == null) {
tokenUrl = "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token";
tokenUrl = "https://account-staging.gdata.de/realms/vaas-staging/protocol/openid-connect/token";
}
var vaasUrl = System.getenv("VAAS_URL");
if (vaasUrl == null) {
vaasUrl = "wss://gateway.production.vaas.gdatasecurity.de";
}
vaasUrl = "wss://gateway.staging.vaas.gdatasecurity.de";
}

IAuthenticator authenticator;
if (clientId == null) {
if (userName == null) {
throw new IllegalStateException("Either CLIENT_ID or VAAS_USER_NAME must be set");
}
authenticator = new ResourceOwnerPasswordGrantAuthenticator("vaas-customer", userName, password, new URI(tokenUrl));
} else {
authenticator = new ClientCredentialsGrantAuthenticator(clientId, clientSecret, new URI(tokenUrl));
}

var authenticator = new ClientCredentialsGrantAuthenticator(clientId, clientSecret, new URI(tokenUrl));
var config = new VaasConfig(
new URI(vaasUrl));
var vaas = new Vaas(config, authenticator);
Expand Down

0 comments on commit dc6898c

Please sign in to comment.