GetAttributes() public method

public GetAttributes ( ) : ICollection
return ICollection
コード例 #1
0
ファイル: ExchangeUtility.cs プロジェクト: Evolveum/openicf
        public static string GetRecipientType(ConnectorObject cobject)
        {
            long? recipientTypeDetails =
                ExchangeUtility.GetAttValue(ExchangeConnectorAttributes.AttMsExchRecipientTypeDetailsADName, cobject.GetAttributes()) as long?;
            switch (recipientTypeDetails) { // see http://blogs.technet.com/b/benw/archive/2007/04/05/exchange-2007-and-recipient-type-details.aspx

                case 1: return ExchangeConnectorAttributes.RcptTypeMailBox;
                case 128: return ExchangeConnectorAttributes.RcptTypeMailUser;

                case null:          // we are dealing with user accounts, so we can assume that an account without Exchange information is an ordinary User
                case 65536: return ExchangeConnectorAttributes.RcptTypeUser;

                default:
                    LOGGER.TraceEvent(TraceEventType.Information, CAT_DEFAULT, "Unknown recipientTypeDetails: {0} ({1})", recipientTypeDetails,
                        ExchangeUtility.GetAttValue(ExchangeConnectorAttributes.AttMsExchRecipientTypeDetailsADName, cobject.GetAttributes()));
                    return null;
            }
        }
コード例 #2
0
 public void UpdateMergeTests()
 {
     ConnectorAttribute expected, actual;
     Configuration config = new MockConfiguration(false);
     ConnectorFacadeFactory factory = ConnectorFacadeFactory.GetInstance();
     SafeType<Connector> clazz = SafeType<Connector>.Get<MockUpdateConnector>();
     // **test only**
     APIConfiguration impl = TestHelpers.CreateTestConfiguration(clazz, config);
     impl.SetTimeout(SafeType<APIOperation>.Get<GetApiOp>(), APIConstants.NO_TIMEOUT);
     impl.SetTimeout(SafeType<APIOperation>.Get<UpdateApiOp>(), APIConstants.NO_TIMEOUT);
     impl.SetTimeout(SafeType<APIOperation>.Get<SearchApiOp>(), APIConstants.NO_TIMEOUT);
     ConnectorFacade facade = factory.NewInstance(impl);
     // sniff test to make sure we can get an object..
     ConnectorObject obj = facade.GetObject(ObjectClass.ACCOUNT, NewUid(1), null);
     Assert.AreEqual(NewUid(1), obj.Uid);
     // ok lets add an attribute that doesn't exist..
     String ADDED = "somthing to add to the object";
     String ATTR_NAME = "added";
     ICollection<ConnectorAttribute> addAttrSet;
     addAttrSet = CollectionUtil.NewSet((IEnumerable<ConnectorAttribute>)obj.GetAttributes());
     addAttrSet.Add(ConnectorAttributeBuilder.Build(ATTR_NAME, ADDED));
     Name name = obj.Name;
     addAttrSet.Remove(name);
     Uid uid = facade.AddAttributeValues(ObjectClass.ACCOUNT, obj.Uid, ConnectorAttributeUtil.FilterUid(addAttrSet), null);
     // get back the object and see if there are the same..
     addAttrSet.Add(name);
     ConnectorObject addO = new ConnectorObject(ObjectClass.ACCOUNT, addAttrSet);
     obj = facade.GetObject(ObjectClass.ACCOUNT, NewUid(1), null);
     Assert.AreEqual(addO, obj);
     // attempt to add on to an existing attribute..
     addAttrSet.Remove(name);
     uid = facade.AddAttributeValues(ObjectClass.ACCOUNT, obj.Uid, ConnectorAttributeUtil.FilterUid(addAttrSet), null);
     // get the object back out and check on it..
     obj = facade.GetObject(ObjectClass.ACCOUNT, uid, null);
     expected = ConnectorAttributeBuilder.Build(ATTR_NAME, ADDED, ADDED);
     actual = obj.GetAttributeByName(ATTR_NAME);
     Assert.AreEqual(expected, actual);
     // attempt to delete a value from an attribute..
     ICollection<ConnectorAttribute> deleteAttrs = CollectionUtil.NewSet((IEnumerable<ConnectorAttribute>)addO.GetAttributes());
     deleteAttrs.Remove(name);
     uid = facade.RemoveAttributeValues(ObjectClass.ACCOUNT, addO.Uid, ConnectorAttributeUtil.FilterUid(deleteAttrs), null);
     obj = facade.GetObject(ObjectClass.ACCOUNT, uid, null);
     expected = ConnectorAttributeBuilder.Build(ATTR_NAME, ADDED);
     actual = obj.GetAttributeByName(ATTR_NAME);
     Assert.AreEqual(expected, actual);
     // attempt to delete an attribute that doesn't exist..
     ICollection<ConnectorAttribute> nonExist = new HashSet<ConnectorAttribute>();
     nonExist.Add(NewUid(1));
     nonExist.Add(ConnectorAttributeBuilder.Build("does not exist", "asdfe"));
     uid = facade.RemoveAttributeValues(ObjectClass.ACCOUNT, addO.Uid, ConnectorAttributeUtil.FilterUid(nonExist), null);
     obj = facade.GetObject(ObjectClass.ACCOUNT, NewUid(1), null);
     Assert.IsTrue(obj.GetAttributeByName("does not exist") == null);
 }
コード例 #3
0
 // =======================================================================
 // 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;
 }
コード例 #4
0
        /// <summary>
        /// Finds the attributes in connector object and rename it according to input array of names, but only
        /// if the atribute name is in attributes to get
        /// </summary>
        /// <param name="cobject">ConnectorObject which attributes should be replaced</param>
        /// <param name="attsToGet">Attributes to get list</param>
        /// <param name="map">Replace mapping</param>
        /// <returns>ConnectorObject with replaced attributes</returns>        
        /// <exception cref="ArgumentNullException">If some of the params is null</exception>
        internal static ConnectorObject ReplaceAttributes(ConnectorObject cobject, ICollection<string> attsToGet, IDictionary<string, string> map)
        {
            Assertions.NullCheck(cobject, "cobject");
            Assertions.NullCheck(map, "map");
            if (attsToGet == null)
            {
                return cobject;
            }

            var attributes = cobject.GetAttributes();
            var builder = new ConnectorObjectBuilder();
            foreach (ConnectorAttribute attribute in attributes)
            {
                string newName;
                if (map.TryGetValue(attribute.Name, out newName) && attsToGet.Contains(newName))
                {
                    var newAttribute = RenameAttribute(attribute, newName);
                    builder.AddAttribute(newAttribute);
                    break;
                }

                builder.AddAttribute(attribute);
            }

            builder.AddAttributes(attributes);
            builder.ObjectClass = cobject.ObjectClass;
            builder.SetName(cobject.Name);
            builder.SetUid(cobject.Uid);
            return builder.Build();
        }
コード例 #5
0
ファイル: ExchangeUtility.cs プロジェクト: Evolveum/openicf
        /// <summary>
        /// Finds the attributes in connector object and rename it according to input array of names, but only
        /// if the atribute name is in attributes to get
        /// </summary>
        /// <param name="cobject">ConnectorObject which attributes should be replaced</param>
        /// <param name="map">Replace mapping</param>
        /// <returns>ConnectorObject with replaced attributes</returns>        
        /// <exception cref="ArgumentNullException">If some of the params is null</exception>
        internal static ConnectorObject ConvertAdAttributesToExchange(ConnectorObject cobject)
        {
            Assertions.NullCheck(cobject, "cobject");

            var attributes = cobject.GetAttributes();
            var builder = new ConnectorObjectBuilder();

            bool emailAddressPolicyEnabled = true;
            foreach (ConnectorAttribute attribute in attributes)
            {
                string newName;
                if (attribute.Is(ExchangeConnectorAttributes.AttMsExchPoliciesExcludedADName))
                {
                    if (attribute.Value != null && attribute.Value.Contains("{26491cfc-9e50-4857-861b-0cb8df22b5d7}"))
                    {
                        emailAddressPolicyEnabled = false;
                    }
                }
                else if (attribute.Is(ExchangeConnectorAttributes.AttAddressBookPolicyADName))
                {
                    var newAttribute = ExtractCommonName(attribute, ExchangeConnectorAttributes.AttAddressBookPolicy);
                    builder.AddAttribute(newAttribute);
                    builder.AddAttribute(attribute);        // keep the original one as well
                }
                else if (attribute.Is(ExchangeConnectorAttributes.AttOfflineAddressBookADName))
                {
                    var newAttribute = ExtractCommonName(attribute, ExchangeConnectorAttributes.AttOfflineAddressBook);
                    builder.AddAttribute(newAttribute);
                    builder.AddAttribute(attribute);        // keep the original one as well
                }
                else if (ExchangeConnectorAttributes.AttMapFromAD.TryGetValue(attribute.Name, out newName))
                {
                    var newAttribute = RenameAttribute(attribute, newName);
                    builder.AddAttribute(newAttribute);
                }
                else
                {
                    builder.AddAttribute(attribute);
                }
            }

            builder.AddAttribute(ConnectorAttributeBuilder.Build(ExchangeConnectorAttributes.AttEmailAddressPolicyEnabled, emailAddressPolicyEnabled));

            copyAttribute(builder, cobject, ExchangeConnectorAttributes.AttPrimarySmtpAddressADName, ExchangeConnectorAttributes.AttPrimarySmtpAddress);

            // derive recipient type
            string recipientType = GetRecipientType(cobject);
            if (recipientType != null)
            {
                builder.AddAttribute(ConnectorAttributeBuilder.Build(ExchangeConnectorAttributes.AttRecipientType, new string[] { recipientType }));
            }

            builder.ObjectClass = cobject.ObjectClass;
            builder.SetName(cobject.Name);
            builder.SetUid(cobject.Uid);
            return builder.Build();
        }