Ejemplo n.º 1
0
 public Uid ResolveUsername(ObjectClass objectClass, string username, OperationOptions options)
 {
     Trace.TraceInformation("Invoke ResolveUsername ObjectClass:{0}=>{1}", objectClass.GetObjectClassValue(), username);
     try
     {
         Object uidAfter = ExecuteResolveUsername(_configuration.ResolveUsernameScriptFileName, objectClass,
                                                  username, options);
         if (uidAfter is String)
         {
             Trace.TraceInformation("{0}:{1} resolved", objectClass.GetObjectClassValue(), uidAfter);
             return(new Uid((String)uidAfter));
         }
         if (uidAfter is Uid)
         {
             Trace.TraceInformation("{0}:{1} resolved", objectClass.GetObjectClassValue(), uidAfter);
             return((Uid)uidAfter);
         }
         throw new ConnectorException("ResolveUsername script didn't return with the uid (__UID__) string value");
     }
     catch (Exception e)
     {
         if (e.InnerException != null)
         {
             throw e.InnerException;
         }
         throw;
     }
 }
Ejemplo n.º 2
0
 public Uid Authenticate(ObjectClass objectClass, string username, GuardedString password, OperationOptions options)
 {
     Trace.TraceInformation("Invoke Authenticate ObjectClass:{0}=>{1}", objectClass.GetObjectClassValue(), username);
     try
     {
         Object uidAfter = ExecuteAuthenticate(_configuration.AuthenticateScriptFileName, objectClass, username,
                                               password, options);
         if (uidAfter is String)
         {
             Trace.TraceInformation("{0}:{1} authenticated", objectClass.GetObjectClassValue(), uidAfter);
             return(new Uid((String)uidAfter));
         }
         if (uidAfter is Uid)
         {
             var u = uidAfter as Uid;
             Trace.TraceInformation("{0}:{1} authenticated", objectClass.GetObjectClassValue(), u.GetUidValue());
             return(u);
         }
         throw new ConnectorException("Authenticate script didn't return with the uid (__UID__) string value");
     }
     catch (Exception e)
     {
         if (e.InnerException != null)
         {
             throw e.InnerException;
         }
         throw;
     }
 }
Ejemplo n.º 3
0
        public virtual Uid Update(ObjectClass objectClass, Uid uid, ICollection <ConnectorAttribute> replaceAttributes,
                                  OperationOptions options)
        {
            var  attributesAccessor = new ConnectorAttributesAccessor(replaceAttributes);
            Name newName            = attributesAccessor.GetName();
            Uid  uidAfterUpdate     = uid;

            if (newName != null)
            {
                Trace.TraceInformation("Rename the object {0}:{1} to {2}", objectClass.GetObjectClassValue(),
                                       uid.GetUidValue(), newName.GetNameValue());
                uidAfterUpdate = new Uid(newName.GetNameValue().ToLower());
            }

            if (ObjectClass.ACCOUNT.Equals(objectClass))
            {
            }
            else if (ObjectClass.GROUP.Is(objectClass.GetObjectClassValue()))
            {
                if (attributesAccessor.HasAttribute("members"))
                {
                    throw new InvalidAttributeValueException("Requested to update a read only attribute");
                }
            }
            else
            {
                Trace.TraceWarning("Update of type {0} is not supported",
                                   _configuration.ConnectorMessages.Format(objectClass.GetDisplayNameKey(),
                                                                           objectClass.GetObjectClassValue()));
                throw new NotSupportedException("Update of type" + objectClass.GetObjectClassValue() +
                                                " is not supported");
            }
            return(uidAfterUpdate);
        }
Ejemplo n.º 4
0
 public virtual SyncToken GetLatestSyncToken(ObjectClass objectClass)
 {
     if (ObjectClass.ACCOUNT.Equals(objectClass))
     {
         return(new SyncToken(10));
     }
     Trace.TraceWarning("Sync of type {0} is not supported",
                        _configuration.ConnectorMessages.Format(objectClass.GetDisplayNameKey(),
                                                                objectClass.GetObjectClassValue()));
     throw new NotSupportedException("Sync of type" + objectClass.GetObjectClassValue() + " is not supported");
 }
Ejemplo n.º 5
0
 public virtual Uid ResolveUsername(ObjectClass objectClass, string userName, OperationOptions options)
 {
     if (ObjectClass.ACCOUNT.Equals(objectClass))
     {
         return(new Uid(userName));
     }
     Trace.TraceWarning("ResolveUsername of type {0} is not supported",
                        _configuration.ConnectorMessages.Format(objectClass.GetDisplayNameKey(),
                                                                objectClass.GetObjectClassValue()));
     throw new NotSupportedException("ResolveUsername of type" + objectClass.GetObjectClassValue() +
                                     " is not supported");
 }
Ejemplo n.º 6
0
 public virtual void Delete(ObjectClass objectClass, Uid uid, OperationOptions options)
 {
     if (ObjectClass.ACCOUNT.Equals(objectClass) || ObjectClass.GROUP.Equals(objectClass))
     {
         // do real delete here
     }
     else
     {
         Trace.TraceWarning("Delete of type {0} is not supported",
                            _configuration.ConnectorMessages.Format(objectClass.GetDisplayNameKey(),
                                                                    objectClass.GetObjectClassValue()));
         throw new NotSupportedException("Delete of type" + objectClass.GetObjectClassValue() +
                                         " is not supported");
     }
 }
Ejemplo n.º 7
0
        internal ConnectorObject CreateConnectorObject(ExchangeConnector connector, PSObject psobject, ObjectClass objectClass)
        {
            ConnectorObjectBuilder builder = new ConnectorObjectBuilder();

            string guid = (string)psobject.Properties["guid"].Value.ToString();
            string name = (string)psobject.Properties["name"].Value;

            builder.SetUid(new Uid(guid));
            builder.SetName(new Name(name));

            ObjectClassInfo ocinfo = connector.GetSchema().FindObjectClassInfo(objectClass.GetObjectClassValue());

            IDictionary <string, PSPropertyInfo> properties = psobject.Properties.ToDictionary(psinfo => psinfo.Name);

            LOG.Trace("Building connector object with UID = {0} and Name = {1}", guid, name);
            foreach (ConnectorAttributeInfo cai in ocinfo.ConnectorAttributeInfos)
            {
                if (cai.IsReadable && properties.ContainsKey(cai.Name))
                {
                    object value = properties[cai.Name].Value;
                    LOG.Trace(" - attribute {0} = {1}", cai.Name, value);

                    if (value is PSObject)
                    {
                        var ps = value as PSObject;
                        value = ps.BaseObject;
                        LOG.Trace(" - attribute {0} UNWRAPPED = {1} ({2})", cai.Name, value, value.GetType());
                    }
                    builder.AddAttribute(cai.Name, CommonUtils.ConvertToSupportedForm(cai, value));
                }
            }
            return(builder.Build());
        }
Ejemplo n.º 8
0
        public virtual SyncToken GetLatestSyncToken(ObjectClass objectClass)
        {
            Trace.TraceInformation("Invoke GetLatestSyncToken ObjectClass:{0}", objectClass.GetObjectClassValue());
            SyncToken token = null;

            try
            {
                Object result = ExecuteGetLatestSyncToken(_configuration.SyncScriptFileName, objectClass);
                if (result is SyncToken)
                {
                    token = result as SyncToken;
                }
                else if (null != result)
                {
                    token = new SyncToken(result);
                }
                Trace.TraceInformation("GetLatestSyncToken ok");
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    throw e.InnerException;
                }
                throw;
            }
            return(token);
        }
Ejemplo n.º 9
0
 public virtual Uid Create(ObjectClass objectClass, ICollection <ConnectorAttribute> createAttributes,
                           OperationOptions options)
 {
     if (ObjectClass.ACCOUNT.Equals(objectClass) || ObjectClass.GROUP.Equals(objectClass))
     {
         Name name = ConnectorAttributeUtil.GetNameFromAttributes(createAttributes);
         if (name != null)
         {
             // do real create here
             return(new Uid(ConnectorAttributeUtil.GetStringValue(name).ToLower()));
         }
         throw new InvalidAttributeValueException("Name attribute is required");
     }
     Trace.TraceWarning("Delete of type {0} is not supported",
                        _configuration.ConnectorMessages.Format(objectClass.GetDisplayNameKey(),
                                                                objectClass.GetObjectClassValue()));
     throw new NotSupportedException("Delete of type" + objectClass.GetObjectClassValue() + " is not supported");
 }
Ejemplo n.º 10
0
 public Uid Update(ObjectClass objectClass, Uid uid, ICollection <ConnectorAttribute> valuesToReplace, OperationOptions options)
 {
     Trace.TraceInformation("Invoke Update ObjectClass: {0}/{1}", objectClass.GetObjectClassValue(), uid.GetUidValue());
     try
     {
         Uid uidAfter = ExecuteUpdate(_configuration.UpdateScriptFileName, objectClass, uid, valuesToReplace, options);
         if (uidAfter == null)
         {
             throw new ConnectorException("Update script didn't return with a valid uid (__UID__) value");
         }
         Trace.TraceInformation("{0}:{1} updated", objectClass.GetObjectClassValue(), uidAfter.GetUidValue());
         return(uidAfter);
     }
     catch (Exception e)
     {
         if (e.InnerException != null)
         {
             throw e.InnerException;
         }
         throw;
     }
 }
Ejemplo n.º 11
0
 // implementation of CreateSpiOp
 public virtual Uid Create(ObjectClass objectClass, ICollection <ConnectorAttribute> createAttributes, OperationOptions options)
 {
     Trace.TraceInformation("Invoke Create ObjectClass:{0}", objectClass.GetObjectClassValue());
     try
     {
         Uid uid = ExecuteCreate(_configuration.CreateScriptFileName, objectClass, createAttributes, options);
         if (uid == null)
         {
             throw new ConnectorException("Create script didn't return with a valid uid (__UID__) string value");
         }
         Trace.TraceInformation("{0}:{1} created", objectClass.GetObjectClassValue(), uid.GetUidValue());
         return(uid);
     }
     catch (Exception e)
     {
         if (e.InnerException != null)
         {
             throw e.InnerException;
         }
         throw;
     }
 }
Ejemplo n.º 12
0
        public virtual void Sync(ObjectClass objectClass, SyncToken token, SyncResultsHandler handler,
                                 OperationOptions options)
        {
            if (ObjectClass.ALL.Equals(objectClass))
            {
                //
            }
            else if (ObjectClass.ACCOUNT.Equals(objectClass))
            {
                var builder = new ConnectorObjectBuilder();
                builder.SetUid("3f50eca0-f5e9-11e3-a3ac-0800200c9a66");
                builder.SetName("Foo");
                builder.AddAttribute(ConnectorAttributeBuilder.BuildEnabled(true));

                var deltaBuilder = new SyncDeltaBuilder
                {
                    Object    = builder.Build(),
                    DeltaType = SyncDeltaType.CREATE,
                    Token     = new SyncToken(10)
                };

                foreach (SyncDelta connectorObject in CollectionUtil.NewSet(deltaBuilder.Build()))
                {
                    if (!handler.Handle(connectorObject))
                    {
                        // Stop iterating because the handler stopped processing
                        break;
                    }
                }
            }
            else
            {
                Trace.TraceWarning("Sync of type {0} is not supported",
                                   _configuration.ConnectorMessages.Format(objectClass.GetDisplayNameKey(),
                                                                           objectClass.GetObjectClassValue()));
                throw new NotSupportedException("Sync of type" + objectClass.GetObjectClassValue() + " is not supported");
            }
            ((SyncTokenResultsHandler)handler).HandleResult(new SyncToken(10));
        }
Ejemplo n.º 13
0
        /// <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);
                }
            }
        }
Ejemplo n.º 14
0
        // implementation of DeleteSpiOp
        public virtual void Delete(ObjectClass objectClass, Uid uid, OperationOptions options)
        {
            Trace.TraceInformation("Invoke Delete ObjectClass:{0}/{1}", objectClass.GetObjectClassValue(), uid.GetUidValue());

            try
            {
                ExecuteDelete(_configuration.DeleteScriptFileName, objectClass, uid, options);
                Trace.TraceInformation("Delete ok");
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    throw e.InnerException;
                }
                throw;
            }
        }
Ejemplo n.º 15
0
        // implementation of SearchSpiOp
        public virtual void ExecuteQuery(ObjectClass objectClass, Filter query,
                                         ResultsHandler handler, OperationOptions options)
        {
            Trace.TraceInformation("Invoke ExecuteQuery ObjectClass:{0}", objectClass.GetObjectClassValue());

            try
            {
                ExecuteQuery(_configuration.SearchScriptFileName, objectClass, query, handler, options);
                Trace.TraceInformation("Search ok");
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    throw e.InnerException;
                }
                throw;
            }
        }
        /// <summary>
        /// Implementation of CreateOp.Create
        /// </summary>
        /// <param name="oclass">Object class</param>
        /// <param name="attributes">Object attributes</param>
        /// <param name="options">Operation options</param>
        /// <returns>Uid of the created object</returns>
        public Uid Create(ObjectClass oclass, ICollection <ConnectorAttribute> attributes, OperationOptions options)
        {
            const string operation = "Create";

            ExchangeUtility.NullCheck(oclass, "oclass", this._configuration);
            ExchangeUtility.NullCheck(attributes, "attributes", this._configuration);

            LOG.Info("Exchange.Create method for {0}; attributes:\n{1}", oclass.GetObjectClassValue(), CommonUtils.DumpConnectorAttributes(attributes));

            String database = (String)ExchangeUtility.GetAttValue("Database", attributes);

            LOG.Info("Database attribute before plugins call: " + database);
            plugins.OnBeforeCreate(oclass, attributes, options, _configuration);
            database = (String)ExchangeUtility.GetAttValue("Database", attributes);
            LOG.Info("Database attribute after plugins call: " + database);

            CreateOpContext context = new CreateOpContext()
            {
                Attributes             = attributes,
                Connector              = this,
                ConnectorConfiguration = this._configuration,
                ObjectClass            = oclass,
                OperationName          = operation,
                Options = options
            };

            try {
                _scripting.ExecutePowerShell(context, Scripting.Position.BeforeMain);

                if (!_scripting.ExecutePowerShell(context, Scripting.Position.InsteadOfMain))
                {
                    CreateMain(context);
                }

                _scripting.ExecutePowerShell(context, Scripting.Position.AfterMain);

                return(context.Uid);
            } catch (Exception e) {
                LOG.Error(e, "Exception while executing Create operation: {0}");
                throw;
            }
        }
Ejemplo n.º 17
0
        public virtual void Sync(ObjectClass objectClass, SyncToken token,
                                 SyncResultsHandler handler, OperationOptions options)
        {
            Trace.TraceInformation("Invoke Sync ObjectClass:{0}->{1}", objectClass.GetObjectClassValue(), token);

            try
            {
                ExecuteSync(_configuration.SyncScriptFileName, objectClass, token, handler, options);
                Trace.TraceInformation("Sync ok");
            }
            catch (ConnectorException)
            {
                throw;
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    throw e.InnerException;
                }
                throw;
            }
        }
        // TODO Exchange-specific attributes

        /// <summary>
        /// Implementation of SearchOp.CreateFilterTranslator
        /// </summary>
        /// <param name="oclass">Object class</param>
        /// <param name="options">Operation options</param>
        /// <returns>Filter translator</returns>
        public FilterTranslator <string> CreateFilterTranslator(ObjectClass oclass, OperationOptions options)
        {
            return(_handlers[oclass.GetObjectClassValue()].CreateFilterTranslator(this, oclass, options));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Implementation of CreateOp.Create
        /// </summary>
        /// <param name="oclass">Object class</param>
        /// <param name="attributes">Object attributes</param>
        /// <param name="options">Operation options</param>
        /// <returns>Uid of the created object</returns>
        public Uid Create(ObjectClass oclass, ICollection <ConnectorAttribute> attributes, OperationOptions options)
        {
            const string operation = "Create";

            ExchangeUtility.NullCheck(oclass, "oclass", this._configuration);
            ExchangeUtility.NullCheck(attributes, "attributes", this._configuration);

            LOGGER_API.TraceEvent(TraceEventType.Information, CAT_DEFAULT,
                                  "Exchange.Create method for {0}; attributes:\n{1}", oclass.GetObjectClassValue(), CommonUtils.DumpConnectorAttributes(attributes));

            CreateOpContext context = new CreateOpContext()
            {
                Attributes             = attributes,
                Connector              = this,
                ConnectorConfiguration = this._configuration,
                ObjectClass            = oclass,
                OperationName          = operation,
                Options = options
            };

            try {
                _scripting.ExecutePowerShell(context, Scripting.Position.BeforeMain);

                if (!_scripting.ExecutePowerShell(context, Scripting.Position.InsteadOfMain))
                {
                    CreateMain(context);
                }

                _scripting.ExecutePowerShell(context, Scripting.Position.AfterMain);

                return(context.Uid);
            } catch (Exception e) {
                LOGGER.TraceEvent(TraceEventType.Error, CAT_DEFAULT, "Exception while executing Create operation: {0}", e);
                throw;
            }
        }