Search in sources :

Example 1 with PasswordCredentials

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

the class ApplicationStep method createAadApplication.

// helpers
// Create AAD Application
private ApplicationRet createAadApplication(String displayName, String homePage, String[] identifierUris, String password) throws IOException {
    /*
            POST https://graph.windows.net/72f988bf-86f1-41af-91ab-2d7cd011db47/applications?api-version=1.6

            {
              "availableToOtherTenants": false,
              "displayName": "ShchAadApp",
              "homepage": "http://github.com/Microsoft/azure-tools-for-java",
              "identifierUris": [
                "http://github.com/Microsoft/azure-tools-for-java"
              ],
              "passwordCredentials": [
                {
                  "startDate": "2016-08-16T04:55:00.3381704Z",
                  "endDate": "2017-08-16T04:55:00.3381704Z",
                  "keyId": "61d97a80-147a-44d2-bccc-13ffda967071",
                  "value": "Zxcv1234"
                }
              ]
            }

        */
    Application app = new Application();
    app.displayName = displayName;
    app.homepage = homePage;
    app.identifierUris.addAll(Arrays.asList(identifierUris));
    PasswordCredentials pc = new PasswordCredentials();
    LocalDateTime dt = LocalDateTime.now(ZoneOffset.UTC);
    //pc.startDate = dt.format( DateTimeFormatter.ISO_DATE_TIME );
    pc.endDate = dt.plusYears(1).format(DateTimeFormatter.ISO_DATE_TIME);
    ;
    pc.keyId = UUID.randomUUID();
    pc.value = password;
    app.passwordCredentials.add(pc);
    ObjectMapper mapper = new ObjectMapper();
    String applicationJson = mapper.writeValueAsString(app);
    String resp = graphRestHelper.doPost("applications", null, applicationJson);
    ApplicationRet applicationRet = mapper.readValue(resp, ApplicationRet.class);
    return applicationRet;
}
Also used : LocalDateTime(java.time.LocalDateTime) PasswordCredentials(com.microsoft.azuretools.authmanage.srvpri.entities.PasswordCredentials) Application(com.microsoft.azuretools.authmanage.srvpri.entities.Application) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) ApplicationRet(com.microsoft.azuretools.authmanage.srvpri.entities.ApplicationRet)

Aggregations

Application (com.microsoft.azuretools.authmanage.srvpri.entities.Application)1 ApplicationRet (com.microsoft.azuretools.authmanage.srvpri.entities.ApplicationRet)1 PasswordCredentials (com.microsoft.azuretools.authmanage.srvpri.entities.PasswordCredentials)1 LocalDateTime (java.time.LocalDateTime)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1