Skip to content

Commit 9338eee

Browse files
Examples
1 parent 45ec27c commit 9338eee

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

java/examples/VaasExample/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies {
1414
implementation 'org.slf4j:slf4j-nop:2.0.16'
1515
implementation 'de.gdata:vaas:0.0.0'
1616
implementation 'org.projectlombok:lombok:1.18.36'
17+
implementation 'io.github.cdimascio:dotenv-java:3.1.0'
1718
}
1819

1920
tasks.register('sha256Scan', JavaExec) {

java/examples/VaasExample/src/main/java/de/gdata/vaasexample/Authentication.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
import de.gdata.vaas.*;
44
import de.gdata.vaas.authentication.*;
5+
56
import java.net.URI;
67

78

89
public class Authentication {
910
public static void main(String[] args) throws Exception {
10-
var clientId = System.getenv("CLIENT_ID");
11-
var clientSecret = System.getenv("CLIENT_SECRET");
12-
var vaasclientId = System.getenv("VAAS_CLIENT_ID");
13-
var userName = System.getenv("VAAS_USER_NAME");
14-
var password = System.getenv("VAAS_PASSWORD");
15-
var tokenUrl = System.getenv("TOKEN_URL");
16-
if (tokenUrl == null) { tokenUrl = "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token"; }
17-
var vaasUrl = System.getenv("VAAS_URL");
18-
if (vaasUrl == null) { vaasUrl = "wss://gateway.production.vaas.gdatasecurity.de"; }
11+
var env = new Environment();
12+
13+
var clientId = env.clientId;
14+
var clientSecret = env.clientSecret;
15+
var vaasclientId = env.vaasClientId;
16+
var userName = env.userName;
17+
var password = env.password;
18+
var tokenUrl = env.tokenUrl;
19+
var vaasUrl = env.vaasUrl;
1920

2021
// If you got a username and password from us, you can use the ResourceOwnerPasswordAuthenticator like this
2122
var authenticator = new ResourceOwnerPasswordGrantAuthenticator(

java/examples/VaasExample/src/main/java/de/gdata/vaasexample/Environment.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,51 @@
11
package de.gdata.vaasexample;
22

3+
import io.github.cdimascio.dotenv.Dotenv;
34
import lombok.Getter;
45
import lombok.Setter;
56

67
@Getter
78
@Setter
89
public class Environment {
10+
private static final Dotenv dotenv = Dotenv.configure()
11+
.ignoreIfMissing()
12+
.load();
913
public String clientId;
1014
public String clientSecret;
15+
public String vaasClientId;
1116
public String userName;
1217
public String password;
1318
public String vaasUrl;
1419
public String tokenUrl;
1520

1621
public Environment() {
1722
clientId = System.getenv("CLIENT_ID");
23+
if (clientId == null || clientId.isBlank()) {
24+
clientId = dotenv.get("CLIENT_ID");
25+
}
1826
clientSecret = System.getenv("CLIENT_SECRET");
27+
if (clientSecret == null || clientSecret.isBlank()) {
28+
clientSecret = dotenv.get("CLIENT_SECRET");
29+
}
1930
userName = System.getenv("VAAS_USER_NAME");
31+
if (userName == null || userName.isBlank()) {
32+
userName = dotenv.get("VAAS_USER_NAME");
33+
}
2034
password = System.getenv("VAAS_PASSWORD");
35+
if (password == null || password.isBlank()) {
36+
password = dotenv.get("VAAS_PASSWORD");
37+
}
2138
vaasUrl = System.getenv("VAAS_URL");
22-
if (vaasUrl == null) {
23-
vaasUrl = "wss://gateway.staging.vaas.gdatasecurity.de";
39+
if (vaasUrl == null || vaasUrl.isBlank()) {
40+
vaasUrl = dotenv.get("VAAS_URL");
2441
}
2542
tokenUrl = System.getenv("TOKEN_URL");
26-
if (tokenUrl == null) {
27-
tokenUrl = "https://account-staging.gdata.de/realms/vaas-staging/protocol/openid-connect/token";
43+
if (tokenUrl == null || tokenUrl.isBlank()) {
44+
tokenUrl = dotenv.get("TOKEN_URL");
45+
}
46+
vaasClientId = System.getenv("VAAS_CLIENT_ID");
47+
if (vaasClientId == null || vaasClientId.isBlank()) {
48+
vaasClientId = dotenv.get("VAAS_CLIENT_ID");
2849
}
2950
}
3051

0 commit comments

Comments
 (0)