com.microsoft.azure.management.keyvault.implementation.AccessPolicyImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-mgmt-keyvault Show documentation
Show all versions of azure-mgmt-keyvault Show documentation
This package contains Microsoft Azure Key Vault Management SDK. This package has been deprecated. A replacement package com.azure.resourcemanager:azure-resourcemanager-keyvault is available as of 31-March-2022. We strongly encourage you to upgrade to continue receiving updates. See Migration Guide https://aka.ms/java-track2-migration-guide for guidance on upgrading. Refer to our deprecation policy https://azure.github.io/azure-sdk/policies_support.html for more details.
/**
* 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 java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import com.microsoft.azure.management.apigeneration.LangDefinition;
import com.microsoft.azure.management.graphrbac.ActiveDirectoryGroup;
import com.microsoft.azure.management.graphrbac.ActiveDirectoryUser;
import com.microsoft.azure.management.graphrbac.ServicePrincipal;
import com.microsoft.azure.management.keyvault.AccessPolicy;
import com.microsoft.azure.management.keyvault.AccessPolicyEntry;
import com.microsoft.azure.management.keyvault.CertificatePermissions;
import com.microsoft.azure.management.keyvault.KeyPermissions;
import com.microsoft.azure.management.keyvault.Permissions;
import com.microsoft.azure.management.keyvault.SecretPermissions;
import com.microsoft.azure.management.keyvault.StoragePermissions;
import com.microsoft.azure.management.keyvault.Vault;
import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.ChildResourceImpl;
/**
* Implementation for AccessPolicy and its parent interfaces.
*/
@LangDefinition
class AccessPolicyImpl extends ChildResourceImpl
implements AccessPolicy, AccessPolicy.Definition,
AccessPolicy.UpdateDefinition, AccessPolicy.Update {
private String userPrincipalName;
private String servicePrincipalName;
AccessPolicyImpl(AccessPolicyEntry innerObject, VaultImpl parent) {
super(innerObject, parent);
inner().withTenantId(UUID.fromString(parent.tenantId()));
}
String userPrincipalName() {
return userPrincipalName;
}
String servicePrincipalName() {
return servicePrincipalName;
}
@Override
public String tenantId() {
if (inner().tenantId() == null) {
return null;
}
return inner().tenantId().toString();
}
@Override
public String objectId() {
if (inner().objectId() == null) {
return null;
}
return inner().objectId();
}
@Override
public String applicationId() {
if (inner().applicationId() == null) {
return null;
}
return inner().applicationId().toString();
}
@Override
public Permissions permissions() {
return inner().permissions();
}
@Override
public String name() {
return inner().objectId();
}
private void initializeKeyPermissions() {
if (inner().permissions() == null) {
inner().withPermissions(new Permissions());
}
if (inner().permissions().keys() == null) {
inner().permissions().withKeys(new ArrayList());
}
}
private void initializeSecretPermissions() {
if (inner().permissions() == null) {
inner().withPermissions(new Permissions());
}
if (inner().permissions().secrets() == null) {
inner().permissions().withSecrets(new ArrayList());
}
}
private void initializeCertificatePermissions() {
if (inner().permissions() == null) {
inner().withPermissions(new Permissions());
}
if (inner().permissions().certificates() == null) {
inner().permissions().withCertificates(new ArrayList());
}
}
private void initializeStoragePermissions() {
if (inner().permissions() == null) {
inner().withPermissions(new Permissions());
}
if (inner().permissions().storage() == null) {
inner().permissions().withStorage(new ArrayList());
}
}
@Override
public AccessPolicyImpl allowKeyPermissions(KeyPermissions... permissions) {
initializeKeyPermissions();
for (KeyPermissions permission : permissions) {
if (!inner().permissions().keys().contains(permission)) {
inner().permissions().keys().add(permission);
}
}
return this;
}
@Override
public AccessPolicyImpl allowKeyPermissions(List permissions) {
initializeKeyPermissions();
for (KeyPermissions permission : permissions) {
if (!inner().permissions().keys().contains(permission)) {
inner().permissions().keys().add(permission);
}
}
return this;
}
@Override
public AccessPolicyImpl allowSecretPermissions(SecretPermissions... permissions) {
initializeSecretPermissions();
for (SecretPermissions permission : permissions) {
if (!inner().permissions().secrets().contains(permission)) {
inner().permissions().secrets().add(permission);
}
}
return this;
}
@Override
public AccessPolicyImpl allowSecretPermissions(List permissions) {
initializeSecretPermissions();
for (SecretPermissions permission : permissions) {
if (!inner().permissions().secrets().contains(permission)) {
inner().permissions().secrets().add(permission);
}
}
return this;
}
@Override
public AccessPolicyImpl allowCertificateAllPermissions() {
for (CertificatePermissions permission : CertificatePermissions.values()) {
allowCertificatePermissions(permission);
}
return this;
}
@Override
public AccessPolicyImpl allowCertificatePermissions(CertificatePermissions... permissions) {
initializeCertificatePermissions();
for (CertificatePermissions permission : permissions) {
if (!inner().permissions().certificates().contains(permission)) {
inner().permissions().certificates().add(permission);
}
}
return this;
}
@Override
public AccessPolicyImpl allowCertificatePermissions(List permissions) {
initializeCertificatePermissions();
for (CertificatePermissions permission : permissions) {
if (!inner().permissions().certificates().contains(permission)) {
inner().permissions().certificates().add(permission);
}
}
return this;
}
@Override
public AccessPolicyImpl allowStorageAllPermissions() {
for (StoragePermissions permission : StoragePermissions.values()) {
allowStoragePermissions(permission);
}
return this;
}
@Override
public AccessPolicyImpl allowStoragePermissions(StoragePermissions... permissions) {
initializeStoragePermissions();
for (StoragePermissions permission : permissions) {
if (!inner().permissions().storage().contains(permission)) {
inner().permissions().storage().add(permission);
}
}
return this;
}
@Override
public AccessPolicyImpl allowStoragePermissions(List permissions) {
initializeStoragePermissions();
for (StoragePermissions permission : permissions) {
if (!inner().permissions().storage().contains(permission)) {
inner().permissions().storage().add(permission);
}
}
return this;
}
@Override
public AccessPolicyImpl disallowCertificateAllPermissions() {
initializeCertificatePermissions();
inner().permissions().secrets().clear();
return this;
}
@Override
public AccessPolicyImpl disallowCertificatePermissions(CertificatePermissions... permissions) {
initializeCertificatePermissions();
inner().permissions().certificates().removeAll(Arrays.asList(permissions));
return this;
}
@Override
public AccessPolicyImpl disallowCertificatePermissions(List permissions) {
initializeCertificatePermissions();
inner().permissions().certificates().removeAll(permissions);
return this;
}
@Override
public VaultImpl attach() {
parent().withAccessPolicy(this);
return parent();
}
@Override
public AccessPolicyImpl forObjectId(String objectId) {
inner().withObjectId(objectId);
return this;
}
@Override
public AccessPolicyImpl forUser(ActiveDirectoryUser user) {
inner().withObjectId(user.id());
return this;
}
@Override
public AccessPolicyImpl forUser(String userPrincipalName) {
this.userPrincipalName = userPrincipalName;
return this;
}
@Override
public AccessPolicyImpl forApplicationId(String applicationId) {
inner().withApplicationId(UUID.fromString(applicationId));
return this;
}
@Override
public AccessPolicyImpl forTenantId(String tenantId) {
inner().withTenantId(UUID.fromString(tenantId));
return this;
}
@Override
public AccessPolicyImpl forGroup(ActiveDirectoryGroup activeDirectoryGroup) {
inner().withObjectId(activeDirectoryGroup.id());
return this;
}
@Override
public AccessPolicyImpl forServicePrincipal(ServicePrincipal servicePrincipal) {
inner().withObjectId(servicePrincipal.id());
return this;
}
@Override
public AccessPolicyImpl forServicePrincipal(String servicePrincipalName) {
this.servicePrincipalName = servicePrincipalName;
return this;
}
@Override
public AccessPolicyImpl allowKeyAllPermissions() {
for (KeyPermissions permission : KeyPermissions.values()) {
allowKeyPermissions(permission);
}
return this;
}
@Override
public AccessPolicyImpl disallowKeyAllPermissions() {
initializeKeyPermissions();
inner().permissions().keys().clear();
return this;
}
@Override
public AccessPolicyImpl disallowKeyPermissions(KeyPermissions... permissions) {
initializeSecretPermissions();
inner().permissions().keys().removeAll(Arrays.asList(permissions));
return this;
}
@Override
public AccessPolicyImpl disallowKeyPermissions(List permissions) {
initializeSecretPermissions();
inner().permissions().keys().removeAll(permissions);
return this;
}
@Override
public AccessPolicyImpl allowSecretAllPermissions() {
for (SecretPermissions permission : SecretPermissions.values()) {
allowSecretPermissions(permission);
}
return this;
}
@Override
public AccessPolicyImpl disallowSecretAllPermissions() {
initializeSecretPermissions();
inner().permissions().secrets().clear();
return this;
}
@Override
public AccessPolicyImpl disallowSecretPermissions(SecretPermissions... permissions) {
initializeSecretPermissions();
inner().permissions().secrets().removeAll(Arrays.asList(permissions));
return this;
}
@Override
public AccessPolicyImpl disallowSecretPermissions(List permissions) {
initializeSecretPermissions();
inner().permissions().secrets().removeAll(permissions);
return this;
}
@Override
public AccessPolicyImpl disallowStorageAllPermissions() {
initializeStoragePermissions();
inner().permissions().storage().clear();
return this;
}
@Override
public AccessPolicyImpl disallowStoragePermissions(StoragePermissions... permissions) {
initializeStoragePermissions();
inner().permissions().storage().removeAll(Arrays.asList(permissions));
return this;
}
@Override
public AccessPolicyImpl disallowStoragePermissions(List permissions) {
initializeStoragePermissions();
inner().permissions().storage().removeAll(permissions);
return this;
}
}