Пример #1
0
        public void Create(CreateOpContext context)
        {
            ExchangeConnector        exconn = (ExchangeConnector)context.Connector;
            ActiveDirectoryConnector adconn = exconn.ActiveDirectoryConnector;

            context.Uid = adconn.Create(context.ObjectClass, context.Attributes, context.Options);
        }
        public Uid CreateObject(ActiveDirectoryConnector connector,
            ObjectClass oclass, ICollection<ConnectorAttribute> attributes)
        {
            // if it exists, remove and recreate
            Filter nameFilter = FilterBuilder.EqualTo(ConnectorAttributeBuilder.Build(
                Name.NAME, ConnectorAttributeUtil.GetNameFromAttributes(attributes).Value));
            ICollection<ConnectorObject> foundObjects = TestHelpers.SearchToList(connector, oclass, nameFilter);
            if ((foundObjects != null) && (foundObjects.Count > 0))
            {
                Assert.AreEqual(1, foundObjects.Count);
                DeleteAndVerifyObject(connector, oclass, foundObjects.ElementAt(0).Uid, false, true);
            }

            // create object
            Uid uid = connector.Create(oclass, attributes, null);
            Assert.IsNotNull(uid);

            return uid;
        }
        public void TestBasics_Group()
        {
            //Initialize Connector
            ActiveDirectoryConnector connector = new ActiveDirectoryConnector();
            connector.Init(ConfigHelper.GetConfiguration());

            Uid uidToDelete = null;
            try
            {
                // create group
                ICollection<ConnectorAttribute> createAttributes = GetNormalAttributes_Group();
                createAttributes.Add(ConnectorAttributeBuilder.Build(ActiveDirectoryConnector.ATT_ACCOUNTS,
                    CreateGroupMember(connector)));

                // create object
                uidToDelete = connector.Create(ActiveDirectoryConnector.groupObjectClass, createAttributes, null);
                Uid createUid = uidToDelete;
                Assert.IsNotNull(createUid);

                // find new object ... have to add groups to list of things to return
                OperationOptionsBuilder optionsBuilder = new OperationOptionsBuilder();
                ICollection<String> attributesToGet = GetDefaultAttributesToGet(ActiveDirectoryConnector.groupObjectClass);
                attributesToGet.Add(ActiveDirectoryConnector.ATT_ACCOUNTS);
                optionsBuilder.AttributesToGet = attributesToGet.ToArray();

                ConnectorObject newObject = GetConnectorObjectFromUid(connector,
                    ActiveDirectoryConnector.groupObjectClass, createUid, optionsBuilder.Build());
                VerifyObject(createAttributes, newObject);
                // update the group - replace
                ICollection<ConnectorAttribute> updateReplaceAttrs =
                    new List<ConnectorAttribute>();
                Name oldName = ConnectorAttributeUtil.GetNameFromAttributes(createAttributes);
                String newName = ActiveDirectoryUtils.GetRelativeName(oldName);
                newName = newName.Trim() + "_new, " + GetProperty(ConfigHelper.CONFIG_PROPERTY_CONTAINER);

                updateReplaceAttrs.Add(createUid);
                updateReplaceAttrs.Add(ConnectorAttributeBuilder.Build(
                    Name.NAME, newName));
                updateReplaceAttrs.Add(ConnectorAttributeBuilder.Build(
                    "description", "New description"));
                uidToDelete = UpdateReplaceAndVerifyObject(connector,
                    ActiveDirectoryConnector.groupObjectClass, createUid, updateReplaceAttrs);
                Uid updateReplaceUid = uidToDelete;

                // update the group - add
                ICollection<ConnectorAttribute> updateAddAttrs =
                    new List<ConnectorAttribute>();
                updateAddAttrs.Add(ConnectorAttributeBuilder.Build(ActiveDirectoryConnector.ATT_ACCOUNTS,
                    CreateGroupMember(connector), CreateGroupMember(connector)));

                uidToDelete = UpdateAddAndVerifyUser(connector,
                    ActiveDirectoryConnector.groupObjectClass, updateReplaceUid, updateAddAttrs, optionsBuilder.Build());
            }
            finally
            {
                if (uidToDelete != null)
                {
                    // delete user
                    DeleteAndVerifyObject(connector, ActiveDirectoryConnector.groupObjectClass, uidToDelete, true, true);
                }
            }
        }
Пример #4
0
        public void Create(CreateOpContext context)
        {
            context.Attributes = DeduplicateEmailAddresses(context, context.Attributes);

            // get recipient type
            string rcptType = ExchangeUtility.GetAttValue(ExchangeConnectorAttributes.AttRecipientType, context.Attributes) as string;

            if (rcptType == null || rcptType.Equals(""))
            {
                rcptType = ExchangeConnectorAttributes.RcptTypeUser;
            }

            ExchangeConnector        exconn = (ExchangeConnector)context.Connector;
            ActiveDirectoryConnector adconn = exconn.ActiveDirectoryConnector;

            PSExchangeConnector.CommandInfo cmdInfoEnable = null;
            PSExchangeConnector.CommandInfo cmdInfoSet    = null;
            switch (rcptType)
            {
            case ExchangeConnectorAttributes.RcptTypeMailBox:
                cmdInfoEnable = PSExchangeConnector.CommandInfo.EnableMailbox;
                cmdInfoSet    = PSExchangeConnector.CommandInfo.SetMailbox;
                break;

            case ExchangeConnectorAttributes.RcptTypeMailUser:
                cmdInfoEnable = PSExchangeConnector.CommandInfo.EnableMailUser;
                cmdInfoSet    = PSExchangeConnector.CommandInfo.SetMailUser;
                break;

            case ExchangeConnectorAttributes.RcptTypeUser:
                break;

            default:
                throw new ArgumentException(
                          context.ConnectorConfiguration.ConnectorMessages.Format(
                              "ex_bad_rcpt", "Recipient type [{0}] is not supported", rcptType));
            }

            // first create the object in AD
            ICollection <ConnectorAttribute> adAttributes = ExchangeUtility.FilterOut(context.Attributes,
                                                                                      PSExchangeConnector.CommandInfo.EnableMailbox,
                                                                                      PSExchangeConnector.CommandInfo.SetMailbox,
                                                                                      PSExchangeConnector.CommandInfo.EnableMailUser,
                                                                                      PSExchangeConnector.CommandInfo.SetMailUser);
            Uid uid = adconn.Create(context.ObjectClass, adAttributes, context.Options);

            if (rcptType == ExchangeConnectorAttributes.RcptTypeUser)
            {
                // AD account only, we do nothing
                context.Uid = uid;
                return;
            }

            // add a empty "EmailAddresses" attribute if needed (address policy is disabled and no addresses are provided)
            ICollection <ConnectorAttribute> enhancedAttributes;
            ConnectorAttribute policyEnabledAttribute = ConnectorAttributeUtil.Find(ExchangeConnectorAttributes.AttEmailAddressPolicyEnabled, context.Attributes);

            if (policyEnabledAttribute != null &&
                ConnectorAttributeUtil.GetBooleanValue(policyEnabledAttribute).HasValue&&
                ConnectorAttributeUtil.GetBooleanValue(policyEnabledAttribute).Value == false &&
                ConnectorAttributeUtil.Find(ExchangeConnectorAttributes.AttPrimarySmtpAddress, context.Attributes) == null &&
                ConnectorAttributeUtil.Find(ExchangeConnectorAttributes.AttEmailAddresses, context.Attributes) == null)
            {
                enhancedAttributes = new HashSet <ConnectorAttribute>(context.Attributes);
                enhancedAttributes.Add(ConnectorAttributeBuilder.Build(ExchangeConnectorAttributes.AttEmailAddresses));
                LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "Added empty EmailAddresses attribute because address policy use is disabled and no addresses were provided");
            }
            else
            {
                enhancedAttributes = context.Attributes;        // no change
            }

            // prepare the command
            Command cmdEnable = ExchangeUtility.GetCommand(cmdInfoEnable, enhancedAttributes, uid, (ExchangeConfiguration)context.ConnectorConfiguration);
            Command cmdSet    = ExchangeUtility.GetCommand(cmdInfoSet, enhancedAttributes, uid, (ExchangeConfiguration)context.ConnectorConfiguration);

            try {
                _helper.InvokePipeline(exconn, cmdEnable);
                _helper.InvokePipeline(exconn, cmdSet);
            }
            catch {
                LOGGER.TraceEvent(TraceEventType.Information, CAT_DEFAULT, "Rolling back AD create for UID: " + uid.GetUidValue());

                // rollback AD create
                try {
                    adconn.Delete(context.ObjectClass, uid, context.Options);
                } catch {
                    LOGGER.TraceEvent(TraceEventType.Warning, CAT_DEFAULT, "Not able to rollback AD create for UID: " + uid.GetUidValue());
                    // note: this is not perfect, we hide the original exception
                    throw;
                }

                // rethrow original exception
                throw;
            }

            context.Uid = uid;
        }