use of com.google.api.services.directory.Directory in project styx by spotify.
the class ServiceAccountUsageAuthorizer method create.
static ServiceAccountUsageAuthorizer create(Closer closer, String serviceAccountUserRole, AuthorizationPolicy authorizationPolicy, GoogleCredentials credentials, String gsuiteUserEmail, String serviceName, String message, List<String> administrators, List<String> blacklist) {
final HttpTransport httpTransport;
try {
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
} catch (GeneralSecurityException | IOException e) {
throw new RuntimeException(e);
}
final JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
final CloudResourceManager crm = new CloudResourceManager.Builder(httpTransport, jsonFactory, new HttpCredentialsAdapter(credentials.createScoped(IamScopes.all()))).setApplicationName(serviceName).build();
final Iam iam = new Iam.Builder(httpTransport, jsonFactory, new HttpCredentialsAdapter(credentials.createScoped(IamScopes.all()))).setApplicationName(serviceName).build();
final IamCredentialsClient iamCredentialsClient;
try {
iamCredentialsClient = IamCredentialsClient.create();
} catch (IOException e) {
throw new RuntimeException(e);
}
closer.register(iamCredentialsClient::close);
final GoogleCredential directoryCredential = new ManagedServiceAccountKeyCredential.Builder(iamCredentialsClient).setServiceAccountId(ServiceAccounts.serviceAccountEmail(credentials)).setServiceAccountUser(gsuiteUserEmail).setServiceAccountScopes(Set.of(ADMIN_DIRECTORY_GROUP_MEMBER_READONLY)).build();
final Directory directory = new Directory.Builder(httpTransport, jsonFactory, directoryCredential).setApplicationName(serviceName).build();
return new Impl(iam, crm, directory, serviceAccountUserRole, authorizationPolicy, Impl.DEFAULT_WAIT_STRATEGY, Impl.DEFAULT_RETRY_STOP_STRATEGY, message, administrators, blacklist);
}
use of com.google.api.services.directory.Directory in project perun by CESNET.
the class ExtSourceGoogleTest method setUp.
@Before
public void setUp() throws Exception {
extSourceGoogle = new ExtSourceGoogle();
Members members = fillInMemberList();
domainName = "parker.sm";
groupName = "spectacular";
MockitoAnnotations.initMocks(this);
// mock google connection
Directory directory = mock(Directory.class, RETURNS_DEEP_STUBS);
doReturn(directory).when(extSourceGoogle).getDirectoryService();
when(directory.members().list(groupName).execute()).thenReturn(members);
}
use of com.google.api.services.directory.Directory in project workbench by all-of-us.
the class DirectoryServiceImpl method countUsersInDomain.
private long countUsersInDomain(String gSuiteDomain) {
long result = 0;
try {
final Directory directoryService = getGoogleDirectoryService();
Optional<String> nextPageToken = Optional.empty();
do {
final Directory.Users.List listQuery = directoryService.users().list().setDomain(gSuiteDomain).setViewType(USER_VIEW_TYPE).setCustomFieldMask("email").setMaxResults(MAX_USERS_LIST_PAGE_SIZE).setOrderBy(EMAIL_USER_FIELD);
nextPageToken.ifPresent(listQuery::setPageToken);
final Users usersQueryResult = listQuery.execute();
result += usersQueryResult.getUsers().size();
nextPageToken = Optional.ofNullable(usersQueryResult.getNextPageToken());
} while (nextPageToken.isPresent());
return result;
} catch (IOException e) {
log.warn("Failed to retrieve GSuite User List.", e);
return 0;
}
}
Aggregations