AuthenticationResult acquireNewAccessToken(String resource) throws IOException { String authorityUrl = this.environment().activeDirectoryEndpoint() + this.domain(); ExecutorService executor = Executors.newSingleThreadExecutor(); AuthenticationContext context = new AuthenticationContext(authorityUrl, false, executor); if (proxy() != null) { context.setProxy(proxy()); } try { return context.acquireToken( resource, this.clientId(), this.username(), this.password, null).get(); } catch (Exception e) { throw new IOException(e.getMessage(), e); } finally { executor.shutdown(); } }