public MsPowerShellSyncResults(ObjectClass objectClass, SyncResultsHandler handler)
 {
     _objectClass = objectClass;
     _handler = handler;
 }
 /// <summary>
 /// Implementation of SynOp.Sync
 /// </summary>
 /// <param name="objClass">Object class</param>
 /// <param name="token">Syncronization token</param>
 /// <param name="handler">Handler for syncronization results</param>
 /// <param name="options">Operation options, can be null</param>
 public override void Sync(
     ObjectClass objClass,
     SyncToken token,
     SyncResultsHandler handler,
     OperationOptions options)
 {
     // TODO: implement Sync
     base.Sync(objClass, token, handler, options);
 }
 /// <summary>
 /// Gets the object class info for specified object class, used for schema building
 /// </summary>
 /// <param name="oc">ObjectClass to get info for</param>
 /// <returns>ObjectClass' ObjectClassInfo</returns>
 protected override ObjectClassInfo GetObjectClassInfo(ObjectClass oc)
 {
     ObjectClassInfo ret = CollectionUtil.GetValue(this.mapOcInfo, oc, null) ?? base.GetObjectClassInfo(oc);
     Assertions.NullCheck(ret, "ret");
     return ret;
 }
 public Uid Update(ObjectClass objclass, Uid uid, ICollection<ConnectorAttribute> attrs, OperationOptions options)
 {
     return ((UpdateApiOp)GetOperationCheckSupported(SafeType<APIOperation>.Get<UpdateApiOp>()))
             .Update(objclass, uid, attrs, options);
 }
 /// <summary>
 /// Implementation of SearchOp.ExecuteQuery
 /// </summary>
 /// <param name="oclass">Object class</param>
 /// <param name="query">Query to execute</param>
 /// <param name="handler">Result handler</param>
 /// <param name="options">Operation options</param>
 public override void ExecuteQuery(
     ObjectClass oclass,
     string query,
     ResultsHandler handler,
     OperationOptions options)
 {
     // TODO: Implement ExecuteQuery
     base.ExecuteQuery(oclass, query, handler, options);
 }
 public SearchResult Search(ObjectClass objectClass, Filter filter, ResultsHandler handler, OperationOptions options)
 {
     return ((SearchApiOp)GetOperationCheckSupported(SafeType<APIOperation>.Get<SearchApiOp>())).Search(
             objectClass, filter, handler, options);
 }
 public ISubscription Subscribe(ObjectClass objectClass, SyncToken token, IObserver<SyncDelta> handler, OperationOptions operationOptions)
 {
     return ((ISyncEventSubscriptionApiOp)GetOperationCheckSupported(SafeType<APIOperation>.Get<ISyncEventSubscriptionApiOp>()))
      .Subscribe(objectClass, token, handler, operationOptions);
 }
 // =======================================================================
 // Clone basically..
 // =======================================================================
 /// <summary>
 /// Takes all the attribute from a <see cref="ConnectorObject" /> and add/overwrite
 /// the current attributes.
 /// </summary>
 public ConnectorObjectBuilder Add(ConnectorObject obj)
 {
     // simply add all the attributes it will include (Uid, ObjectClass..)
     foreach (ConnectorAttribute attr in obj.GetAttributes())
     {
         AddAttribute(attr);
     }
     ObjectClass = obj.ObjectClass;
     return this;
 }
 /// <summary>
 /// Determines if this object class is a special object class.
 /// Special object classes include the predefined ones, such as
 /// <see cref="ObjectClass.ACCOUNT"/> and <see cref="ObjectClass.GROUP"/>.
 /// </summary>
 /// <param name="oclass">the object class to test</param>
 /// <returns>true iff the object class is special</returns>
 /// <exception cref="NullReferenceException">if the object class parameter is null</exception>
 public static bool IsSpecial(ObjectClass oclass)
 {
     String name = oclass.GetObjectClassValue();
     return IsSpecialName(name);
 }
        /// <summary>
        /// Updates an AD object (also called by create after object is created)
        /// </summary>
        /// <param name="oclass"></param>
        /// <param name="directoryEntry"></param>
        /// <param name="attributes"></param>
        /// <param name="type"></param>
        /// <param name="config"></param>
        internal void UpdateADObject(ObjectClass oclass, 
            DirectoryEntry directoryEntry, ICollection<ConnectorAttribute> attributes,
            UpdateType type, ActiveDirectoryConfiguration config)
        {
            if(oclass.Equals(ObjectClass.ACCOUNT))
            {
                // translate attribute passed in
                foreach (ConnectorAttribute attribute in attributes)
                {
                    // encountered problems when processing change password at the same time
                    // as setting expired.  It would be set to expired, but the change would
                    // clear that.  So we must ensure that expired comes last.
                    if (OperationalAttributes.PASSWORD_EXPIRED_NAME.Equals(attribute.Name))
                    {
                        continue;
                    }

                    AddConnectorAttributeToADProperties(oclass,
                        directoryEntry, attribute, type);

                    //  Uncommenting the next line is very helpful in
                    //  finding mysterious errors.
                    // Trace.TraceInformation("Committing after setting attribute {0} to {1}", attribute.Name, attribute.Value);
                    // directoryEntry.CommitChanges();
                }

                directoryEntry.CommitChanges();

                // now do the password change.  This is handled separately, because
                // it might be a user changing his own password, or it might be an
                // administrative change.

                GuardedString gsNewPassword = ConnectorAttributeUtil.GetPasswordValue(attributes);
                if (gsNewPassword != null)
                {
                    GuardedString gsCurrentPassword = ConnectorAttributeUtil.GetCurrentPasswordValue(attributes);
                    PasswordChangeHandler changeHandler = new PasswordChangeHandler(_configuration);
                    if (gsCurrentPassword == null)
                    {
                        // just a normal password change
                        changeHandler.changePassword(directoryEntry, gsNewPassword);
                    }
                    else
                    {
                        changeHandler.changePassword(directoryEntry,
                            gsCurrentPassword, gsNewPassword);
                    }

                UserAccountControl.Set(directoryEntry.Properties[ActiveDirectoryConnector.ATT_USER_ACOUNT_CONTROL],
                    UserAccountControl.PASSWD_NOTREQD, false);
                    directoryEntry.CommitChanges();
                }

                // see note in loop above for explaination of this
                ConnectorAttribute expirePasswordAttribute = ConnectorAttributeUtil.Find(
                    OperationalAttributes.PASSWORD_EXPIRED_NAME, attributes);

                if (expirePasswordAttribute != null)
                {
                    AddConnectorAttributeToADProperties(oclass,
                        directoryEntry, expirePasswordAttribute, type);
                    directoryEntry.CommitChanges();
                }
                /*
                UserAccountControl.Set(directoryEntry.Properties[ActiveDirectoryConnector.ATT_USER_ACOUNT_CONTROL],
                    UserAccountControl.PASSWD_NOTREQD, false);
                */
                directoryEntry.CommitChanges();

                HandleNameAndContainerChange(type, directoryEntry, attributes, config);
            }
            else if (oclass.Equals(ActiveDirectoryConnector.groupObjectClass))
            {
                // translate attribute passed in
                foreach (ConnectorAttribute attribute in attributes)
                {
                    // Temporary
                    // Trace.TraceInformation(String.Format("Setting attribute {0} to {1}",
                    //    attribute.Name, attribute.Value));
                    AddConnectorAttributeToADProperties(oclass,
                        directoryEntry, attribute, type);
                    //                  Uncommenting the next line is very helpful in
                    //                  finding mysterious errors.
                    //                 directoryEntry.CommitChanges();
                }

                directoryEntry.CommitChanges();
                HandleNameAndContainerChange(type, directoryEntry, attributes, config);
            }
            else if (oclass.Equals(ActiveDirectoryConnector.ouObjectClass))
            {
                // translate attribute passed in
                foreach (ConnectorAttribute attribute in attributes)
                {
                    // Temporary
                    // Trace.TraceInformation(String.Format("Setting attribute {0} to {1}",
                    //    attribute.Name, attribute.Value));
                    AddConnectorAttributeToADProperties(oclass,
                        directoryEntry, attribute, type);
                    //                  Uncommenting the next line is very helpful in
                    //                  finding mysterious errors.
                    // directoryEntry.CommitChanges();
                }

                directoryEntry.CommitChanges();
                HandleNameAndContainerChange(type, directoryEntry, attributes, config);
            }
            else
            {
                String objectClassName = GetADObjectClass(oclass);
                // translate attribute passed in
                foreach (ConnectorAttribute attribute in attributes)
                {
                    // Temporary
                    // Trace.TraceInformation(String.Format("Setting attribute {0} to {1}",
                    //    attribute.Name, attribute.Value));
                    AddConnectorAttributeToADProperties(oclass,
                        directoryEntry, attribute, type);
                    //                  Uncommenting the next line is very helpful in
                    //                  finding mysterious errors.
                    // directoryEntry.CommitChanges();
                }

                directoryEntry.CommitChanges();
                HandleNameAndContainerChange(type, directoryEntry, attributes, config);
            }
        }
 public ConnectorObject(ObjectClass objectClass, ICollection<ConnectorAttribute> attrs)
 {
     if (objectClass == null)
     {
         throw new ArgumentException("ObjectClass may not be null");
     }
     if (attrs == null || attrs.Count == 0)
     {
         throw new ArgumentException("attrs cannot be empty or null.");
     }
     _objectClass = objectClass;
     _attrs =
     CollectionUtil.NewReadOnlyDictionary(attrs,
                                  value => { return value.Name; });
     if (!_attrs.ContainsKey(Uid.NAME))
     {
         const String MSG = "The ConnectorAttribute set must contain a Uid.";
         throw new ArgumentException(MSG);
     }
     if (!_attrs.ContainsKey(Name.NAME))
     {
         const string MSG = "The ConnectorAttribute set must contain a Name.";
         throw new ArgumentException(MSG);
     }
 }
        // entry may be null, needs to be get fresh in that case
        internal ConnectorAttribute GetConnectorAttributeFromADEntry(ObjectClass oclass,
            String attributeName, DS.SearchResult searchResult, DirectoryEntry entry)
        {
            Boolean ourEntry = false;
            // Boolean translated = false;
            if (searchResult == null)
            {
                throw new ConnectorException(_configuration.ConnectorMessages.Format(
                    "ex_AttributeNull",
                    "Could not add connector attribute to <null> search result"));
            }

            if (entry == null)
            {
                ourEntry = true;
                entry = searchResult.GetDirectoryEntry();
            }
            try
            {
                return _customHandlers.GetCaFromDe(oclass,
                    attributeName, searchResult, entry);
            }
            finally
            {
                if (ourEntry && entry != null)
                {
                    entry.Dispose();
                }
            }
        }
        /// <summary>
        /// Returns the AD ObjectClass associated with a particular
        /// Connector ObjectClass
        /// </summary>
        /// <param name="oclass"></param>
        /// <returns></returns>
        internal String GetADObjectClass(ObjectClass oclass)
        {
            if (oclass.Equals(ObjectClass.ACCOUNT))
            {
                return _configuration.ObjectClass;
            }
            else if (ActiveDirectoryConnector.groupObjectClass.Equals(oclass))
            {
                return "Group";
            }
            else if (ActiveDirectoryConnector.ouObjectClass.Equals(oclass))
            {
                return "organizationalUnit";
            }
            else
            {
                // It's not something I know about, so I'll consult the AD schema.
                // if it's there, fine, but if not throw an exception.

                //first check to see if we have seen it before.
                String objectClassName = oclass.GetObjectClassValue();
                if(_knownObjectClasses.Contains(objectClassName))
                {
                    return objectClassName;
                }

                // if we havent seen it before, consult AD's schema
                ActiveDirectorySchema ADSchema = GetADSchema();
                ActiveDirectorySchemaClass ADSchemaClass = null;
                try
                {
                    ADSchemaClass = ADSchema.FindClass(objectClassName);
                    _knownObjectClasses.Add(objectClassName);
                    return objectClassName;
                }
                catch (ActiveDirectoryObjectNotFoundException exception)
                {
                    String msg = _configuration.ConnectorMessages.Format(
                        "ex_ObjectClassInvalidForConnector",
                        "ObjectClass \'{0}\' is not valid for this connector",
                        objectClassName);
                    throw new ConnectorException(msg);
                }

            }
        }
        internal void AddConnectorAttributeToADProperties(ObjectClass oclass,
            DirectoryEntry directoryEntry, ConnectorAttribute attribute,
            UpdateType type)
        {
            // Boolean translated = false;
            if (directoryEntry == null)
            {
                throw new ConnectorException(_configuration.ConnectorMessages.Format(
                    "ex_CouldNotAddNullAttributeToDe",
                    "Could not add connector attribute to <null> directory entry"));
            }

            _customHandlers.UpdateDeFromCa(oclass, type,
                directoryEntry, attribute);
        }
 public ConnectorObject GetObject(ObjectClass objClass, Uid uid, OperationOptions options)
 {
     return ((GetApiOp)GetOperationCheckSupported(SafeType<APIOperation>.Get<GetApiOp>()))
             .GetObject(objClass, uid, options);
 }
 /// <summary>
 /// Create a QualifiedUid.
 /// </summary>
 /// <param name="objectClass">The object class. May not be null.</param>
 /// <param name="uid">The uid. May not be null.</param>
 public QualifiedUid(ObjectClass objectClass,
     Uid uid)
 {
     Assertions.NullCheck(objectClass, "objectClass");
     Assertions.NullCheck(uid, "uid");
     _objectClass = objectClass;
     _uid = uid;
 }
 public Uid ResolveUsername(ObjectClass objectClass, String username, OperationOptions options)
 {
     return ((ResolveUsernameApiOp)GetOperationCheckSupported(SafeType<APIOperation>.Get<ResolveUsernameApiOp>())).ResolveUsername(
             objectClass, username, options);
 }
 public ConnectorAttribute NormalizeAttribute(ObjectClass oclass, ConnectorAttribute attribute)
 {
     if (attribute.Is("foo"))
     {
         String val = ConnectorAttributeUtil.GetStringValue(attribute);
         return ConnectorAttributeBuilder.Build("foo", val.Trim());
     }
     else
     {
         return attribute;
     }
 }
 public ISubscription Subscribe(ObjectClass objectClass, Filter eventFilter, IObserver<ConnectorObject> handler,
     OperationOptions operationOptions)
 {
     return ((IConnectorEventSubscriptionApiOp)GetOperationCheckSupported(SafeType<APIOperation>.Get<IConnectorEventSubscriptionApiOp>()))
      .Subscribe(objectClass, eventFilter, handler, operationOptions);
 }
 public void TestObjectClass()
 {
     ObjectClass v1 = new ObjectClass("test");
     ObjectClass v2 = (ObjectClass)CloneObject(v1);
     Assert.AreEqual(v1, v2);
 }
 public SyncToken Sync(ObjectClass objectClass, SyncToken token,
     SyncResultsHandler handler,
     OperationOptions options)
 {
     return ((SyncApiOp)GetOperationCheckSupported(SafeType<APIOperation>.Get<SyncApiOp>()))
     .Sync(objectClass, token, handler, options);
 }
 public Uid Authenticate(ObjectClass objectClass, String username, GuardedString password, OperationOptions options)
 {
     return ((AuthenticationApiOp)GetOperationCheckSupported(SafeType<APIOperation>.Get<AuthenticationApiOp>())).Authenticate(
             objectClass, username, password, options);
 }
 /// <summary>
 /// Implementation of SearchOp.CreateFilterTranslator
 /// </summary>
 /// <param name="oclass">Object class</param>
 /// <param name="options">Operation options</param>
 /// <returns>Exchange specific Filter translator</returns>
 public override Org.IdentityConnectors.Framework.Common.Objects.Filters.FilterTranslator<string> CreateFilterTranslator(
     ObjectClass oclass,
     OperationOptions options)
 {
     // TODO: Implement CreateFilterTranslator
     return base.CreateFilterTranslator(oclass, options);
 }
 public Uid Create(ObjectClass oclass, ICollection<ConnectorAttribute> attrs, OperationOptions options)
 {
     return ((CreateApiOp)GetOperationCheckSupported(SafeType<APIOperation>.Get<CreateApiOp>())).Create(oclass, attrs, options);
 }
 /// <summary>
 /// Implementation of SynOp.GetLatestSyncToken
 /// </summary>
 /// <param name="objectClass">Object class</param>
 /// <returns><see cref="SyncToken" /> of the last sync</returns>
 public override SyncToken GetLatestSyncToken(ObjectClass objectClass)
 {
     // TODO: Implement GetLatestSyncToken
     return base.GetLatestSyncToken(objectClass);
 }
 public void Delete(ObjectClass objClass, Uid uid, OperationOptions options)
 {
     ((DeleteApiOp)GetOperationCheckSupported(SafeType<APIOperation>.Get<DeleteApiOp>()))
         .Delete(objClass, uid, options);
 }
 /// <summary>
 /// Implementation of UpdateOp.Update
 /// </summary>
 /// <param name="type">Update type</param>
 /// <param name="oclass">Object class</param>
 /// <param name="attributes">Object attributes</param>
 /// <param name="options">Operation options</param>
 /// <returns><see cref="Uid"/> of the updated object</returns>
 public override Uid Update(
     UpdateType type,
     ObjectClass oclass,
     ICollection<ConnectorAttribute> attributes,
     OperationOptions options)
 {
     // TODO: Implement Update
     return base.Update(type, oclass, attributes, options);
 }
 public SyncToken GetLatestSyncToken(ObjectClass objectClass)
 {
     return ((SyncApiOp)GetOperationCheckSupported(SafeType<APIOperation>.Get<SyncApiOp>()))
     .GetLatestSyncToken(objectClass);
 }
        /// <summary>
        /// Implementation of CreateOp.Create
        /// </summary>
        /// <param name="oclass">Object class</param>(oc
        /// <param name="attributes">Object attributes</param>
        /// <param name="options">Operation options</param>
        /// <returns><see cref="Uid"/> of the created object</returns>
        public override Uid Create(
            ObjectClass oclass,
            ICollection<ConnectorAttribute> attributes,
            OperationOptions options)
        {
            const string METHOD = "Create";
            Debug.WriteLine(METHOD + ":entry", ClassName);

            // first create the object in AD
            Uid uid = base.Create(oclass, attributes, options);

            try
            {
                if (oclass.Is(MailboxName))
                {
                    // enable mailbox for person
                    Command cmd = ExchangeUtility.GetCommand(CommandInfo.EnableMailbox, attributes, this.configuration);
                    this.runspace.InvokePipeline(cmd);
                }
                else if (oclass.Is(MailUserName))
                {
                    // enable mailuser
                    Command cmd = ExchangeUtility.GetCommand(CommandInfo.EnableMailUser, attributes, this.configuration);
                    this.runspace.InvokePipeline(cmd);
                }

                Debug.WriteLine(METHOD + ":exit", ClassName);
            }
            catch
            {
                // do the rollback - delete the object by uid
                // no need to check the uid is null, ensured by the create contract
                this.Delete(oclass, uid, options);
                throw;
            }

            return uid;
        }
 public ObjectClassInfo GetObjectClassInfo(ExchangeConnector connector, ObjectClass oc)
 {
     return connector.GetObjectClassInfoGeneric(oc);
 }