Skip to content

Commit

Permalink
Allow specifying upn and spn
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghaolu committed Aug 9, 2016
1 parent 159d5a4 commit 571391e
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
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;
import com.microsoft.rest.ServiceCall;
import com.microsoft.rest.ServiceCallback;

import java.io.IOException;

Expand All @@ -25,7 +27,7 @@ public interface ServicePrincipals extends
* @param objectId the unique object id
* @return an immutable representation of the resource
* @throws GraphErrorException exceptions thrown from the graph API
* @throws IOException exceptions thrown from serialization/deserialization
* @throws IOException exceptions thrown from serialization/deserialization
*/
ServicePrincipal getByObjectId(String objectId) throws GraphErrorException, IOException;

Expand All @@ -35,7 +37,7 @@ public interface ServicePrincipals extends
* @param appId the application id (or the client id)
* @return an immutable representation of the resource
* @throws GraphErrorException exceptions thrown from the graph API
* @throws IOException exceptions thrown from serialization/deserialization
* @throws IOException exceptions thrown from serialization/deserialization
*/
ServicePrincipal getByAppId(String appId) throws GraphErrorException, IOException;

Expand All @@ -45,7 +47,16 @@ public interface ServicePrincipals extends
* @param spn the service principal name
* @return an immutable representation of the resource
* @throws GraphErrorException exceptions thrown from the graph API
* @throws IOException exceptions thrown from serialization/deserialization
* @throws IOException exceptions thrown from serialization/deserialization
*/
ServicePrincipal getByServicePrincipalName(String spn) throws GraphErrorException, IOException;

/**
* Gets the information about a service principal.
*
* @param spn the service principal name
* @param callback the call back to handle response
* @return the Future based service call
*/
ServiceCall<ServicePrincipal> getByServicePrincipalNameAsync(String spn, final ServiceCallback<ServicePrincipal> callback);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
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;
import com.microsoft.rest.ServiceCall;
import com.microsoft.rest.ServiceCallback;

import java.io.IOException;

Expand Down Expand Up @@ -38,4 +40,13 @@ public interface Users extends
* @throws IOException exceptions thrown from serialization/deserialization
*/
User getByUserPrincipalName(String upn) throws GraphErrorException, IOException;

/**
* Gets the information about a user.
*
* @param upn the user principal name
* @param callback the callback to handle the response
* @return an Future based service call
*/
ServiceCall<User> getByUserPrincipalNameAsync(String upn, ServiceCallback<User> callback);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
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 com.microsoft.rest.ServiceCall;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceResponse;

import java.io.IOException;
import java.util.List;

/**
* The implementation of StorageAccounts and its parent interfaces.
Expand Down Expand Up @@ -70,6 +74,32 @@ public ServicePrincipal getByAppId(String appId) throws GraphErrorException, IOE

@Override
public ServicePrincipal getByServicePrincipalName(String spn) throws GraphErrorException, IOException {
return null;
List<ServicePrincipalInner> spList = innerCollection.list(String.format("servicePrincipalNames/any(c:c eq '%s')", spn)).getBody();
if (spList == null || spList.isEmpty()) {
return null;
} else {
return new ServicePrincipalImpl(spList.get(0), innerCollection);
}
}

@Override
public ServiceCall<ServicePrincipal> getByServicePrincipalNameAsync(String spn, final ServiceCallback<ServicePrincipal> callback) {
final ServiceCall<ServicePrincipal> serviceCall = new ServiceCall<>(null);
serviceCall.newCall(innerCollection.getAsync(spn, new ServiceCallback<ServicePrincipalInner>() {
@Override
public void failure(Throwable t) {
callback.failure(t);
serviceCall.failure(t);
}

@Override
public void success(ServiceResponse<ServicePrincipalInner> result) {
ServicePrincipal user = new ServicePrincipalImpl(result.getBody(), innerCollection);
ServiceResponse<ServicePrincipal> clientResponse = new ServiceResponse<>(user, result.getResponse());
callback.success(clientResponse);
serviceCall.success(clientResponse);
}
}).getCall());
return serviceCall;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import com.microsoft.azure.management.graphrbac.Users;
import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.CreatableWrappersImpl;
import com.microsoft.rest.RestException;
import com.microsoft.rest.ServiceCall;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceResponse;

import java.io.IOException;

Expand Down Expand Up @@ -68,4 +71,25 @@ public UserImpl getByObjectId(String objectId) throws GraphErrorException, IOExc
public UserImpl getByUserPrincipalName(String upn) throws GraphErrorException, IOException {
return new UserImpl(innerCollection.get(upn).getBody(), innerCollection);
}

@Override
public ServiceCall<User> getByUserPrincipalNameAsync(String upn, final ServiceCallback<User> callback) {
final ServiceCall<User> serviceCall = new ServiceCall<>(null);
serviceCall.newCall(innerCollection.getAsync(upn, new ServiceCallback<UserInner>() {
@Override
public void failure(Throwable t) {
callback.failure(t);
serviceCall.failure(t);
}

@Override
public void success(ServiceResponse<UserInner> result) {
User user = new UserImpl(result.getBody(), innerCollection);
ServiceResponse<User> clientResponse = new ServiceResponse<User>(user, result.getResponse());
callback.success(clientResponse);
serviceCall.success(clientResponse);
}
}).getCall());
return serviceCall;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ interface Blank<ParentT> extends WithIdentity<ParentT> {
interface WithIdentity<ParentT> {
WithAttach<ParentT> forObjectId(UUID objectId);
WithAttach<ParentT> forUser(User user);
WithAttach<ParentT> forUser(String userPrincipalName);
WithAttach<ParentT> forGroup(Group group);
WithAttach<ParentT> forServicePrincipal(ServicePrincipal servicePrincipal);
WithAttach<ParentT> forServicePrincipal(String servicePrincipalName);
}

/**
Expand Down Expand Up @@ -120,7 +122,10 @@ interface Blank<ParentT> extends WithIdentity<ParentT> {
interface WithIdentity<ParentT> {
WithAttach<ParentT> forObjectId(UUID objectId);
WithAttach<ParentT> forUser(User user);
WithAttach<ParentT> forUser(String userPrincipalName);
WithAttach<ParentT> forGroup(Group group);
WithAttach<ParentT> forServicePrincipal(ServicePrincipal servicePrincipal);
WithAttach<ParentT> forServicePrincipal(String servicePrincipalName);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class AccessPolicyImpl
AccessPolicy.Definition<Vault.DefinitionStages.WithCreate>,
AccessPolicy.UpdateDefinition<Vault.Update>,
AccessPolicy.Update {
String userPrincipalName;
String servicePrincipalName;

AccessPolicyImpl(AccessPolicyEntry innerObject, VaultImpl parent) {
super(innerObject, parent);
Expand Down Expand Up @@ -119,34 +121,48 @@ public VaultImpl attach() {
@Override
public AccessPolicyImpl forObjectId(UUID objectId) {
inner().withObjectId(objectId);
inner().withTenantId(parent().tenantId());
return this;
}

@Override
public AccessPolicyImpl forUser(User user) {
inner().withObjectId(UUID.fromString(user.objectId()));
inner().withTenantId(parent().tenantId());
return this;
}

@Override
public AccessPolicyImpl forUser(String userPrincipalName) {
this.userPrincipalName = userPrincipalName;
return this;
}

@Override
public AccessPolicyImpl forGroup(Group group) {
inner().withObjectId(UUID.fromString(group.objectId()));
inner().withTenantId(parent().tenantId());
return this;
}

@Override
public AccessPolicyImpl forServicePrincipal(ServicePrincipal servicePrincipal) {
inner().withObjectId(UUID.fromString(servicePrincipal.objectId()));
inner().withTenantId(parent().tenantId());
return this;
}

@Override
public AccessPolicyImpl allowKeyAllPermissions() {
initializeKeyPermissions();
// TODO: Add all
public AccessPolicyImpl forServicePrincipal(String servicePrincipalName) {
this.servicePrincipalName = servicePrincipalName;
return this;
}

@Override
public AccessPolicyImpl allowKeyAllPermissions() {
return allowKeyPermissions(KeyPermissions.ALL);
}

@Override
public AccessPolicyImpl disallowKeyAllPermissions() {
initializeKeyPermissions();
Expand All @@ -170,8 +186,7 @@ public AccessPolicyImpl disallowKeyPermissions(List<KeyPermissions> permissions)

@Override
public AccessPolicyImpl allowSecretAllPermissions() {
// TODO: add all
return null;
return allowSecretPermissions(SecretPermissions.ALL);
}

@Override
Expand Down
Loading

0 comments on commit 571391e

Please sign in to comment.