-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #302 from GDATASoftwareAG/authentication_examples
Complete authentication examples
- Loading branch information
Showing
7 changed files
with
68 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
java/examples/VaasExample/src/main/java/de/gdata/vaasexample/Authentication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package de.gdata.vaasexample; | ||
|
||
import de.gdata.vaas.ClientCredentialsGrantAuthenticator; | ||
import de.gdata.vaas.ResourceOwnerPasswordGrantAuthenticator; | ||
import de.gdata.vaas.Vaas; | ||
import de.gdata.vaas.VaasConfig; | ||
import de.gdata.vaas.messages.VerdictRequestAttributes; | ||
import java.net.URI; | ||
import java.nio.file.Path; | ||
|
||
|
||
public class Authentication { | ||
public static void main(String[] args) throws Exception { | ||
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 = System.getenv("SCAN_PATH"); | ||
var tokenUrl = System.getenv("TOKEN_URL"); | ||
if (tokenUrl == null) { tokenUrl = "https://account.gdata.de/realms/vaas-production/protocol/openid-connect/token"; } | ||
var vaasUrl = System.getenv("VAAS_URL"); | ||
if (vaasUrl == null) { vaasUrl = "wss://gateway.production.vaas.gdatasecurity.de"; } | ||
|
||
// If you got a username and password from us, you can use the ResourceOwnerPasswordAuthenticator like this | ||
var authenticator = new ResourceOwnerPasswordGrantAuthenticator( | ||
"vaas-customer", | ||
userName, | ||
password, | ||
new URI(tokenUrl) | ||
); | ||
// You may use self registration and create a new username and password for the | ||
// ResourceOwnerPasswordAuthenticator by yourself like the example above on https://vaas.gdata.de/login | ||
|
||
// Else if you got a client id and client secret from us, you can use the ClientCredentialsGrantAuthenticator like this | ||
// var authenticator = new ClientCredentialsGrantAuthenticator( | ||
// clientId, | ||
// clientSecret, | ||
// new URI(tokenUrl) | ||
// ); | ||
|
||
var config = new VaasConfig(new URI(vaasUrl)); | ||
var vaas = new Vaas(config, authenticator); | ||
vaas.connect(); | ||
|
||
var file = Path.of(scanPath); | ||
var verdictRequestAttributes = new VerdictRequestAttributes(); | ||
verdictRequestAttributes.setTenantId("fileTenant"); | ||
var verdict = vaas.forFile(file, verdictRequestAttributes); | ||
vaas.disconnect(); | ||
System.out.printf("File %s was detected as %s", verdict.getSha256(), verdict.getVerdict()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters