From 4c972b261903d77ec96b4ba4ebc24b82c0b859f7 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Thu, 28 Jul 2016 10:55:15 -0700 Subject: [PATCH 1/7] Add graph rbac project --- azure-mgmt-graph-rbac/pom.xml | 116 ++ .../graphrbac/GroupAddMemberParameters.java | 47 + .../GroupGetMemberGroupsParameters.java | 44 + .../management/graphrbac/KeyCredential.java | 167 +++ .../graphrbac/PasswordCredential.java | 117 ++ .../management/graphrbac/PasswordProfile.java | 68 ++ .../UserGetMemberGroupsParameters.java | 44 + .../implementation/AADObjectInner.java | 267 +++++ .../implementation/ADGroupInner.java | 141 +++ .../ApplicationCreateParametersInner.java | 199 ++++ .../implementation/ApplicationInner.java | 242 ++++ .../ApplicationUpdateParametersInner.java | 169 +++ .../implementation/ApplicationsInner.java | 493 ++++++++ .../CheckGroupMembershipParametersInner.java | 70 ++ .../CheckGroupMembershipResultInner.java | 43 + .../GraphRbacManagementClientImpl.java | 256 +++++ .../GroupCreateParametersInner.java | 131 +++ .../graphrbac/implementation/GroupsInner.java | 1008 +++++++++++++++++ .../implementation/ObjectsInner.java | 121 ++ .../graphrbac/implementation/PageImpl.java | 75 ++ .../graphrbac/implementation/PageImpl1.java | 75 ++ ...ServicePrincipalCreateParametersInner.java | 69 ++ .../implementation/ServicePrincipalInner.java | 142 +++ .../ServicePrincipalsInner.java | 515 +++++++++ .../UserCreateParametersInner.java | 177 +++ .../graphrbac/implementation/UserInner.java | 191 ++++ .../UserUpdateParametersInner.java | 117 ++ .../graphrbac/implementation/UsersInner.java | 682 +++++++++++ .../implementation/package-info.java | 11 + .../management/graphrbac/package-info.java | 11 + gulpfile.js | 6 + pom.xml | 1 + 32 files changed, 5815 insertions(+) create mode 100644 azure-mgmt-graph-rbac/pom.xml create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GroupAddMemberParameters.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GroupGetMemberGroupsParameters.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/KeyCredential.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordCredential.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordProfile.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/UserGetMemberGroupsParameters.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/AADObjectInner.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ADGroupInner.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationCreateParametersInner.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationInner.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationUpdateParametersInner.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationsInner.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/CheckGroupMembershipParametersInner.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/CheckGroupMembershipResultInner.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManagementClientImpl.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupCreateParametersInner.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ObjectsInner.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/PageImpl.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/PageImpl1.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalCreateParametersInner.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalInner.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserCreateParametersInner.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserInner.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserUpdateParametersInner.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/package-info.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/package-info.java diff --git a/azure-mgmt-graph-rbac/pom.xml b/azure-mgmt-graph-rbac/pom.xml new file mode 100644 index 0000000000000..29f28a4bb91a7 --- /dev/null +++ b/azure-mgmt-graph-rbac/pom.xml @@ -0,0 +1,116 @@ + + + 4.0.0 + + com.microsoft.azure + azure-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + azure-mgmt-graph-rbac + jar + + Microsoft Azure SDK for Graph RBAC Management + This package contains Microsoft Azure Graph RBAC Management SDK. + https://github.com/Azure/azure-sdk-for-java + + + + The MIT License (MIT) + http://opensource.org/licenses/MIT + repo + + + + + scm:git:https://github.com/Azure/azure-sdk-for-java + scm:git:git@github.com:Azure/azure-sdk-for-java.git + HEAD + + + + UTF-8 + + + + + + microsoft + Microsoft + + + + + + com.microsoft.azure + azure-client-runtime + 1.0.0-SNAPSHOT + + + com.microsoft.azure + azure-mgmt-resources + 1.0.0-SNAPSHOT + + + junit + junit + test + + + com.microsoft.azure + azure-client-authentication + 1.0.0-SNAPSHOT + test + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + true + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.8 + + *.implementation.*;*.utils.*;com.microsoft.schemas._2003._10.serialization;*.blob.core.storage + /** +
* Copyright (c) Microsoft Corporation. All rights reserved. +
* Licensed under the MIT License. See License.txt in the project root for +
* license information. +
*/]]>
+
+
+ +
+
+
diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GroupAddMemberParameters.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GroupAddMemberParameters.java new file mode 100644 index 0000000000000..70df168cd455b --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GroupAddMemberParameters.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Request parameters for adding a member to a group. + */ +public class GroupAddMemberParameters { + /** + * Member Object Url as + * "https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd", + * where "0b1f9851-1bf0-433f-aec3-cb9272f093dc" is the tenantId and + * "f260bbc4-c254-447b-94cf-293b5ec434dd" is the objectId of the member + * (user, application, servicePrincipal, group) to be added. + */ + @JsonProperty(required = true) + private String url; + + /** + * Get the url value. + * + * @return the url value + */ + public String url() { + return this.url; + } + + /** + * Set the url value. + * + * @param url the url value to set + * @return the GroupAddMemberParameters object itself. + */ + public GroupAddMemberParameters withUrl(String url) { + this.url = url; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GroupGetMemberGroupsParameters.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GroupGetMemberGroupsParameters.java new file mode 100644 index 0000000000000..91c409e8d6511 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GroupGetMemberGroupsParameters.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Request parameters for GetMemberGroups API call. + */ +public class GroupGetMemberGroupsParameters { + /** + * If true only membership in security enabled groups should be checked. + * Otherwise membership in all groups should be checked. + */ + @JsonProperty(required = true) + private boolean securityEnabledOnly; + + /** + * Get the securityEnabledOnly value. + * + * @return the securityEnabledOnly value + */ + public boolean securityEnabledOnly() { + return this.securityEnabledOnly; + } + + /** + * Set the securityEnabledOnly value. + * + * @param securityEnabledOnly the securityEnabledOnly value to set + * @return the GroupGetMemberGroupsParameters object itself. + */ + public GroupGetMemberGroupsParameters withSecurityEnabledOnly(boolean securityEnabledOnly) { + this.securityEnabledOnly = securityEnabledOnly; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/KeyCredential.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/KeyCredential.java new file mode 100644 index 0000000000000..a872fc2465af8 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/KeyCredential.java @@ -0,0 +1,167 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac; + +import org.joda.time.DateTime; + +/** + * Active Directory service principal Key Credential information. + */ +public class KeyCredential { + /** + * Gets or sets start date. + */ + private DateTime startDate; + + /** + * Gets or sets end date. + */ + private DateTime endDate; + + /** + * Gets or sets value. + */ + private String value; + + /** + * Gets or sets key Id. + */ + private String keyId; + + /** + * Gets or sets usage. + */ + private String usage; + + /** + * Gets or sets type. + */ + private String type; + + /** + * Get the startDate value. + * + * @return the startDate value + */ + public DateTime startDate() { + return this.startDate; + } + + /** + * Set the startDate value. + * + * @param startDate the startDate value to set + * @return the KeyCredential object itself. + */ + public KeyCredential withStartDate(DateTime startDate) { + this.startDate = startDate; + return this; + } + + /** + * Get the endDate value. + * + * @return the endDate value + */ + public DateTime endDate() { + return this.endDate; + } + + /** + * Set the endDate value. + * + * @param endDate the endDate value to set + * @return the KeyCredential object itself. + */ + public KeyCredential withEndDate(DateTime endDate) { + this.endDate = endDate; + return this; + } + + /** + * Get the value value. + * + * @return the value value + */ + public String value() { + return this.value; + } + + /** + * Set the value value. + * + * @param value the value value to set + * @return the KeyCredential object itself. + */ + public KeyCredential withValue(String value) { + this.value = value; + return this; + } + + /** + * Get the keyId value. + * + * @return the keyId value + */ + public String keyId() { + return this.keyId; + } + + /** + * Set the keyId value. + * + * @param keyId the keyId value to set + * @return the KeyCredential object itself. + */ + public KeyCredential withKeyId(String keyId) { + this.keyId = keyId; + return this; + } + + /** + * Get the usage value. + * + * @return the usage value + */ + public String usage() { + return this.usage; + } + + /** + * Set the usage value. + * + * @param usage the usage value to set + * @return the KeyCredential object itself. + */ + public KeyCredential withUsage(String usage) { + this.usage = usage; + return this; + } + + /** + * Get the type value. + * + * @return the type value + */ + public String type() { + return this.type; + } + + /** + * Set the type value. + * + * @param type the type value to set + * @return the KeyCredential object itself. + */ + public KeyCredential withType(String type) { + this.type = type; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordCredential.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordCredential.java new file mode 100644 index 0000000000000..67660ebb9d30a --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordCredential.java @@ -0,0 +1,117 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac; + +import org.joda.time.DateTime; + +/** + * Active Directory service principal Password Credential information. + */ +public class PasswordCredential { + /** + * Gets or sets start date. + */ + private DateTime startDate; + + /** + * Gets or sets end date. + */ + private DateTime endDate; + + /** + * Gets or sets key Id. + */ + private String keyId; + + /** + * Gets or sets value. + */ + private String value; + + /** + * Get the startDate value. + * + * @return the startDate value + */ + public DateTime startDate() { + return this.startDate; + } + + /** + * Set the startDate value. + * + * @param startDate the startDate value to set + * @return the PasswordCredential object itself. + */ + public PasswordCredential withStartDate(DateTime startDate) { + this.startDate = startDate; + return this; + } + + /** + * Get the endDate value. + * + * @return the endDate value + */ + public DateTime endDate() { + return this.endDate; + } + + /** + * Set the endDate value. + * + * @param endDate the endDate value to set + * @return the PasswordCredential object itself. + */ + public PasswordCredential withEndDate(DateTime endDate) { + this.endDate = endDate; + return this; + } + + /** + * Get the keyId value. + * + * @return the keyId value + */ + public String keyId() { + return this.keyId; + } + + /** + * Set the keyId value. + * + * @param keyId the keyId value to set + * @return the PasswordCredential object itself. + */ + public PasswordCredential withKeyId(String keyId) { + this.keyId = keyId; + return this; + } + + /** + * Get the value value. + * + * @return the value value + */ + public String value() { + return this.value; + } + + /** + * Set the value value. + * + * @param value the value value to set + * @return the PasswordCredential object itself. + */ + public PasswordCredential withValue(String value) { + this.value = value; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordProfile.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordProfile.java new file mode 100644 index 0000000000000..0684dd11b28b9 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordProfile.java @@ -0,0 +1,68 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Contains the password profile associated with a user. + */ +public class PasswordProfile { + /** + * Password. + */ + @JsonProperty(required = true) + private String password; + + /** + * Force change password on next login. + */ + private Boolean forceChangePasswordNextLogin; + + /** + * Get the password value. + * + * @return the password value + */ + public String password() { + return this.password; + } + + /** + * Set the password value. + * + * @param password the password value to set + * @return the PasswordProfile object itself. + */ + public PasswordProfile withPassword(String password) { + this.password = password; + return this; + } + + /** + * Get the forceChangePasswordNextLogin value. + * + * @return the forceChangePasswordNextLogin value + */ + public Boolean forceChangePasswordNextLogin() { + return this.forceChangePasswordNextLogin; + } + + /** + * Set the forceChangePasswordNextLogin value. + * + * @param forceChangePasswordNextLogin the forceChangePasswordNextLogin value to set + * @return the PasswordProfile object itself. + */ + public PasswordProfile withForceChangePasswordNextLogin(Boolean forceChangePasswordNextLogin) { + this.forceChangePasswordNextLogin = forceChangePasswordNextLogin; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/UserGetMemberGroupsParameters.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/UserGetMemberGroupsParameters.java new file mode 100644 index 0000000000000..29474ab87960e --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/UserGetMemberGroupsParameters.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Request parameters for GetMemberGroups API call. + */ +public class UserGetMemberGroupsParameters { + /** + * If true only membership in security enabled groups should be checked. + * Otherwise membership in all groups should be checked. + */ + @JsonProperty(required = true) + private boolean securityEnabledOnly; + + /** + * Get the securityEnabledOnly value. + * + * @return the securityEnabledOnly value + */ + public boolean securityEnabledOnly() { + return this.securityEnabledOnly; + } + + /** + * Set the securityEnabledOnly value. + * + * @param securityEnabledOnly the securityEnabledOnly value to set + * @return the UserGetMemberGroupsParameters object itself. + */ + public UserGetMemberGroupsParameters withSecurityEnabledOnly(boolean securityEnabledOnly) { + this.securityEnabledOnly = securityEnabledOnly; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/AADObjectInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/AADObjectInner.java new file mode 100644 index 0000000000000..87922b8c92fdf --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/AADObjectInner.java @@ -0,0 +1,267 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import java.util.List; + +/** + * Active Directory object information. + */ +public class AADObjectInner { + /** + * Gets or sets object Id. + */ + private String objectId; + + /** + * Gets or sets object type. + */ + private String objectType; + + /** + * Gets or sets object display name. + */ + private String displayName; + + /** + * Gets or sets principal name. + */ + private String userPrincipalName; + + /** + * Gets or sets mail. + */ + private String mail; + + /** + * Gets or sets MailEnabled field. + */ + private Boolean mailEnabled; + + /** + * Gets or sets SecurityEnabled field. + */ + private Boolean securityEnabled; + + /** + * Gets or sets signIn name. + */ + private String signInName; + + /** + * Gets or sets the list of service principal names. + */ + private List servicePrincipalNames; + + /** + * Gets or sets the user type. + */ + private String userType; + + /** + * Get the objectId value. + * + * @return the objectId value + */ + public String objectId() { + return this.objectId; + } + + /** + * Set the objectId value. + * + * @param objectId the objectId value to set + * @return the AADObjectInner object itself. + */ + public AADObjectInner withObjectId(String objectId) { + this.objectId = objectId; + return this; + } + + /** + * Get the objectType value. + * + * @return the objectType value + */ + public String objectType() { + return this.objectType; + } + + /** + * Set the objectType value. + * + * @param objectType the objectType value to set + * @return the AADObjectInner object itself. + */ + public AADObjectInner withObjectType(String objectType) { + this.objectType = objectType; + return this; + } + + /** + * Get the displayName value. + * + * @return the displayName value + */ + public String displayName() { + return this.displayName; + } + + /** + * Set the displayName value. + * + * @param displayName the displayName value to set + * @return the AADObjectInner object itself. + */ + public AADObjectInner withDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + /** + * Get the userPrincipalName value. + * + * @return the userPrincipalName value + */ + public String userPrincipalName() { + return this.userPrincipalName; + } + + /** + * Set the userPrincipalName value. + * + * @param userPrincipalName the userPrincipalName value to set + * @return the AADObjectInner object itself. + */ + public AADObjectInner withUserPrincipalName(String userPrincipalName) { + this.userPrincipalName = userPrincipalName; + return this; + } + + /** + * Get the mail value. + * + * @return the mail value + */ + public String mail() { + return this.mail; + } + + /** + * Set the mail value. + * + * @param mail the mail value to set + * @return the AADObjectInner object itself. + */ + public AADObjectInner withMail(String mail) { + this.mail = mail; + return this; + } + + /** + * Get the mailEnabled value. + * + * @return the mailEnabled value + */ + public Boolean mailEnabled() { + return this.mailEnabled; + } + + /** + * Set the mailEnabled value. + * + * @param mailEnabled the mailEnabled value to set + * @return the AADObjectInner object itself. + */ + public AADObjectInner withMailEnabled(Boolean mailEnabled) { + this.mailEnabled = mailEnabled; + return this; + } + + /** + * Get the securityEnabled value. + * + * @return the securityEnabled value + */ + public Boolean securityEnabled() { + return this.securityEnabled; + } + + /** + * Set the securityEnabled value. + * + * @param securityEnabled the securityEnabled value to set + * @return the AADObjectInner object itself. + */ + public AADObjectInner withSecurityEnabled(Boolean securityEnabled) { + this.securityEnabled = securityEnabled; + return this; + } + + /** + * Get the signInName value. + * + * @return the signInName value + */ + public String signInName() { + return this.signInName; + } + + /** + * Set the signInName value. + * + * @param signInName the signInName value to set + * @return the AADObjectInner object itself. + */ + public AADObjectInner withSignInName(String signInName) { + this.signInName = signInName; + return this; + } + + /** + * Get the servicePrincipalNames value. + * + * @return the servicePrincipalNames value + */ + public List servicePrincipalNames() { + return this.servicePrincipalNames; + } + + /** + * Set the servicePrincipalNames value. + * + * @param servicePrincipalNames the servicePrincipalNames value to set + * @return the AADObjectInner object itself. + */ + public AADObjectInner withServicePrincipalNames(List servicePrincipalNames) { + this.servicePrincipalNames = servicePrincipalNames; + return this; + } + + /** + * Get the userType value. + * + * @return the userType value + */ + public String userType() { + return this.userType; + } + + /** + * Set the userType value. + * + * @param userType the userType value to set + * @return the AADObjectInner object itself. + */ + public AADObjectInner withUserType(String userType) { + this.userType = userType; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ADGroupInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ADGroupInner.java new file mode 100644 index 0000000000000..d2fd0568b922b --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ADGroupInner.java @@ -0,0 +1,141 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + + +/** + * Active Directory group information. + */ +public class ADGroupInner { + /** + * Gets or sets object Id. + */ + private String objectId; + + /** + * Gets or sets object type. + */ + private String objectType; + + /** + * Gets or sets group display name. + */ + private String displayName; + + /** + * Gets or sets security enabled field. + */ + private Boolean securityEnabled; + + /** + * Gets or sets mail field. + */ + private String mail; + + /** + * Get the objectId value. + * + * @return the objectId value + */ + public String objectId() { + return this.objectId; + } + + /** + * Set the objectId value. + * + * @param objectId the objectId value to set + * @return the ADGroupInner object itself. + */ + public ADGroupInner withObjectId(String objectId) { + this.objectId = objectId; + return this; + } + + /** + * Get the objectType value. + * + * @return the objectType value + */ + public String objectType() { + return this.objectType; + } + + /** + * Set the objectType value. + * + * @param objectType the objectType value to set + * @return the ADGroupInner object itself. + */ + public ADGroupInner withObjectType(String objectType) { + this.objectType = objectType; + return this; + } + + /** + * Get the displayName value. + * + * @return the displayName value + */ + public String displayName() { + return this.displayName; + } + + /** + * Set the displayName value. + * + * @param displayName the displayName value to set + * @return the ADGroupInner object itself. + */ + public ADGroupInner withDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + /** + * Get the securityEnabled value. + * + * @return the securityEnabled value + */ + public Boolean securityEnabled() { + return this.securityEnabled; + } + + /** + * Set the securityEnabled value. + * + * @param securityEnabled the securityEnabled value to set + * @return the ADGroupInner object itself. + */ + public ADGroupInner withSecurityEnabled(Boolean securityEnabled) { + this.securityEnabled = securityEnabled; + return this; + } + + /** + * Get the mail value. + * + * @return the mail value + */ + public String mail() { + return this.mail; + } + + /** + * Set the mail value. + * + * @param mail the mail value to set + * @return the ADGroupInner object itself. + */ + public ADGroupInner withMail(String mail) { + this.mail = mail; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationCreateParametersInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationCreateParametersInner.java new file mode 100644 index 0000000000000..334e0768005ba --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationCreateParametersInner.java @@ -0,0 +1,199 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import java.util.List; +import com.microsoft.azure.management.graphrbac.KeyCredential; +import com.microsoft.azure.management.graphrbac.PasswordCredential; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Request parameters for create a new application. + */ +public class ApplicationCreateParametersInner { + /** + * Indicates if the application will be available to other tenants. + */ + @JsonProperty(required = true) + private boolean availableToOtherTenants; + + /** + * Application display name. + */ + @JsonProperty(required = true) + private String displayName; + + /** + * Application homepage. + */ + @JsonProperty(required = true) + private String homepage; + + /** + * Application Uris. + */ + @JsonProperty(required = true) + private List identifierUris; + + /** + * Application reply Urls. + */ + private List replyUrls; + + /** + * Gets or sets the list of KeyCredential objects. + */ + private List keyCredentials; + + /** + * Gets or sets the list of PasswordCredential objects. + */ + private List passwordCredentials; + + /** + * Get the availableToOtherTenants value. + * + * @return the availableToOtherTenants value + */ + public boolean availableToOtherTenants() { + return this.availableToOtherTenants; + } + + /** + * Set the availableToOtherTenants value. + * + * @param availableToOtherTenants the availableToOtherTenants value to set + * @return the ApplicationCreateParametersInner object itself. + */ + public ApplicationCreateParametersInner withAvailableToOtherTenants(boolean availableToOtherTenants) { + this.availableToOtherTenants = availableToOtherTenants; + return this; + } + + /** + * Get the displayName value. + * + * @return the displayName value + */ + public String displayName() { + return this.displayName; + } + + /** + * Set the displayName value. + * + * @param displayName the displayName value to set + * @return the ApplicationCreateParametersInner object itself. + */ + public ApplicationCreateParametersInner withDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + /** + * Get the homepage value. + * + * @return the homepage value + */ + public String homepage() { + return this.homepage; + } + + /** + * Set the homepage value. + * + * @param homepage the homepage value to set + * @return the ApplicationCreateParametersInner object itself. + */ + public ApplicationCreateParametersInner withHomepage(String homepage) { + this.homepage = homepage; + return this; + } + + /** + * Get the identifierUris value. + * + * @return the identifierUris value + */ + public List identifierUris() { + return this.identifierUris; + } + + /** + * Set the identifierUris value. + * + * @param identifierUris the identifierUris value to set + * @return the ApplicationCreateParametersInner object itself. + */ + public ApplicationCreateParametersInner withIdentifierUris(List identifierUris) { + this.identifierUris = identifierUris; + return this; + } + + /** + * Get the replyUrls value. + * + * @return the replyUrls value + */ + public List replyUrls() { + return this.replyUrls; + } + + /** + * Set the replyUrls value. + * + * @param replyUrls the replyUrls value to set + * @return the ApplicationCreateParametersInner object itself. + */ + public ApplicationCreateParametersInner withReplyUrls(List replyUrls) { + this.replyUrls = replyUrls; + return this; + } + + /** + * Get the keyCredentials value. + * + * @return the keyCredentials value + */ + public List keyCredentials() { + return this.keyCredentials; + } + + /** + * Set the keyCredentials value. + * + * @param keyCredentials the keyCredentials value to set + * @return the ApplicationCreateParametersInner object itself. + */ + public ApplicationCreateParametersInner withKeyCredentials(List keyCredentials) { + this.keyCredentials = keyCredentials; + return this; + } + + /** + * Get the passwordCredentials value. + * + * @return the passwordCredentials value + */ + public List passwordCredentials() { + return this.passwordCredentials; + } + + /** + * Set the passwordCredentials value. + * + * @param passwordCredentials the passwordCredentials value to set + * @return the ApplicationCreateParametersInner object itself. + */ + public ApplicationCreateParametersInner withPasswordCredentials(List passwordCredentials) { + this.passwordCredentials = passwordCredentials; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationInner.java new file mode 100644 index 0000000000000..1e4259ec221d1 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationInner.java @@ -0,0 +1,242 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import java.util.List; + +/** + * Active Directory user information. + */ +public class ApplicationInner { + /** + * Gets or sets object Id. + */ + private String objectId; + + /** + * Gets or sets object type. + */ + private String objectType; + + /** + * Gets or sets application Id. + */ + private String appId; + + /** + * Gets or sets application permissions. + */ + private List appPermissions; + + /** + * Indicates if the application will be available to other tenants. + */ + private Boolean availableToOtherTenants; + + /** + * Gets or sets the displayName. + */ + private String displayName; + + /** + * Gets or sets the application identifier Uris. + */ + private List identifierUris; + + /** + * Gets or sets the application reply Urls. + */ + private List replyUrls; + + /** + * Application homepage. + */ + private String homepage; + + /** + * Get the objectId value. + * + * @return the objectId value + */ + public String objectId() { + return this.objectId; + } + + /** + * Set the objectId value. + * + * @param objectId the objectId value to set + * @return the ApplicationInner object itself. + */ + public ApplicationInner withObjectId(String objectId) { + this.objectId = objectId; + return this; + } + + /** + * Get the objectType value. + * + * @return the objectType value + */ + public String objectType() { + return this.objectType; + } + + /** + * Set the objectType value. + * + * @param objectType the objectType value to set + * @return the ApplicationInner object itself. + */ + public ApplicationInner withObjectType(String objectType) { + this.objectType = objectType; + return this; + } + + /** + * Get the appId value. + * + * @return the appId value + */ + public String appId() { + return this.appId; + } + + /** + * Set the appId value. + * + * @param appId the appId value to set + * @return the ApplicationInner object itself. + */ + public ApplicationInner withAppId(String appId) { + this.appId = appId; + return this; + } + + /** + * Get the appPermissions value. + * + * @return the appPermissions value + */ + public List appPermissions() { + return this.appPermissions; + } + + /** + * Set the appPermissions value. + * + * @param appPermissions the appPermissions value to set + * @return the ApplicationInner object itself. + */ + public ApplicationInner withAppPermissions(List appPermissions) { + this.appPermissions = appPermissions; + return this; + } + + /** + * Get the availableToOtherTenants value. + * + * @return the availableToOtherTenants value + */ + public Boolean availableToOtherTenants() { + return this.availableToOtherTenants; + } + + /** + * Set the availableToOtherTenants value. + * + * @param availableToOtherTenants the availableToOtherTenants value to set + * @return the ApplicationInner object itself. + */ + public ApplicationInner withAvailableToOtherTenants(Boolean availableToOtherTenants) { + this.availableToOtherTenants = availableToOtherTenants; + return this; + } + + /** + * Get the displayName value. + * + * @return the displayName value + */ + public String displayName() { + return this.displayName; + } + + /** + * Set the displayName value. + * + * @param displayName the displayName value to set + * @return the ApplicationInner object itself. + */ + public ApplicationInner withDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + /** + * Get the identifierUris value. + * + * @return the identifierUris value + */ + public List identifierUris() { + return this.identifierUris; + } + + /** + * Set the identifierUris value. + * + * @param identifierUris the identifierUris value to set + * @return the ApplicationInner object itself. + */ + public ApplicationInner withIdentifierUris(List identifierUris) { + this.identifierUris = identifierUris; + return this; + } + + /** + * Get the replyUrls value. + * + * @return the replyUrls value + */ + public List replyUrls() { + return this.replyUrls; + } + + /** + * Set the replyUrls value. + * + * @param replyUrls the replyUrls value to set + * @return the ApplicationInner object itself. + */ + public ApplicationInner withReplyUrls(List replyUrls) { + this.replyUrls = replyUrls; + return this; + } + + /** + * Get the homepage value. + * + * @return the homepage value + */ + public String homepage() { + return this.homepage; + } + + /** + * Set the homepage value. + * + * @param homepage the homepage value to set + * @return the ApplicationInner object itself. + */ + public ApplicationInner withHomepage(String homepage) { + this.homepage = homepage; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationUpdateParametersInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationUpdateParametersInner.java new file mode 100644 index 0000000000000..ea7d6deeb6629 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationUpdateParametersInner.java @@ -0,0 +1,169 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import java.util.List; +import com.microsoft.azure.management.graphrbac.KeyCredential; +import com.microsoft.azure.management.graphrbac.PasswordCredential; + +/** + * Request parameters for updating an existing application. + */ +public class ApplicationUpdateParametersInner { + /** + * Application display name. + */ + private String displayName; + + /** + * Application homepage. + */ + private String homepage; + + /** + * Application Uris. + */ + private List identifierUris; + + /** + * Application reply Urls. + */ + private List replyUrls; + + /** + * Gets or sets the list of KeyCredential objects. + */ + private List keyCredentials; + + /** + * Gets or sets the list of PasswordCredential objects. + */ + private List passwordCredentials; + + /** + * Get the displayName value. + * + * @return the displayName value + */ + public String displayName() { + return this.displayName; + } + + /** + * Set the displayName value. + * + * @param displayName the displayName value to set + * @return the ApplicationUpdateParametersInner object itself. + */ + public ApplicationUpdateParametersInner withDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + /** + * Get the homepage value. + * + * @return the homepage value + */ + public String homepage() { + return this.homepage; + } + + /** + * Set the homepage value. + * + * @param homepage the homepage value to set + * @return the ApplicationUpdateParametersInner object itself. + */ + public ApplicationUpdateParametersInner withHomepage(String homepage) { + this.homepage = homepage; + return this; + } + + /** + * Get the identifierUris value. + * + * @return the identifierUris value + */ + public List identifierUris() { + return this.identifierUris; + } + + /** + * Set the identifierUris value. + * + * @param identifierUris the identifierUris value to set + * @return the ApplicationUpdateParametersInner object itself. + */ + public ApplicationUpdateParametersInner withIdentifierUris(List identifierUris) { + this.identifierUris = identifierUris; + return this; + } + + /** + * Get the replyUrls value. + * + * @return the replyUrls value + */ + public List replyUrls() { + return this.replyUrls; + } + + /** + * Set the replyUrls value. + * + * @param replyUrls the replyUrls value to set + * @return the ApplicationUpdateParametersInner object itself. + */ + public ApplicationUpdateParametersInner withReplyUrls(List replyUrls) { + this.replyUrls = replyUrls; + return this; + } + + /** + * Get the keyCredentials value. + * + * @return the keyCredentials value + */ + public List keyCredentials() { + return this.keyCredentials; + } + + /** + * Set the keyCredentials value. + * + * @param keyCredentials the keyCredentials value to set + * @return the ApplicationUpdateParametersInner object itself. + */ + public ApplicationUpdateParametersInner withKeyCredentials(List keyCredentials) { + this.keyCredentials = keyCredentials; + return this; + } + + /** + * Get the passwordCredentials value. + * + * @return the passwordCredentials value + */ + public List passwordCredentials() { + return this.passwordCredentials; + } + + /** + * Set the passwordCredentials value. + * + * @param passwordCredentials the passwordCredentials value to set + * @return the ApplicationUpdateParametersInner object itself. + */ + public ApplicationUpdateParametersInner withPasswordCredentials(List passwordCredentials) { + this.passwordCredentials = passwordCredentials; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationsInner.java new file mode 100644 index 0000000000000..9c6b519e4ea39 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationsInner.java @@ -0,0 +1,493 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceResponseBuilder; +import com.microsoft.azure.CloudException; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceResponse; +import com.microsoft.rest.ServiceResponseCallback; +import com.microsoft.rest.Validator; +import java.io.IOException; +import java.util.List; +import okhttp3.ResponseBody; +import retrofit2.Call; +import retrofit2.http.Body; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.HTTP; +import retrofit2.http.PATCH; +import retrofit2.http.Path; +import retrofit2.http.POST; +import retrofit2.http.Query; +import retrofit2.Response; + +/** + * An instance of this class provides access to all the operations defined + * in Applications. + */ +public final class ApplicationsInner { + /** The Retrofit service to perform REST calls. */ + private ApplicationsService service; + /** The service client containing this operation class. */ + private GraphRbacManagementClientImpl client; + + /** + * Initializes an instance of ApplicationsInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public ApplicationsInner(Retrofit retrofit, GraphRbacManagementClientImpl client) { + this.service = retrofit.create(ApplicationsService.class); + this.client = client; + } + + /** + * The interface defining all the services for Applications to be + * used by Retrofit to perform actually REST calls. + */ + interface ApplicationsService { + @Headers("Content-Type: application/json; charset=utf-8") + @POST("{tenantID}/applications") + Call create(@Path("tenantID") String tenantID, @Body ApplicationCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/applications") + Call list(@Path("tenantID") String tenantID, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @HTTP(path = "{tenantID}/applications/{applicationObjectId}", method = "DELETE", hasBody = true) + Call delete(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/applications/{applicationObjectId}") + Call get(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @PATCH("{tenantID}/applications/{applicationObjectId}") + Call patch(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Body ApplicationUpdateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * Create a new application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param parameters Parameters to create an application. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the ApplicationInner object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse create(ApplicationCreateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(parameters); + Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return createDelegate(call.execute()); + } + + /** + * Create a new application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param parameters Parameters to create an application. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall createAsync(ApplicationCreateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (parameters == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Validator.validate(parameters, serviceCallback); + Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(createDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse createDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(201, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<ApplicationInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> list() throws CloudException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + final String filter = null; + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listDelegate(call.execute()); + List result = response.getBody().getItems(); + return new ServiceResponse<>(result, response.getResponse()); + } + + /** + * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall listAsync(final ServiceCallback> serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + final String filter = null; + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listDelegate(response); + serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + /** + * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param filter The filters to apply on the operation + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<ApplicationInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> list(String filter) throws CloudException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listDelegate(call.execute()); + List result = response.getBody().getItems(); + return new ServiceResponse<>(result, response.getResponse()); + } + + /** + * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param filter The filters to apply on the operation + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall listAsync(String filter, final ServiceCallback> serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listDelegate(response); + serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Delete an application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse delete(String applicationObjectId) throws CloudException, IOException, IllegalArgumentException { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.delete(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return deleteDelegate(call.execute()); + } + + /** + * Delete an application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall deleteAsync(String applicationObjectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (applicationObjectId == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null.")); + return null; + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.delete(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(deleteDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse deleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .build(response); + } + + /** + * Get an application by object Id. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the ApplicationInner object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse get(String applicationObjectId) throws CloudException, IOException, IllegalArgumentException { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.get(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return getDelegate(call.execute()); + } + + /** + * Get an application by object Id. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall getAsync(String applicationObjectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (applicationObjectId == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null.")); + return null; + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.get(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(getDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse getDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Update existing application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @param parameters Parameters to update an existing application. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse patch(String applicationObjectId, ApplicationUpdateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(parameters); + Call call = service.patch(applicationObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return patchDelegate(call.execute()); + } + + /** + * Update existing application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @param parameters Parameters to update an existing application. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall patchAsync(String applicationObjectId, ApplicationUpdateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (applicationObjectId == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null.")); + return null; + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (parameters == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Validator.validate(parameters, serviceCallback); + Call call = service.patch(applicationObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(patchDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse patchDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .build(response); + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/CheckGroupMembershipParametersInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/CheckGroupMembershipParametersInner.java new file mode 100644 index 0000000000000..128c5949e63c9 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/CheckGroupMembershipParametersInner.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Request parameters for IsMemberOf API call. + */ +public class CheckGroupMembershipParametersInner { + /** + * The object ID of the group to check. + */ + @JsonProperty(required = true) + private String groupId; + + /** + * The object ID of the contact, group, user, or service principal to + * check for membership in the specified group. + */ + @JsonProperty(required = true) + private String memberId; + + /** + * Get the groupId value. + * + * @return the groupId value + */ + public String groupId() { + return this.groupId; + } + + /** + * Set the groupId value. + * + * @param groupId the groupId value to set + * @return the CheckGroupMembershipParametersInner object itself. + */ + public CheckGroupMembershipParametersInner withGroupId(String groupId) { + this.groupId = groupId; + return this; + } + + /** + * Get the memberId value. + * + * @return the memberId value + */ + public String memberId() { + return this.memberId; + } + + /** + * Set the memberId value. + * + * @param memberId the memberId value to set + * @return the CheckGroupMembershipParametersInner object itself. + */ + public CheckGroupMembershipParametersInner withMemberId(String memberId) { + this.memberId = memberId; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/CheckGroupMembershipResultInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/CheckGroupMembershipResultInner.java new file mode 100644 index 0000000000000..5d52faed8491d --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/CheckGroupMembershipResultInner.java @@ -0,0 +1,43 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + + +/** + * Server response for IsMemberOf API call. + */ +public class CheckGroupMembershipResultInner { + /** + * true if the specified user, group, contact, or service principal has + * either direct or transitive membership in the specified group; + * otherwise, false. + */ + private Boolean value; + + /** + * Get the value value. + * + * @return the value value + */ + public Boolean value() { + return this.value; + } + + /** + * Set the value value. + * + * @param value the value value to set + * @return the CheckGroupMembershipResultInner object itself. + */ + public CheckGroupMembershipResultInner withValue(Boolean value) { + this.value = value; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManagementClientImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManagementClientImpl.java new file mode 100644 index 0000000000000..e95756e1703d4 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManagementClientImpl.java @@ -0,0 +1,256 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import com.microsoft.azure.AzureClient; +import com.microsoft.azure.AzureServiceClient; +import com.microsoft.azure.RestClient; +import com.microsoft.rest.credentials.ServiceClientCredentials; + +/** + * Initializes a new instance of the GraphRbacManagementClientImpl class. + */ +public final class GraphRbacManagementClientImpl extends AzureServiceClient { + /** the {@link AzureClient} used for long running operations. */ + private AzureClient azureClient; + + /** + * Gets the {@link AzureClient} used for long running operations. + * @return the azure client; + */ + public AzureClient getAzureClient() { + return this.azureClient; + } + + /** Client Api Version. */ + private String apiVersion; + + /** + * Gets Client Api Version. + * + * @return the apiVersion value. + */ + public String apiVersion() { + return this.apiVersion; + } + + /** Gets or sets the tenant Id. */ + private String tenantID; + + /** + * Gets Gets or sets the tenant Id. + * + * @return the tenantID value. + */ + public String tenantID() { + return this.tenantID; + } + + /** + * Sets Gets or sets the tenant Id. + * + * @param tenantID the tenantID value. + * @return the service client itself + */ + public GraphRbacManagementClientImpl withTenantID(String tenantID) { + this.tenantID = tenantID; + return this; + } + + /** Gets or sets the preferred language for the response. */ + private String acceptLanguage; + + /** + * Gets Gets or sets the preferred language for the response. + * + * @return the acceptLanguage value. + */ + public String acceptLanguage() { + return this.acceptLanguage; + } + + /** + * Sets Gets or sets the preferred language for the response. + * + * @param acceptLanguage the acceptLanguage value. + * @return the service client itself + */ + public GraphRbacManagementClientImpl withAcceptLanguage(String acceptLanguage) { + this.acceptLanguage = acceptLanguage; + return this; + } + + /** Gets or sets the retry timeout in seconds for Long Running Operations. Default value is 30. */ + private int longRunningOperationRetryTimeout; + + /** + * Gets Gets or sets the retry timeout in seconds for Long Running Operations. Default value is 30. + * + * @return the longRunningOperationRetryTimeout value. + */ + public int longRunningOperationRetryTimeout() { + return this.longRunningOperationRetryTimeout; + } + + /** + * Sets Gets or sets the retry timeout in seconds for Long Running Operations. Default value is 30. + * + * @param longRunningOperationRetryTimeout the longRunningOperationRetryTimeout value. + * @return the service client itself + */ + public GraphRbacManagementClientImpl withLongRunningOperationRetryTimeout(int longRunningOperationRetryTimeout) { + this.longRunningOperationRetryTimeout = longRunningOperationRetryTimeout; + return this; + } + + /** When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true. */ + private boolean generateClientRequestId; + + /** + * Gets When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true. + * + * @return the generateClientRequestId value. + */ + public boolean generateClientRequestId() { + return this.generateClientRequestId; + } + + /** + * Sets When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true. + * + * @param generateClientRequestId the generateClientRequestId value. + * @return the service client itself + */ + public GraphRbacManagementClientImpl withGenerateClientRequestId(boolean generateClientRequestId) { + this.generateClientRequestId = generateClientRequestId; + return this; + } + + /** + * The ObjectsInner object to access its operations. + */ + private ObjectsInner objects; + + /** + * Gets the ObjectsInner object to access its operations. + * @return the ObjectsInner object. + */ + public ObjectsInner objects() { + return this.objects; + } + + /** + * The ApplicationsInner object to access its operations. + */ + private ApplicationsInner applications; + + /** + * Gets the ApplicationsInner object to access its operations. + * @return the ApplicationsInner object. + */ + public ApplicationsInner applications() { + return this.applications; + } + + /** + * The GroupsInner object to access its operations. + */ + private GroupsInner groups; + + /** + * Gets the GroupsInner object to access its operations. + * @return the GroupsInner object. + */ + public GroupsInner groups() { + return this.groups; + } + + /** + * The ServicePrincipalsInner object to access its operations. + */ + private ServicePrincipalsInner servicePrincipals; + + /** + * Gets the ServicePrincipalsInner object to access its operations. + * @return the ServicePrincipalsInner object. + */ + public ServicePrincipalsInner servicePrincipals() { + return this.servicePrincipals; + } + + /** + * The UsersInner object to access its operations. + */ + private UsersInner users; + + /** + * Gets the UsersInner object to access its operations. + * @return the UsersInner object. + */ + public UsersInner users() { + return this.users; + } + + /** + * Initializes an instance of GraphRbacManagementClient client. + * + * @param credentials the management credentials for Azure + */ + public GraphRbacManagementClientImpl(ServiceClientCredentials credentials) { + this("https://graph.windows.net", credentials); + } + + /** + * Initializes an instance of GraphRbacManagementClient client. + * + * @param baseUrl the base URL of the host + * @param credentials the management credentials for Azure + */ + public GraphRbacManagementClientImpl(String baseUrl, ServiceClientCredentials credentials) { + this(new RestClient.Builder() + .withBaseUrl(baseUrl) + .withCredentials(credentials) + .build()); + } + + /** + * Initializes an instance of GraphRbacManagementClient client. + * + * @param restClient the REST client to connect to Azure. + */ + public GraphRbacManagementClientImpl(RestClient restClient) { + super(restClient); + initialize(); + } + + protected void initialize() { + this.apiVersion = "1.6"; + this.acceptLanguage = "en-US"; + this.longRunningOperationRetryTimeout = 30; + this.generateClientRequestId = true; + this.objects = new ObjectsInner(restClient().retrofit(), this); + this.applications = new ApplicationsInner(restClient().retrofit(), this); + this.groups = new GroupsInner(restClient().retrofit(), this); + this.servicePrincipals = new ServicePrincipalsInner(restClient().retrofit(), this); + this.users = new UsersInner(restClient().retrofit(), this); + this.azureClient = new AzureClient(this); + } + + /** + * Gets the User-Agent header for the client. + * + * @return the user agent string. + */ + @Override + public String userAgent() { + return String.format("Azure-SDK-For-Java/%s (%s)", + getClass().getPackage().getImplementationVersion(), + "GraphRbacManagementClient, 1.6"); + } +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupCreateParametersInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupCreateParametersInner.java new file mode 100644 index 0000000000000..9bf03add91c74 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupCreateParametersInner.java @@ -0,0 +1,131 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Request parameters for create a new group. + */ +public class GroupCreateParametersInner { + /** + * Group display name. + */ + @JsonProperty(required = true) + private String displayName; + + /** + * Specifies whether the group is mail-enabled. Must be false. This is + * because only pure security groups can be created using the Graph API. + */ + @JsonProperty(required = true) + private boolean mailEnabled; + + /** + * Mail nick name. + */ + @JsonProperty(required = true) + private String mailNickname; + + /** + * Specifies whether the group is a security group. Must be true. This is + * because only pure security groups can be created using the Graph API. + */ + @JsonProperty(required = true) + private boolean securityEnabled; + + /** + * Creates an instance of GroupCreateParametersInner class. + */ + public GroupCreateParametersInner() { + mailEnabled = false; + securityEnabled = true; + } + + /** + * Get the displayName value. + * + * @return the displayName value + */ + public String displayName() { + return this.displayName; + } + + /** + * Set the displayName value. + * + * @param displayName the displayName value to set + * @return the GroupCreateParametersInner object itself. + */ + public GroupCreateParametersInner withDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + /** + * Get the mailEnabled value. + * + * @return the mailEnabled value + */ + public boolean mailEnabled() { + return this.mailEnabled; + } + + /** + * Set the mailEnabled value. + * + * @param mailEnabled the mailEnabled value to set + * @return the GroupCreateParametersInner object itself. + */ + public GroupCreateParametersInner withMailEnabled(boolean mailEnabled) { + this.mailEnabled = mailEnabled; + return this; + } + + /** + * Get the mailNickname value. + * + * @return the mailNickname value + */ + public String mailNickname() { + return this.mailNickname; + } + + /** + * Set the mailNickname value. + * + * @param mailNickname the mailNickname value to set + * @return the GroupCreateParametersInner object itself. + */ + public GroupCreateParametersInner withMailNickname(String mailNickname) { + this.mailNickname = mailNickname; + return this; + } + + /** + * Get the securityEnabled value. + * + * @return the securityEnabled value + */ + public boolean securityEnabled() { + return this.securityEnabled; + } + + /** + * Set the securityEnabled value. + * + * @param securityEnabled the securityEnabled value to set + * @return the GroupCreateParametersInner object itself. + */ + public GroupCreateParametersInner withSecurityEnabled(boolean securityEnabled) { + this.securityEnabled = securityEnabled; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java new file mode 100644 index 0000000000000..ab9463780f1c8 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java @@ -0,0 +1,1008 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceResponseBuilder; +import com.microsoft.azure.CloudException; +import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.management.graphrbac.GroupAddMemberParameters; +import com.microsoft.azure.management.graphrbac.GroupGetMemberGroupsParameters; +import com.microsoft.azure.Page; +import com.microsoft.azure.PagedList; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceResponse; +import com.microsoft.rest.ServiceResponseCallback; +import com.microsoft.rest.Validator; +import java.io.IOException; +import java.util.List; +import okhttp3.ResponseBody; +import retrofit2.Call; +import retrofit2.http.Body; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.HTTP; +import retrofit2.http.Path; +import retrofit2.http.POST; +import retrofit2.http.Query; +import retrofit2.Response; + +/** + * An instance of this class provides access to all the operations defined + * in Groups. + */ +public final class GroupsInner { + /** The Retrofit service to perform REST calls. */ + private GroupsService service; + /** The service client containing this operation class. */ + private GraphRbacManagementClientImpl client; + + /** + * Initializes an instance of GroupsInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public GroupsInner(Retrofit retrofit, GraphRbacManagementClientImpl client) { + this.service = retrofit.create(GroupsService.class); + this.client = client; + } + + /** + * The interface defining all the services for Groups to be + * used by Retrofit to perform actually REST calls. + */ + interface GroupsService { + @Headers("Content-Type: application/json; charset=utf-8") + @POST("{tenantID}/isMemberOf") + Call isMemberOf(@Path("tenantID") String tenantID, @Body CheckGroupMembershipParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @HTTP(path = "{tenantID}/groups/{groupObjectId}/$links/members/{memberObjectId}", method = "DELETE", hasBody = true) + Call removeMember(@Path(value = "groupObjectId", encoded = true) String groupObjectId, @Path(value = "memberObjectId", encoded = true) String memberObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @POST("{tenantID}/groups/{groupObjectId}/$links/members") + Call addMember(@Path(value = "groupObjectId", encoded = true) String groupObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body GroupAddMemberParameters parameters, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @HTTP(path = "{tenantID}/groups/{groupObjectId}", method = "DELETE", hasBody = true) + Call delete(@Path(value = "groupObjectId", encoded = true) String groupObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @POST("{tenantID}/groups") + Call create(@Path("tenantID") String tenantID, @Body GroupCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/groups") + Call list(@Path("tenantID") String tenantID, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/groups/{objectId}/members") + Call getGroupMembers(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/groups/{objectId}") + Call get(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @POST("{tenantID}/groups/{objectId}/getMemberGroups") + Call getMemberGroups(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body GroupGetMemberGroupsParameters parameters, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/{nextLink}") + Call listNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/{nextLink}") + Call getGroupMembersNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * Checks whether the specified user, group, contact, or service principal is a direct or a transitive member of the specified group. + * + * @param parameters Check group membership parameters. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the CheckGroupMembershipResultInner object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse isMemberOf(CheckGroupMembershipParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(parameters); + Call call = service.isMemberOf(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return isMemberOfDelegate(call.execute()); + } + + /** + * Checks whether the specified user, group, contact, or service principal is a direct or a transitive member of the specified group. + * + * @param parameters Check group membership parameters. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall isMemberOfAsync(CheckGroupMembershipParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (parameters == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Validator.validate(parameters, serviceCallback); + Call call = service.isMemberOf(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(isMemberOfDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse isMemberOfDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Remove a memeber from a group. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/groups-operations#DeleteGroupMember. + * + * @param groupObjectId Group object id + * @param memberObjectId Member Object id + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse removeMember(String groupObjectId, String memberObjectId) throws CloudException, IOException, IllegalArgumentException { + if (groupObjectId == null) { + throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); + } + if (memberObjectId == null) { + throw new IllegalArgumentException("Parameter memberObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.removeMember(groupObjectId, memberObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return removeMemberDelegate(call.execute()); + } + + /** + * Remove a memeber from a group. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/groups-operations#DeleteGroupMember. + * + * @param groupObjectId Group object id + * @param memberObjectId Member Object id + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall removeMemberAsync(String groupObjectId, String memberObjectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (groupObjectId == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter groupObjectId is required and cannot be null.")); + return null; + } + if (memberObjectId == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter memberObjectId is required and cannot be null.")); + return null; + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.removeMember(groupObjectId, memberObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(removeMemberDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse removeMemberDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .build(response); + } + + /** + * Add a memeber to a group. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/groups-operations#AddGroupMembers. + * + * @param groupObjectId Group object id + * @param url Member Object Url as "https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd", where "0b1f9851-1bf0-433f-aec3-cb9272f093dc" is the tenantId and "f260bbc4-c254-447b-94cf-293b5ec434dd" is the objectId of the member (user, application, servicePrincipal, group) to be added. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse addMember(String groupObjectId, String url) throws CloudException, IOException, IllegalArgumentException { + if (groupObjectId == null) { + throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (url == null) { + throw new IllegalArgumentException("Parameter url is required and cannot be null."); + } + GroupAddMemberParameters parameters = new GroupAddMemberParameters(); + parameters.withUrl(url); + Call call = service.addMember(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + return addMemberDelegate(call.execute()); + } + + /** + * Add a memeber to a group. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/groups-operations#AddGroupMembers. + * + * @param groupObjectId Group object id + * @param url Member Object Url as "https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd", where "0b1f9851-1bf0-433f-aec3-cb9272f093dc" is the tenantId and "f260bbc4-c254-447b-94cf-293b5ec434dd" is the objectId of the member (user, application, servicePrincipal, group) to be added. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall addMemberAsync(String groupObjectId, String url, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (groupObjectId == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter groupObjectId is required and cannot be null.")); + return null; + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + if (url == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter url is required and cannot be null.")); + return null; + } + GroupAddMemberParameters parameters = new GroupAddMemberParameters(); + parameters.withUrl(url); + Call call = service.addMember(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(addMemberDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse addMemberDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .build(response); + } + + /** + * Delete a group in the directory. Reference: http://msdn.microsoft.com/en-us/library/azure/dn151676.aspx. + * + * @param groupObjectId Object id + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse delete(String groupObjectId) throws CloudException, IOException, IllegalArgumentException { + if (groupObjectId == null) { + throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.delete(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return deleteDelegate(call.execute()); + } + + /** + * Delete a group in the directory. Reference: http://msdn.microsoft.com/en-us/library/azure/dn151676.aspx. + * + * @param groupObjectId Object id + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall deleteAsync(String groupObjectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (groupObjectId == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter groupObjectId is required and cannot be null.")); + return null; + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.delete(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(deleteDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse deleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .build(response); + } + + /** + * Create a group in the directory. Reference: http://msdn.microsoft.com/en-us/library/azure/dn151676.aspx. + * + * @param parameters Parameters to create a group + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the ADGroupInner object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse create(GroupCreateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(parameters); + Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return createDelegate(call.execute()); + } + + /** + * Create a group in the directory. Reference: http://msdn.microsoft.com/en-us/library/azure/dn151676.aspx. + * + * @param parameters Parameters to create a group + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall createAsync(GroupCreateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (parameters == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Validator.validate(parameters, serviceCallback); + Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(createDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse createDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(201, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets list of groups for the current tenant. + * + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<ADGroupInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> list() throws CloudException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + final String filter = null; + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listDelegate(call.execute()); + PagedList result = new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextPageLink) throws CloudException, IOException { + return listNext(nextLink).getBody(); + } + }; + return new ServiceResponse<>(result, response.getResponse()); + } + + /** + * Gets list of groups for the current tenant. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall listAsync(final ListOperationCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + final String filter = null; + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + /** + * Gets list of groups for the current tenant. + * + * @param filter The filter to apply on the operation. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<ADGroupInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> list(final String filter) throws CloudException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listDelegate(call.execute()); + PagedList result = new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextPageLink) throws CloudException, IOException { + return listNext(nextLink).getBody(); + } + }; + return new ServiceResponse<>(result, response.getResponse()); + } + + /** + * Gets list of groups for the current tenant. + * + * @param filter The filter to apply on the operation. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall listAsync(final String filter, final ListOperationCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets the members of a group. + * + * @param objectId Group object Id who's members should be retrieved. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<AADObjectInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> getGroupMembers(final String objectId) throws CloudException, IOException, IllegalArgumentException { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.getGroupMembers(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = getGroupMembersDelegate(call.execute()); + PagedList result = new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextPageLink) throws CloudException, IOException { + return getGroupMembersNext(nextLink).getBody(); + } + }; + return new ServiceResponse<>(result, response.getResponse()); + } + + /** + * Gets the members of a group. + * + * @param objectId Group object Id who's members should be retrieved. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall getGroupMembersAsync(final String objectId, final ListOperationCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (objectId == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter objectId is required and cannot be null.")); + return null; + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.getGroupMembers(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = getGroupMembersDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + getGroupMembersNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse> getGroupMembersDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets group information from the directory. + * + * @param objectId User objectId to get group information. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the ADGroupInner object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse get(String objectId) throws CloudException, IOException, IllegalArgumentException { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return getDelegate(call.execute()); + } + + /** + * Gets group information from the directory. + * + * @param objectId User objectId to get group information. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall getAsync(String objectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (objectId == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter objectId is required and cannot be null.")); + return null; + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(getDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse getDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets a collection that contains the Object IDs of the groups of which the group is a member. + * + * @param objectId Group filtering parameters. + * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<String> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> getMemberGroups(String objectId, boolean securityEnabledOnly) throws CloudException, IOException, IllegalArgumentException { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + GroupGetMemberGroupsParameters parameters = new GroupGetMemberGroupsParameters(); + parameters.withSecurityEnabledOnly(securityEnabledOnly); + Call call = service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + ServiceResponse> response = getMemberGroupsDelegate(call.execute()); + List result = response.getBody().getItems(); + return new ServiceResponse<>(result, response.getResponse()); + } + + /** + * Gets a collection that contains the Object IDs of the groups of which the group is a member. + * + * @param objectId Group filtering parameters. + * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall getMemberGroupsAsync(String objectId, boolean securityEnabledOnly, final ServiceCallback> serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (objectId == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter objectId is required and cannot be null.")); + return null; + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + GroupGetMemberGroupsParameters parameters = new GroupGetMemberGroupsParameters(); + parameters.withSecurityEnabledOnly(securityEnabledOnly); + Call call = service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = getMemberGroupsDelegate(response); + serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse> getMemberGroupsDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets list of groups for the current tenant. + * + * @param nextLink Next link for list operation. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<ADGroupInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> listNext(final String nextLink) throws CloudException, IOException, IllegalArgumentException { + if (nextLink == null) { + throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return listNextDelegate(call.execute()); + } + + /** + * Gets list of groups for the current tenant. + * + * @param nextLink Next link for list operation. + * @param serviceCall the ServiceCall object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall listNextAsync(final String nextLink, final ServiceCall serviceCall, final ListOperationCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (nextLink == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); + return null; + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + serviceCall.newCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listNextDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse> listNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets the members of a group. + * + * @param nextLink Next link for list operation. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<AADObjectInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> getGroupMembersNext(final String nextLink) throws CloudException, IOException, IllegalArgumentException { + if (nextLink == null) { + throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.getGroupMembersNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return getGroupMembersNextDelegate(call.execute()); + } + + /** + * Gets the members of a group. + * + * @param nextLink Next link for list operation. + * @param serviceCall the ServiceCall object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall getGroupMembersNextAsync(final String nextLink, final ServiceCall serviceCall, final ListOperationCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (nextLink == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); + return null; + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.getGroupMembersNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + serviceCall.newCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = getGroupMembersNextDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + getGroupMembersNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse> getGroupMembersNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ObjectsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ObjectsInner.java new file mode 100644 index 0000000000000..51d87506eecef --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ObjectsInner.java @@ -0,0 +1,121 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceResponseBuilder; +import com.microsoft.azure.CloudException; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceResponse; +import com.microsoft.rest.ServiceResponseCallback; +import java.io.IOException; +import okhttp3.ResponseBody; +import retrofit2.Call; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.Path; +import retrofit2.http.Query; +import retrofit2.Response; + +/** + * An instance of this class provides access to all the operations defined + * in Objects. + */ +public final class ObjectsInner { + /** The Retrofit service to perform REST calls. */ + private ObjectsService service; + /** The service client containing this operation class. */ + private GraphRbacManagementClientImpl client; + + /** + * Initializes an instance of ObjectsInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public ObjectsInner(Retrofit retrofit, GraphRbacManagementClientImpl client) { + this.service = retrofit.create(ObjectsService.class); + this.client = client; + } + + /** + * The interface defining all the services for Objects to be + * used by Retrofit to perform actually REST calls. + */ + interface ObjectsService { + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/me") + Call getCurrentUser(@Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * Gets the details for current logged in user. + * + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the AADObjectInner object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse getCurrentUser() throws CloudException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.getCurrentUser(this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return getCurrentUserDelegate(call.execute()); + } + + /** + * Gets the details for current logged in user. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall getCurrentUserAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.getCurrentUser(this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(getCurrentUserDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse getCurrentUserDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/PageImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/PageImpl.java new file mode 100644 index 0000000000000..aacd2fba4f469 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/PageImpl.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.azure.Page; +import java.util.List; + +/** + * An instance of this class defines a page of Azure resources and a link to + * get the next page of resources, if any. + * + * @param type of Azure resource + */ +public class PageImpl implements Page { + /** + * The link to the next page. + */ + @JsonProperty("") + private String nextPageLink; + + /** + * The list of items. + */ + @JsonProperty("value") + private List items; + + /** + * Gets the link to the next page. + * + * @return the link to the next page. + */ + @Override + public String getNextPageLink() { + return this.nextPageLink; + } + + /** + * Gets the list of items. + * + * @return the list of items in {@link List}. + */ + @Override + public List getItems() { + return items; + } + + /** + * Sets the link to the next page. + * + * @param nextPageLink the link to the next page. + * @return this Page object itself. + */ + public PageImpl setNextPageLink(String nextPageLink) { + this.nextPageLink = nextPageLink; + return this; + } + + /** + * Sets the list of items. + * + * @param items the list of items in {@link List}. + * @return this Page object itself. + */ + public PageImpl setItems(List items) { + this.items = items; + return this; + } +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/PageImpl1.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/PageImpl1.java new file mode 100644 index 0000000000000..8a2feb4e0ffe6 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/PageImpl1.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.azure.Page; +import java.util.List; + +/** + * An instance of this class defines a page of Azure resources and a link to + * get the next page of resources, if any. + * + * @param type of Azure resource + */ +public class PageImpl1 implements Page { + /** + * The link to the next page. + */ + @JsonProperty("odata.nextLink") + private String nextPageLink; + + /** + * The list of items. + */ + @JsonProperty("value") + private List items; + + /** + * Gets the link to the next page. + * + * @return the link to the next page. + */ + @Override + public String getNextPageLink() { + return this.nextPageLink; + } + + /** + * Gets the list of items. + * + * @return the list of items in {@link List}. + */ + @Override + public List getItems() { + return items; + } + + /** + * Sets the link to the next page. + * + * @param nextPageLink the link to the next page. + * @return this Page object itself. + */ + public PageImpl1 setNextPageLink(String nextPageLink) { + this.nextPageLink = nextPageLink; + return this; + } + + /** + * Sets the list of items. + * + * @param items the list of items in {@link List}. + * @return this Page object itself. + */ + public PageImpl1 setItems(List items) { + this.items = items; + return this; + } +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalCreateParametersInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalCreateParametersInner.java new file mode 100644 index 0000000000000..aa4aa749beced --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalCreateParametersInner.java @@ -0,0 +1,69 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Request parameters for create a new service principal. + */ +public class ServicePrincipalCreateParametersInner { + /** + * Gets or sets application Id. + */ + @JsonProperty(required = true) + private String appId; + + /** + * Specifies if the account is enabled. + */ + @JsonProperty(required = true) + private boolean accountEnabled; + + /** + * Get the appId value. + * + * @return the appId value + */ + public String appId() { + return this.appId; + } + + /** + * Set the appId value. + * + * @param appId the appId value to set + * @return the ServicePrincipalCreateParametersInner object itself. + */ + public ServicePrincipalCreateParametersInner withAppId(String appId) { + this.appId = appId; + return this; + } + + /** + * Get the accountEnabled value. + * + * @return the accountEnabled value + */ + public boolean accountEnabled() { + return this.accountEnabled; + } + + /** + * Set the accountEnabled value. + * + * @param accountEnabled the accountEnabled value to set + * @return the ServicePrincipalCreateParametersInner object itself. + */ + public ServicePrincipalCreateParametersInner withAccountEnabled(boolean accountEnabled) { + this.accountEnabled = accountEnabled; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalInner.java new file mode 100644 index 0000000000000..c5b41719ebd70 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalInner.java @@ -0,0 +1,142 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import java.util.List; + +/** + * Active Directory service principal information. + */ +public class ServicePrincipalInner { + /** + * Gets or sets object Id. + */ + private String objectId; + + /** + * Gets or sets object type. + */ + private String objectType; + + /** + * Gets or sets service principal display name. + */ + private String displayName; + + /** + * Gets or sets app id. + */ + private String appId; + + /** + * Gets or sets the list of names. + */ + private List servicePrincipalNames; + + /** + * Get the objectId value. + * + * @return the objectId value + */ + public String objectId() { + return this.objectId; + } + + /** + * Set the objectId value. + * + * @param objectId the objectId value to set + * @return the ServicePrincipalInner object itself. + */ + public ServicePrincipalInner withObjectId(String objectId) { + this.objectId = objectId; + return this; + } + + /** + * Get the objectType value. + * + * @return the objectType value + */ + public String objectType() { + return this.objectType; + } + + /** + * Set the objectType value. + * + * @param objectType the objectType value to set + * @return the ServicePrincipalInner object itself. + */ + public ServicePrincipalInner withObjectType(String objectType) { + this.objectType = objectType; + return this; + } + + /** + * Get the displayName value. + * + * @return the displayName value + */ + public String displayName() { + return this.displayName; + } + + /** + * Set the displayName value. + * + * @param displayName the displayName value to set + * @return the ServicePrincipalInner object itself. + */ + public ServicePrincipalInner withDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + /** + * Get the appId value. + * + * @return the appId value + */ + public String appId() { + return this.appId; + } + + /** + * Set the appId value. + * + * @param appId the appId value to set + * @return the ServicePrincipalInner object itself. + */ + public ServicePrincipalInner withAppId(String appId) { + this.appId = appId; + return this; + } + + /** + * Get the servicePrincipalNames value. + * + * @return the servicePrincipalNames value + */ + public List servicePrincipalNames() { + return this.servicePrincipalNames; + } + + /** + * Set the servicePrincipalNames value. + * + * @param servicePrincipalNames the servicePrincipalNames value to set + * @return the ServicePrincipalInner object itself. + */ + public ServicePrincipalInner withServicePrincipalNames(List servicePrincipalNames) { + this.servicePrincipalNames = servicePrincipalNames; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java new file mode 100644 index 0000000000000..9b8686372831f --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java @@ -0,0 +1,515 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceResponseBuilder; +import com.microsoft.azure.CloudException; +import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.Page; +import com.microsoft.azure.PagedList; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceResponse; +import com.microsoft.rest.ServiceResponseCallback; +import com.microsoft.rest.Validator; +import java.io.IOException; +import java.util.List; +import okhttp3.ResponseBody; +import retrofit2.Call; +import retrofit2.http.Body; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.HTTP; +import retrofit2.http.Path; +import retrofit2.http.POST; +import retrofit2.http.Query; +import retrofit2.Response; + +/** + * An instance of this class provides access to all the operations defined + * in ServicePrincipals. + */ +public final class ServicePrincipalsInner { + /** The Retrofit service to perform REST calls. */ + private ServicePrincipalsService service; + /** The service client containing this operation class. */ + private GraphRbacManagementClientImpl client; + + /** + * Initializes an instance of ServicePrincipalsInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public ServicePrincipalsInner(Retrofit retrofit, GraphRbacManagementClientImpl client) { + this.service = retrofit.create(ServicePrincipalsService.class); + this.client = client; + } + + /** + * The interface defining all the services for ServicePrincipals to be + * used by Retrofit to perform actually REST calls. + */ + interface ServicePrincipalsService { + @Headers("Content-Type: application/json; charset=utf-8") + @POST("{tenantID}/servicePrincipals") + Call create(@Path("tenantID") String tenantID, @Body ServicePrincipalCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/servicePrincipals") + Call list(@Path("tenantID") String tenantID, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @HTTP(path = "{tenantID}/servicePrincipals/{objectId}", method = "DELETE", hasBody = true) + Call delete(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/servicePrincipals/{objectId}") + Call get(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/{nextLink}") + Call listNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * Creates a service principal in the directory. + * + * @param parameters Parameters to create a service principal. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the ServicePrincipalInner object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse create(ServicePrincipalCreateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(parameters); + Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return createDelegate(call.execute()); + } + + /** + * Creates a service principal in the directory. + * + * @param parameters Parameters to create a service principal. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall createAsync(ServicePrincipalCreateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (parameters == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Validator.validate(parameters, serviceCallback); + Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(createDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse createDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(201, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets list of service principals from the current tenant. + * + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> list() throws CloudException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + final String filter = null; + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listDelegate(call.execute()); + PagedList result = new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextPageLink) throws CloudException, IOException { + return listNext(nextLink).getBody(); + } + }; + return new ServiceResponse<>(result, response.getResponse()); + } + + /** + * Gets list of service principals from the current tenant. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall listAsync(final ListOperationCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + final String filter = null; + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + /** + * Gets list of service principals from the current tenant. + * + * @param filter The filter to apply on the operation. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> list(final String filter) throws CloudException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listDelegate(call.execute()); + PagedList result = new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextPageLink) throws CloudException, IOException { + return listNext(nextLink).getBody(); + } + }; + return new ServiceResponse<>(result, response.getResponse()); + } + + /** + * Gets list of service principals from the current tenant. + * + * @param filter The filter to apply on the operation. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall listAsync(final String filter, final ListOperationCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Deletes service principal from the directory. + * + * @param objectId Object id to delete service principal information. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse delete(String objectId) throws CloudException, IOException, IllegalArgumentException { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.delete(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return deleteDelegate(call.execute()); + } + + /** + * Deletes service principal from the directory. + * + * @param objectId Object id to delete service principal information. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall deleteAsync(String objectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (objectId == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter objectId is required and cannot be null.")); + return null; + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.delete(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(deleteDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse deleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .build(response); + } + + /** + * Gets service principal information from the directory. + * + * @param objectId Object id to get service principal information. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the ServicePrincipalInner object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse get(String objectId) throws CloudException, IOException, IllegalArgumentException { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return getDelegate(call.execute()); + } + + /** + * Gets service principal information from the directory. + * + * @param objectId Object id to get service principal information. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall getAsync(String objectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (objectId == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter objectId is required and cannot be null.")); + return null; + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(getDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse getDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets list of service principals from the current tenant. + * + * @param nextLink Next link for list operation. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> listNext(final String nextLink) throws CloudException, IOException, IllegalArgumentException { + if (nextLink == null) { + throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return listNextDelegate(call.execute()); + } + + /** + * Gets list of service principals from the current tenant. + * + * @param nextLink Next link for list operation. + * @param serviceCall the ServiceCall object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall listNextAsync(final String nextLink, final ServiceCall serviceCall, final ListOperationCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (nextLink == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); + return null; + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + serviceCall.newCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listNextDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse> listNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserCreateParametersInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserCreateParametersInner.java new file mode 100644 index 0000000000000..18e490213ebe6 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserCreateParametersInner.java @@ -0,0 +1,177 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import com.microsoft.azure.management.graphrbac.PasswordProfile; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Request parameters for create a new work or school account user. + */ +public class UserCreateParametersInner { + /** + * Enable the account. If it is enabled then true else false. + */ + @JsonProperty(required = true) + private boolean accountEnabled; + + /** + * User display name. + */ + @JsonProperty(required = true) + private String displayName; + + /** + * Password Profile. + */ + @JsonProperty(required = true) + private PasswordProfile passwordProfile; + + /** + * The user principal name (someuser@contoso.com). It must contain one of + * the verified domains for the tenant. + */ + @JsonProperty(required = true) + private String userPrincipalName; + + /** + * The mail alias for the user. + */ + @JsonProperty(required = true) + private String mailNickname; + + /** + * Needs to be specified if you are using a federated domain for the + * user's userPrincipalName (UPN) property while creating a new user + * account. It is used to associate an on-premises Active Directory user + * account to their Azure AD user object. + */ + private String immutableId; + + /** + * Get the accountEnabled value. + * + * @return the accountEnabled value + */ + public boolean accountEnabled() { + return this.accountEnabled; + } + + /** + * Set the accountEnabled value. + * + * @param accountEnabled the accountEnabled value to set + * @return the UserCreateParametersInner object itself. + */ + public UserCreateParametersInner withAccountEnabled(boolean accountEnabled) { + this.accountEnabled = accountEnabled; + return this; + } + + /** + * Get the displayName value. + * + * @return the displayName value + */ + public String displayName() { + return this.displayName; + } + + /** + * Set the displayName value. + * + * @param displayName the displayName value to set + * @return the UserCreateParametersInner object itself. + */ + public UserCreateParametersInner withDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + /** + * Get the passwordProfile value. + * + * @return the passwordProfile value + */ + public PasswordProfile passwordProfile() { + return this.passwordProfile; + } + + /** + * Set the passwordProfile value. + * + * @param passwordProfile the passwordProfile value to set + * @return the UserCreateParametersInner object itself. + */ + public UserCreateParametersInner withPasswordProfile(PasswordProfile passwordProfile) { + this.passwordProfile = passwordProfile; + return this; + } + + /** + * Get the userPrincipalName value. + * + * @return the userPrincipalName value + */ + public String userPrincipalName() { + return this.userPrincipalName; + } + + /** + * Set the userPrincipalName value. + * + * @param userPrincipalName the userPrincipalName value to set + * @return the UserCreateParametersInner object itself. + */ + public UserCreateParametersInner withUserPrincipalName(String userPrincipalName) { + this.userPrincipalName = userPrincipalName; + return this; + } + + /** + * Get the mailNickname value. + * + * @return the mailNickname value + */ + public String mailNickname() { + return this.mailNickname; + } + + /** + * Set the mailNickname value. + * + * @param mailNickname the mailNickname value to set + * @return the UserCreateParametersInner object itself. + */ + public UserCreateParametersInner withMailNickname(String mailNickname) { + this.mailNickname = mailNickname; + return this; + } + + /** + * Get the immutableId value. + * + * @return the immutableId value + */ + public String immutableId() { + return this.immutableId; + } + + /** + * Set the immutableId value. + * + * @param immutableId the immutableId value to set + * @return the UserCreateParametersInner object itself. + */ + public UserCreateParametersInner withImmutableId(String immutableId) { + this.immutableId = immutableId; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserInner.java new file mode 100644 index 0000000000000..33cff51127ea8 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserInner.java @@ -0,0 +1,191 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + + +/** + * Active Directory user information. + */ +public class UserInner { + /** + * Gets or sets object Id. + */ + private String objectId; + + /** + * Gets or sets object type. + */ + private String objectType; + + /** + * Gets or sets user principal name. + */ + private String userPrincipalName; + + /** + * Gets or sets user display name. + */ + private String displayName; + + /** + * Gets or sets user signIn name. + */ + private String signInName; + + /** + * Gets or sets user mail. + */ + private String mail; + + /** + * The mail alias for the user. + */ + private String mailNickname; + + /** + * Get the objectId value. + * + * @return the objectId value + */ + public String objectId() { + return this.objectId; + } + + /** + * Set the objectId value. + * + * @param objectId the objectId value to set + * @return the UserInner object itself. + */ + public UserInner withObjectId(String objectId) { + this.objectId = objectId; + return this; + } + + /** + * Get the objectType value. + * + * @return the objectType value + */ + public String objectType() { + return this.objectType; + } + + /** + * Set the objectType value. + * + * @param objectType the objectType value to set + * @return the UserInner object itself. + */ + public UserInner withObjectType(String objectType) { + this.objectType = objectType; + return this; + } + + /** + * Get the userPrincipalName value. + * + * @return the userPrincipalName value + */ + public String userPrincipalName() { + return this.userPrincipalName; + } + + /** + * Set the userPrincipalName value. + * + * @param userPrincipalName the userPrincipalName value to set + * @return the UserInner object itself. + */ + public UserInner withUserPrincipalName(String userPrincipalName) { + this.userPrincipalName = userPrincipalName; + return this; + } + + /** + * Get the displayName value. + * + * @return the displayName value + */ + public String displayName() { + return this.displayName; + } + + /** + * Set the displayName value. + * + * @param displayName the displayName value to set + * @return the UserInner object itself. + */ + public UserInner withDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + /** + * Get the signInName value. + * + * @return the signInName value + */ + public String signInName() { + return this.signInName; + } + + /** + * Set the signInName value. + * + * @param signInName the signInName value to set + * @return the UserInner object itself. + */ + public UserInner withSignInName(String signInName) { + this.signInName = signInName; + return this; + } + + /** + * Get the mail value. + * + * @return the mail value + */ + public String mail() { + return this.mail; + } + + /** + * Set the mail value. + * + * @param mail the mail value to set + * @return the UserInner object itself. + */ + public UserInner withMail(String mail) { + this.mail = mail; + return this; + } + + /** + * Get the mailNickname value. + * + * @return the mailNickname value + */ + public String mailNickname() { + return this.mailNickname; + } + + /** + * Set the mailNickname value. + * + * @param mailNickname the mailNickname value to set + * @return the UserInner object itself. + */ + public UserInner withMailNickname(String mailNickname) { + this.mailNickname = mailNickname; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserUpdateParametersInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserUpdateParametersInner.java new file mode 100644 index 0000000000000..ecda3ebc54b7d --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserUpdateParametersInner.java @@ -0,0 +1,117 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import com.microsoft.azure.management.graphrbac.PasswordProfile; + +/** + * Request parameters for updating an existing work or school account user. + */ +public class UserUpdateParametersInner { + /** + * Enable the account. If it is enabled then true else false. + */ + private Boolean accountEnabled; + + /** + * User display name. + */ + private String displayName; + + /** + * Password Profile. + */ + private PasswordProfile passwordProfile; + + /** + * The mail alias for the user. + */ + private String mailNickname; + + /** + * Get the accountEnabled value. + * + * @return the accountEnabled value + */ + public Boolean accountEnabled() { + return this.accountEnabled; + } + + /** + * Set the accountEnabled value. + * + * @param accountEnabled the accountEnabled value to set + * @return the UserUpdateParametersInner object itself. + */ + public UserUpdateParametersInner withAccountEnabled(Boolean accountEnabled) { + this.accountEnabled = accountEnabled; + return this; + } + + /** + * Get the displayName value. + * + * @return the displayName value + */ + public String displayName() { + return this.displayName; + } + + /** + * Set the displayName value. + * + * @param displayName the displayName value to set + * @return the UserUpdateParametersInner object itself. + */ + public UserUpdateParametersInner withDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + /** + * Get the passwordProfile value. + * + * @return the passwordProfile value + */ + public PasswordProfile passwordProfile() { + return this.passwordProfile; + } + + /** + * Set the passwordProfile value. + * + * @param passwordProfile the passwordProfile value to set + * @return the UserUpdateParametersInner object itself. + */ + public UserUpdateParametersInner withPasswordProfile(PasswordProfile passwordProfile) { + this.passwordProfile = passwordProfile; + return this; + } + + /** + * Get the mailNickname value. + * + * @return the mailNickname value + */ + public String mailNickname() { + return this.mailNickname; + } + + /** + * Set the mailNickname value. + * + * @param mailNickname the mailNickname value to set + * @return the UserUpdateParametersInner object itself. + */ + public UserUpdateParametersInner withMailNickname(String mailNickname) { + this.mailNickname = mailNickname; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java new file mode 100644 index 0000000000000..3b30be9ab0a5c --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java @@ -0,0 +1,682 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceResponseBuilder; +import com.microsoft.azure.CloudException; +import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.management.graphrbac.UserGetMemberGroupsParameters; +import com.microsoft.azure.Page; +import com.microsoft.azure.PagedList; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceResponse; +import com.microsoft.rest.ServiceResponseCallback; +import com.microsoft.rest.Validator; +import java.io.IOException; +import java.util.List; +import okhttp3.ResponseBody; +import retrofit2.Call; +import retrofit2.http.Body; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.HTTP; +import retrofit2.http.PATCH; +import retrofit2.http.Path; +import retrofit2.http.POST; +import retrofit2.http.Query; +import retrofit2.Response; + +/** + * An instance of this class provides access to all the operations defined + * in Users. + */ +public final class UsersInner { + /** The Retrofit service to perform REST calls. */ + private UsersService service; + /** The service client containing this operation class. */ + private GraphRbacManagementClientImpl client; + + /** + * Initializes an instance of UsersInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public UsersInner(Retrofit retrofit, GraphRbacManagementClientImpl client) { + this.service = retrofit.create(UsersService.class); + this.client = client; + } + + /** + * The interface defining all the services for Users to be + * used by Retrofit to perform actually REST calls. + */ + interface UsersService { + @Headers("Content-Type: application/json; charset=utf-8") + @POST("{tenantID}/users") + Call create(@Path("tenantID") String tenantID, @Body UserCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/users") + Call list(@Path("tenantID") String tenantID, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/users/{upnOrObjectId}") + Call get(@Path(value = "upnOrObjectId", encoded = true) String upnOrObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @PATCH("{tenantID}/users/{upnOrObjectId}") + Call update(@Path(value = "upnOrObjectId", encoded = true) String upnOrObjectId, @Path("tenantID") String tenantID, @Body UserUpdateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @HTTP(path = "{tenantID}/users/{upnOrObjectId}", method = "DELETE", hasBody = true) + Call delete(@Path(value = "upnOrObjectId", encoded = true) String upnOrObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @POST("{tenantID}/users/{objectId}/getMemberGroups") + Call getMemberGroups(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body UserGetMemberGroupsParameters parameters, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/{nextLink}") + Call listNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * Create a new user. Reference: https://msdn.microsoft.com/library/azure/ad/graph/api/users-operations#CreateUser. + * + * @param parameters Parameters to create a user. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the UserInner object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse create(UserCreateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(parameters); + Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return createDelegate(call.execute()); + } + + /** + * Create a new user. Reference: https://msdn.microsoft.com/library/azure/ad/graph/api/users-operations#CreateUser. + * + * @param parameters Parameters to create a user. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall createAsync(UserCreateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (parameters == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Validator.validate(parameters, serviceCallback); + Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(createDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse createDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(201, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. + * + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<UserInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> list() throws CloudException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + final String filter = null; + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listDelegate(call.execute()); + PagedList result = new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextPageLink) throws CloudException, IOException { + return listNext(nextLink).getBody(); + } + }; + return new ServiceResponse<>(result, response.getResponse()); + } + + /** + * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall listAsync(final ListOperationCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + final String filter = null; + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + /** + * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. + * + * @param filter The filter to apply on the operation. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<UserInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> list(final String filter) throws CloudException, IOException, IllegalArgumentException { + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listDelegate(call.execute()); + PagedList result = new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextPageLink) throws CloudException, IOException { + return listNext(nextLink).getBody(); + } + }; + return new ServiceResponse<>(result, response.getResponse()); + } + + /** + * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. + * + * @param filter The filter to apply on the operation. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall listAsync(final String filter, final ListOperationCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets user information from the directory. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetAUser. + * + * @param upnOrObjectId User object Id or user principal name to get user information. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the UserInner object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse get(String upnOrObjectId) throws CloudException, IOException, IllegalArgumentException { + if (upnOrObjectId == null) { + throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.get(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return getDelegate(call.execute()); + } + + /** + * Gets user information from the directory. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetAUser. + * + * @param upnOrObjectId User object Id or user principal name to get user information. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall getAsync(String upnOrObjectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (upnOrObjectId == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null.")); + return null; + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.get(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(getDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse getDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Updates an exisitng user. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#UpdateUser. + * + * @param upnOrObjectId User object Id or user principal name to get user information. + * @param parameters Parameters to update an exisitng user. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse update(String upnOrObjectId, UserUpdateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { + if (upnOrObjectId == null) { + throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(parameters); + Call call = service.update(upnOrObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return updateDelegate(call.execute()); + } + + /** + * Updates an exisitng user. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#UpdateUser. + * + * @param upnOrObjectId User object Id or user principal name to get user information. + * @param parameters Parameters to update an exisitng user. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall updateAsync(String upnOrObjectId, UserUpdateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (upnOrObjectId == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null.")); + return null; + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (parameters == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Validator.validate(parameters, serviceCallback); + Call call = service.update(upnOrObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(updateDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse updateDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .build(response); + } + + /** + * Delete a user. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#DeleteUser. + * + * @param upnOrObjectId user object id or user principal name (upn) + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse delete(String upnOrObjectId) throws CloudException, IOException, IllegalArgumentException { + if (upnOrObjectId == null) { + throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.delete(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return deleteDelegate(call.execute()); + } + + /** + * Delete a user. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#DeleteUser. + * + * @param upnOrObjectId user object id or user principal name (upn) + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall deleteAsync(String upnOrObjectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (upnOrObjectId == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null.")); + return null; + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.delete(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(deleteDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse deleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .build(response); + } + + /** + * Gets a collection that contains the Object IDs of the groups of which the user is a member. + * + * @param objectId User filtering parameters. + * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<String> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> getMemberGroups(String objectId, boolean securityEnabledOnly) throws CloudException, IOException, IllegalArgumentException { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + UserGetMemberGroupsParameters parameters = new UserGetMemberGroupsParameters(); + parameters.withSecurityEnabledOnly(securityEnabledOnly); + Call call = service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + ServiceResponse> response = getMemberGroupsDelegate(call.execute()); + List result = response.getBody().getItems(); + return new ServiceResponse<>(result, response.getResponse()); + } + + /** + * Gets a collection that contains the Object IDs of the groups of which the user is a member. + * + * @param objectId User filtering parameters. + * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall getMemberGroupsAsync(String objectId, boolean securityEnabledOnly, final ServiceCallback> serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (objectId == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter objectId is required and cannot be null.")); + return null; + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + UserGetMemberGroupsParameters parameters = new UserGetMemberGroupsParameters(); + parameters.withSecurityEnabledOnly(securityEnabledOnly); + Call call = service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = getMemberGroupsDelegate(response); + serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse> getMemberGroupsDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets list of users for the current tenant. + * + * @param nextLink Next link for list operation. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<UserInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> listNext(final String nextLink) throws CloudException, IOException, IllegalArgumentException { + if (nextLink == null) { + throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return listNextDelegate(call.execute()); + } + + /** + * Gets list of users for the current tenant. + * + * @param nextLink Next link for list operation. + * @param serviceCall the ServiceCall object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall listNextAsync(final String nextLink, final ServiceCall serviceCall, final ListOperationCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (nextLink == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); + return null; + } + if (this.client.tenantID() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + serviceCall.newCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listNextDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse> listNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/package-info.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/package-info.java new file mode 100644 index 0000000000000..7633d929c27d7 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/package-info.java @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. + +/** + * This package contains the implementation classes for GraphRbacManagementClient. + * The Graph RBAC Management Client. + */ +package com.microsoft.azure.management.graphrbac.implementation; diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/package-info.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/package-info.java new file mode 100644 index 0000000000000..3b4e564abd527 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/package-info.java @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. + +/** + * This package contains the classes for GraphRbacManagementClient. + * The Graph RBAC Management Client. + */ +package com.microsoft.azure.management.graphrbac; diff --git a/gulpfile.js b/gulpfile.js index 028ca18becb4c..00ad44375de67 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -11,6 +11,12 @@ var mappings = { 'package': 'com.microsoft.azure.management.compute', 'args': '-FT 1' }, + 'graph': { + 'dir': 'azure-mgmt-graph-rbac', + 'source': 'arm-graphrbac/1.6/swagger/graphrbac.json', + 'package': 'com.microsoft.azure.management.graphrbac', + 'args': '-FT 1' + }, 'storage': { 'dir': 'azure-mgmt-storage', 'source': 'arm-storage/2016-01-01/swagger/storage.json', diff --git a/pom.xml b/pom.xml index 32f6770ed5f5e..4d9114da545e7 100644 --- a/pom.xml +++ b/pom.xml @@ -236,6 +236,7 @@ ./azure ./azure-batch ./azure-mgmt-compute + ./azure-mgmt-graph-rbac ./azure-mgmt-resources ./azure-mgmt-storage ./azure-mgmt-network From 3a17183105cd5b4f1382b63ba226b523fc86a8f0 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Thu, 28 Jul 2016 17:34:35 -0700 Subject: [PATCH 2/7] Add User to Graph --- .../azure/management/graphrbac/User.java | 109 ++++++++++++++++++ .../azure/management/graphrbac/Users.java | 22 ++++ .../implementation/GraphRbacManager.java | 79 +++++++++++++ .../graphrbac/implementation/GroupsInner.java | 16 +-- .../ServicePrincipalsInner.java | 10 +- .../graphrbac/implementation/UserImpl.java | 95 +++++++++++++++ .../graphrbac/implementation/UsersImpl.java | 84 ++++++++++++++ .../graphrbac/implementation/UsersInner.java | 25 ++-- .../resources/fluentcore/model/Wrapper.java | 8 ++ .../IndexableRefreshableWrapperImpl.java | 1 + .../model/implementation/WrapperImpl.java | 5 + 11 files changed, 429 insertions(+), 25 deletions(-) create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/User.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManager.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/User.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/User.java new file mode 100644 index 0000000000000..72cb254e81c5d --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/User.java @@ -0,0 +1,109 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.graphrbac; + +import com.microsoft.azure.management.graphrbac.implementation.UserInner; +import com.microsoft.azure.management.resources.fluentcore.model.Creatable; +import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; + +/** + * An immutable client-side representation of an Azure tenant. + */ +public interface User extends + Wrapper { + + /** + * @return Gets or sets object Id. + */ + String objectId(); + + /** + * @return Gets or sets object type. + */ + String objectType(); + + /** + * @return Gets or sets user principal name. + */ + String userPrincipalName(); + + /** + * @return Gets or sets user display name. + */ + String displayName(); + + /** + * @return Gets or sets user signIn name. + */ + String signInName(); + + /** + * @return Gets or sets user mail. + */ + String mail(); + + /** + * @return The mail alias for the user. + */ + String mailNickname(); + + /************************************************************** + * Fluent interfaces to provision a StorageAccount + **************************************************************/ + + /** + * Container interface for all the definitions that need to be implemented. + */ + interface Definition extends + DefinitionStages.Blank, + DefinitionStages.WithCreate { + } + + /** + * Grouping of all the storage account definition stages. + */ + interface DefinitionStages { + /** + * The first stage of the storage account definition. + */ + interface Blank extends WithDisplayName { + } + + interface WithDisplayName { + WithCreate withDisplayName(String displayName); + } + + interface WithPassword { + + } + + interface WithAccountEnabled { + WithCreate withAccountEnabled(boolean enabled); + } + + /** + * A storage account definition with sufficient inputs to create a new + * storage account in the cloud, but exposing additional optional inputs to + * specify. + */ + interface WithCreate extends + Creatable { + } + } + + /** + * Grouping of all the storage account update stages. + */ + interface UpdateStages { + } + + /** + * The template for a storage account update operation, containing all the settings that can be modified. + */ + interface Update { + } +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java new file mode 100644 index 0000000000000..832ffb2bcdbf3 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/Users.java @@ -0,0 +1,22 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.graphrbac; + +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByName; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +/** + * Entry point to tenant management API. + */ +public interface Users extends + SupportsCreating, + SupportsListing, + SupportsGettingByName, + SupportsDeleting { +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManager.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManager.java new file mode 100644 index 0000000000000..533cba7e50c16 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManager.java @@ -0,0 +1,79 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import com.microsoft.azure.AzureEnvironment; +import com.microsoft.azure.RestClient; +import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; +import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; +import com.microsoft.rest.credentials.ServiceClientCredentials; + +/** + * Entry point to Azure resource management. + */ +public final class GraphRbacManager { + // The sdk clients + private final GraphRbacManagementClientImpl graphRbacManagementClient; + // The collections + + /** + * Creates an instance of GraphRbacManager that exposes resource management API entry points. + * + * @param credentials the credentials to use + * @return the GraphRbacManager instance + */ + public static GraphRbacManager authenticate(ServiceClientCredentials credentials) { + return new GraphRbacManager(AzureEnvironment.AZURE.newRestClientBuilder() + .withCredentials(credentials) + .build()); + } + + /** + * Creates an instance of GraphRbacManager that exposes resource management API entry points. + * + * @param restClient the RestClient to be used for API calls + * @return the interface exposing resource management API entry points that work across subscriptions + */ + public static GraphRbacManager authenticate(RestClient restClient) { + return new GraphRbacManager(restClient); + } + + /** + * Get a Configurable instance that can be used to create GraphRbacManager with optional configuration. + * + * @return the instance allowing configurations + */ + public static Configurable configure() { + return new GraphRbacManager.ConfigurableImpl(); + } + + /** + * The interface allowing configurations to be set. + */ + public interface Configurable extends AzureConfigurable { + /** + * Creates an instance of GraphRbacManager that exposes resource management API entry points. + * + * @param credentials the credentials to use + * @return the interface exposing resource management API entry points that work across subscriptions + */ + GraphRbacManager authenticate(ServiceClientCredentials credentials); + } + + /** + * The implementation for Configurable interface. + */ + private static class ConfigurableImpl extends AzureConfigurableImpl implements Configurable { + public GraphRbacManager authenticate(ServiceClientCredentials credentials) { + return GraphRbacManager.authenticate(buildRestClient(credentials)); + } + } + + private GraphRbacManager(RestClient restClient) { + this.graphRbacManagementClient = new GraphRbacManagementClientImpl(restClient); + } +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java index ab9463780f1c8..dc6fb1951e648 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java @@ -496,7 +496,7 @@ public ServiceResponse> list() throws CloudException, IO ServiceResponse> response = listDelegate(call.execute()); PagedList result = new PagedList(response.getBody()) { @Override - public Page nextPage(String nextPageLink) throws CloudException, IOException { + public Page nextPage(String nextLink) throws CloudException, IOException { return listNext(nextLink).getBody(); } }; @@ -533,7 +533,7 @@ public void onResponse(Call call, Response response) serviceCallback.load(result.getBody().getItems()); if (result.getBody().getNextPageLink() != null && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); } else { serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); } @@ -565,7 +565,7 @@ public ServiceResponse> list(final String filter) throws ServiceResponse> response = listDelegate(call.execute()); PagedList result = new PagedList(response.getBody()) { @Override - public Page nextPage(String nextPageLink) throws CloudException, IOException { + public Page nextPage(String nextLink) throws CloudException, IOException { return listNext(nextLink).getBody(); } }; @@ -602,7 +602,7 @@ public void onResponse(Call call, Response response) serviceCallback.load(result.getBody().getItems()); if (result.getBody().getNextPageLink() != null && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); } else { serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); } @@ -644,7 +644,7 @@ public ServiceResponse> getGroupMembers(final String o ServiceResponse> response = getGroupMembersDelegate(call.execute()); PagedList result = new PagedList(response.getBody()) { @Override - public Page nextPage(String nextPageLink) throws CloudException, IOException { + public Page nextPage(String nextLink) throws CloudException, IOException { return getGroupMembersNext(nextLink).getBody(); } }; @@ -685,7 +685,7 @@ public void onResponse(Call call, Response response) serviceCallback.load(result.getBody().getItems()); if (result.getBody().getNextPageLink() != null && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - getGroupMembersNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + getGroupMembersNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); } else { serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); } @@ -909,7 +909,7 @@ public void onResponse(Call call, Response response) serviceCallback.load(result.getBody().getItems()); if (result.getBody().getNextPageLink() != null && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); } else { serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); } @@ -986,7 +986,7 @@ public void onResponse(Call call, Response response) serviceCallback.load(result.getBody().getItems()); if (result.getBody().getNextPageLink() != null && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - getGroupMembersNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + getGroupMembersNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); } else { serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java index 9b8686372831f..d24ea4be93f1f 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java @@ -173,7 +173,7 @@ public ServiceResponse> list() throws CloudExce ServiceResponse> response = listDelegate(call.execute()); PagedList result = new PagedList(response.getBody()) { @Override - public Page nextPage(String nextPageLink) throws CloudException, IOException { + public Page nextPage(String nextLink) throws CloudException, IOException { return listNext(nextLink).getBody(); } }; @@ -210,7 +210,7 @@ public void onResponse(Call call, Response response) serviceCallback.load(result.getBody().getItems()); if (result.getBody().getNextPageLink() != null && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); } else { serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); } @@ -242,7 +242,7 @@ public ServiceResponse> list(final String filte ServiceResponse> response = listDelegate(call.execute()); PagedList result = new PagedList(response.getBody()) { @Override - public Page nextPage(String nextPageLink) throws CloudException, IOException { + public Page nextPage(String nextLink) throws CloudException, IOException { return listNext(nextLink).getBody(); } }; @@ -279,7 +279,7 @@ public void onResponse(Call call, Response response) serviceCallback.load(result.getBody().getItems()); if (result.getBody().getNextPageLink() != null && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); } else { serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); } @@ -493,7 +493,7 @@ public void onResponse(Call call, Response response) serviceCallback.load(result.getBody().getItems()); if (result.getBody().getNextPageLink() != null && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); } else { serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java new file mode 100644 index 0000000000000..1def80b9c72ec --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java @@ -0,0 +1,95 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import com.microsoft.azure.management.graphrbac.User; +import com.microsoft.azure.management.resources.fluentcore.model.implementation.WrapperImpl; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceResponse; + +/** + * Implementation for StorageAccount and its parent interfaces. + */ +class UserImpl + extends WrapperImpl + implements + User, + User.Definition, + User.Update { + private UsersInner client; + private UserCreateParametersInner createParameters; + + protected UserImpl(UserInner innerObject, UsersInner client) { + super(innerObject); + this.client = client; + this.createParameters = new UserCreateParametersInner(); + } + + @Override + public String objectId() { + return inner().objectId(); + } + + @Override + public String objectType() { + return inner().objectType(); + } + + @Override + public String userPrincipalName() { + return inner().userPrincipalName(); + } + + @Override + public String displayName() { + return inner().displayName(); + } + + @Override + public String signInName() { + return inner().signInName(); + } + + @Override + public String mail() { + return inner().mail(); + } + + @Override + public String mailNickname() { + return inner().mailNickname(); + } + + @Override + public UserImpl create() throws Exception { + setInner(client.create(createParameters).getBody()); + return this; + } + + @Override + public ServiceCall createAsync(final ServiceCallback callback) { + final UserImpl self = this; + return client.createAsync(createParameters, new ServiceCallback() { + @Override + public void failure(Throwable t) { + callback.failure(t); + } + + @Override + public void success(ServiceResponse result) { + setInner(result.getBody()); + callback.success(new ServiceResponse(self, result.getResponse())); + } + }); + } + + @Override + public String key() { + return objectId(); + } +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java new file mode 100644 index 0000000000000..15cda67d8482c --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java @@ -0,0 +1,84 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import com.microsoft.azure.CloudException; +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.graphrbac.User; +import com.microsoft.azure.management.graphrbac.Users; +import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.CreatableWrappersImpl; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl; +import com.microsoft.azure.management.storage.CheckNameAvailabilityResult; +import com.microsoft.azure.management.storage.SkuName; +import com.microsoft.azure.management.storage.StorageAccount; + +import java.io.IOException; + +/** + * The implementation of StorageAccounts and its parent interfaces. + */ +class UsersImpl + extends CreatableWrappersImpl< + User, + UserImpl, + UserInner> + implements Users { + private UsersInner innerCollection; + private GraphRbacManager manager; + + UsersImpl( + final UsersInner client, + final GraphRbacManager graphRbacManager) { + } + + @Override + public PagedList list() throws CloudException, IOException { + return wrapList(this.innerCollection.list().getBody()); + } + + @Override + public void delete(String id) throws Exception { + innerCollection.delete(id); + } + + @Override + public UserImpl define(String name) { + return wrapModel(name) + .withSku(SkuName.STANDARD_GRS) + .withGeneralPurposeAccountKind(); + } + + @Override + protected UserImpl wrapModel(String name) { + return new UserImpl( + name, + new UserInner(), + innerCollection, + manager); + } + + @Override + protected StorageAccountImpl wrapModel(UserInner userInner) { + return new StorageAccountImpl( + userInner.name(), + userInner, + this.innerCollection, + manager); + } + + @Override + public User getByName(String name) throws CloudException, IOException { + return null; + } + + @Override + protected UserImpl wrapModel(UserInner inner) { + return null; + } +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java index 3b30be9ab0a5c..d9a3e5da72c71 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java @@ -8,33 +8,34 @@ package com.microsoft.azure.management.graphrbac.implementation; -import retrofit2.Retrofit; import com.google.common.reflect.TypeToken; import com.microsoft.azure.AzureServiceResponseBuilder; import com.microsoft.azure.CloudException; import com.microsoft.azure.ListOperationCallback; -import com.microsoft.azure.management.graphrbac.UserGetMemberGroupsParameters; import com.microsoft.azure.Page; import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.graphrbac.UserGetMemberGroupsParameters; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; import com.microsoft.rest.ServiceResponseCallback; import com.microsoft.rest.Validator; -import java.io.IOException; -import java.util.List; import okhttp3.ResponseBody; import retrofit2.Call; +import retrofit2.Response; +import retrofit2.Retrofit; import retrofit2.http.Body; import retrofit2.http.GET; +import retrofit2.http.HTTP; import retrofit2.http.Header; import retrofit2.http.Headers; -import retrofit2.http.HTTP; import retrofit2.http.PATCH; -import retrofit2.http.Path; import retrofit2.http.POST; +import retrofit2.http.Path; import retrofit2.http.Query; -import retrofit2.Response; + +import java.io.IOException; +import java.util.List; /** * An instance of this class provides access to all the operations defined @@ -183,7 +184,7 @@ public ServiceResponse> list() throws CloudException, IOExc ServiceResponse> response = listDelegate(call.execute()); PagedList result = new PagedList(response.getBody()) { @Override - public Page nextPage(String nextPageLink) throws CloudException, IOException { + public Page nextPage(String nextLink) throws CloudException, IOException { return listNext(nextLink).getBody(); } }; @@ -220,7 +221,7 @@ public void onResponse(Call call, Response response) serviceCallback.load(result.getBody().getItems()); if (result.getBody().getNextPageLink() != null && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); } else { serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); } @@ -252,7 +253,7 @@ public ServiceResponse> list(final String filter) throws Cl ServiceResponse> response = listDelegate(call.execute()); PagedList result = new PagedList(response.getBody()) { @Override - public Page nextPage(String nextPageLink) throws CloudException, IOException { + public Page nextPage(String nextLink) throws CloudException, IOException { return listNext(nextLink).getBody(); } }; @@ -289,7 +290,7 @@ public void onResponse(Call call, Response response) serviceCallback.load(result.getBody().getItems()); if (result.getBody().getNextPageLink() != null && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); } else { serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); } @@ -660,7 +661,7 @@ public void onResponse(Call call, Response response) serviceCallback.load(result.getBody().getItems()); if (result.getBody().getNextPageLink() != null && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), nextLink, serviceCall, serviceCallback); + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); } else { serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/Wrapper.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/Wrapper.java index 2f7bf935d9f39..0a6e631b84cf8 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/Wrapper.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/Wrapper.java @@ -17,4 +17,12 @@ public interface Wrapper { * auto-generated API implementation, based on Azure REST API */ T inner(); + + /** + * Set the wrapped inner model. + * (For internal use only) + * + * @param inner the new inner model + */ + void setInner(T inner); } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/IndexableRefreshableWrapperImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/IndexableRefreshableWrapperImpl.java index 127b83325be6b..cc3c0e25ce67f 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/IndexableRefreshableWrapperImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/IndexableRefreshableWrapperImpl.java @@ -37,6 +37,7 @@ public InnerModelT inner() { * * @param inner the new inner model */ + @Override public void setInner(InnerModelT inner) { this.innerObject = inner; } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/WrapperImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/WrapperImpl.java index e844a8cab6879..c4cd8a7e7f606 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/WrapperImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/WrapperImpl.java @@ -24,4 +24,9 @@ protected WrapperImpl(InnerT innerObject) { public InnerT inner() { return this.innerObject; } + + @Override + public void setInner(InnerT inner) { + this.innerObject = inner; + } } From 67c8f325fe85733b8616a8d40a5035b8a74fd6f0 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Mon, 1 Aug 2016 10:30:20 -0700 Subject: [PATCH 3/7] Add graph tests --- .../graphrbac/ServicePrincipal.java | 94 ++++++++++++++++++ .../graphrbac/ServicePrincipals.java | 22 +++++ .../azure/management/graphrbac/User.java | 13 ++- .../implementation/GraphRbacManager.java | 54 +++++++--- .../implementation/ServicePrincipalImpl.java | 99 +++++++++++++++++++ .../implementation/ServicePrincipalsImpl.java | 65 ++++++++++++ .../graphrbac/implementation/UserImpl.java | 39 +++++++- .../graphrbac/implementation/UsersImpl.java | 39 ++------ .../GraphRbacManagementTestBase.java | 32 ++++++ .../graphrbac/ServicePrincipalsTests.java | 35 +++++++ .../implementation/AzureConfigurableImpl.java | 2 +- .../implementation/IndexableWrapperImpl.java | 5 + .../resources/GroupPagedListTests.java | 4 + .../ApplicationTokenCredentials.java | 28 +++++- .../credentials/UserTokenCredentials.java | 32 +++++- .../com/microsoft/azure/AzureEnvironment.java | 2 +- 16 files changed, 518 insertions(+), 47 deletions(-) create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipal.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalImpl.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java create mode 100644 azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java create mode 100644 azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/ServicePrincipalsTests.java diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipal.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipal.java new file mode 100644 index 0000000000000..08fb88f510a88 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipal.java @@ -0,0 +1,94 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.graphrbac; + +import com.microsoft.azure.management.graphrbac.implementation.ServicePrincipalInner; +import com.microsoft.azure.management.resources.fluentcore.model.Creatable; +import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; + +import java.util.List; + +/** + * An immutable client-side representation of an Azure tenant. + */ +public interface ServicePrincipal extends + Wrapper { + + /** + * @return object Id. + */ + String objectId(); + + /** + * @return object type. + */ + String objectType(); + + /** + * @return service principal display name. + */ + String displayName(); + + /** + * @return app id. + */ + String appId(); + + /** + * @return the list of names. + */ + List servicePrincipalNames(); + + /************************************************************** + * Fluent interfaces to provision a service principal + **************************************************************/ + + /** + * Container interface for all the definitions that need to be implemented. + */ + interface Definition extends + DefinitionStages.Blank, + DefinitionStages.WithCreate { + } + + /** + * Grouping of all the storage account definition stages. + */ + interface DefinitionStages { + /** + * The first stage of the storage account definition. + */ + interface Blank extends WithCreate { + } + + interface WithAccountEnabled { + WithCreate withAccountEnabled(boolean enabled); + } + + /** + * A storage account definition with sufficient inputs to create a new + * storage account in the cloud, but exposing additional optional inputs to + * specify. + */ + interface WithCreate extends + Creatable, + WithAccountEnabled { + } + } + + /** + * Grouping of all the storage account update stages. + */ + interface UpdateStages { + } + + /** + * The template for a storage account update operation, containing all the settings that can be modified. + */ + interface Update { + } +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java new file mode 100644 index 0000000000000..3084db1c6e79e --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/ServicePrincipals.java @@ -0,0 +1,22 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.graphrbac; + +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByName; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +/** + * Entry point to tenant management API. + */ +public interface ServicePrincipals extends + SupportsCreating, + SupportsListing, + SupportsGettingByName, + SupportsDeleting { +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/User.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/User.java index 72cb254e81c5d..e277dec590c80 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/User.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/User.java @@ -60,6 +60,9 @@ public interface User extends */ interface Definition extends DefinitionStages.Blank, + DefinitionStages.WithDisplayName, + DefinitionStages.WithPassword, + DefinitionStages.WithMailNickname, DefinitionStages.WithCreate { } @@ -74,11 +77,16 @@ interface Blank extends WithDisplayName { } interface WithDisplayName { - WithCreate withDisplayName(String displayName); + WithPassword withDisplayName(String displayName); } interface WithPassword { + WithMailNickname withPassword(String password); + WithMailNickname withPassword(String password, boolean forceChangePasswordNextLogin); + } + interface WithMailNickname { + WithCreate withMailNickname(String mailNickname); } interface WithAccountEnabled { @@ -91,7 +99,8 @@ interface WithAccountEnabled { * specify. */ interface WithCreate extends - Creatable { + Creatable, + WithAccountEnabled { } } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManager.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManager.java index 533cba7e50c16..3c0b086690d4a 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManager.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManager.java @@ -6,8 +6,10 @@ package com.microsoft.azure.management.graphrbac.implementation; -import com.microsoft.azure.AzureEnvironment; +import com.microsoft.azure.RequestIdHeaderInterceptor; import com.microsoft.azure.RestClient; +import com.microsoft.azure.management.graphrbac.ServicePrincipals; +import com.microsoft.azure.management.graphrbac.Users; import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; import com.microsoft.rest.credentials.ServiceClientCredentials; @@ -19,6 +21,8 @@ public final class GraphRbacManager { // The sdk clients private final GraphRbacManagementClientImpl graphRbacManagementClient; // The collections + private Users users; + private ServicePrincipals servicePrincipals; /** * Creates an instance of GraphRbacManager that exposes resource management API entry points. @@ -26,10 +30,12 @@ public final class GraphRbacManager { * @param credentials the credentials to use * @return the GraphRbacManager instance */ - public static GraphRbacManager authenticate(ServiceClientCredentials credentials) { - return new GraphRbacManager(AzureEnvironment.AZURE.newRestClientBuilder() + public static GraphRbacManager authenticate(ServiceClientCredentials credentials, String tenantId) { + return new GraphRbacManager(new RestClient.Builder() + .withBaseUrl("https://graph.windows.net") + .withInterceptor(new RequestIdHeaderInterceptor()) .withCredentials(credentials) - .build()); + .build(), tenantId); } /** @@ -38,8 +44,8 @@ public static GraphRbacManager authenticate(ServiceClientCredentials credentials * @param restClient the RestClient to be used for API calls * @return the interface exposing resource management API entry points that work across subscriptions */ - public static GraphRbacManager authenticate(RestClient restClient) { - return new GraphRbacManager(restClient); + public static GraphRbacManager authenticate(RestClient restClient, String tenantId) { + return new GraphRbacManager(restClient, tenantId); } /** @@ -61,19 +67,45 @@ public interface Configurable extends AzureConfigurable { * @param credentials the credentials to use * @return the interface exposing resource management API entry points that work across subscriptions */ - GraphRbacManager authenticate(ServiceClientCredentials credentials); + GraphRbacManager authenticate(ServiceClientCredentials credentials, String tenantId); } /** * The implementation for Configurable interface. */ private static class ConfigurableImpl extends AzureConfigurableImpl implements Configurable { - public GraphRbacManager authenticate(ServiceClientCredentials credentials) { - return GraphRbacManager.authenticate(buildRestClient(credentials)); + protected ConfigurableImpl() { + super.restClientBuilder = new RestClient.Builder() + .withBaseUrl("https://graph.windows.net") + .withInterceptor(new RequestIdHeaderInterceptor()); } + + public GraphRbacManager authenticate(ServiceClientCredentials credentials, String tenantId) { + return GraphRbacManager.authenticate(buildRestClient(credentials), tenantId); + } + } + + private GraphRbacManager(RestClient restClient, String tenantId) { + this.graphRbacManagementClient = new GraphRbacManagementClientImpl(restClient).withTenantID(tenantId); + } + + /** + * @return the storage account management API entry point + */ + public Users storageAccounts() { + if (users == null) { + users = new UsersImpl(graphRbacManagementClient.users(), this); + } + return users; } - private GraphRbacManager(RestClient restClient) { - this.graphRbacManagementClient = new GraphRbacManagementClientImpl(restClient); + /** + * @return the storage account management API entry point + */ + public ServicePrincipals servicePrincipals() { + if (servicePrincipals == null) { + servicePrincipals = new ServicePrincipalsImpl(graphRbacManagementClient.servicePrincipals(), this); + } + return servicePrincipals; } } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalImpl.java new file mode 100644 index 0000000000000..93a040a896f59 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalImpl.java @@ -0,0 +1,99 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import com.microsoft.azure.management.graphrbac.ServicePrincipal; +import com.microsoft.azure.management.resources.fluentcore.model.implementation.WrapperImpl; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceResponse; + +import java.util.List; + +/** + * Implementation for StorageAccount and its parent interfaces. + */ +class ServicePrincipalImpl + extends WrapperImpl + implements + ServicePrincipal, + ServicePrincipal.Definition, + ServicePrincipal.Update { + private ServicePrincipalsInner client; + private ServicePrincipalCreateParametersInner createParameters; + + ServicePrincipalImpl(String appId, ServicePrincipalsInner client) { + super(new ServicePrincipalInner()); + this.client = client; + this.createParameters = new ServicePrincipalCreateParametersInner().withAppId(appId); + } + + ServicePrincipalImpl(ServicePrincipalInner innerObject, ServicePrincipalsInner client) { + super(innerObject); + this.client = client; + this.createParameters = new ServicePrincipalCreateParametersInner(); + } + + @Override + public String objectId() { + return inner().objectId(); + } + + @Override + public String objectType() { + return inner().objectType(); + } + + @Override + public String displayName() { + return inner().displayName(); + } + + @Override + public String appId() { + return inner().appId(); + } + + @Override + public List servicePrincipalNames() { + return inner().servicePrincipalNames(); + } + + @Override + public ServicePrincipalImpl withAccountEnabled(boolean enabled) { + createParameters.withAccountEnabled(enabled); + return this; + } + + @Override + public ServicePrincipalImpl create() throws Exception { + this.setInner(client.create(createParameters).getBody()); + return this; + } + + @Override + public ServiceCall createAsync(final ServiceCallback callback) { + final ServicePrincipalImpl self = this; + return client.createAsync(createParameters, new ServiceCallback() { + @Override + public void failure(Throwable t) { + callback.failure(t); + } + + @Override + public void success(ServiceResponse result) { + self.setInner(result.getBody()); + callback.success(new ServiceResponse(self, result.getResponse())); + } + }); + } + + @Override + public String key() { + return objectId(); + } +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java new file mode 100644 index 0000000000000..5304ba661fc4d --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsImpl.java @@ -0,0 +1,65 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.graphrbac.implementation; + +import com.microsoft.azure.CloudException; +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.graphrbac.ServicePrincipal; +import com.microsoft.azure.management.graphrbac.ServicePrincipals; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.CreatableWrappersImpl; + +import java.io.IOException; + +/** + * The implementation of StorageAccounts and its parent interfaces. + */ +class ServicePrincipalsImpl + extends CreatableWrappersImpl< + ServicePrincipal, + ServicePrincipalImpl, + ServicePrincipalInner> + implements ServicePrincipals { + private ServicePrincipalsInner innerCollection; + private GraphRbacManager manager; + + ServicePrincipalsImpl( + final ServicePrincipalsInner client, + final GraphRbacManager graphRbacManager) { + this.innerCollection = client; + this.manager = graphRbacManager; + } + + @Override + public PagedList list() throws CloudException, IOException { + return wrapList(this.innerCollection.list().getBody()); + } + + @Override + public void delete(String id) throws Exception { + innerCollection.delete(id); + } + + @Override + public ServicePrincipalImpl define(String appId) { + return wrapModel(appId); + } + + @Override + protected ServicePrincipalImpl wrapModel(String appId) { + return new ServicePrincipalImpl(appId, innerCollection); + } + + @Override + protected ServicePrincipalImpl wrapModel(ServicePrincipalInner servicePrincipalInner) { + return new ServicePrincipalImpl(servicePrincipalInner, this.innerCollection); + } + + @Override + public ServicePrincipalImpl getByName(String objectId) throws CloudException, IOException { + return new ServicePrincipalImpl(innerCollection.get(objectId).getBody(), innerCollection); + } +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java index 1def80b9c72ec..fb48278c65ff2 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserImpl.java @@ -6,6 +6,7 @@ package com.microsoft.azure.management.graphrbac.implementation; +import com.microsoft.azure.management.graphrbac.PasswordProfile; import com.microsoft.azure.management.graphrbac.User; import com.microsoft.azure.management.resources.fluentcore.model.implementation.WrapperImpl; import com.microsoft.rest.ServiceCall; @@ -24,7 +25,13 @@ class UserImpl private UsersInner client; private UserCreateParametersInner createParameters; - protected UserImpl(UserInner innerObject, UsersInner client) { + UserImpl(String userPrincipalName, UsersInner client) { + super(new UserInner()); + this.client = client; + this.createParameters = new UserCreateParametersInner().withUserPrincipalName(userPrincipalName); + } + + UserImpl(UserInner innerObject, UsersInner client) { super(innerObject); this.client = client; this.createParameters = new UserCreateParametersInner(); @@ -92,4 +99,34 @@ public void success(ServiceResponse result) { public String key() { return objectId(); } + + @Override + public UserImpl withAccountEnabled(boolean enabled) { + createParameters.withAccountEnabled(enabled); + return this; + } + + @Override + public UserImpl withDisplayName(String displayName) { + createParameters.withDisplayName(displayName); + return this; + } + + @Override + public UserImpl withMailNickname(String mailNickname) { + createParameters.withMailNickname(mailNickname); + return this; + } + + @Override + public UserImpl withPassword(String password) { + createParameters.withPasswordProfile(new PasswordProfile().withPassword(password)); + return this; + } + + @Override + public UserImpl withPassword(String password, boolean forceChangePasswordNextLogin) { + createParameters.withPasswordProfile(new PasswordProfile().withPassword(password).withForceChangePasswordNextLogin(forceChangePasswordNextLogin)); + return this; + } } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java index 15cda67d8482c..782959a65bee8 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersImpl.java @@ -10,13 +10,7 @@ import com.microsoft.azure.PagedList; import com.microsoft.azure.management.graphrbac.User; import com.microsoft.azure.management.graphrbac.Users; -import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.CreatableWrappersImpl; -import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; -import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl; -import com.microsoft.azure.management.storage.CheckNameAvailabilityResult; -import com.microsoft.azure.management.storage.SkuName; -import com.microsoft.azure.management.storage.StorageAccount; import java.io.IOException; @@ -35,6 +29,8 @@ class UsersImpl UsersImpl( final UsersInner client, final GraphRbacManager graphRbacManager) { + this.innerCollection = client; + this.manager = graphRbacManager; } @Override @@ -48,37 +44,22 @@ public void delete(String id) throws Exception { } @Override - public UserImpl define(String name) { - return wrapModel(name) - .withSku(SkuName.STANDARD_GRS) - .withGeneralPurposeAccountKind(); + public UserImpl define(String userPrincipalName) { + return wrapModel(userPrincipalName); } @Override - protected UserImpl wrapModel(String name) { - return new UserImpl( - name, - new UserInner(), - innerCollection, - manager); + protected UserImpl wrapModel(String userPrincipalName) { + return new UserImpl(userPrincipalName, innerCollection); } @Override - protected StorageAccountImpl wrapModel(UserInner userInner) { - return new StorageAccountImpl( - userInner.name(), - userInner, - this.innerCollection, - manager); + protected UserImpl wrapModel(UserInner userInner) { + return new UserImpl(userInner, this.innerCollection); } @Override - public User getByName(String name) throws CloudException, IOException { - return null; - } - - @Override - protected UserImpl wrapModel(UserInner inner) { - return null; + public UserImpl getByName(String upnOrId) throws CloudException, IOException { + return new UserImpl(innerCollection.get(upnOrId).getBody(), innerCollection); } } diff --git a/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java b/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java new file mode 100644 index 0000000000000..88f0a8b9d6392 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.graphrbac; + +import com.microsoft.azure.credentials.ApplicationTokenCredentials; +import com.microsoft.azure.management.graphrbac.implementation.GraphRbacManager; +import okhttp3.logging.HttpLoggingInterceptor; + +/** + * The base for storage manager tests. + */ +public abstract class GraphRbacManagementTestBase { + protected static GraphRbacManager graphRbacManager; + + protected static void createClients() { + ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( + System.getenv("client-id"), + System.getenv("domain"), + System.getenv("secret"), + "https://graph.windows.net", + null); + + graphRbacManager = GraphRbacManager + .configure() + .withLogLevel(HttpLoggingInterceptor.Level.BODY) + .authenticate(credentials, credentials.getDomain()); + } +} diff --git a/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/ServicePrincipalsTests.java b/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/ServicePrincipalsTests.java new file mode 100644 index 0000000000000..45f97c3962d7a --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/ServicePrincipalsTests.java @@ -0,0 +1,35 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.graphrbac; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.List; + +public class ServicePrincipalsTests extends GraphRbacManagementTestBase { + private static final String RG_NAME = "javacsmrg350"; + private static final String APP_NAME = "app-javacsm350"; + + @BeforeClass + public static void setup() throws Exception { + createClients(); + } + + @AfterClass + public static void cleanup() throws Exception { + } + + @Test + public void getServicePrincipal() throws Exception { + List servicePrincipals = graphRbacManager.servicePrincipals().list(); + Assert.assertNotNull(servicePrincipals); + } + +} diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigurableImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigurableImpl.java index 2bb36b05ac718..a18696ddb4b19 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigurableImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigurableImpl.java @@ -25,7 +25,7 @@ */ public class AzureConfigurableImpl> implements AzureConfigurable { - private RestClient.Builder.Buildable restClientBuilder; + protected RestClient.Builder.Buildable restClientBuilder; protected AzureConfigurableImpl() { this.restClientBuilder = AzureEnvironment.AZURE.newRestClientBuilder(); diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/IndexableWrapperImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/IndexableWrapperImpl.java index d41f3115b3ec5..c15f8a43d881d 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/IndexableWrapperImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/model/implementation/IndexableWrapperImpl.java @@ -27,4 +27,9 @@ protected IndexableWrapperImpl(String name, InnerT innerObject) { public InnerT inner() { return this.innerObject; } + + @Override + public void setInner(InnerT innerObject) { + this.innerObject = innerObject; + } } diff --git a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/GroupPagedListTests.java b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/GroupPagedListTests.java index 3e003f36e1b4a..7069a3a5ca46a 100644 --- a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/GroupPagedListTests.java +++ b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/GroupPagedListTests.java @@ -172,6 +172,10 @@ public ResourceGroup refresh() throws Exception { public ResourceGroupInner inner() { return null; } + + @Override + public void setInner(ResourceGroupInner inner) { + } }; } } diff --git a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java index 384ab3f7671af..abe3a65c9bdd8 100644 --- a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java +++ b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/ApplicationTokenCredentials.java @@ -24,6 +24,8 @@ * Token based credentials for use with a REST Service Client. */ public class ApplicationTokenCredentials extends TokenCredentials { + /** The endpoint of the target resource. */ + private String resourceEndpoint; /** The active directory application client id. */ private String clientId; /** The tenant or domain the containing the application. */ @@ -56,6 +58,30 @@ public ApplicationTokenCredentials(String clientId, String domain, String secret } else { this.environment = environment; } + this.resourceEndpoint = this.environment.getTokenAudience(); + } + + /** + * Initializes a new instance of the UserTokenCredentials. + * + * @param clientId the active directory application client id. + * @param domain the domain or tenant id containing this application. + * @param secret the authentication secret for the application. + * @param resourceEndpoint the endpoint of the target resource. + * @param environment the Azure environment to authenticate with. + * If null is provided, AzureEnvironment.AZURE will be used. + */ + public ApplicationTokenCredentials(String clientId, String domain, String secret, String resourceEndpoint, AzureEnvironment environment) { + super(null, null); // defer token acquisition + this.clientId = clientId; + this.domain = domain; + this.secret = secret; + this.resourceEndpoint = resourceEndpoint; + if (environment == null) { + this.environment = AzureEnvironment.AZURE; + } else { + this.environment = environment; + } } /** @@ -212,7 +238,7 @@ private void acquireAccessToken() throws IOException { AuthenticationContext context = new AuthenticationContext(authorityUrl, this.getEnvironment().isValidateAuthority(), executor); try { authenticationResult = context.acquireToken( - this.getEnvironment().getTokenAudience(), + this.resourceEndpoint, new ClientCredential(this.getClientId(), this.getSecret()), null).get(); } catch (Exception e) { diff --git a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java index 60d6bdb3c0a58..c37479771a9b9 100644 --- a/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java +++ b/runtimes/azure-client-authentication/src/main/java/com/microsoft/azure/credentials/UserTokenCredentials.java @@ -21,6 +21,8 @@ * Token based credentials for use with a REST Service Client. */ public class UserTokenCredentials extends TokenCredentials { + /** The endpoint of the target resource. */ + private String resourceEndpoint; /** The Active Directory application client id. */ private String clientId; /** The domain or tenant id containing this application. */ @@ -59,6 +61,34 @@ public UserTokenCredentials(String clientId, String domain, String username, Str } else { this.environment = environment; } + this.resourceEndpoint = this.environment.getTokenAudience(); + } + + /** + * Initializes a new instance of the UserTokenCredentials. + * + * @param clientId the active directory application client id. + * @param domain the domain or tenant id containing this application. + * @param username the user name for the Organization Id account. + * @param password the password for the Organization Id account. + * @param clientRedirectUri the Uri where the user will be redirected after authenticating with AD. + * @param resourceEndpoint the endpoint of the target resource. + * @param environment the Azure environment to authenticate with. + * If null is provided, AzureEnvironment.AZURE will be used. + */ + public UserTokenCredentials(String clientId, String domain, String username, String password, String clientRedirectUri, String resourceEndpoint, AzureEnvironment environment) { + super(null, null); // defer token acquisition + this.clientId = clientId; + this.domain = domain; + this.username = username; + this.password = password; + this.clientRedirectUri = clientRedirectUri; + this.resourceEndpoint = resourceEndpoint; + if (environment == null) { + this.environment = AzureEnvironment.AZURE; + } else { + this.environment = environment; + } } /** @@ -136,7 +166,7 @@ private void acquireAccessToken() throws IOException { AuthenticationContext context = new AuthenticationContext(authorityUrl, this.getEnvironment().isValidateAuthority(), Executors.newSingleThreadExecutor()); try { authenticationResult = context.acquireToken( - this.getEnvironment().getTokenAudience(), + this.resourceEndpoint, this.getClientId(), this.getUsername(), this.getPassword(), diff --git a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java index 04a6af99d93db..897e29b622c09 100644 --- a/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java +++ b/runtimes/azure-client-runtime/src/main/java/com/microsoft/azure/AzureEnvironment.java @@ -56,7 +56,7 @@ public AzureEnvironment( * Provides the settings for authentication with Azure. */ public static final AzureEnvironment AZURE = new AzureEnvironment( - "https://login.windows.net/", + "https://login.microsoftonline.com/", "https://management.core.windows.net/", true, "https://management.azure.com/"); From 8ec4fc71993837c5dff64614e27b28cf31425310 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Tue, 26 Jul 2016 11:02:26 -0700 Subject: [PATCH 4/7] Add key vault --- azure-mgmt-keyvault/pom.xml | 124 +++ .../keyvault/AccessPolicyEntry.java | 121 +++ .../management/keyvault/Permissions.java | 67 ++ .../azure/management/keyvault/Sku.java | 69 ++ .../azure/management/keyvault/SkuFamily.java | 20 + .../azure/management/keyvault/SkuName.java | 53 ++ .../management/keyvault/VaultProperties.java | 203 +++++ .../KeyVaultManagementClientImpl.java | 200 +++++ .../keyvault/implementation/PageImpl.java | 75 ++ .../VaultCreateOrUpdateParametersInner.java | 96 +++ .../keyvault/implementation/VaultInner.java | 46 ++ .../keyvault/implementation/VaultsInner.java | 767 ++++++++++++++++++ .../keyvault/implementation/package-info.java | 11 + .../management/keyvault/package-info.java | 11 + gulpfile.js | 6 + pom.xml | 1 + 16 files changed, 1870 insertions(+) create mode 100644 azure-mgmt-keyvault/pom.xml create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicyEntry.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Permissions.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Sku.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SkuFamily.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SkuName.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/VaultProperties.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManagementClientImpl.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/PageImpl.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultCreateOrUpdateParametersInner.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultInner.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsInner.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/package-info.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/package-info.java diff --git a/azure-mgmt-keyvault/pom.xml b/azure-mgmt-keyvault/pom.xml new file mode 100644 index 0000000000000..0b99f6b535626 --- /dev/null +++ b/azure-mgmt-keyvault/pom.xml @@ -0,0 +1,124 @@ + + + 4.0.0 + + com.microsoft.azure + azure-parent + 1.0.0-SNAPSHOT + ../pom.xml + + + azure-mgmt-keyvault + jar + + Microsoft Azure SDK for Key Vault Management + This package contains Microsoft Azure Key Vault Management SDK. + https://github.com/Azure/azure-sdk-for-java + + + + The MIT License (MIT) + http://opensource.org/licenses/MIT + repo + + + + + scm:git:https://github.com/Azure/azure-sdk-for-java + scm:git:git@github.com:Azure/azure-sdk-for-java.git + HEAD + + + + UTF-8 + + + + + + microsoft + Microsoft + + + + + + com.microsoft.azure + azure-client-runtime + 1.0.0-SNAPSHOT + + + com.microsoft.azure + azure-mgmt-resources + 1.0.0-SNAPSHOT + + + com.microsoft.azure + azure-mgmt-storage + 1.0.0-SNAPSHOT + + + com.microsoft.azure + azure-mgmt-network + 1.0.0-SNAPSHOT + + + junit + junit + test + + + com.microsoft.azure + azure-client-authentication + 1.0.0-SNAPSHOT + test + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + true + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + + + org.codehaus.mojo + build-helper-maven-plugin + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.8 + + *.implementation.*;*.utils.*;com.microsoft.schemas._2003._10.serialization;*.blob.core.storage + /** +
* Copyright (c) Microsoft Corporation. All rights reserved. +
* Licensed under the MIT License. See License.txt in the project root for +
* license information. +
*/]]>
+
+
+
+
+
diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicyEntry.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicyEntry.java new file mode 100644 index 0000000000000..1bc9de5052af4 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicyEntry.java @@ -0,0 +1,121 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.keyvault; + +import java.util.UUID; + +/** + * An array of 0 to 16 identities that have access to the key vault. All + * identities in the array must use the same tenant ID as the key vault's + * tenant ID. + */ +public class AccessPolicyEntry { + /** + * The Azure Active Directory tenant ID that should be used for + * authenticating requests to the key vault. + */ + private UUID tenantId; + + /** + * The object ID of a user or service principal in the Azure Active + * Directory tenant for the vault. + */ + private UUID objectId; + + /** + * Application ID of the client making request on behalf of a principal. + */ + private UUID applicationId; + + /** + * Permissions the identity has for keys and secrets. + */ + private Permissions permissions; + + /** + * Get the tenantId value. + * + * @return the tenantId value + */ + public UUID tenantId() { + return this.tenantId; + } + + /** + * Set the tenantId value. + * + * @param tenantId the tenantId value to set + * @return the AccessPolicyEntry object itself. + */ + public AccessPolicyEntry withTenantId(UUID tenantId) { + this.tenantId = tenantId; + return this; + } + + /** + * Get the objectId value. + * + * @return the objectId value + */ + public UUID objectId() { + return this.objectId; + } + + /** + * Set the objectId value. + * + * @param objectId the objectId value to set + * @return the AccessPolicyEntry object itself. + */ + public AccessPolicyEntry withObjectId(UUID objectId) { + this.objectId = objectId; + return this; + } + + /** + * Get the applicationId value. + * + * @return the applicationId value + */ + public UUID applicationId() { + return this.applicationId; + } + + /** + * Set the applicationId value. + * + * @param applicationId the applicationId value to set + * @return the AccessPolicyEntry object itself. + */ + public AccessPolicyEntry withApplicationId(UUID applicationId) { + this.applicationId = applicationId; + return this; + } + + /** + * Get the permissions value. + * + * @return the permissions value + */ + public Permissions permissions() { + return this.permissions; + } + + /** + * Set the permissions value. + * + * @param permissions the permissions value to set + * @return the AccessPolicyEntry object itself. + */ + public AccessPolicyEntry withPermissions(Permissions permissions) { + this.permissions = permissions; + return this; + } + +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Permissions.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Permissions.java new file mode 100644 index 0000000000000..1db622fd6ac45 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Permissions.java @@ -0,0 +1,67 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.keyvault; + +import java.util.List; + +/** + * Permissions the identity has for keys and secrets. + */ +public class Permissions { + /** + * Permissions to keys. + */ + private List keys; + + /** + * Permissions to secrets. + */ + private List secrets; + + /** + * Get the keys value. + * + * @return the keys value + */ + public List keys() { + return this.keys; + } + + /** + * Set the keys value. + * + * @param keys the keys value to set + * @return the Permissions object itself. + */ + public Permissions withKeys(List keys) { + this.keys = keys; + return this; + } + + /** + * Get the secrets value. + * + * @return the secrets value + */ + public List secrets() { + return this.secrets; + } + + /** + * Set the secrets value. + * + * @param secrets the secrets value to set + * @return the Permissions object itself. + */ + public Permissions withSecrets(List secrets) { + this.secrets = secrets; + return this; + } + +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Sku.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Sku.java new file mode 100644 index 0000000000000..7403d947e9c4a --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Sku.java @@ -0,0 +1,69 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.keyvault; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * SKU details. + */ +public class Sku { + /** + * SKU family name. Possible values include: 'A'. + */ + private String family; + + /** + * SKU name to specify whether the key vault is a standard vault or a + * premium vault. Possible values include: 'standard', 'premium'. + */ + @JsonProperty(required = true) + private SkuName name; + + /** + * Get the family value. + * + * @return the family value + */ + public String family() { + return this.family; + } + + /** + * Set the family value. + * + * @param family the family value to set + * @return the Sku object itself. + */ + public Sku withFamily(String family) { + this.family = family; + return this; + } + + /** + * Get the name value. + * + * @return the name value + */ + public SkuName name() { + return this.name; + } + + /** + * Set the name value. + * + * @param name the name value to set + * @return the Sku object itself. + */ + public Sku withName(SkuName name) { + this.name = name; + return this; + } + +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SkuFamily.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SkuFamily.java new file mode 100644 index 0000000000000..3b170cc4be9df --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SkuFamily.java @@ -0,0 +1,20 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.keyvault; + +/** + * Defines values for SkuFamily. + */ +public final class SkuFamily { + /** Static value A for SkuFamily. */ + public static final String A = "A"; + + private SkuFamily() { + } +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SkuName.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SkuName.java new file mode 100644 index 0000000000000..d31ee025f569a --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SkuName.java @@ -0,0 +1,53 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.keyvault; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Defines values for SkuName. + */ +public enum SkuName { + /** Enum value standard. */ + STANDARD("standard"), + + /** Enum value premium. */ + PREMIUM("premium"); + + /** The actual serialized value for a SkuName instance. */ + private String value; + + SkuName(String value) { + this.value = value; + } + + /** + * Parses a serialized value to a SkuName instance. + * + * @param value the serialized value to parse. + * @return the parsed SkuName object, or null if unable to parse. + */ + @JsonCreator + public static SkuName fromString(String value) { + SkuName[] items = SkuName.values(); + for (SkuName item : items) { + if (item.toString().equalsIgnoreCase(value)) { + return item; + } + } + return null; + } + + @JsonValue + @Override + public String toString() { + return this.value; + } +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/VaultProperties.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/VaultProperties.java new file mode 100644 index 0000000000000..167a94ddf2e0e --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/VaultProperties.java @@ -0,0 +1,203 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.keyvault; + +import java.util.UUID; +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Properties of the vault. + */ +public class VaultProperties { + /** + * The URI of the vault for performing operations on keys and secrets. + */ + private String vaultUri; + + /** + * The Azure Active Directory tenant ID that should be used for + * authenticating requests to the key vault. + */ + @JsonProperty(required = true) + private UUID tenantId; + + /** + * SKU details. + */ + @JsonProperty(required = true) + private Sku sku; + + /** + * An array of 0 to 16 identities that have access to the key vault. All + * identities in the array must use the same tenant ID as the key vault's + * tenant ID. + */ + @JsonProperty(required = true) + private List accessPolicies; + + /** + * Property to specify whether Azure Virtual Machines are permitted to + * retrieve certificates stored as secrets from the key vault. + */ + private Boolean enabledForDeployment; + + /** + * Property to specify whether Azure Disk Encryption is permitted to + * retrieve secrets from the vault and unwrap keys. + */ + private Boolean enabledForDiskEncryption; + + /** + * Property to specify whether Azure Resource Manager is permitted to + * retrieve secrets from the key vault. + */ + private Boolean enabledForTemplateDeployment; + + /** + * Get the vaultUri value. + * + * @return the vaultUri value + */ + public String vaultUri() { + return this.vaultUri; + } + + /** + * Set the vaultUri value. + * + * @param vaultUri the vaultUri value to set + * @return the VaultProperties object itself. + */ + public VaultProperties withVaultUri(String vaultUri) { + this.vaultUri = vaultUri; + return this; + } + + /** + * Get the tenantId value. + * + * @return the tenantId value + */ + public UUID tenantId() { + return this.tenantId; + } + + /** + * Set the tenantId value. + * + * @param tenantId the tenantId value to set + * @return the VaultProperties object itself. + */ + public VaultProperties withTenantId(UUID tenantId) { + this.tenantId = tenantId; + return this; + } + + /** + * Get the sku value. + * + * @return the sku value + */ + public Sku sku() { + return this.sku; + } + + /** + * Set the sku value. + * + * @param sku the sku value to set + * @return the VaultProperties object itself. + */ + public VaultProperties withSku(Sku sku) { + this.sku = sku; + return this; + } + + /** + * Get the accessPolicies value. + * + * @return the accessPolicies value + */ + public List accessPolicies() { + return this.accessPolicies; + } + + /** + * Set the accessPolicies value. + * + * @param accessPolicies the accessPolicies value to set + * @return the VaultProperties object itself. + */ + public VaultProperties withAccessPolicies(List accessPolicies) { + this.accessPolicies = accessPolicies; + return this; + } + + /** + * Get the enabledForDeployment value. + * + * @return the enabledForDeployment value + */ + public Boolean enabledForDeployment() { + return this.enabledForDeployment; + } + + /** + * Set the enabledForDeployment value. + * + * @param enabledForDeployment the enabledForDeployment value to set + * @return the VaultProperties object itself. + */ + public VaultProperties withEnabledForDeployment(Boolean enabledForDeployment) { + this.enabledForDeployment = enabledForDeployment; + return this; + } + + /** + * Get the enabledForDiskEncryption value. + * + * @return the enabledForDiskEncryption value + */ + public Boolean enabledForDiskEncryption() { + return this.enabledForDiskEncryption; + } + + /** + * Set the enabledForDiskEncryption value. + * + * @param enabledForDiskEncryption the enabledForDiskEncryption value to set + * @return the VaultProperties object itself. + */ + public VaultProperties withEnabledForDiskEncryption(Boolean enabledForDiskEncryption) { + this.enabledForDiskEncryption = enabledForDiskEncryption; + return this; + } + + /** + * Get the enabledForTemplateDeployment value. + * + * @return the enabledForTemplateDeployment value + */ + public Boolean enabledForTemplateDeployment() { + return this.enabledForTemplateDeployment; + } + + /** + * Set the enabledForTemplateDeployment value. + * + * @param enabledForTemplateDeployment the enabledForTemplateDeployment value to set + * @return the VaultProperties object itself. + */ + public VaultProperties withEnabledForTemplateDeployment(Boolean enabledForTemplateDeployment) { + this.enabledForTemplateDeployment = enabledForTemplateDeployment; + return this; + } + +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManagementClientImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManagementClientImpl.java new file mode 100644 index 0000000000000..d135a59ec609c --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManagementClientImpl.java @@ -0,0 +1,200 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.keyvault.implementation; + +import com.microsoft.azure.AzureClient; +import com.microsoft.azure.AzureServiceClient; +import com.microsoft.azure.RestClient; +import com.microsoft.rest.credentials.ServiceClientCredentials; + +/** + * Initializes a new instance of the KeyVaultManagementClientImpl class. + */ +public final class KeyVaultManagementClientImpl extends AzureServiceClient { + /** the {@link AzureClient} used for long running operations. */ + private AzureClient azureClient; + + /** + * Gets the {@link AzureClient} used for long running operations. + * @return the azure client; + */ + public AzureClient getAzureClient() { + return this.azureClient; + } + + /** Gets subscription credentials which uniquely identify Microsoft Azure subscription. The subscription ID forms part of the URI for every service call. */ + private String subscriptionId; + + /** + * Gets Gets subscription credentials which uniquely identify Microsoft Azure subscription. The subscription ID forms part of the URI for every service call. + * + * @return the subscriptionId value. + */ + public String subscriptionId() { + return this.subscriptionId; + } + + /** + * Sets Gets subscription credentials which uniquely identify Microsoft Azure subscription. The subscription ID forms part of the URI for every service call. + * + * @param subscriptionId the subscriptionId value. + * @return the service client itself + */ + public KeyVaultManagementClientImpl withSubscriptionId(String subscriptionId) { + this.subscriptionId = subscriptionId; + return this; + } + + /** Client Api Version. */ + private String apiVersion; + + /** + * Gets Client Api Version. + * + * @return the apiVersion value. + */ + public String apiVersion() { + return this.apiVersion; + } + + /** Gets or sets the preferred language for the response. */ + private String acceptLanguage; + + /** + * Gets Gets or sets the preferred language for the response. + * + * @return the acceptLanguage value. + */ + public String acceptLanguage() { + return this.acceptLanguage; + } + + /** + * Sets Gets or sets the preferred language for the response. + * + * @param acceptLanguage the acceptLanguage value. + * @return the service client itself + */ + public KeyVaultManagementClientImpl withAcceptLanguage(String acceptLanguage) { + this.acceptLanguage = acceptLanguage; + return this; + } + + /** Gets or sets the retry timeout in seconds for Long Running Operations. Default value is 30. */ + private int longRunningOperationRetryTimeout; + + /** + * Gets Gets or sets the retry timeout in seconds for Long Running Operations. Default value is 30. + * + * @return the longRunningOperationRetryTimeout value. + */ + public int longRunningOperationRetryTimeout() { + return this.longRunningOperationRetryTimeout; + } + + /** + * Sets Gets or sets the retry timeout in seconds for Long Running Operations. Default value is 30. + * + * @param longRunningOperationRetryTimeout the longRunningOperationRetryTimeout value. + * @return the service client itself + */ + public KeyVaultManagementClientImpl withLongRunningOperationRetryTimeout(int longRunningOperationRetryTimeout) { + this.longRunningOperationRetryTimeout = longRunningOperationRetryTimeout; + return this; + } + + /** When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true. */ + private boolean generateClientRequestId; + + /** + * Gets When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true. + * + * @return the generateClientRequestId value. + */ + public boolean generateClientRequestId() { + return this.generateClientRequestId; + } + + /** + * Sets When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true. + * + * @param generateClientRequestId the generateClientRequestId value. + * @return the service client itself + */ + public KeyVaultManagementClientImpl withGenerateClientRequestId(boolean generateClientRequestId) { + this.generateClientRequestId = generateClientRequestId; + return this; + } + + /** + * The VaultsInner object to access its operations. + */ + private VaultsInner vaults; + + /** + * Gets the VaultsInner object to access its operations. + * @return the VaultsInner object. + */ + public VaultsInner vaults() { + return this.vaults; + } + + /** + * Initializes an instance of KeyVaultManagementClient client. + * + * @param credentials the management credentials for Azure + */ + public KeyVaultManagementClientImpl(ServiceClientCredentials credentials) { + this("https://management.azure.com", credentials); + } + + /** + * Initializes an instance of KeyVaultManagementClient client. + * + * @param baseUrl the base URL of the host + * @param credentials the management credentials for Azure + */ + public KeyVaultManagementClientImpl(String baseUrl, ServiceClientCredentials credentials) { + this(new RestClient.Builder() + .withBaseUrl(baseUrl) + .withCredentials(credentials) + .build()); + } + + /** + * Initializes an instance of KeyVaultManagementClient client. + * + * @param restClient the REST client to connect to Azure. + */ + public KeyVaultManagementClientImpl(RestClient restClient) { + super(restClient); + initialize(); + } + + protected void initialize() { + this.apiVersion = "2015-06-01"; + this.acceptLanguage = "en-US"; + this.longRunningOperationRetryTimeout = 30; + this.generateClientRequestId = true; + this.vaults = new VaultsInner(restClient().retrofit(), this); + this.azureClient = new AzureClient(this); + } + + /** + * Gets the User-Agent header for the client. + * + * @return the user agent string. + */ + @Override + public String userAgent() { + return String.format("Azure-SDK-For-Java/%s (%s)", + getClass().getPackage().getImplementationVersion(), + "KeyVaultManagementClient, 2015-06-01"); + } +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/PageImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/PageImpl.java new file mode 100644 index 0000000000000..b54eb8adb7572 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/PageImpl.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.keyvault.implementation; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.azure.Page; +import java.util.List; + +/** + * An instance of this class defines a page of Azure resources and a link to + * get the next page of resources, if any. + * + * @param type of Azure resource + */ +public class PageImpl implements Page { + /** + * The link to the next page. + */ + @JsonProperty("nextLink") + private String nextPageLink; + + /** + * The list of items. + */ + @JsonProperty("value") + private List items; + + /** + * Gets the link to the next page. + * + * @return the link to the next page. + */ + @Override + public String getNextPageLink() { + return this.nextPageLink; + } + + /** + * Gets the list of items. + * + * @return the list of items in {@link List}. + */ + @Override + public List getItems() { + return items; + } + + /** + * Sets the link to the next page. + * + * @param nextPageLink the link to the next page. + * @return this Page object itself. + */ + public PageImpl setNextPageLink(String nextPageLink) { + this.nextPageLink = nextPageLink; + return this; + } + + /** + * Sets the list of items. + * + * @param items the list of items in {@link List}. + * @return this Page object itself. + */ + public PageImpl setItems(List items) { + this.items = items; + return this; + } +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultCreateOrUpdateParametersInner.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultCreateOrUpdateParametersInner.java new file mode 100644 index 0000000000000..195358a0038e5 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultCreateOrUpdateParametersInner.java @@ -0,0 +1,96 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.keyvault.implementation; + +import java.util.Map; +import com.microsoft.azure.management.keyvault.VaultProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Parameters for creating or updating a vault. + */ +public class VaultCreateOrUpdateParametersInner { + /** + * The supported Azure location where the key vault should be created. + */ + @JsonProperty(required = true) + private String location; + + /** + * The tags that will be assigned to the key vault. + */ + private Map tags; + + /** + * Properties of the vault. + */ + @JsonProperty(required = true) + private VaultProperties properties; + + /** + * Get the location value. + * + * @return the location value + */ + public String location() { + return this.location; + } + + /** + * Set the location value. + * + * @param location the location value to set + * @return the VaultCreateOrUpdateParametersInner object itself. + */ + public VaultCreateOrUpdateParametersInner withLocation(String location) { + this.location = location; + return this; + } + + /** + * Get the tags value. + * + * @return the tags value + */ + public Map tags() { + return this.tags; + } + + /** + * Set the tags value. + * + * @param tags the tags value to set + * @return the VaultCreateOrUpdateParametersInner object itself. + */ + public VaultCreateOrUpdateParametersInner withTags(Map tags) { + this.tags = tags; + return this; + } + + /** + * Get the properties value. + * + * @return the properties value + */ + public VaultProperties properties() { + return this.properties; + } + + /** + * Set the properties value. + * + * @param properties the properties value to set + * @return the VaultCreateOrUpdateParametersInner object itself. + */ + public VaultCreateOrUpdateParametersInner withProperties(VaultProperties properties) { + this.properties = properties; + return this; + } + +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultInner.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultInner.java new file mode 100644 index 0000000000000..7f85bfedae227 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultInner.java @@ -0,0 +1,46 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.keyvault.implementation; + +import com.microsoft.azure.management.keyvault.VaultProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.azure.Resource; +import com.microsoft.azure.Resource; + +/** + * Resource information with extended details. + */ +public class VaultInner extends Resource { + /** + * Properties of the vault. + */ + @JsonProperty(required = true) + private VaultProperties properties; + + /** + * Get the properties value. + * + * @return the properties value + */ + public VaultProperties properties() { + return this.properties; + } + + /** + * Set the properties value. + * + * @param properties the properties value to set + * @return the VaultInner object itself. + */ + public VaultInner withProperties(VaultProperties properties) { + this.properties = properties; + return this; + } + +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsInner.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsInner.java new file mode 100644 index 0000000000000..68d2d771e5ee5 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsInner.java @@ -0,0 +1,767 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.keyvault.implementation; + +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceResponseBuilder; +import com.microsoft.azure.CloudException; +import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.Page; +import com.microsoft.azure.PagedList; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceResponse; +import com.microsoft.rest.ServiceResponseCallback; +import com.microsoft.rest.Validator; +import java.io.IOException; +import java.util.List; +import okhttp3.ResponseBody; +import retrofit2.Call; +import retrofit2.http.Body; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.HTTP; +import retrofit2.http.Path; +import retrofit2.http.PUT; +import retrofit2.http.Query; +import retrofit2.http.Url; +import retrofit2.Response; + +/** + * An instance of this class provides access to all the operations defined + * in Vaults. + */ +public final class VaultsInner { + /** The Retrofit service to perform REST calls. */ + private VaultsService service; + /** The service client containing this operation class. */ + private KeyVaultManagementClientImpl client; + + /** + * Initializes an instance of VaultsInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public VaultsInner(Retrofit retrofit, KeyVaultManagementClientImpl client) { + this.service = retrofit.create(VaultsService.class); + this.client = client; + } + + /** + * The interface defining all the services for Vaults to be + * used by Retrofit to perform actually REST calls. + */ + interface VaultsService { + @Headers("Content-Type: application/json; charset=utf-8") + @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.KeyVault/vaults/{vaultName}") + Call createOrUpdate(@Path("resourceGroupName") String resourceGroupName, @Path("vaultName") String vaultName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Body VaultCreateOrUpdateParametersInner parameters, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.KeyVault/vaults/{vaultName}", method = "DELETE", hasBody = true) + Call delete(@Path("resourceGroupName") String resourceGroupName, @Path("vaultName") String vaultName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.KeyVault/vaults/{vaultName}") + Call get(@Path("resourceGroupName") String resourceGroupName, @Path("vaultName") String vaultName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.KeyVault/vaults") + Call listByResourceGroup(@Path("resourceGroupName") String resourceGroupName, @Path("subscriptionId") String subscriptionId, @Query("$top") Integer top, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("subscriptions/{subscriptionId}/resources") + Call list(@Path("subscriptionId") String subscriptionId, @Query("$filter") String filter, @Query("$top") Integer top, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET + Call listByResourceGroupNext(@Url String nextPageLink, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET + Call listNext(@Url String nextPageLink, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * Create or update a key vault in the specified subscription. + * + * @param resourceGroupName The name of the Resource Group to which the server belongs. + * @param vaultName Name of the vault + * @param parameters Parameters to create or update the vault + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the VaultInner object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse createOrUpdate(String resourceGroupName, String vaultName, VaultCreateOrUpdateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (vaultName == null) { + throw new IllegalArgumentException("Parameter vaultName is required and cannot be null."); + } + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + Validator.validate(parameters); + Call call = service.createOrUpdate(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), parameters, this.client.acceptLanguage(), this.client.userAgent()); + return createOrUpdateDelegate(call.execute()); + } + + /** + * Create or update a key vault in the specified subscription. + * + * @param resourceGroupName The name of the Resource Group to which the server belongs. + * @param vaultName Name of the vault + * @param parameters Parameters to create or update the vault + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall createOrUpdateAsync(String resourceGroupName, String vaultName, VaultCreateOrUpdateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (resourceGroupName == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); + return null; + } + if (vaultName == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter vaultName is required and cannot be null.")); + return null; + } + if (this.client.subscriptionId() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + if (parameters == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); + return null; + } + Validator.validate(parameters, serviceCallback); + Call call = service.createOrUpdate(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), parameters, this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(createOrUpdateDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse createOrUpdateDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(201, new TypeToken() { }.getType()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Deletes the specified Azure key vault. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @param vaultName The name of the vault to delete + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the {@link ServiceResponse} object if successful. + */ + public ServiceResponse delete(String resourceGroupName, String vaultName) throws CloudException, IOException, IllegalArgumentException { + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (vaultName == null) { + throw new IllegalArgumentException("Parameter vaultName is required and cannot be null."); + } + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.delete(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return deleteDelegate(call.execute()); + } + + /** + * Deletes the specified Azure key vault. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @param vaultName The name of the vault to delete + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall deleteAsync(String resourceGroupName, String vaultName, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (resourceGroupName == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); + return null; + } + if (vaultName == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter vaultName is required and cannot be null.")); + return null; + } + if (this.client.subscriptionId() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.delete(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(deleteDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse deleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(200, new TypeToken() { }.getType()) + .build(response); + } + + /** + * Gets the specified Azure key vault. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @param vaultName The name of the vault. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the VaultInner object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse get(String resourceGroupName, String vaultName) throws CloudException, IOException, IllegalArgumentException { + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (vaultName == null) { + throw new IllegalArgumentException("Parameter vaultName is required and cannot be null."); + } + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.get(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return getDelegate(call.execute()); + } + + /** + * Gets the specified Azure key vault. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @param vaultName The name of the vault. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall getAsync(String resourceGroupName, String vaultName, final ServiceCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (resourceGroupName == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); + return null; + } + if (vaultName == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter vaultName is required and cannot be null.")); + return null; + } + if (this.client.subscriptionId() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.get(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + serviceCallback.success(getDelegate(response)); + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse getDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<VaultInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> listByResourceGroup(final String resourceGroupName) throws CloudException, IOException, IllegalArgumentException { + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + final Integer top = null; + Call call = service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), top, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listByResourceGroupDelegate(call.execute()); + PagedList result = new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextPageLink) throws CloudException, IOException { + return listByResourceGroupNext(nextPageLink).getBody(); + } + }; + return new ServiceResponse<>(result, response.getResponse()); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall listByResourceGroupAsync(final String resourceGroupName, final ListOperationCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (resourceGroupName == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); + return null; + } + if (this.client.subscriptionId() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + final Integer top = null; + Call call = service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), top, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listByResourceGroupDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listByResourceGroupNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @param top Maximum number of results to return. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<VaultInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> listByResourceGroup(final String resourceGroupName, final Integer top) throws CloudException, IOException, IllegalArgumentException { + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Call call = service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), top, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listByResourceGroupDelegate(call.execute()); + PagedList result = new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextPageLink) throws CloudException, IOException { + return listByResourceGroupNext(nextPageLink).getBody(); + } + }; + return new ServiceResponse<>(result, response.getResponse()); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @param top Maximum number of results to return. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall listByResourceGroupAsync(final String resourceGroupName, final Integer top, final ListOperationCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (resourceGroupName == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); + return null; + } + if (this.client.subscriptionId() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); + return null; + } + if (this.client.apiVersion() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); + return null; + } + Call call = service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), top, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listByResourceGroupDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listByResourceGroupNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse> listByResourceGroupDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<VaultInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> list() throws CloudException, IOException, IllegalArgumentException { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + final String filter = "resourceType eq 'Microsoft.KeyVault/vaults'"; + final String apiVersion = "2015-11-01"; + final Integer top = null; + Call call = service.list(this.client.subscriptionId(), filter, top, apiVersion, this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listDelegate(call.execute()); + PagedList result = new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextPageLink) throws CloudException, IOException { + return listNext(nextPageLink).getBody(); + } + }; + return new ServiceResponse<>(result, response.getResponse()); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall listAsync(final ListOperationCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (this.client.subscriptionId() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); + return null; + } + final String filter = "resourceType eq 'Microsoft.KeyVault/vaults'"; + final String apiVersion = "2015-11-01"; + final Integer top = null; + Call call = service.list(this.client.subscriptionId(), filter, top, apiVersion, this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + * @param top Maximum number of results to return. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<VaultInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> list(final Integer top) throws CloudException, IOException, IllegalArgumentException { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + final String filter = "resourceType eq 'Microsoft.KeyVault/vaults'"; + final String apiVersion = "2015-11-01"; + Call call = service.list(this.client.subscriptionId(), filter, top, apiVersion, this.client.acceptLanguage(), this.client.userAgent()); + ServiceResponse> response = listDelegate(call.execute()); + PagedList result = new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextPageLink) throws CloudException, IOException { + return listNext(nextPageLink).getBody(); + } + }; + return new ServiceResponse<>(result, response.getResponse()); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + * @param top Maximum number of results to return. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall listAsync(final Integer top, final ListOperationCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (this.client.subscriptionId() == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); + return null; + } + final String filter = "resourceType eq 'Microsoft.KeyVault/vaults'"; + final String apiVersion = "2015-11-01"; + Call call = service.list(this.client.subscriptionId(), filter, top, apiVersion, this.client.acceptLanguage(), this.client.userAgent()); + final ServiceCall serviceCall = new ServiceCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<VaultInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> listByResourceGroupNext(final String nextPageLink) throws CloudException, IOException, IllegalArgumentException { + if (nextPageLink == null) { + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); + } + Call call = service.listByResourceGroupNext(nextPageLink, this.client.acceptLanguage(), this.client.userAgent()); + return listByResourceGroupNextDelegate(call.execute()); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @param serviceCall the ServiceCall object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall listByResourceGroupNextAsync(final String nextPageLink, final ServiceCall serviceCall, final ListOperationCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (nextPageLink == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter nextPageLink is required and cannot be null.")); + return null; + } + Call call = service.listByResourceGroupNext(nextPageLink, this.client.acceptLanguage(), this.client.userAgent()); + serviceCall.newCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listByResourceGroupNextDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listByResourceGroupNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse> listByResourceGroupNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws CloudException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<VaultInner> object wrapped in {@link ServiceResponse} if successful. + */ + public ServiceResponse> listNext(final String nextPageLink) throws CloudException, IOException, IllegalArgumentException { + if (nextPageLink == null) { + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); + } + Call call = service.listNext(nextPageLink, this.client.acceptLanguage(), this.client.userAgent()); + return listNextDelegate(call.execute()); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @param serviceCall the ServiceCall object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if callback is null + * @return the {@link Call} object + */ + public ServiceCall listNextAsync(final String nextPageLink, final ServiceCall serviceCall, final ListOperationCallback serviceCallback) throws IllegalArgumentException { + if (serviceCallback == null) { + throw new IllegalArgumentException("ServiceCallback is required for async calls."); + } + if (nextPageLink == null) { + serviceCallback.failure(new IllegalArgumentException("Parameter nextPageLink is required and cannot be null.")); + return null; + } + Call call = service.listNext(nextPageLink, this.client.acceptLanguage(), this.client.userAgent()); + serviceCall.newCall(call); + call.enqueue(new ServiceResponseCallback>(serviceCallback) { + @Override + public void onResponse(Call call, Response response) { + try { + ServiceResponse> result = listNextDelegate(response); + serviceCallback.load(result.getBody().getItems()); + if (result.getBody().getNextPageLink() != null + && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { + listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); + } else { + serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + } + } catch (CloudException | IOException exception) { + serviceCallback.failure(exception); + } + } + }); + return serviceCall; + } + + private ServiceResponse> listNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/package-info.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/package-info.java new file mode 100644 index 0000000000000..84763cd550ec1 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/package-info.java @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. + +/** + * This package contains the implementation classes for KeyVaultManagementClient. + * The Azure management API provides a RESTful set of web services that interact with Azure Key Vault. + */ +package com.microsoft.azure.management.keyvault.implementation; diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/package-info.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/package-info.java new file mode 100644 index 0000000000000..1f051f3fc6dac --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/package-info.java @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. + +/** + * This package contains the classes for KeyVaultManagementClient. + * The Azure management API provides a RESTful set of web services that interact with Azure Key Vault. + */ +package com.microsoft.azure.management.keyvault; diff --git a/gulpfile.js b/gulpfile.js index 00ad44375de67..6a5bad0cd3c02 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -17,6 +17,12 @@ var mappings = { 'package': 'com.microsoft.azure.management.graphrbac', 'args': '-FT 1' }, + 'keyvault': { + 'dir': 'azure-mgmt-keyvault', + 'source': 'arm-keyvault/2015-06-01/swagger/keyvault.json', + 'package': 'com.microsoft.azure.management.keyvault', + 'args': '-FT 1' + }, 'storage': { 'dir': 'azure-mgmt-storage', 'source': 'arm-storage/2016-01-01/swagger/storage.json', diff --git a/pom.xml b/pom.xml index 4d9114da545e7..9295bc8ff07d3 100644 --- a/pom.xml +++ b/pom.xml @@ -237,6 +237,7 @@ ./azure-batch ./azure-mgmt-compute ./azure-mgmt-graph-rbac + ./azure-mgmt-keyvault ./azure-mgmt-resources ./azure-mgmt-storage ./azure-mgmt-network From 8e51cd47d520ee52aa27501794374d66e0a0d0a9 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Tue, 26 Jul 2016 17:30:13 -0700 Subject: [PATCH 5/7] Add interfaces for vault & access policy --- azure-mgmt-keyvault/pom.xml | 10 - .../management/keyvault/AccessPolicy.java | 120 ++++++++++++ .../azure/management/keyvault/Vault.java | 151 +++++++++++++++ .../azure/management/keyvault/Vaults.java | 28 +++ .../implementation/AccessPolicyImpl.java | 123 ++++++++++++ .../implementation/KeyVaultManager.java | 101 ++++++++++ .../keyvault/implementation/VaultImpl.java | 180 ++++++++++++++++++ 7 files changed, 703 insertions(+), 10 deletions(-) create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vaults.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java diff --git a/azure-mgmt-keyvault/pom.xml b/azure-mgmt-keyvault/pom.xml index 0b99f6b535626..27dc43d2f31ff 100644 --- a/azure-mgmt-keyvault/pom.xml +++ b/azure-mgmt-keyvault/pom.xml @@ -56,16 +56,6 @@ azure-mgmt-resources 1.0.0-SNAPSHOT - - com.microsoft.azure - azure-mgmt-storage - 1.0.0-SNAPSHOT - - - com.microsoft.azure - azure-mgmt-network - 1.0.0-SNAPSHOT - junit junit diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java new file mode 100644 index 0000000000000..77500c7b09764 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java @@ -0,0 +1,120 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.keyvault; + +import com.microsoft.azure.management.resources.fluentcore.arm.models.ChildResource; +import com.microsoft.azure.management.resources.fluentcore.model.Attachable; +import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; + +import java.util.List; +import java.util.UUID; + +/** + * An immutable client-side representation of a key vault access policy. + */ +public interface AccessPolicy extends + ChildResource, + Wrapper { + /** + * @return The Azure Active Directory tenant ID that should be used for + * authenticating requests to the key vault. + */ + UUID tenantId(); + + /** + * @return The object ID of a user or service principal in the Azure Active + * Directory tenant for the vault. + */ + UUID objectId(); + + /** + * @return Application ID of the client making request on behalf of a principal. + */ + UUID applicationId(); + + /** + * @return Permissions the identity has for keys and secrets. + */ + Permissions permissions(); + + /************************************************************** + * Fluent interfaces to attach an access policy + **************************************************************/ + + interface Definition extends + DefinitionStages.Blank, + DefinitionStages.WithTenantId, + DefinitionStages.WithApplicationId, + DefinitionStages.WithAttach { + } + + /** + * Grouping of access policy definition stages applicable as part of a key vault creation. + */ + interface DefinitionStages { + /** + * The first stage of an access policy definition. + * + * @param the return type of the final {@link WithAttach#attach()} + */ + interface Blank extends WithTenantId { + } + + /** + * The access policy definition stage allowing tenant ID to be specified. + * @param the return type of the final {@link WithAttach#attach()} + */ + interface WithTenantId { + WithPermissions withTenantId(UUID tenantId); + } + + /** + * The access policy definition stage allowing permissions to be added. + * @param the return type of the final {@link WithAttach#attach()} + */ + interface WithPermissions { + WithAttach withPermissionToKey(String key); + WithAttach withPermissionToKeys(List keys); + WithAttach withPermissionToSecret(String secret); + WithAttach withPermissionToSecrets(List secrets); + } + + /** + * The access policy definition stage allowing application ID to be specified. + * @param the return type of the final {@link WithAttach#attach()} + */ + interface WithApplicationId { + WithAttach withApplicationId(UUID applicationId); + } + + /** The final stage of the access policy definition. + *

+ * At this stage, more permissions can be added or application ID can be specified, + * or the access policy definition can be attached to the parent key vault definition + * using {@link WithAttach#attach()}. + * @param the return type of {@link WithAttach#attach()} + */ + interface WithAttach extends + Attachable.InDefinition, + WithApplicationId, + WithPermissions { + } + } + + /** + * Grouping of all the key vault update stages. + */ + interface UpdateStages { + } + + /** + * The template for a key vault update operation, containing all the settings that can be modified. + */ + interface Update { + } +} + diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java new file mode 100644 index 0000000000000..9ae1fa85e029f --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java @@ -0,0 +1,151 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.keyvault; + +import com.microsoft.azure.management.keyvault.implementation.VaultInner; +import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource; +import com.microsoft.azure.management.resources.fluentcore.model.Appliable; +import com.microsoft.azure.management.resources.fluentcore.model.Creatable; +import com.microsoft.azure.management.resources.fluentcore.model.Refreshable; +import com.microsoft.azure.management.resources.fluentcore.model.Updatable; +import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; + +import java.util.List; +import java.util.UUID; + +/** + * An immutable client-side representation of an Azure Key Vault. + */ +public interface Vault extends + GroupableResource, + Refreshable, + Updatable, + Wrapper { + /** + * @return The URI of the vault for performing operations on keys and secrets. + */ + String vaultUri(); + + /** + * @return The Azure Active Directory tenant ID that should be used for + * authenticating requests to the key vault. + */ + UUID tenantId(); + + /** + * @return SKU details. + */ + Sku sku(); + + /** + * @return An array of 0 to 16 identities that have access to the key vault. All + * identities in the array must use the same tenant ID as the key vault's + * tenant ID. + */ + List accessPolicies(); + + /** + * @return Property to specify whether Azure Virtual Machines are permitted to + * retrieve certificates stored as secrets from the key vault. + */ + Boolean enabledForDeployment(); + + /** + * @return Property to specify whether Azure Disk Encryption is permitted to + * retrieve secrets from the vault and unwrap keys. + */ + Boolean enabledForDiskEncryption(); + + /** + * @return Property to specify whether Azure Resource Manager is permitted to + * retrieve secrets from the key vault. + */ + Boolean enabledForTemplateDeployment(); + + /************************************************************** + * Fluent interfaces to provision a Vault + **************************************************************/ + + /** + * Container interface for all the definitions that need to be implemented. + */ + interface Definition extends + DefinitionStages.Blank, + DefinitionStages.WithGroup, + DefinitionStages.WithCreate { + } + + /** + * Grouping of all the key vault definition stages. + */ + interface DefinitionStages { + /** + * The first stage of the key vault definition. + */ + interface Blank extends DefinitionWithRegion { + } + + /** + * A key vault definition allowing resource group to be set. + */ + interface WithGroup extends GroupableResource.DefinitionStages.WithGroup { + } + + /** + * A key vault definition allowing the sku to be set. + */ + interface WithSku { + /** + * Specifies the sku of the key vault. + * + * @param skuName the sku + * @return the next stage of key vault definition + */ + WithCreate withSku(SkuName skuName); + } + + interface WithAccessPolicy { + WithCreate withEmptyAccessPolicy(); + WithCreate withAccessPolicy(AccessPolicy accessPolicy); + AccessPolicy.DefinitionStages.Blank defineAccessPolicy(String objectId); + } + + interface WithConfigurations { + WithCreate enabledForDeployment(boolean enabled); + WithCreate enabledForDiskEncryption(boolean enabled); + WithCreate enabledForTemplateDeployment(boolean enabled); + } + + /** + * A key vault definition with sufficient inputs to create a new + * storage account in the cloud, but exposing additional optional inputs to + * specify. + */ + interface WithCreate extends + Creatable, + GroupableResource.DefinitionWithTags, + DefinitionStages.WithSku, + DefinitionStages.WithAccessPolicy, + DefinitionStages.WithConfigurations { + } + } + + /** + * Grouping of all the key vault update stages. + */ + interface UpdateStages { + } + + /** + * The template for a key vault update operation, containing all the settings that can be modified. + */ + interface Update extends + Appliable, + UpdateWithTags { + } +} + diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vaults.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vaults.java new file mode 100644 index 0000000000000..6c47f5ed4d750 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vaults.java @@ -0,0 +1,28 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.keyvault; + +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +/** + * Entry point for storage accounts management API. + */ +public interface Vaults extends + SupportsListing, + SupportsCreating, + SupportsDeleting, + SupportsListingByGroup, + SupportsGettingByGroup, + SupportsGettingById, + SupportsDeletingByGroup { +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java new file mode 100644 index 0000000000000..57b08544102ad --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java @@ -0,0 +1,123 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.keyvault.implementation; + +import com.microsoft.azure.management.keyvault.AccessPolicy; +import com.microsoft.azure.management.keyvault.AccessPolicyEntry; +import com.microsoft.azure.management.keyvault.Permissions; +import com.microsoft.azure.management.keyvault.Vault; +import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.ChildResourceImpl; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + * Implementation for StorageAccount and its parent interfaces. + */ +class AccessPolicyImpl + extends ChildResourceImpl< + AccessPolicyEntry, + VaultImpl> + implements + AccessPolicy, + AccessPolicy.Definition { + protected AccessPolicyImpl(String name, AccessPolicyEntry innerObject, VaultImpl parent) { + super(name, innerObject, parent); + } + + @Override + public UUID tenantId() { + return inner().tenantId(); + } + + @Override + public UUID objectId() { + return inner().objectId(); + } + + @Override + public UUID applicationId() { + return inner().applicationId(); + } + + @Override + public Permissions permissions() { + return inner().permissions(); + } + + @Override + public String name() { + return inner().objectId().toString(); + } + + @Override + public AccessPolicyImpl withApplicationId(UUID applicationId) { + inner().withApplicationId(applicationId); + return this; + } + + @Override + public AccessPolicyImpl withPermissionToKey(String key) { + if (inner().permissions() == null) { + inner().withPermissions(new Permissions()); + } + if (inner().permissions().keys() == null) { + inner().permissions().withKeys(new ArrayList()); + } + inner().permissions().keys().add(key); + return this; + } + + @Override + public AccessPolicyImpl withPermissionToKeys(List keys) { + if (inner().permissions() == null) { + inner().withPermissions(new Permissions()); + } + if (inner().permissions().keys() == null) { + inner().permissions().withKeys(new ArrayList()); + } + inner().permissions().keys().addAll(keys); + return this; + } + + @Override + public AccessPolicyImpl withPermissionToSecret(String secret) { + if (inner().permissions() == null) { + inner().withPermissions(new Permissions()); + } + if (inner().permissions().secrets() == null) { + inner().permissions().withSecrets(new ArrayList()); + } + inner().permissions().secrets().add(secret); + return this; + } + + @Override + public AccessPolicyImpl withPermissionToSecrets(List secrets) { + if (inner().permissions() == null) { + inner().withPermissions(new Permissions()); + } + if (inner().permissions().secrets() == null) { + inner().permissions().withSecrets(new ArrayList()); + } + inner().permissions().secrets().addAll(secrets); + return this; + } + + @Override + public AccessPolicyImpl withTenantId(UUID tenantId) { + inner().withTenantId(tenantId); + return this; + } + + @Override + public VaultImpl attach() { + parent().withAccessPolicy(this); + return parent(); + } +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java new file mode 100644 index 0000000000000..3bb7d93bb0a84 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java @@ -0,0 +1,101 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.keyvault.implementation; + +import com.microsoft.azure.AzureEnvironment; +import com.microsoft.azure.RestClient; +import com.microsoft.azure.management.keyvault.Vaults; +import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; +import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; +import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager; +import com.microsoft.azure.management.storage.StorageAccounts; +import com.microsoft.azure.management.storage.implementation.StorageAccountsImpl; +import com.microsoft.azure.management.storage.implementation.StorageManagementClientImpl; +import com.microsoft.rest.credentials.ServiceClientCredentials; + +/** + * Entry point to Azure storage resource management. + */ +public final class KeyVaultManager extends Manager { + // Collections + private Vaults vaults; + + /** + * Get a Configurable instance that can be used to create StorageManager with optional configuration. + * + * @return the instance allowing configurations + */ + public static Configurable configure() { + return new KeyVaultManager.ConfigurableImpl(); + } + + /** + * Creates an instance of StorageManager that exposes storage resource management API entry points. + * + * @param credentials the credentials to use + * @param subscriptionId the subscription UUID + * @return the StorageManager + */ + public static KeyVaultManager authenticate(ServiceClientCredentials credentials, String subscriptionId) { + return new KeyVaultManager(AzureEnvironment.AZURE.newRestClientBuilder() + .withCredentials(credentials) + .build(), subscriptionId); + } + + /** + * Creates an instance of StorageManager that exposes storage resource management API entry points. + * + * @param restClient the RestClient to be used for API calls. + * @param subscriptionId the subscription UUID + * @return the StorageManager + */ + public static KeyVaultManager authenticate(RestClient restClient, String subscriptionId) { + return new KeyVaultManager(restClient, subscriptionId); + } + + /** + * The interface allowing configurations to be set. + */ + public interface Configurable extends AzureConfigurable { + /** + * Creates an instance of StorageManager that exposes storage management API entry points. + * + * @param credentials the credentials to use + * @param subscriptionId the subscription UUID + * @return the interface exposing storage management API entry points that work across subscriptions + */ + KeyVaultManager authenticate(ServiceClientCredentials credentials, String subscriptionId); + } + + /** + * The implementation for Configurable interface. + */ + private static final class ConfigurableImpl extends AzureConfigurableImpl implements Configurable { + public KeyVaultManager authenticate(ServiceClientCredentials credentials, String subscriptionId) { + return KeyVaultManager.authenticate(buildRestClient(credentials), subscriptionId); + } + } + + private KeyVaultManager(RestClient restClient, String subscriptionId) { + super( + restClient, + subscriptionId, + new KeyVaultManagementClientImpl(restClient).withSubscriptionId(subscriptionId)); + } + + /** + * @return the storage account management API entry point + */ + public Vaults vaults() { + if (vaults == null) { + vaults = new VaultsImpl( + super.innerManagementClient.vaults(), + this); + } + return vaults; + } +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java new file mode 100644 index 0000000000000..60b5b33d68cc5 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java @@ -0,0 +1,180 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.keyvault.implementation; + +import com.microsoft.azure.management.keyvault.AccessPolicy; +import com.microsoft.azure.management.keyvault.AccessPolicyEntry; +import com.microsoft.azure.management.keyvault.Sku; +import com.microsoft.azure.management.keyvault.SkuFamily; +import com.microsoft.azure.management.keyvault.SkuName; +import com.microsoft.azure.management.keyvault.Vault; +import com.microsoft.azure.management.keyvault.VaultProperties; +import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource; +import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableResourceImpl; +import com.microsoft.rest.ServiceCall; +import com.microsoft.rest.ServiceCallback; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + * Implementation for StorageAccount and its parent interfaces. + */ +class VaultImpl + extends GroupableResourceImpl< + Vault, + VaultInner, + VaultImpl, + KeyVaultManager> + implements + Vault, + Vault.Definition, + Vault.Update { + private VaultsInner client; + + protected VaultImpl(String key, VaultInner innerObject, VaultsInner client, KeyVaultManager manager) { + super(key, innerObject, manager); + this.client = client; + } + + @Override + public String vaultUri() { + if (inner().properties() == null) { + return null; + } + return inner().properties().vaultUri(); + } + + @Override + public UUID tenantId() { + if (inner().properties() == null) { + return null; + } + return inner().properties().tenantId(); + } + + @Override + public Sku sku() { + if (inner().properties() == null) { + return null; + } + return inner().properties().sku(); + } + + @Override + public List accessPolicies() { + if (inner().properties() == null) { + return null; + } + return inner().properties().accessPolicies(); + } + + @Override + public Boolean enabledForDeployment() { + if (inner().properties() == null) { + return null; + } + return inner().properties().enabledForDeployment(); + } + + @Override + public Boolean enabledForDiskEncryption() { + if (inner().properties() == null) { + return null; + } + return inner().properties().enabledForDiskEncryption(); + } + + @Override + public Boolean enabledForTemplateDeployment() { + if (inner().properties() == null) { + return null; + } + return inner().properties().enabledForTemplateDeployment(); + } + + @Override + public VaultImpl withEmptyAccessPolicy() { + if (inner().properties() == null) { + inner().withProperties(new VaultProperties()); + } + inner().properties().withAccessPolicies(new ArrayList()); + return this; + } + + @Override + public VaultImpl withAccessPolicy(AccessPolicy accessPolicy) { + if (inner().properties() == null) { + inner().withProperties(new VaultProperties()); + } + if (inner().properties().accessPolicies() == null) { + inner().properties().withAccessPolicies(new ArrayList()); + } + inner().properties().accessPolicies().add(accessPolicy.inner()); + return this; + } + + @Override + public AccessPolicyImpl defineAccessPolicy(String objectId) { + return new AccessPolicyImpl(objectId, new AccessPolicyEntry(), this); + } + + @Override + public VaultImpl enabledForDeployment(boolean enabled) { + inner().properties().withEnabledForDeployment(enabled); + return this; + } + + @Override + public VaultImpl enabledForDiskEncryption(boolean enabled) { + inner().properties().withEnabledForDiskEncryption(enabled); + return this; + } + + @Override + public VaultImpl enabledForTemplateDeployment(boolean enabled) { + inner().properties().withEnabledForTemplateDeployment(enabled); + return this; + } + + @Override + public VaultImpl withSku(SkuName skuName) { + inner().properties().withSku(new Sku().withName(skuName).withFamily(SkuFamily.A)); + return this; + } + + @Override + public VaultImpl apply() throws Exception { + return createResource(); + } + + @Override + public ServiceCall applyAsync(ServiceCallback callback) { + return null; + } + + @Override + public ServiceCall createResourceAsync(ServiceCallback serviceCallback) { + return null; + } + + @Override + public VaultImpl createResource() throws Exception { + VaultCreateOrUpdateParametersInner parameters = new VaultCreateOrUpdateParametersInner(); + parameters.withLocation(regionName()); + parameters.withProperties(inner().properties()); + parameters.withTags(inner().getTags()); + this.setInner(client.createOrUpdate(resourceGroupName(), name(), parameters).getBody()); + return this; + } + + @Override + public VaultImpl refresh() throws Exception { + return null; + } +} From 85e445345569cfb53bff6c16456b5a03d758336b Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 27 Jul 2016 15:11:24 -0700 Subject: [PATCH 6/7] Basic Create --- .../azure/management/keyvault/Vault.java | 10 ++- .../implementation/KeyVaultManager.java | 3 - .../keyvault/implementation/VaultImpl.java | 12 +++ .../keyvault/implementation/VaultsImpl.java | 86 +++++++++++++++++++ .../keyvault/KeyVaultManagementTestBase.java | 42 +++++++++ .../azure/management/keyvault/VaultTests.java | 44 ++++++++++ 6 files changed, 191 insertions(+), 6 deletions(-) create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java create mode 100644 azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java create mode 100644 azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java index 9ae1fa85e029f..e421a7f73a0a7 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java @@ -76,6 +76,7 @@ public interface Vault extends interface Definition extends DefinitionStages.Blank, DefinitionStages.WithGroup, + DefinitionStages.WithTenantId, DefinitionStages.WithCreate { } @@ -92,7 +93,11 @@ interface Blank extends DefinitionWithRegion { /** * A key vault definition allowing resource group to be set. */ - interface WithGroup extends GroupableResource.DefinitionStages.WithGroup { + interface WithGroup extends GroupableResource.DefinitionStages.WithGroup { + } + + interface WithTenantId { + WithCreate withTenantId(UUID tenantId); } /** @@ -144,8 +149,7 @@ interface UpdateStages { * The template for a key vault update operation, containing all the settings that can be modified. */ interface Update extends - Appliable, - UpdateWithTags { + Appliable { } } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java index 3bb7d93bb0a84..59a7bf6f9077f 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/KeyVaultManager.java @@ -12,9 +12,6 @@ import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; import com.microsoft.azure.management.resources.fluentcore.arm.implementation.Manager; -import com.microsoft.azure.management.storage.StorageAccounts; -import com.microsoft.azure.management.storage.implementation.StorageAccountsImpl; -import com.microsoft.azure.management.storage.implementation.StorageManagementClientImpl; import com.microsoft.rest.credentials.ServiceClientCredentials; /** diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java index 60b5b33d68cc5..e4a11789202ed 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java @@ -144,10 +144,22 @@ public VaultImpl enabledForTemplateDeployment(boolean enabled) { @Override public VaultImpl withSku(SkuName skuName) { + if (inner().properties() == null) { + inner().withProperties(new VaultProperties()); + } inner().properties().withSku(new Sku().withName(skuName).withFamily(SkuFamily.A)); return this; } + @Override + public VaultImpl withTenantId(UUID tenantId) { + if (inner().properties() == null) { + inner().withProperties(new VaultProperties()); + } + inner().properties().withTenantId(tenantId); + return this; + } + @Override public VaultImpl apply() throws Exception { return createResource(); diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java new file mode 100644 index 0000000000000..f199654654240 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsImpl.java @@ -0,0 +1,86 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.keyvault.implementation; + +import com.microsoft.azure.CloudException; +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.keyvault.SkuName; +import com.microsoft.azure.management.keyvault.Vault; +import com.microsoft.azure.management.keyvault.Vaults; +import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; + +import java.io.IOException; + +/** + * The implementation of StorageAccounts and its parent interfaces. + */ +class VaultsImpl + extends GroupableResourcesImpl< + Vault, + VaultImpl, + VaultInner, + VaultsInner, + KeyVaultManager> + implements Vaults { + + VaultsImpl( + final VaultsInner client, + final KeyVaultManager keyVaultManager) { + super(client, keyVaultManager); + } + + @Override + public PagedList list() throws CloudException, IOException { + return wrapList(this.innerCollection.list().getBody()); + } + + @Override + public PagedList listByGroup(String groupName) throws CloudException, IOException { + return wrapList(this.innerCollection.listByResourceGroup(groupName).getBody()); + } + + @Override + public Vault getByGroup(String groupName, String name) throws CloudException, IOException { + return wrapModel(this.innerCollection.get(groupName, name).getBody()); + } + + @Override + public void delete(String id) throws Exception { + delete(ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id)); + } + + @Override + public void delete(String groupName, String name) throws Exception { + this.innerCollection.delete(groupName, name); + } + + @Override + public VaultImpl define(String name) { + return wrapModel(name) + .withSku(SkuName.STANDARD) + .withEmptyAccessPolicy(); + } + + @Override + protected VaultImpl wrapModel(String name) { + return new VaultImpl( + name, + new VaultInner(), + this.innerCollection, + super.myManager); + } + + @Override + protected VaultImpl wrapModel(VaultInner storageAccountInner) { + return new VaultImpl( + storageAccountInner.name(), + storageAccountInner, + this.innerCollection, + super.myManager); + } +} diff --git a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java new file mode 100644 index 0000000000000..19ceb7ca66df0 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java @@ -0,0 +1,42 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.keyvault; + +import com.microsoft.azure.AzureEnvironment; +import com.microsoft.azure.RestClient; +import com.microsoft.azure.credentials.ApplicationTokenCredentials; +import com.microsoft.azure.management.keyvault.implementation.KeyVaultManager; +import com.microsoft.azure.management.resources.implementation.ResourceManager; +import okhttp3.logging.HttpLoggingInterceptor; + +/** + * The base for storage manager tests. + */ +public abstract class KeyVaultManagementTestBase { + protected static ResourceManager resourceManager; + protected static KeyVaultManager keyVaultManager; + + protected static void createClients() { + ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( + System.getenv("client-id"), + System.getenv("domain"), + System.getenv("secret"), + null); + + RestClient restClient = AzureEnvironment.AZURE.newRestClientBuilder() + .withCredentials(credentials) + .withLogLevel(HttpLoggingInterceptor.Level.BODY) + .build(); + + resourceManager = ResourceManager + .authenticate(restClient) + .withSubscription(System.getenv("subscription-id")); + + keyVaultManager = KeyVaultManager + .authenticate(restClient, System.getenv("subscription-id")); + } +} diff --git a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java new file mode 100644 index 0000000000000..47b6524656ac9 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.microsoft.azure.management.keyvault; + +import com.microsoft.azure.management.resources.ResourceGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.Region; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.UUID; + +public class VaultTests extends KeyVaultManagementTestBase { + private static final String RG_NAME = "javacsmrg901"; + private static final String VAULT_NAME = "java-keyvault-901"; + private static ResourceGroup resourceGroup; + + @BeforeClass + public static void setup() throws Exception { + createClients(); + } + + @AfterClass + public static void cleanup() throws Exception { + resourceManager.resourceGroups().delete(RG_NAME); + } + + @Test + public void canCRUDVault() throws Exception { + // CREATE + Vault vault = keyVaultManager.vaults().define(VAULT_NAME) + .withRegion(Region.US_WEST) + .withNewResourceGroup(RG_NAME) + .withTenantId(UUID.fromString("72f988bf-86f1-41af-91ab-2d7cd011db47")) + .create(); + Assert.assertNotNull(vault); + // GET + } +} From 6865f008c85acd44aa79a24b5533256711aca57b Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Mon, 1 Aug 2016 16:10:30 -0700 Subject: [PATCH 7/7] Add graph to key vault flow --- .../GraphRbacManagementTestBase.java | 2 +- azure-mgmt-keyvault/pom.xml | 5 + .../management/keyvault/AccessPolicy.java | 77 +++- .../azure/management/keyvault/Vault.java | 12 +- .../implementation/AccessPolicyImpl.java | 413 ++++++++++++++++-- .../keyvault/implementation/VaultImpl.java | 4 +- .../keyvault/KeyVaultManagementTestBase.java | 15 +- .../azure/management/keyvault/VaultTests.java | 11 +- 8 files changed, 472 insertions(+), 67 deletions(-) diff --git a/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java b/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java index 88f0a8b9d6392..b3fb18e2acf46 100644 --- a/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java +++ b/azure-mgmt-graph-rbac/src/main/test/com/microsoft/azure/management/graphrbac/GraphRbacManagementTestBase.java @@ -27,6 +27,6 @@ protected static void createClients() { graphRbacManager = GraphRbacManager .configure() .withLogLevel(HttpLoggingInterceptor.Level.BODY) - .authenticate(credentials, credentials.getDomain()); + .authenticate(credentials, "myorganization"); } } diff --git a/azure-mgmt-keyvault/pom.xml b/azure-mgmt-keyvault/pom.xml index 27dc43d2f31ff..6b7471bc35ff9 100644 --- a/azure-mgmt-keyvault/pom.xml +++ b/azure-mgmt-keyvault/pom.xml @@ -56,6 +56,11 @@ azure-mgmt-resources 1.0.0-SNAPSHOT + + com.microsoft.azure + azure-mgmt-graph-rbac + 1.0.0-SNAPSHOT + junit junit diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java index 77500c7b09764..db46dc0a5071d 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicy.java @@ -6,6 +6,8 @@ package com.microsoft.azure.management.keyvault; +import com.microsoft.azure.management.graphrbac.ServicePrincipal; +import com.microsoft.azure.management.graphrbac.User; import com.microsoft.azure.management.resources.fluentcore.arm.models.ChildResource; import com.microsoft.azure.management.resources.fluentcore.model.Attachable; import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; @@ -47,8 +49,6 @@ public interface AccessPolicy extends interface Definition extends DefinitionStages.Blank, - DefinitionStages.WithTenantId, - DefinitionStages.WithApplicationId, DefinitionStages.WithAttach { } @@ -61,15 +61,13 @@ interface DefinitionStages { * * @param the return type of the final {@link WithAttach#attach()} */ - interface Blank extends WithTenantId { + interface Blank extends WithIdentity { } - /** - * The access policy definition stage allowing tenant ID to be specified. - * @param the return type of the final {@link WithAttach#attach()} - */ - interface WithTenantId { - WithPermissions withTenantId(UUID tenantId); + interface WithIdentity { + WithAttach forObjectId(UUID objectId); + WithAttach forUser(User user); + WithAttach forServicePrincipal(ServicePrincipal servicePrincipal); } /** @@ -77,18 +75,54 @@ interface WithTenantId { * @param the return type of the final {@link WithAttach#attach()} */ interface WithPermissions { - WithAttach withPermissionToKey(String key); - WithAttach withPermissionToKeys(List keys); - WithAttach withPermissionToSecret(String secret); - WithAttach withPermissionToSecrets(List secrets); - } - - /** - * The access policy definition stage allowing application ID to be specified. - * @param the return type of the final {@link WithAttach#attach()} - */ - interface WithApplicationId { - WithAttach withApplicationId(UUID applicationId); + WithAttach allowKeyDecrypting(); + WithAttach allowKeyEncrypting(); + WithAttach allowKeyUnwrapping(); + WithAttach allowKeyWrapping(); + WithAttach allowKeyVerifying(); + WithAttach allowKeySigning(); + WithAttach allowKeyGetting(); + WithAttach allowKeyListing(); + WithAttach allowKeyUpdating(); + WithAttach allowKeyCreating(); + WithAttach allowKeyImporting(); + WithAttach allowKeyDeleting(); + WithAttach allowKeyBackingUp(); + WithAttach allowKeyRestoring(); + WithAttach allowKeyAllPermissions(); + WithAttach allowKeyPermission(String permission); + WithAttach allowKeyPermissions(List permissions); + WithAttach disallowKeyDecrypting(); + WithAttach disallowKeyEncrypting(); + WithAttach disallowKeyUnwrapping(); + WithAttach disallowKeyWrapping(); + WithAttach disallowKeyVerifying(); + WithAttach disallowKeySigning(); + WithAttach disallowKeyGetting(); + WithAttach disallowKeyListing(); + WithAttach disallowKeyUpdating(); + WithAttach disallowKeyCreating(); + WithAttach disallowKeyImporting(); + WithAttach disallowKeyDeleting(); + WithAttach disallowKeyBackingUp(); + WithAttach disallowKeyRestoring(); + WithAttach disallowKeyAllPermissions(); + WithAttach disallowKeyPermission(String permission); + WithAttach disallowKeyPermissions(List permissions); + WithAttach allowSecretGetting(); + WithAttach allowSecretListing(); + WithAttach allowSecretSetting(); + WithAttach allowSecretDeleting(); + WithAttach allowSecretAllPermissions(); + WithAttach allowSecretPermission(String permission); + WithAttach allowSecretPermissions(List permissions); + WithAttach disallowSecretGetting(); + WithAttach disallowSecretListing(); + WithAttach disallowSecretSetting(); + WithAttach disallowSecretDeleting(); + WithAttach disallowSecretAllPermissions(); + WithAttach disallowSecretPermission(String permission); + WithAttach disallowSecretPermissions(List permissions); } /** The final stage of the access policy definition. @@ -100,7 +134,6 @@ interface WithApplicationId { */ interface WithAttach extends Attachable.InDefinition, - WithApplicationId, WithPermissions { } } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java index e421a7f73a0a7..46b32579bed6f 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Vault.java @@ -76,7 +76,7 @@ public interface Vault extends interface Definition extends DefinitionStages.Blank, DefinitionStages.WithGroup, - DefinitionStages.WithTenantId, + DefinitionStages.WithTenantIdOrAccessPolicy, DefinitionStages.WithCreate { } @@ -93,11 +93,14 @@ interface Blank extends DefinitionWithRegion { /** * A key vault definition allowing resource group to be set. */ - interface WithGroup extends GroupableResource.DefinitionStages.WithGroup { + interface WithGroup extends GroupableResource.DefinitionStages.WithGroup { + } + + interface WithTenantIdOrAccessPolicy extends WithTenantId, WithAccessPolicy { } interface WithTenantId { - WithCreate withTenantId(UUID tenantId); + WithAccessPolicy withTenantId(UUID tenantId); } /** @@ -116,7 +119,7 @@ interface WithSku { interface WithAccessPolicy { WithCreate withEmptyAccessPolicy(); WithCreate withAccessPolicy(AccessPolicy accessPolicy); - AccessPolicy.DefinitionStages.Blank defineAccessPolicy(String objectId); + AccessPolicy.DefinitionStages.Blank defineAccessPolicy(); } interface WithConfigurations { @@ -134,7 +137,6 @@ interface WithCreate extends Creatable, GroupableResource.DefinitionWithTags, DefinitionStages.WithSku, - DefinitionStages.WithAccessPolicy, DefinitionStages.WithConfigurations { } } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java index 57b08544102ad..03db44b392189 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/AccessPolicyImpl.java @@ -6,6 +6,8 @@ package com.microsoft.azure.management.keyvault.implementation; +import com.microsoft.azure.management.graphrbac.ServicePrincipal; +import com.microsoft.azure.management.graphrbac.User; import com.microsoft.azure.management.keyvault.AccessPolicy; import com.microsoft.azure.management.keyvault.AccessPolicyEntry; import com.microsoft.azure.management.keyvault.Permissions; @@ -26,8 +28,32 @@ class AccessPolicyImpl implements AccessPolicy, AccessPolicy.Definition { - protected AccessPolicyImpl(String name, AccessPolicyEntry innerObject, VaultImpl parent) { - super(name, innerObject, parent); + private enum ALLOWED_KEY_PERMISSIONS { + DECRYPT("Decrypt"), ENCRYPT("Encrypt"), UNWRAPKEY("UnwrapKey"), WRAPKEY("WrapKey"), VERIFY("Verify"), SIGN("Sign"), GET("Get"), LIST("List"), UPDATE("Update"), CREATE("Create"), IMPORT("Import"), DELETE("Delete"), BACKUP("Backup"), RESTORE("Restore"), ALL("All"); + private String value; + ALLOWED_KEY_PERMISSIONS(String value) { + this.value = value; + } + @Override + public String toString() { + return value; + } + } + + private enum ALLOWED_SECRET_PERMISSIONS { + GET("Get"), LIST("List"), SET("Set"), DELETE("Delete"), ALL("All"); + private String value; + ALLOWED_SECRET_PERMISSIONS(String value) { + this.value = value; + } + @Override + public String toString() { + return value; + } + } + + AccessPolicyImpl(AccessPolicyEntry innerObject, VaultImpl parent) { + super(null, innerObject, parent); } @Override @@ -55,63 +81,49 @@ public String name() { return inner().objectId().toString(); } - @Override - public AccessPolicyImpl withApplicationId(UUID applicationId) { - inner().withApplicationId(applicationId); - return this; - } - - @Override - public AccessPolicyImpl withPermissionToKey(String key) { + private void initializeKeyPermissions() { if (inner().permissions() == null) { inner().withPermissions(new Permissions()); } if (inner().permissions().keys() == null) { inner().permissions().withKeys(new ArrayList()); } - inner().permissions().keys().add(key); - return this; } - @Override - public AccessPolicyImpl withPermissionToKeys(List keys) { + private void initializeSecretPermissions() { if (inner().permissions() == null) { inner().withPermissions(new Permissions()); } - if (inner().permissions().keys() == null) { - inner().permissions().withKeys(new ArrayList()); + if (inner().permissions().secrets() == null) { + inner().permissions().withSecrets(new ArrayList()); } - inner().permissions().keys().addAll(keys); + } + + @Override + public AccessPolicyImpl allowKeyPermission(String permission) { + initializeKeyPermissions(); + inner().permissions().keys().add(permission); return this; } @Override - public AccessPolicyImpl withPermissionToSecret(String secret) { - if (inner().permissions() == null) { - inner().withPermissions(new Permissions()); - } - if (inner().permissions().secrets() == null) { - inner().permissions().withSecrets(new ArrayList()); - } - inner().permissions().secrets().add(secret); + public AccessPolicyImpl allowKeyPermissions(List permissions) { + initializeKeyPermissions(); + inner().permissions().keys().addAll(permissions); return this; } @Override - public AccessPolicyImpl withPermissionToSecrets(List secrets) { - if (inner().permissions() == null) { - inner().withPermissions(new Permissions()); - } - if (inner().permissions().secrets() == null) { - inner().permissions().withSecrets(new ArrayList()); - } - inner().permissions().secrets().addAll(secrets); + public AccessPolicyImpl allowSecretPermission(String permission) { + initializeSecretPermissions(); + inner().permissions().secrets().add(permission); return this; } @Override - public AccessPolicyImpl withTenantId(UUID tenantId) { - inner().withTenantId(tenantId); + public AccessPolicyImpl allowSecretPermissions(List permissions) { + initializeSecretPermissions(); + inner().permissions().secrets().addAll(permissions); return this; } @@ -120,4 +132,335 @@ public VaultImpl attach() { parent().withAccessPolicy(this); return parent(); } + + @Override + public AccessPolicyImpl forObjectId(UUID objectId) { + inner().withObjectId(objectId); + return this; + } + + @Override + public AccessPolicyImpl forUser(User user) { + inner().withObjectId(UUID.fromString(user.objectId())); + return this; + } + + @Override + public AccessPolicyImpl forServicePrincipal(ServicePrincipal servicePrincipal) { + inner().withObjectId(UUID.fromString(servicePrincipal.objectId())); + return this; + } + + @Override + public AccessPolicyImpl allowKeyDecrypting() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.DECRYPT.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyEncrypting() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.ENCRYPT.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyUnwrapping() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.UNWRAPKEY.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyWrapping() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.WRAPKEY.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyVerifying() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.VERIFY.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeySigning() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.SIGN.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyGetting() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.GET.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyListing() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.LIST.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyUpdating() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.UPDATE.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyCreating() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.CREATE.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyImporting() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.IMPORT.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyDeleting() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.DELETE.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyBackingUp() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.BACKUP.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyRestoring() { + initializeKeyPermissions(); + inner().permissions().keys().add(ALLOWED_KEY_PERMISSIONS.RESTORE.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowKeyAllPermissions() { + initializeKeyPermissions(); + for(ALLOWED_KEY_PERMISSIONS permission : ALLOWED_KEY_PERMISSIONS.values()) { + inner().permissions().keys().add(permission.toString()); + } + return this; + } + + @Override + public AccessPolicyImpl disallowKeyDecrypting() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.DECRYPT.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyEncrypting() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.ENCRYPT.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyUnwrapping() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.UNWRAPKEY.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyWrapping() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.WRAPKEY.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyVerifying() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.VERIFY.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeySigning() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.SIGN.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyGetting() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.GET.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyListing() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.LIST.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyUpdating() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.UPDATE.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyCreating() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.CREATE.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyImporting() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.IMPORT.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyDeleting() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.DELETE.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyBackingUp() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.BACKUP.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyRestoring() { + initializeKeyPermissions(); + inner().permissions().keys().remove(ALLOWED_KEY_PERMISSIONS.RESTORE.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyAllPermissions() { + initializeKeyPermissions(); + inner().permissions().keys().clear(); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyPermission(String permission) { + initializeKeyPermissions(); + inner().permissions().keys().remove(permission); + return this; + } + + @Override + public AccessPolicyImpl disallowKeyPermissions(List permissions) { + initializeKeyPermissions(); + inner().permissions().keys().removeAll(permissions); + return this; + } + + @Override + public AccessPolicyImpl allowSecretGetting() { + initializeSecretPermissions(); + inner().permissions().keys().add(ALLOWED_SECRET_PERMISSIONS.GET.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowSecretListing() { + initializeSecretPermissions(); + inner().permissions().keys().add(ALLOWED_SECRET_PERMISSIONS.LIST.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowSecretSetting() { + initializeSecretPermissions(); + inner().permissions().keys().add(ALLOWED_SECRET_PERMISSIONS.SET.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowSecretDeleting() { + initializeSecretPermissions(); + inner().permissions().keys().add(ALLOWED_SECRET_PERMISSIONS.DELETE.toString()); + return this; + } + + @Override + public AccessPolicyImpl allowSecretAllPermissions() { + return null; + } + + @Override + public AccessPolicyImpl disallowSecretGetting() { + initializeSecretPermissions(); + inner().permissions().keys().remove(ALLOWED_SECRET_PERMISSIONS.GET.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowSecretListing() { + initializeSecretPermissions(); + inner().permissions().keys().remove(ALLOWED_SECRET_PERMISSIONS.LIST.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowSecretSetting() { + initializeSecretPermissions(); + inner().permissions().keys().remove(ALLOWED_SECRET_PERMISSIONS.SET.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowSecretDeleting() { + initializeSecretPermissions(); + inner().permissions().keys().remove(ALLOWED_SECRET_PERMISSIONS.DELETE.toString()); + return this; + } + + @Override + public AccessPolicyImpl disallowSecretAllPermissions() { + initializeSecretPermissions(); + inner().permissions().keys().clear(); + return this; + } + + @Override + public AccessPolicyImpl disallowSecretPermission(String permission) { + initializeSecretPermissions(); + inner().permissions().keys().remove(permission); + return this; + } + + @Override + public AccessPolicyImpl disallowSecretPermissions(List permissions) { + initializeSecretPermissions(); + inner().permissions().keys().removeAll(permissions); + return this; + } + + @Override + public String key() { + return objectId().toString(); + } } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java index e4a11789202ed..e957e2ec6ce5b 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultImpl.java @@ -120,8 +120,8 @@ public VaultImpl withAccessPolicy(AccessPolicy accessPolicy) { } @Override - public AccessPolicyImpl defineAccessPolicy(String objectId) { - return new AccessPolicyImpl(objectId, new AccessPolicyEntry(), this); + public AccessPolicyImpl defineAccessPolicy() { + return new AccessPolicyImpl(new AccessPolicyEntry(), this); } @Override diff --git a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java index 19ceb7ca66df0..3e9f9bb9ac14d 100644 --- a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java +++ b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/KeyVaultManagementTestBase.java @@ -9,6 +9,7 @@ import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.RestClient; import com.microsoft.azure.credentials.ApplicationTokenCredentials; +import com.microsoft.azure.management.graphrbac.implementation.GraphRbacManager; import com.microsoft.azure.management.keyvault.implementation.KeyVaultManager; import com.microsoft.azure.management.resources.implementation.ResourceManager; import okhttp3.logging.HttpLoggingInterceptor; @@ -18,15 +19,24 @@ */ public abstract class KeyVaultManagementTestBase { protected static ResourceManager resourceManager; + protected static GraphRbacManager graphRbacManager; protected static KeyVaultManager keyVaultManager; + protected static ApplicationTokenCredentials credentials; protected static void createClients() { - ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( + credentials = new ApplicationTokenCredentials( System.getenv("client-id"), System.getenv("domain"), System.getenv("secret"), null); + ApplicationTokenCredentials graphCredentials = new ApplicationTokenCredentials( + System.getenv("client-id"), + System.getenv("domain"), + System.getenv("secret"), + "https://graph.windows.net/", + null); + RestClient restClient = AzureEnvironment.AZURE.newRestClientBuilder() .withCredentials(credentials) .withLogLevel(HttpLoggingInterceptor.Level.BODY) @@ -36,6 +46,9 @@ protected static void createClients() { .authenticate(restClient) .withSubscription(System.getenv("subscription-id")); + graphRbacManager = GraphRbacManager + .authenticate(graphCredentials, System.getenv("domain")); + keyVaultManager = KeyVaultManager .authenticate(restClient, System.getenv("subscription-id")); } diff --git a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java index 47b6524656ac9..3782ec8f26472 100644 --- a/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java +++ b/azure-mgmt-keyvault/src/main/test/com/microsoft/azure/management/keyvault/VaultTests.java @@ -6,6 +6,7 @@ package com.microsoft.azure.management.keyvault; +import com.microsoft.azure.management.graphrbac.ServicePrincipal; import com.microsoft.azure.management.resources.ResourceGroup; import com.microsoft.azure.management.resources.fluentcore.arm.Region; import org.junit.AfterClass; @@ -33,10 +34,18 @@ public static void cleanup() throws Exception { @Test public void canCRUDVault() throws Exception { // CREATE + ServicePrincipal sp = graphRbacManager.servicePrincipals().getByName(credentials.getClientId()); Vault vault = keyVaultManager.vaults().define(VAULT_NAME) .withRegion(Region.US_WEST) .withNewResourceGroup(RG_NAME) - .withTenantId(UUID.fromString("72f988bf-86f1-41af-91ab-2d7cd011db47")) + .withTenantId(UUID.fromString(credentials.getDomain())) + .defineAccessPolicy() + .forServicePrincipal(sp) + .allowKeyGetting() + .allowKeyListing() + .allowKeyCreating() + .allowSecretAllPermissions() + .attach() .create(); Assert.assertNotNull(vault); // GET