use of com.microsoft.aad.adal4j.ClientCredential in project azure-sdk-for-java by Azure.
the class KeyVaultClientIntegrationTestBase method getAccessToken.
private static AuthenticationResult getAccessToken(String authorization, String resource) throws Exception {
String clientId = System.getenv("arm.clientid");
if (clientId == null) {
throw new Exception("Please inform arm.clientid in the environment settings.");
}
String clientKey = System.getenv("arm.clientkey");
String username = System.getenv("arm.username");
String password = System.getenv("arm.password");
AuthenticationResult result = null;
ExecutorService service = null;
try {
service = Executors.newFixedThreadPool(1);
AuthenticationContext context = new AuthenticationContext(authorization, false, service);
Future<AuthenticationResult> future = null;
if (clientKey != null && password == null) {
ClientCredential credentials = new ClientCredential(clientId, clientKey);
future = context.acquireToken(resource, credentials, null);
}
if (password != null && clientKey == null) {
future = context.acquireToken(resource, clientId, username, password, null);
}
if (future == null) {
throw new Exception("Missing or ambiguous credentials - please inform exactly one of arm.clientkey or arm.password in the environment settings.");
}
result = future.get();
} finally {
service.shutdown();
}
if (result == null) {
throw new RuntimeException("authentication result was null");
}
return result;
}
use of com.microsoft.aad.adal4j.ClientCredential in project azure-sdk-for-java by Azure.
the class KeyVaultClientIntegrationTestBase method getAccessToken.
private static AuthenticationResult getAccessToken(String authorization, String resource) throws Exception {
String clientId = System.getenv("arm.clientid");
if (clientId == null) {
throw new Exception("Please inform arm.clientid in the environment settings.");
}
String clientKey = System.getenv("arm.clientkey");
String username = System.getenv("arm.username");
String password = System.getenv("arm.password");
AuthenticationResult result = null;
ExecutorService service = null;
try {
service = Executors.newFixedThreadPool(1);
AuthenticationContext context = new AuthenticationContext(authorization, false, service);
Future<AuthenticationResult> future = null;
if (clientKey != null && password == null) {
ClientCredential credentials = new ClientCredential(clientId, clientKey);
future = context.acquireToken(resource, credentials, null);
}
if (password != null && clientKey == null) {
future = context.acquireToken(resource, clientId, username, password, null);
}
if (future == null) {
throw new Exception("Missing or ambiguous credentials - please inform exactly one of arm.clientkey or arm.password in the environment settings.");
}
result = future.get();
} finally {
service.shutdown();
}
if (result == null) {
throw new RuntimeException("authentication result was null");
}
return result;
}
Aggregations