private static AuthenticationResult getAccessTokenFromUserCredentials( String username, String password) throws Exception { AuthenticationContext context = null; AuthenticationResult result = null; ExecutorService service = null; try { service = Executors.newFixedThreadPool(1); context = new AuthenticationContext( System.getenv("arm.aad.url") + System.getenv("arm.tenant"), false, service); Future<AuthenticationResult> future = context.acquireToken( System.getenv(ManagementConfiguration.URI), System.getenv("arm.clientid"), username, password, null); result = future.get(); } finally { service.shutdown(); } if (result == null) { throw new ServiceUnavailableException("authentication result was null"); } return result; }