com.microsoft.azure.management.graphrbac.implementation.ActiveDirectoryGroupImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-mgmt-graph-rbac Show documentation
Show all versions of azure-mgmt-graph-rbac Show documentation
This package contains Microsoft Azure Graph RBAC Management SDK. This package has been deprecated. A replacement package com.azure.resourcemanager:azure-resourcemanager-authorization 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.graphrbac.implementation;
import com.microsoft.azure.Page;
import com.microsoft.azure.management.apigeneration.LangDefinition;
import com.microsoft.azure.management.graphrbac.ActiveDirectoryGroup;
import com.microsoft.azure.management.graphrbac.ActiveDirectoryObject;
import com.microsoft.azure.management.graphrbac.ActiveDirectoryUser;
import com.microsoft.azure.management.graphrbac.ServicePrincipal;
import com.microsoft.azure.management.resources.fluentcore.model.implementation.CreatableUpdatableImpl;
import com.microsoft.azure.management.resources.fluentcore.utils.Utils;
import com.microsoft.rest.protocol.SerializerAdapter;
import rx.Observable;
import rx.functions.Action0;
import rx.functions.Func1;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
* Implementation for Group and its parent interfaces.
*/
@LangDefinition(ContainerName = "/Microsoft.Azure.Management.Graph.RBAC.Fluent")
class ActiveDirectoryGroupImpl
extends CreatableUpdatableImpl
implements ActiveDirectoryGroup,
ActiveDirectoryGroup.Definition,
ActiveDirectoryGroup.Update {
private final GraphRbacManager manager;
private GroupCreateParametersInner createParameters;
private String domainName;
private Set membersToAdd;
private Set membersToRemove;
ActiveDirectoryGroupImpl(ADGroupInner innerModel, GraphRbacManager manager) {
super(innerModel.displayName(), innerModel);
this.manager = manager;
this.createParameters = new GroupCreateParametersInner()
.withDisplayName(innerModel.displayName())
.withMailEnabled(false)
.withSecurityEnabled(true);
membersToAdd = new HashSet<>();
membersToRemove = new HashSet<>();
}
@Override
public String id() {
return inner().objectId();
}
@Override
public String name() {
return inner().displayName();
}
@Override
public boolean securityEnabled() {
return Utils.toPrimitiveBoolean(inner().securityEnabled());
}
@Override
public String mail() {
return inner().mail();
}
@Override
public Set listMembers() {
return Collections.unmodifiableSet(new HashSet<>(listMembersAsync().toList().toBlocking().single()));
}
@Override
public Observable listMembersAsync() {
return manager().inner().groups().getGroupMembersAsync(id())
.flatMap(new Func1, Observable>() {
@Override
public Observable call(Page aadObjectInnerPage) {
return Observable.from(aadObjectInnerPage.items());
}
}).map(new Func1() {
@Override
public ActiveDirectoryObject call(AADObjectInner aadObjectInner) {
SerializerAdapter> adapter = manager().inner().restClient().serializerAdapter();
try {
String serialized = adapter.serialize(aadObjectInner);
switch (aadObjectInner.objectType()) {
case "User":
return new ActiveDirectoryUserImpl(adapter.deserialize(serialized, UserInner.class), manager());
case "Group":
return new ActiveDirectoryGroupImpl(adapter.deserialize(serialized, ADGroupInner.class), manager());
case "ServicePrincipal":
return new ServicePrincipalImpl(adapter.deserialize(serialized, ServicePrincipalInner.class), manager());
case "Application":
return new ActiveDirectoryApplicationImpl(adapter.deserialize(serialized, ApplicationInner.class), manager());
default:
return null;
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
}
@Override
public GraphRbacManager manager() {
return manager;
}
@Override
protected Observable getInnerAsync() {
return manager().inner().groups().getAsync(id());
}
@Override
public boolean isInCreateMode() {
return id() == null;
}
@Override
public Observable createResourceAsync() {
Observable> group = Observable.just(this);
if (isInCreateMode()) {
group = manager().inner().groups().createAsync(createParameters)
.map(innerToFluentMap(this));
}
if (!membersToRemove.isEmpty()) {
group = group.flatMap(new Func1