use of com.microsoft.aad.adal4j.AuthenticationContext in project tdi-studio-se by Talend.
the class DynamicsCRMClient method getAccessToken.
protected AuthenticationResult getAccessToken() throws ServiceUnavailableException {
AuthenticationContext context = null;
AuthenticationResult result = null;
ExecutorService service = null;
try {
service = Executors.newFixedThreadPool(1);
context = new AuthenticationContext(clientConfiguration.getAuthoryEndpoint(), false, service);
Proxy proxy = getProxy();
if (proxy != null) {
context.setProxy(proxy);
}
Future<AuthenticationResult> future = context.acquireToken(clientConfiguration.getResource(), clientConfiguration.getClientId(), clientConfiguration.getUserName(), clientConfiguration.getPassword(), null);
result = future.get();
} catch (Exception e) {
throw new ServiceUnavailableException(e.getMessage());
} finally {
service.shutdown();
}
if (result == null) {
throw new ServiceUnavailableException("Authenticated failed! Please check your configuration!");
}
return result;
}
use of com.microsoft.aad.adal4j.AuthenticationContext 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.AuthenticationContext 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