September 9, 2009

AzMan Create/Remove/Get SIDs or UPN ApplicationGroup with C#

We have already seen how to add a store,create an application, add an operation, add tasks, and create roles in AzMan using C#. Now, let's go on to creating an application group within AzMan as well as get the group member names and the group members by their SIDs or UPN using c#. I have uploaded a helper class here which has some comments not included in the short snippets below as well as some other methods (check if exists etc.). This class was designed to work with XML and AD (sorry not sql server yet).
 public static IAzApplicationGroup AddApplicationGroup(IAzApplication app, string applicationGroupName)
{
if (applicationGroupName == null || applicationGroupName.Length == 0)
{
throw new ArgumentNullException("applicationGroupName", "ApplicationGroup name can not be null or empty.");
}
if (app == null)
{
throw new ArgumentNullException("app", "Application can not be null.");
}

IAzApplicationGroup applicationGroup = app.CreateApplicationGroup(applicationGroupName, null);

applicationGroup.Submit(0, null);

return applicationGroup;
}
Now let's remove that group:
 public static void RemoveApplicationGroup(IAzApplication app, string applicationGroupName)
{
if (applicationGroupName == null || applicationGroupName.Length == 0)
{
throw new ArgumentNullException("applicationGroupName", "ApplicationGroup name can not be null or empty.");
}
if (app == null)
{
throw new ArgumentNullException("app", "Application can not be null.");
}

app.DeleteApplicationGroup(applicationGroupName , null);

app.Submit(0, null);
}
We need to get by the SID as well:
public static string[] GetApplicationGroupMembers(IAzApplicationGroup applicationGroup)
{
if (applicationGroup == null)
{
throw new ArgumentNullException("applicationGroup", "Application group can not be null.");
}

Array sourceApplicationGroupMembers = (Array)applicationGroup.Members;
string[] applicationGroupMembers = new string[sourceApplicationGroupMembers.Length];
sourceApplicationGroupMembers.CopyTo(applicationGroupMembers, 0);
return applicationGroupMembers;
}
Check the actual helper class on how to get the user based off UPN as well as a few other methods.

No comments:

Post a Comment