Search in sources :

Example 1 with GraphRestHelper

use of com.microsoft.azuretools.authmanage.srvpri.rest.GraphRestHelper in project azure-tools-for-java by Microsoft.

the class ServicePrincipalStep method execute.

@Override
public void execute(Map<String, Object> params) throws IOException, InterruptedException {
    //System.out.println("ServicePrincipalStep execute...");
    UUID appId = (UUID) params.get("appId");
    //UUID tenantId = (UUID) params.get("tenantId");
    String tenantId = CommonParams.getTenantId();
    graphRestHelper = new GraphRestHelper(tenantId);
    reporter = CommonParams.getReporter();
    reporter.report("appId: " + appId);
    ServicePrincipalRet sp = createAadServicePrincipal(appId);
    params.put("spObjectId", sp.objectId);
    Thread.sleep(1000);
    params.put("status", "sp");
    CommonParams.getStatusReporter().report(new Status(getName(), Status.Result.SUCCESSFUL, String.format("spObjectId: %s", sp.objectId)));
}
Also used : GraphRestHelper(com.microsoft.azuretools.authmanage.srvpri.rest.GraphRestHelper) ServicePrincipalRet(com.microsoft.azuretools.authmanage.srvpri.entities.ServicePrincipalRet) UUID(java.util.UUID)

Example 2 with GraphRestHelper

use of com.microsoft.azuretools.authmanage.srvpri.rest.GraphRestHelper in project azure-tools-for-java by Microsoft.

the class Program method graphApiAction.

@SuppressWarnings("unused")
private static void graphApiAction() throws Exception {
    AdAuthManager adAuthManager = AdAuthManager.getInstance();
    if (!adAuthManager.isSignedIn()) {
        adAuthManager.signIn();
    }
    String request = "tenantDetails";
    List<com.microsoft.azure.management.resources.Tenant> tl = AccessTokenAzureManager.getTenants("common");
    for (com.microsoft.azure.management.resources.Tenant t : tl) {
        String tid = t.tenantId();
        System.out.println("==> tenant ID: " + tid);
        String tenantId = tid;
        try {
            GraphRestHelper grh = new GraphRestHelper(tenantId);
            String resp = grh.doGet(request, null);
            System.out.println("Graph response:" + resp);
        } catch (Exception ex) {
            System.out.println("GraphApiAction ex: " + ex.getMessage());
        }
    }
}
Also used : GraphRestHelper(com.microsoft.azuretools.authmanage.srvpri.rest.GraphRestHelper) AdAuthManager(com.microsoft.azuretools.authmanage.AdAuthManager) IOException(java.io.IOException)

Example 3 with GraphRestHelper

use of com.microsoft.azuretools.authmanage.srvpri.rest.GraphRestHelper in project azure-tools-for-java by Microsoft.

the class ApplicationStep method execute.

@Override
public void execute(Map<String, Object> params) throws IOException, InterruptedException {
    //System.out.println("ApplicationStep execute...");
    String displayName = params.get("displayName").toString();
    String homePage = params.get("homePage").toString();
    String identifierUri = params.get("identifierUri").toString();
    String password = params.get("password").toString();
    //UUID tenantId = (UUID) params.get("tenantId");
    String tenantId = CommonParams.getTenantId();
    graphRestHelper = new GraphRestHelper(tenantId);
    reporter = CommonParams.getReporter();
    reporter.report("displayName: " + displayName);
    reporter.report("homePage: " + homePage);
    reporter.report("identifierUri: " + identifierUri);
    reporter.report("password: " + password);
    reporter.report("Creating ADD Application...");
    ApplicationRet app = createAadApplication(displayName, homePage, new String[] { identifierUri }, password);
    reporter.report("Done.");
    reporter.report(String.format("Checking ADD Application availability..."));
    final int RETRY_QNTY = 5;
    final int SLEEP_SEC = 10;
    int retry_count = 0;
    while (retry_count < RETRY_QNTY) {
        ApplicationGet applicationGet = getAadApplication(app.appId);
        if (applicationGet.value.size() > 0) {
            reporter.report("Done.");
            break;
        }
        retry_count++;
        reporter.report(String.format("Not available. Will retry in %d sec...", SLEEP_SEC));
        Thread.sleep(SLEEP_SEC * 1000);
    }
    if ((retry_count >= RETRY_QNTY)) {
        String errorDetails = String.format("The AD Application (appId: %s) is not available after %s retries", app.appId, RETRY_QNTY);
        CommonParams.getStatusReporter().report(new Status(getName(), Status.Result.FAILED, errorDetails));
        throw new IOException(errorDetails);
    }
    params.put("appId", app.appId);
    params.put("appObjectId", app.objectId);
    params.put("status", "app");
    CommonParams.getStatusReporter().report(new Status(getName(), Status.Result.SUCCESSFUL, String.format("appId: %s; appObjectId: %s", app.appId, app.objectId)));
}
Also used : GraphRestHelper(com.microsoft.azuretools.authmanage.srvpri.rest.GraphRestHelper) ApplicationGet(com.microsoft.azuretools.authmanage.srvpri.entities.ApplicationGet) IOException(java.io.IOException) ApplicationRet(com.microsoft.azuretools.authmanage.srvpri.entities.ApplicationRet)

Aggregations

GraphRestHelper (com.microsoft.azuretools.authmanage.srvpri.rest.GraphRestHelper)3 IOException (java.io.IOException)2 AdAuthManager (com.microsoft.azuretools.authmanage.AdAuthManager)1 ApplicationGet (com.microsoft.azuretools.authmanage.srvpri.entities.ApplicationGet)1 ApplicationRet (com.microsoft.azuretools.authmanage.srvpri.entities.ApplicationRet)1 ServicePrincipalRet (com.microsoft.azuretools.authmanage.srvpri.entities.ServicePrincipalRet)1 UUID (java.util.UUID)1