September 8, 2009

AzMan Create/Remove/Get Role with C#

We have already seen how to add a store,create an application, add an operation, and create tasks in AzMan using C#. Now, let's go on to creating a role 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 IAzRole AddRole(IAzApplication app, string roleName)
{
if (roleName == null || roleName.Length == 0)
{
throw new ArgumentNullException("roleName", "Role name can not be null or empty.");
}
if (app == null)
{
throw new ArgumentNullException("app", "Application can not be null.");
}

IAzRole role = app.CreateRole(roleName, null);

role.Submit(0, null);

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

app.DeleteRole(roleName , null);

app.Submit(0, null);
}
Get role by name:
 public static IAzRole GetRole(IAzApplication app, string roleName)
{
if (roleName == null || roleName.Length == 0)
{
throw new ArgumentNullException("roleName", "Role name can not be null or empty.");
}
if (app == null)
{
throw new ArgumentNullException("app", "Application can not be null.");
}

return app.OpenRole(roleName, null);
}

No comments:

Post a Comment