Код: Выделить всё
private static Properties _properties;
private static ClientSecretCredential _clientSecretCredential;
private static GraphServiceClient _appClient;
public static void initializeGraphForAppOnlyAuth(Properties properties) throws Exception {
// Ensure properties isn't null
if (properties == null) {
throw new Exception("Properties cannot be null");
}
_properties = properties;
if (_clientSecretCredential == null) {
final String clientId = _properties.getProperty("app.clientId");
final String tenantId = _properties.getProperty("app.tenantId");
final String clientSecret = _properties.getProperty("app.clientSecret");
_clientSecretCredential = new ClientSecretCredentialBuilder()
.clientId(clientId)
.tenantId(tenantId)
.clientSecret(clientSecret)
.build();
}
if (_appClient == null) {
_appClient = new GraphServiceClient(_clientSecretCredential,
new String[] { "https://graph.microsoft.com/.default" });
}
}
Код: Выделить всё
_appClient.users().get(requestConfig -> {
requestConfig.queryParameters.filter = "displayName startsWith \'A\'";
requestConfig.queryParameters.select = new String[] { "displayName", "id", "mail" };
requestConfig.queryParameters.top = 25;
requestConfig.queryParameters.orderby = new String[] { "displayName" };
});
Мои запросы:
- Нужно ли каждому потоку создавать экземпляр GraphServiceClient отдельно или мы можем инициализировать один раз и использовать его в нескольких потоках?
- Если экземпляр (_appClient) может быть общим, является ли он потоко- безопасно это сделать или нам нужно синхронизировать доступ к это?
Подробнее здесь: https://stackoverflow.com/questions/791 ... hread-safe