Search in sources :

Example 1 with ServicePrincipalRet

use of com.microsoft.azuretools.authmanage.srvpri.entities.ServicePrincipalRet 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 ServicePrincipalRet

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

the class ServicePrincipalStep method createAadServicePrincipal.

// helpers
// Create Service Principals
private ServicePrincipalRet createAadServicePrincipal(UUID appId) throws IOException {
    /*
        POST https://graph.windows.net/72f988bf-86f1-41af-91ab-2d7cd011db47/servicePrincipals?api-version=1.6-internal HTTP/1.1

        {
          "appId": "425817b6-1cd8-48ea-9cd7-1b9472912bee",
          "accountEnabled": true
        }

         */
    ServicePrincipal sp = new ServicePrincipal();
    sp.accountEnabled = true;
    sp.appId = appId;
    ObjectMapper mapper = new ObjectMapper();
    String spJson = mapper.writeValueAsString(sp);
    String resp = graphRestHelper.doPost("servicePrincipals", null, spJson);
    ServicePrincipalRet spr = mapper.readValue(resp, ServicePrincipalRet.class);
    return spr;
}
Also used : ServicePrincipal(com.microsoft.azuretools.authmanage.srvpri.entities.ServicePrincipal) ServicePrincipalRet(com.microsoft.azuretools.authmanage.srvpri.entities.ServicePrincipalRet) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

ServicePrincipalRet (com.microsoft.azuretools.authmanage.srvpri.entities.ServicePrincipalRet)2 ServicePrincipal (com.microsoft.azuretools.authmanage.srvpri.entities.ServicePrincipal)1 GraphRestHelper (com.microsoft.azuretools.authmanage.srvpri.rest.GraphRestHelper)1 UUID (java.util.UUID)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1