MS Exchange specific configuration
Inheritance: Org.IdentityConnectors.ActiveDirectory.ActiveDirectoryConfiguration
Beispiel #1
0
        // TODO move to appropriate place
        /// <summary>
        /// helper method for searching object in AD by UID
        /// </summary>
        /// <param name="uid">Uid of the searched </param>
        /// <param name="oclass">Object class</param>
        /// <param name="options">Operation options</param>
        /// <returns>Connector object found by the Uid</returns>
        internal ConnectorObject ADSearchByUid(ExchangeConnector connector, Uid uid, ObjectClass oclass, OperationOptions options)
        {
            ExchangeConfiguration configuration = connector.Configuration;

            ExchangeUtility.NullCheck(uid, "uid", configuration);
            ExchangeUtility.NullCheck(oclass, "oclass", configuration);
            if (options == null)
            {
                options = new OperationOptionsBuilder().Build();
            }

            ConnectorObject ret        = null;
            Filter          filter     = FilterBuilder.EqualTo(uid);
            var             translator = connector.ActiveDirectoryConnector.CreateFilterTranslator(oclass, options);
            IList <string>  queries    = translator.Translate(filter);

            if (queries.Count == 1)
            {
                ResultsHandler handler = new ResultsHandler()
                {
                    Handle = cobject =>
                    {
                        ret = cobject;
                        return(false);
                    }
                };
                connector.ActiveDirectoryConnector.ExecuteQuery(oclass, queries[0], handler, options);
            }

            return(ret);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the Exchange user using powershell Get-User command
        /// </summary>
        /// <param name="cmdInfo">command info to get the user</param>
        /// <param name="attributes">attributes containing the Name</param>
        /// <returns><see cref="PSObject"/> with user info</returns>
        private PSObject GetUser(ExchangeConnector connector, PSExchangeConnector.CommandInfo cmdInfo, Name nameAttribute)
        {
            ExchangeConfiguration configuration = connector.Configuration;
            // assert we have user name
            string name = nameAttribute.GetNameValue();

            ExchangeUtility.NullCheck(name, "User name", configuration);

            ICollection <ConnectorAttribute> attributes = new List <ConnectorAttribute>();

            attributes.Add(nameAttribute);
            Command cmdUser = ExchangeUtility.GetCommand(cmdInfo, attributes, configuration);
            ICollection <PSObject> users = _helper.InvokePipeline(connector, cmdUser);

            if (users.Count == 1)
            {
                foreach (PSObject obj in users)
                {
                    return(obj);
                }
            }

            throw new ArgumentException(
                      configuration.ConnectorMessages.Format(
                          "ex_bad_username", "Provided User name is not unique or not existing"));
        }
        /// <summary>
        /// Inits the connector with configuration injected
        /// </summary>
        /// <param name="configuration">Initialized Exchange configuration</param>
        public override void Init(Configuration configuration)
        {
            base.Init(configuration);
            this.configuration = (ExchangeConfiguration)configuration;

            // create runspace instance, will be alive as long as the connector instance is alive
            this.runspace = new RunSpaceInstance(RunSpaceInstance.SnapIn.Exchange, configuration.ConnectorMessages);

            // read the object class info definitions
            this.mapOcInfo = ExchangeUtility.GetOCInfo();
        }
        // ====================================== HERE ARE OBJECT-CLASS-INDEPENDENT CONNECTOR PARTS =====================================

        #region Connector Members
        /// <summary>
        /// Inits the connector with configuration injected
        /// </summary>
        /// <param name="configuration">Connector configuration</param>
        public void Init(Configuration configuration)
        {
            LOG.Info("ExchangeConnector.Init: entry");

            _configuration = (ExchangeConfiguration)configuration;
            _activeDirectoryConnector.Init(configuration);
            _schema           = null;
            _objectClassInfos = null;
            Schema();
            _powershell = new ExchangePowerShellSupport(_configuration.ExchangeVersion, _configuration.ExchangeUri,
                                                        _configuration.ConnectorMessages);
            _scripting = new Scripting(_configuration.ScriptingConfigurationFile, _powershell);

            LOG.Info("ExchangeConnector.Init: exit");
        }
 /// <summary>
 /// Inits the connector with configuration injected
 /// </summary>
 /// <param name="configuration">Connector configuration</param>
 public override void Init(Configuration configuration)
 {
     this.configuration = (ExchangeConfiguration)configuration;
     base.Init(configuration);
     this.runspace = new RunSpaceInstance(RunSpaceInstance.SnapIn.Exchange, configuration.ConnectorMessages);
 }
        /// <summary>
        /// Inits the connector with configuration injected
        /// </summary>
        /// <param name="configuration">Initialized Exchange configuration</param>
        public override void Init(Configuration configuration)
        {
            base.Init(configuration);
            this.configuration = (ExchangeConfiguration)configuration;

            // create runspace instance, will be alive as long as the connector instance is alive
            this.runspace = new RunSpaceInstance(RunSpaceInstance.SnapIn.Exchange, configuration.ConnectorMessages);

            // read the object class info definitions
            this.mapOcInfo = ExchangeUtility.GetOCInfo();
        }
Beispiel #7
0
        /// <summary>
        /// Creates command based on the commanf info, reading the calues from attributes
        /// </summary>
        /// <param name="cmdInfo">Command defition</param>
        /// <param name="attributes">Attribute values</param>
        /// <param name="config">Configuration object</param>
        /// <returns>
        /// Ready to execute Command
        /// </returns>
        /// <exception cref="ArgumentNullException">if some of the param is null</exception>
        internal static Command GetCommand(PSExchangeConnector.CommandInfo cmdInfo, ICollection <ConnectorAttribute> attributes, ExchangeConfiguration config)
        {
            Assertions.NullCheck(cmdInfo, "cmdInfo");
            Assertions.NullCheck(attributes, "attributes");

            // create command
            Command cmd = new Command(cmdInfo.Name);

            // map name attribute, if mapping specified
            if (!string.IsNullOrEmpty(cmdInfo.NameParameter))
            {
                object val = GetAttValue(Name.NAME, attributes);
                if (val != null)
                {
                    cmd.Parameters.Add(cmdInfo.NameParameter, val);
                }
            }

            foreach (string attName in cmdInfo.Parameters)
            {
                object val = GetAttValue(attName, attributes);
                if (val == null && attName.Equals("DomainController"))
                {
                    // add domain controller if not provided
                    val = ActiveDirectoryUtils.GetDomainControllerName(config);
                }

                if (val != null)
                {
                    cmd.Parameters.Add(attName, val);
                }
            }

            return(cmd);
        }
Beispiel #8
0
        /// <summary>
        /// Creates Exchange 2010 Assembly Resolver, <see cref="ResolveEventHandler"/>
        /// </summary>
        /// <param name="sender">The source of the event</param>
        /// <param name="args">A <see cref="System.ResolveEventArgs"/> that contains the event data</param>
        /// <returns>Assembly resolver that resolves Exchange 2010 assemblies</returns>
//        internal static Assembly AssemblyResolver2010(object sender, ResolveEventArgs args)
//        {
//            // Add path for the Exchange 2010 DLLs
//            if (args.Name.Contains("Microsoft.Exchange"))
//            {
//                string installPath = GetRegistryStringValue(Exchange2010RegKey, ExchangeRegValueName);
//                installPath += "\\bin\\" + args.Name.Split(',')[0] + ".dll";
//                return Assembly.LoadFrom(installPath);
//            }
//
//            return null;
//        }


        /// <summary>
        /// reads the object class info definitions from xml
        /// </summary>
        /// <returns>Dictionary of object classes</returns>
        //internal static IDictionary<ObjectClass, ObjectClassInfo> GetOCInfo()
        //{
        //return CommonUtils.GetOCInfoFromFile(FileObjectClassDef);
        //}

        internal static Command GetCommand(PSExchangeConnector.CommandInfo cmdInfo, ExchangeConfiguration config)
        {
            return(GetCommand(cmdInfo, null, null, null, config));
        }
Beispiel #9
0
        /// <summary>
        /// Creates command based on the commanf info, reading the calues from attributes
        /// </summary>
        /// <param name="cmdInfo">Command defition</param>
        /// <param name="attributes">Attribute values - UID in these is ignored! It should be passed as a separate parameter</param>
        /// <param name="config">Configuration object</param>
        /// <returns>
        /// Ready to execute Command
        /// </returns>
        /// <exception cref="ArgumentNullException">if some of the param is null</exception>
        internal static Command GetCommand(PSExchangeConnector.CommandInfo cmdInfo, ICollection <ConnectorAttribute> attributes, Uid uidAttribute, Name nameAttribute, ExchangeConfiguration config)
        {
            Assertions.NullCheck(cmdInfo, "cmdInfo");

            LOG.Trace("GetCommand: cmdInfo name = {0}", cmdInfo.Name);

            ISet <string> parametersSet = new HashSet <string>();

            // create command
            Command cmd = new Command(cmdInfo.Name);

            if (!string.IsNullOrEmpty(cmdInfo.UidParameter) && !parametersSet.Contains(cmdInfo.UidParameter))
            {
                Uid    uidAttr = uidAttribute != null ? uidAttribute : ConnectorAttributeUtil.GetUidAttribute(attributes);
                string uid     = uidAttr != null?uidAttr.GetUidValue() : null;

                if (uid != null)
                {
                    cmd.Parameters.Add(cmdInfo.UidParameter, ActiveDirectoryUtils.ConvertADGUIDtoObjectGUID(uid));
                    parametersSet.Add(cmdInfo.UidParameter);
                }
            }

            // map name attribute, if mapping specified
            if (!string.IsNullOrEmpty(cmdInfo.NameParameter) && !parametersSet.Contains(cmdInfo.NameParameter))
            {
                Name   nameAttr = nameAttribute != null ? nameAttribute : ConnectorAttributeUtil.GetNameFromAttributes(attributes);
                string name     = nameAttr != null?nameAttr.GetNameValue() : null;;
                if (name != null)
                {
                    cmd.Parameters.Add(cmdInfo.NameParameter, name);
                    parametersSet.Add(cmdInfo.NameParameter);
                }
            }

            if (cmdInfo.UsesConfirm)
            {
                cmd.Parameters.Add("confirm", false);
                parametersSet.Add("confirm");
            }

            if (cmdInfo.UsesDomainController)
            {
                cmd.Parameters.Add("DomainController", ActiveDirectoryUtils.GetDomainControllerName(config));
                parametersSet.Add("DomainController");
            }

            // TODO check this only for user-related operations
            bool emailAddressesPresent     = GetAttValues(ExchangeConnectorAttributes.AttEmailAddresses, attributes) != null;
            bool primarySmtpAddressPresent = GetAttValues(ExchangeConnectorAttributes.AttPrimarySmtpAddress, attributes) != null;

            if (emailAddressesPresent && primarySmtpAddressPresent)
            {
                throw new ArgumentException(ExchangeConnectorAttributes.AttEmailAddresses + " and " + ExchangeConnectorAttributes.AttPrimarySmtpAddress + " cannot be both set.");
            }

            if (attributes != null)
            {
                foreach (string attName in cmdInfo.Parameters)
                {
                    object valueToSet = null;

                    ConnectorAttribute attribute = ConnectorAttributeUtil.Find(attName, attributes);
                    if (attribute != null)
                    {
                        if (attribute.Value != null && attribute.Value.Count > 1)
                        {
                            List <string> stringValues = new List <string>();
                            foreach (object val in attribute.Value)
                            {
                                stringValues.Add(val.ToString());
                            }
                            valueToSet = stringValues.ToArray();
                        }
                        else
                        {
                            valueToSet = ConnectorAttributeUtil.GetSingleValue(attribute);
                        }
                        if (parametersSet.Contains(attName))
                        {
                            throw new InvalidOperationException("Parameter " + attName + " is already defined for command " + cmdInfo.Name);
                        }
                        cmd.Parameters.Add(attName, valueToSet);
                        parametersSet.Add(attName);
                    }
                }
            }

            LOG.Trace("GetCommand exit: cmdInfo name = {0}", cmdInfo.Name);
            return(cmd);
        }
Beispiel #10
0
 internal static Command GetCommand(PSExchangeConnector.CommandInfo cmdInfo, ICollection <ConnectorAttribute> attributes, Uid uidAttribute, ExchangeConfiguration config)
 {
     return(GetCommand(cmdInfo, attributes, uidAttribute, null, config));
 }
        /// <summary>
        /// Creates command based on the commanf info, reading the calues from attributes
        /// </summary>
        /// <param name="cmdInfo">Command defition</param>
        /// <param name="attributes">Attribute values</param>
        /// <param name="config">Configuration object</param>
        /// <returns>
        /// Ready to execute Command
        /// </returns>
        /// <exception cref="ArgumentNullException">if some of the param is null</exception>
        internal static Command GetCommand(PSExchangeConnector.CommandInfo cmdInfo, ICollection<ConnectorAttribute> attributes, ExchangeConfiguration config)
        {
            Assertions.NullCheck(cmdInfo, "cmdInfo");
            Assertions.NullCheck(attributes, "attributes");

            // create command
            Command cmd = new Command(cmdInfo.Name);

            // map name attribute, if mapping specified
            if (!string.IsNullOrEmpty(cmdInfo.NameParameter))
            {
                object val = GetAttValue(Name.NAME, attributes);
                if (val != null)
                {
                    cmd.Parameters.Add(cmdInfo.NameParameter, val);
                }
            }

            foreach (string attName in cmdInfo.Parameters)
            {
                object val = GetAttValue(attName, attributes);
                if (val == null && attName.Equals("DomainController"))
                {
                    // add domain controller if not provided
                    val = ActiveDirectoryUtils.GetDomainControllerName(config);
                }

                if (val != null)
                {
                    cmd.Parameters.Add(attName, val);
                }
            }

            return cmd;
        }
Beispiel #12
0
        /// <summary>
        /// Creates command based on the commanf info, reading the calues from attributes
        /// </summary>
        /// <param name="cmdInfo">Command defition</param>
        /// <param name="attributes">Attribute values - UID in these is ignored! It should be passed as a separate parameter</param>
        /// <param name="config">Configuration object</param>
        /// <returns>
        /// Ready to execute Command
        /// </returns>
        /// <exception cref="ArgumentNullException">if some of the param is null</exception>
        internal static Command GetCommand(PSExchangeConnector.CommandInfo cmdInfo, ICollection<ConnectorAttribute> attributes, Uid uidAttribute, Name nameAttribute, ExchangeConfiguration config)
        {
            Assertions.NullCheck(cmdInfo, "cmdInfo");

            LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "GetCommand: cmdInfo name = {0}", cmdInfo.Name);

            ISet<string> parametersSet = new HashSet<string>();

            // create command
            Command cmd = new Command(cmdInfo.Name);

            if (!string.IsNullOrEmpty(cmdInfo.UidParameter) && !parametersSet.Contains(cmdInfo.UidParameter))
            {
                Uid uidAttr = uidAttribute != null ? uidAttribute : ConnectorAttributeUtil.GetUidAttribute(attributes);
                string uid = uidAttr != null ? uidAttr.GetUidValue() : null;
                if (uid != null)
                {
                    cmd.Parameters.Add(cmdInfo.UidParameter, ActiveDirectoryUtils.ConvertADGUIDtoObjectGUID(uid));
                    parametersSet.Add(cmdInfo.UidParameter);
                }
            }

            // map name attribute, if mapping specified
            if (!string.IsNullOrEmpty(cmdInfo.NameParameter) && !parametersSet.Contains(cmdInfo.NameParameter))
            {
                Name nameAttr = nameAttribute != null ? nameAttribute : ConnectorAttributeUtil.GetNameFromAttributes(attributes);
                string name = nameAttr != null ? nameAttr.GetNameValue() : null; ;
                if (name != null)
                {
                    cmd.Parameters.Add(cmdInfo.NameParameter, name);
                    parametersSet.Add(cmdInfo.NameParameter);
                }
            }

            if (cmdInfo.UsesConfirm)
            {
                cmd.Parameters.Add("confirm", false);
                parametersSet.Add("confirm");
            }

            if (cmdInfo.UsesDomainController)
            {
                cmd.Parameters.Add("DomainController", ActiveDirectoryUtils.GetDomainControllerName(config));
                parametersSet.Add("DomainController");
            }

            // TODO check this only for user-related operations
            bool emailAddressesPresent = GetAttValues(ExchangeConnectorAttributes.AttEmailAddresses, attributes) != null;
            bool primarySmtpAddressPresent = GetAttValues(ExchangeConnectorAttributes.AttPrimarySmtpAddress, attributes) != null;

            if (emailAddressesPresent && primarySmtpAddressPresent) {
                throw new ArgumentException(ExchangeConnectorAttributes.AttEmailAddresses + " and " + ExchangeConnectorAttributes.AttPrimarySmtpAddress + " cannot be both set.");
            }

            if (attributes != null) {

                foreach (string attName in cmdInfo.Parameters) {

                    object valueToSet = null;

                    ConnectorAttribute attribute = ConnectorAttributeUtil.Find(attName, attributes);
                    if (attribute != null) {
                        if (attribute.Value != null && attribute.Value.Count > 1) {
                            List<string> stringValues = new List<string>();
                            foreach (object val in attribute.Value) {
                                stringValues.Add(val.ToString());
                            }
                            valueToSet = stringValues.ToArray();
                        } else {
                            valueToSet = ConnectorAttributeUtil.GetSingleValue(attribute);
                        }
                        if (parametersSet.Contains(attName))
                        {
                            throw new InvalidOperationException("Parameter " + attName + " is already defined for command " + cmdInfo.Name);
                        }
                        cmd.Parameters.Add(attName, valueToSet);
                        parametersSet.Add(attName);
                    }
                }
            }

            LOGGER.TraceEvent(TraceEventType.Verbose, CAT_DEFAULT, "GetCommand exit: cmdInfo name = {0}", cmdInfo.Name);
            return cmd;
        }
Beispiel #13
0
 internal static Command GetCommand(PSExchangeConnector.CommandInfo cmdInfo, ICollection<ConnectorAttribute> attributes, Uid uidAttribute, ExchangeConfiguration config)
 {
     return GetCommand(cmdInfo, attributes, uidAttribute, null, config);
 }
Beispiel #14
0
 internal static Command GetCommand(PSExchangeConnector.CommandInfo cmdInfo, Name nameAttribute, ExchangeConfiguration config)
 {
     return GetCommand(cmdInfo, null, null, nameAttribute, config);
 }