internal static ResourceObject CreateTestResource(string attributeName1, object value1) { ResourceObject resource = client.CreateResource(UnitTestHelper.ObjectTypeUnitTestObjectName); resource.Attributes[attributeName1].SetValue(value1); resource.Save(); return(resource); }
public void CompositeDeleteByIDTest() { ResourceManagementClient client = new ResourceManagementClient(); ResourceObject resource1 = client.CreateResource(UnitTestHelper.ObjectTypeUnitTestObjectName); resource1.Save(); resource1 = client.GetResource(resource1.ObjectID); ResourceObject resource2 = client.CreateResource(UnitTestHelper.ObjectTypeUnitTestObjectName); resource2.Save(); resource2 = client.GetResource(resource2.ObjectID); ResourceObject resource3 = client.CreateResource(UnitTestHelper.ObjectTypeUnitTestObjectName); resource3.Save(); resource3 = client.GetResource(resource3.ObjectID); client.DeleteResources(new List <UniqueIdentifier>() { resource1.ObjectID, resource2.ObjectID, resource3.ObjectID }); try { client.GetResource(resource1.ObjectID); Assert.Fail("The object was still present after the delete operation"); } catch (ResourceNotFoundException) { } try { client.GetResource(resource2.ObjectID); Assert.Fail("The object was still present after the delete operation"); } catch (ResourceNotFoundException) { } try { client.GetResource(resource3.ObjectID); Assert.Fail("The object was still present after the delete operation"); } catch (ResourceNotFoundException) { } }
public string CreateResource(DSResource resource, ResourceOption resourceOption = null) { ResourceOption option = resourceOption == null ? new ResourceOption() : resourceOption; ResourceManagementClient client = getClient(option.ConnectionInfo); ResourceObject objResource = client.CreateResource(resource.ObjectType); convertToResourceObject(resource, ref objResource); objResource.Save(); return(objResource.ObjectID.Value); }
static void Main(string[] args) { // Create an instance of the resource management defaultCredentialClient ResourceManagementClient client = new ResourceManagementClient(); // Get the resource with the account name 'testuser' ResourceObject resource = client.GetResourceByKey("Person", "AccountName", "testuser"); // Write the object to the console Console.WriteLine(resource.ToString()); // Get a single attribute Console.WriteLine(resource.Attributes["AccountName"].StringValue); // Change an attribute resource.Attributes["AccountName"].SetValue("NewUsername"); // Save the resource to the fim service resource.Save(); // Create a new object ResourceObject newResource = client.CreateResource("Person"); newResource.Attributes["AccountName"].SetValue("MyNewAccount"); newResource.Attributes["Domain"].SetValue("FIM-DEV1"); // Save the new object to the fim service newResource.Save(); // Search for the newly created object by anchor ResourceObject foundObject = client.GetResourceByKey("Person", "AccountName", "MyNewAccount"); // Delete the object client.DeleteResource(foundObject); // Print the values of the object Console.WriteLine(foundObject.ToString()); // Search for all Sets foreach (ResourceObject result in client.GetResources("/Set")) { Console.WriteLine(result.ToString()); } }
public void DeleteByObject() { ResourceManagementClient client = new ResourceManagementClient(); ResourceObject resource = client.CreateResource(UnitTestHelper.ObjectTypeUnitTestObjectName); resource.Save(); client.DeleteResource(resource); try { client.GetResource(resource.ObjectID); Assert.Fail("The object was still present after the delete operation"); } catch (ResourceNotFoundException) { } }
public void CreateResource() { ResourceManagementClient client = new ResourceManagementClient(); UniqueIdentifier knownID = new UniqueIdentifier("5f491363-4d59-42f9-8f6c-8fd92cd1fb92"); // Create a template to update a resource with a known ID ResourceObject resource = client.CreateResourceTemplateForUpdate("Person", knownID); resource.Attributes["DisplayName"].SetValue("Test User 3"); try { resource.Save(); } catch (Exception) { // An error occurred while updating the resource throw; } }
public void CreateResouruce() { ResourceManagementClient client = new ResourceManagementClient(); // Create a template for a resource object ResourceObject resource = client.CreateResource("Person"); resource.Attributes["AccountName"].SetValue("user0001"); resource.Attributes["Domain"].SetValue("FIM-DEV1"); resource.Attributes["DisplayName"].SetValue("Test user 1"); try { resource.Save(); } catch (Exception) { // An error occurred while creating the resource throw; } }
public void GetObjectByIDWithAllAttributes() { ResourceManagementClient client = new ResourceManagementClient(); ResourceObject resource = client.CreateResource(UnitTestHelper.ObjectTypeUnitTestObjectName); try { UnitTestHelper.PopulateTestUserData(resource); resource.Save(); resource = client.GetResource(resource.ObjectID); UnitTestHelper.ValidateTestUserData(resource); } finally { if (resource != null && !resource.IsPlaceHolder) { client.DeleteResource(resource); } } }
public string UpdateResource(DSResource resource, bool isDelta = false, ResourceOption resourceOption = null) { ResourceOption option = resourceOption == null ? new ResourceOption() : resourceOption; ResourceManagementClient client = getClient(option.ConnectionInfo); ResourceObject objResource = client.CreateResourceTemplateForUpdate( resource.ObjectType, new UniqueIdentifier(resource.ObjectID)); convertToResourceObject(resource, ref objResource, isDelta); try { objResource.Save(); } catch (AuthorizationRequiredException) { return("AuthorizationRequired"); } return(objResource.ObjectID.Value); }
public string CreateResource(string token, DSResource resource) { if (resource == null) { throw new ArgumentException("resource must be specified"); } ResourceManagementClient client = Utiles.GetClient(repoCache, token); ResourceObject ro = client.CreateResource(resource.ObjectType); Utiles.BuildResourceObject(resource, ref ro); try { ro.Save(); return(ro.ObjectID.Value); } catch (AuthorizationRequiredException e) { throw new AuthZRequiredException(e.Message); } }
public void GetObjectByKeyWithAllAttributes() { ResourceManagementClient client = new ResourceManagementClient(); ResourceObject resource = client.CreateResource(UnitTestHelper.ObjectTypeUnitTestObjectName); string newID = Guid.NewGuid().ToString(); try { UnitTestHelper.PopulateTestUserData(resource, newID); resource.Save(); resource = client.GetResourceByKey(UnitTestHelper.ObjectTypeUnitTestObjectName, AttributeNames.AccountName, newID); UnitTestHelper.ValidateTestUserData(resource); } finally { if (resource != null && !resource.IsPlaceHolder) { client.DeleteResource(resource); } } }
public void GetObjectByKeyFailsOnMultipleResults() { ResourceManagementClient client = new ResourceManagementClient(); ResourceObject resource1 = client.CreateResource(UnitTestHelper.ObjectTypeUnitTestObjectName); ResourceObject resource2 = client.CreateResource(UnitTestHelper.ObjectTypeUnitTestObjectName); string newID = Guid.NewGuid().ToString(); try { UnitTestHelper.PopulateTestUserData(resource1); resource1.Save(); UnitTestHelper.PopulateTestUserData(resource2); resource2.Save(); try { resource1 = client.GetResourceByKey(UnitTestHelper.ObjectTypeUnitTestObjectName, UnitTestHelper.AttributeStringSV, UnitTestHelper.TestDataString1); Assert.Fail("The expectedXpath exception was not thrown"); } catch (TooManyResultsException) { } } finally { if (resource1 != null && !resource1.IsPlaceHolder) { client.DeleteResource(resource1); } if (resource2 != null && !resource2.IsPlaceHolder) { client.DeleteResource(resource2); } } }
public string RemoveValuesFromResource(string id, string attributeName, string[] valuesToRemove, ResourceOption resourceOption = null) { if (valuesToRemove == null || valuesToRemove.Length == 0) { return(id); } ResourceOption option = resourceOption == null ? new ResourceOption() : resourceOption; ResourceManagementClient client = getClient(option.ConnectionInfo); client.RefreshSchema(); ResourceObject objResource = client.GetResource(id, new string[] { attributeName }); if (objResource == null) { throw new Exception($"No Resource was found with ObjectID: {id}"); } foreach (string value in valuesToRemove) { objResource.RemoveValue(attributeName, value); } try { objResource.Save(); } catch (AuthorizationRequiredException) { return("AuthorizationRequired"); } return(objResource.ObjectID.Value); }
public static void CreateMpr(string hostname, NetworkCredential creds, string accountName, string setName, string mprName) { ResourceManagementClient c = new ResourceManagementClient(hostname, creds); Dictionary <string, object> keys = new Dictionary <string, object>(); string[] split = Global.GetNtAccountName(accountName); if (split.Length > 1) { keys.Add("Domain", split[0]); keys.Add("AccountName", split[1]); } else { keys.Add("AccountName", accountName); } ResourceObject user = c.GetResourceByKey("Person", keys); if (user == null) { Logger.Trace($"Person {accountName} was not found. Creating"); user = c.CreateResource("Person"); SecurityIdentifier sid = (SecurityIdentifier) new NTAccount(accountName).Translate(typeof(SecurityIdentifier)); user.SetValue("AccountName", split[1]); user.SetValue("Domain", split[0]); byte[] sidBytes = new byte[sid.BinaryLength]; sid.GetBinaryForm(sidBytes, 0); user.SetValue("ObjectSID", sidBytes); user.Save(); } ResourceObject set = c.GetResourceByKey("Set", "DisplayName", setName); if (set == null) { Logger.Trace($"Set {setName} was not found"); set = c.CreateResource("Set"); } set.SetValue("DisplayName", setName); set.AddValue("ExplicitMember", user); set.SetValue("Description", "Contains the Lithnet AutoSync service account"); set.Save(); Logger.Trace($"Set {setName} saved"); ResourceObject allRequestsSet = c.GetResourceByKey("Set", "DisplayName", "All Requests"); if (allRequestsSet == null) { Logger.Trace("Set All Requests was not found"); allRequestsSet = c.CreateResource("Set"); allRequestsSet.SetValue("DisplayName", "All Requests"); allRequestsSet.SetValue("Filter", "<Filter xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" Dialect=\"http://schemas.microsoft.com/2006/11/XPathFilterDialect\" xmlns=\"http://schemas.xmlsoap.org/ws/2004/09/enumeration\">/Request</Filter>"); allRequestsSet.Save(); Logger.Trace($"Set All Requests created"); } ResourceObject mpr = c.GetResourceByKey("ManagementPolicyRule", "DisplayName", mprName); if (mpr == null) { Logger.Trace($"MPR {mprName} does not exist"); mpr = c.CreateResource("ManagementPolicyRule"); } mpr.SetValue("DisplayName", mprName); mpr.SetValue("Description", "Allows the Lithnet AutoSync service account access to read the msidmCompletedTime attribute from Request objects"); mpr.SetValue("ActionParameter", "msidmCompletedTime"); mpr.SetValue("ActionType", "Read"); mpr.SetValue("GrantRight", true); mpr.SetValue("Disabled", false); mpr.SetValue("ManagementPolicyRuleType", "Request"); mpr.SetValue("ResourceCurrentSet", allRequestsSet); mpr.SetValue("PrincipalSet", set); mpr.Save(); Logger.Trace($"MPR {mprName} saved"); }