001package com.pingidentity; 002 003import com.pingidentity.util.MSGraphAPI; 004import com.pingidentity.util.MSGraphResult; 005import com.unboundid.ldap.sdk.Entry; 006 007import java.io.FileInputStream; 008import java.io.IOException; 009import java.io.UnsupportedEncodingException; 010import java.net.URLEncoder; 011import java.util.Properties; 012import java.util.UUID; 013 014import static java.lang.System.exit; 015 016public class AzureADTest { 017 static String propFile = System.getProperty("user.home") + "/.pingidentity/pingone-cloud.properties"; 018 019 public static void main(String[] argv) throws Exception { 020 Properties props = new Properties(); 021 String tenantId = null; 022 String clientId = null; 023 String clientSecret = null; 024 025 try { 026 FileInputStream fis= new FileInputStream(propFile); 027 props.load(fis); 028 029 //get the property value and print it out 030 tenantId = props.getProperty("MS_AZURE_TENANT_ID"); 031 clientId = props.getProperty("MS_AZURE_APP_REGISTRATION_CLIENT_ID"); 032 clientSecret = props.getProperty("MS_AZURE_APP_REGISTRATION_CLIENT_SECRET"); 033 } 034 catch (IOException ex) { 035 System.err.println("Unable to read/open the property file: " + propFile); 036 } 037 038 MSGraphAPI api = new MSGraphAPI(tenantId, clientId, clientSecret); 039 040 MSGraphResult userResults = api.getEntries(MSGraphAPI.OBJECT_TYPE.USERS, 041 "country eq 'USA'", 042 "objectId,userPrincipalName,displayName,givenName,surname,mail"); 043 044 userResults = api.getEntries(MSGraphAPI.OBJECT_TYPE.USERS, 045 null, 046 "objectId,userPrincipalName,displayName,givenName,surname,mail"); 047 048 int userCount = userResults.entries.size(); 049 050 while (userResults.hasMoreEntries()) { 051 userResults = api.nextPage(userResults); 052 userCount += userResults.entries.size(); 053 System.err.println("count = " + userCount); 054 } 055 056 Entry user = api.getEntry(MSGraphAPI.OBJECT_TYPE.USERS, 057 UUID.fromString("a2499d24-235e-444e-9cf2-6226cf9f0b7b"), 058 "objectId,userPrincipalName,displayName,givenName,surname,mail"); 059 060 MSGraphResult graphResult = api.getEntries(MSGraphAPI.OBJECT_TYPE.GROUPS); 061 062 } 063 064 065 // Method to encode a string value using `UTF-8` encoding scheme 066 private static String encodeValue(String value) { 067 try { 068 return URLEncoder.encode(value, "UTF-8"); 069 } catch (UnsupportedEncodingException ex) { 070 throw new RuntimeException(ex.getCause()); 071 } 072 } 073}