Inheritance: CreateUpdateOpContext
        public void Update(UpdateOpContext context)
        {
            ExchangeConnector exconn = (ExchangeConnector)context.Connector;
            ActiveDirectoryConnector adconn = exconn.ActiveDirectoryConnector;

            adconn.Update(context.UpdateType, context.ObjectClass, context.Uid, context.Attributes, context.Options);
        }
Ejemplo n.º 2
0
 public ICollection<ConnectorAttribute> DetermineNewAttributeValues(UpdateOpContext context, string query)
 {
     ConnectorObject originalObject;
     if (context.UpdateType != UpdateType.REPLACE)
     {
         originalObject = GetCurrentObject(context, query);
     }
     else
     {
         originalObject = null;          // not necessary here
     }
     return DetermineNewAttributeValues(context, originalObject);
 }
        public void Update(UpdateOpContext context)
        {
            ExchangeConnector exconn = (ExchangeConnector)context.Connector;

            ICollection<ConnectorAttribute> attributesForReplace = _helper.DetermineNewAttributeValues(context, context.Uid.GetUidValue()); // query string is the UID value!

            Command cmdSet = ExchangeUtility.GetCommand(
                new PSExchangeConnector.CommandInfo(GetSetCommandName()),
                attributesForReplace, context.Uid, exconn.Configuration);

            try {
                _helper.InvokePipeline(exconn, cmdSet);
            } catch (ObjectNotFoundException e) {
                throw new UnknownUidException("Object with UID " + context.Uid.GetUidValue() + " couldn't be modified", e);
            }
        }
Ejemplo n.º 4
0
        // creates a collection of attributes that correspond to the original ones, but resolves ADD/DELETE using existing values of psuser
        public ICollection<ConnectorAttribute> DetermineNewAttributeValues(UpdateOpContext context, ConnectorObject originalObject)
        {
            if (context.UpdateType == UpdateType.REPLACE)
            {
                // TODO check multivaluedness and updateability (as below)
                return new List<ConnectorAttribute>(context.Attributes);
            }
            else
            {
                Boolean add;
                if (context.UpdateType == UpdateType.ADD)
                {
                    add = true;
                }
                else if (context.UpdateType == UpdateType.DELETE)
                {
                    add = false;
                }
                else
                {
                    throw new ArgumentException("Unsupported update type: " + context.UpdateType);
                }

                Schema schema = null;
                ICollection<ConnectorAttribute> rv = new List<ConnectorAttribute>(context.Attributes.Count);
                foreach (ConnectorAttribute attribute in context.Attributes)
                {
                    ConnectorAttribute originalAttribute = originalObject.GetAttributeByName(attribute.Name);
                    IList<object> newValues = originalAttribute != null && originalAttribute.Value != null ? new List<object>(originalAttribute.Value) : new List<object>();
                    Boolean changed = false;
                    if (attribute.Value != null)
                    {
                        foreach (object item in attribute.Value)
                        {
                            if (add)
                            {
                                if (newValues.Contains(item))
                                {
                                    LOGGER.TraceEvent(TraceEventType.Warning, CAT_DEFAULT, "Trying to add value from " + attribute.Name + " that is already there: " + item);
                                }
                                else
                                {
                                    newValues.Add(item);
                                    changed = true;
                                }
                            }
                            else
                            {
                                if (!newValues.Contains(item))
                                {
                                    LOGGER.TraceEvent(TraceEventType.Warning, CAT_DEFAULT, "Trying to remove value from " + attribute.Name + " that is not there: " + item);
                                }
                                else
                                {
                                    newValues.Remove(item);
                                    changed = true;
                                }
                            }
                        }
                    }
                    if (changed)
                    {
                        ConnectorAttributeBuilder b = new ConnectorAttributeBuilder();
                        b.Name = attribute.Name;
                        b.AddValue(newValues);
                        ConnectorAttribute modified = b.Build();

                        if (schema == null)
                        {
                            ExchangeConnector connector = (ExchangeConnector)context.Connector;
                            schema = connector.Schema();
                        }
                        ObjectClassInfo oci = schema.FindObjectClassInfo(context.ObjectClass.Type);
                        if (oci == null)
                        {
                            throw new InvalidOperationException("No object class info for " + context.ObjectClass.Type + " in the schema");
                        }
                        var cai = ConnectorAttributeInfoUtil.Find(attribute.Name, oci.ConnectorAttributeInfos);
                        if (cai == null)
                        {
                            throw new InvalidOperationException("No connector attribute info for " + context.ObjectClass.Type + " in the schema");
                        }

                        if (!cai.IsUpdateable)
                        {
                            throw new ConnectorSecurityException("Attempt to update a non-updateable attribute (" + attribute.Name + "): " +
                                CollectionUtil.Dump(newValues));
                        }

                        if (newValues.Count > 1 && !cai.IsMultiValued)
                        {
                            throw new InvalidAttributeValueException("More than one value in a single-valued attribute (" + attribute.Name + "): " +
                                    CollectionUtil.Dump(newValues));
                        }
                        rv.Add(modified);
                    }
                }
                return rv;
            }
        }
Ejemplo n.º 5
0
        internal ConnectorObject GetCurrentObject(UpdateOpContext context, string query)
        {
            ConnectorObject currentObject = null;
            LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "Fetching object using query {0}", query);

            ResultsHandler handler = new ResultsHandler()
            {
                Handle = cobject =>
                {
                    //LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "Object-to-be-modified: {0}", CommonUtils.DumpConnectorAttributes(cobject.GetAttributes()));
                    if (currentObject != null)
                    {
                        throw new InvalidOperationException("More than one object complying with " + query + " was found");
                    }
                    currentObject = cobject;
                    return true;
                }
            };

            ((ExchangeConnector) context.Connector).ExecuteQuery(context.ObjectClass, query, handler, null);
            if (currentObject == null)
            {
                throw new ObjectNotFoundException("Object with UID " + context.Uid.GetUidValue() + " was not found");
            }

            return currentObject;
        }
Ejemplo n.º 6
0
        public string DetermineOrigAndNewAttributeValue(UpdateOpContext context, ConnectorObject origObject, ICollection<ConnectorAttribute> attributesForReplace, string attributeName, out string origAttributeValue)
        {
            ConnectorAttribute originalAttribute = origObject.GetAttributeByName(attributeName);
            if (originalAttribute != null)
            {
                origAttributeValue = ConnectorAttributeUtil.GetAsStringValue(originalAttribute);
            }
            else
            {
                origAttributeValue = null;
            }

            ConnectorAttribute newAttribute = ConnectorAttributeUtil.Find(attributeName, attributesForReplace);
            if (newAttribute != null)
            {
                return ConnectorAttributeUtil.GetAsStringValue(newAttribute);
            }
            else
            {
                return origAttributeValue;
            }

            /*
            string deltaValue = ConnectorAttributeUtil.GetAsStringValue(attribute);
            if (attribute == null) {
                return origAttributeValue;
            }
            switch (context.UpdateType) {
                case UpdateType.ADD:
                    if (deltaValue == null) {
                        return origAttributeValue;
                    }
                    if (origAttributeValue != null && !origAttributeValue.Equals(deltaValue)) {
                        throw new ArgumentException("Multiple values for " + attribute.Name + " are not allowed: existing = " + origAttributeValue + ", one being added = " + deltaValue);
                    } else {
                        return deltaValue;
                    }
                case UpdateType.REPLACE:
                    return deltaValue;
                case UpdateType.DELETE:
                    if (deltaValue == null) {
                        return origAttributeValue;
                    }
                    if (origAttributeValue == null || !origAttributeValue.Equals(deltaValue)) {
                        LOGGER.TraceEvent(TraceEventType.Warning, CAT_DEFAULT, "Trying to remove value from " + attribute.Name + " that is not there: " + deltaValue);
                        return origAttributeValue;
                    } else {
                        return null;
                    }
                default:
                    throw new ArgumentException("Invalid update type: " + context.UpdateType);
            } */
        }