Provides a singleton logging class for Glyma search that logs messages with custom log categories.
        public static SecurityIdentifier GetSidFromClaim(string claimValue)
        {
            SecurityIdentifier sid = null;

            SPClaimProviderManager claimManager = SPClaimProviderManager.Local;

            if (claimManager == null)
            {
                throw new ApplicationException("Unable to access the claims provider manager.");
            }
            try
            {
                SPClaim claim = claimManager.DecodeClaim(claimValue);
                if (claim.OriginalIssuer.Equals("Windows", StringComparison.OrdinalIgnoreCase))
                {
                    if (claim.ClaimType.Equals(Microsoft.IdentityModel.Claims.ClaimTypes.GroupSid, StringComparison.OrdinalIgnoreCase))
                    {
                        sid = new SecurityIdentifier(claim.Value);
                    }
                    else if (claim.ClaimType.Equals(Microsoft.SharePoint.Administration.Claims.SPClaimTypes.UserLogonName, StringComparison.OrdinalIgnoreCase))
                    {
                        NTAccount userAccount = new NTAccount(claim.Value);
                        sid = (SecurityIdentifier)userAccount.Translate(typeof(SecurityIdentifier));
                    }
                }
            }
            catch (ArgumentException currentException)
            {
                GlymaSearchLogger.WriteTrace(LogCategoryId.Security, TraceSeverity.Unexpected, "The following exception occured when attempting to decode the claim, " + claimValue + " : " + currentException.ToString());
            }

            return(sid);
        }
Beispiel #2
0
        public void Add(K key, T value, DateTime absoluteExpiration, TimeSpan slidingExpiration)
        {
            if (default(K) == null && key == null)
            {
                throw new ArgumentNullException("key");
            }

            lock (_cacheLock)
            {
                if (Count < MaxItems)
                {
                    BasicCacheItem <T> .ValidateExpiration(absoluteExpiration, slidingExpiration);

                    BasicCacheItem <T> cacheItem = new BasicCacheItem <T>(value);
                    cacheItem.DateAddedToCache   = DateTime.Now;
                    cacheItem.AbsoluteExpiration = absoluteExpiration;
                    cacheItem.SlidingExpiration  = slidingExpiration;

                    _cacheItems.Add(key, cacheItem);
                }
                else
                {
                    GlymaSearchLogger.WriteTrace(LogCategoryId.Connector, TraceSeverity.Medium, "Cache item limit of " + MaxItems + " has been reached.  Item with key " + key.ToString() + " will not be added to the cache.");
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Gets the map nodes contained in a map from a Glyma repository.
        /// </summary>
        /// <param name="repositoryName">The name of the Glyma repository.</param>
        /// <param name="domainId">The GUID of the map node's domain.</param>
        /// <param name="rootMapId">The GUID of the node's root map.</param>
        /// <param name="mapId">The GUID of the map node's parent map.</param>
        /// <param name="nodeId">The GUID of the map node to retrieve nodes from.</param>
        /// <param name="lastCrawlStartTime">Specifies the last crawl time.</param>
        /// <param name="entityFields">A ITypeDescriptorCollection object that contains the fields to retrieve for each node.</param>
        /// <returns>A collection of DynamicType objects containing details of the nodes retrieved from a Glyma repository.</returns>
        /// <remarks>This is intended to be used as an AssociationNavigator method for a map entity in a BCS model.</remarks>
        public List <DynamicType> GetMapNodesInMap(string repositoryName, Guid domainId, Guid rootMapId, Guid mapId, Guid nodeId, DateTime lastCrawlStartTime, ITypeDescriptorCollection entityFields)
        {
            GlymaSearchLogger.WriteTrace(LogCategoryId.Connector, TraceSeverity.Verbose, "GetMapNodesInMap(" + repositoryName + ", " + domainId + ", " + rootMapId + ", " + mapId + ", " + nodeId + ")");

            List <DynamicType> nodes = MapRepository.GetNodesInMap(repositoryName, nodeId, entityFields, true);

            nodes.RemoveAll(node => !CrawlRules.Apply(node, MapRepository));

            return(nodes);
        }
Beispiel #4
0
 public void RemoveExpiredItemsCallback(Object stateInfo)
 {
     lock (_cacheLock)
     {
         GlymaSearchLogger.WriteTrace(LogCategoryId.Connector, TraceSeverity.Medium, "Auto expiring items in cache.");
         RemoveExpiredItems();
         if (_autoExpireItemsTimer != null)
         {
             _autoExpireItemsTimer.Change((int)_autoExpireItemsPeriod.TotalMilliseconds, Timeout.Infinite);
         }
     }
 }
Beispiel #5
0
        /// <summary>
        /// Get the details of a Glyma node.
        /// </summary>
        /// <param name="repositoryName">The name of the Glyma repository.</param>
        /// <param name="domainId">The GUID of the node's domain.</param>
        /// <param name="rootMapId">The GUID of the node's root map.</param>
        /// <param name="mapId">The GUID of the node's parent map.</param>
        /// <param name="nodeId">The GUID of the node to retrieve details from.</param>
        /// <param name="entityFields">A ITypeDescriptorCollection object that contains the fields to retrieve for each node.</param>
        /// <returns>A DynamicType object containing the details for the node.</returns>
        public DynamicType GetNode(string repositoryName, Guid domainId, Guid rootMapId, Guid mapId, Guid nodeId, ITypeDescriptorCollection entityFields)
        {
            GlymaSearchLogger.WriteTrace(LogCategoryId.Connector, TraceSeverity.Verbose, "GetNode(" + repositoryName + ", " + domainId + ", " + rootMapId + ", " + mapId + ", " + nodeId + ")");

            DynamicType node = null;

            node = MapRepository.GetNode(repositoryName, nodeId, entityFields);
            if (node != null)
            {
                CrawlRules.Apply(node, MapRepository);
            }

            return(node);
        }
        public void SetGlobalSettings(GlymaRepositoryProxy proxy, INamedPropertyDictionary properties)
        {
            // The global settings will be accessed by multiple threads, so synchronise access to them when configuring a proxy.
            lock (_globalSettingsLock)
            {
                if (!_globalSettingsInitialised)
                {
                    GlymaSearchLogger.WriteTrace(LogCategoryId.Connector, TraceSeverity.Medium, "Initialised global settings.");
                    GetDataAccessType(properties);
                    GetSecurityConnectionString(properties);
                    GetCrawlRules(properties);
                    GetEnableNodeAclCacheSetting(properties);
                    GetNodeAclType(properties);
                    GetEnableSecuritySetting(properties);
                    GetNodeAclCacheDuration(properties);
                    GetNodeAclCacheAutoExpirePeriod(properties);
                    GetNodeAclCacheMaxItems(properties);
                    GetNodeAclTaskWaitDuration(properties);
                    _globalSettingsInitialised = true;
                }

                IGlymaSecurityRepository securityRepository = null;
                if (_dataAccessType == DataAccessType.Sql)
                {
                    securityRepository = new SqlGlymaSecurityRepository(_securityConnectionString);
                }

                GlymaSecurityManager securityManager = null;
                if (_nodeAclType == NodeAclType.Windows)
                {
                    if (_isNodeAclCacheEnabled)
                    {
                        securityManager = new WindowsGlymaSecurityManager(securityRepository, _nodeAclCacheAutoExpirePeriod, _nodeAclCacheMaxItems, _nodeAclCacheDuration, _nodeAclTaskWaitDuration);
                    }
                    else
                    {
                        securityManager = new WindowsGlymaSecurityManager(securityRepository);
                    }
                }
                else
                {
                    throw new ApplicationException("Only the Windows node ACL type is currently supported.");
                }

                proxy.IsSecurityEnabled  = _isSecurityEnabled;
                proxy.SecurityRepository = securityRepository;
                proxy.SecurityManager    = securityManager;
                proxy.CrawlRules         = _crawlRules.DeepCopy();
            }
        }
Beispiel #7
0
        /// <summary>
        /// Get the access control list (ACL) for a node.
        /// </summary>
        /// <param name="repositoryName">The name of the Glyma repository.</param>
        /// <param name="domainId">The GUID of the node's domain.</param>
        /// <param name="rootMapId">The GUID of the node's root map.</param>
        /// <param name="mapId">The GUID of the node's parent map.</param>
        /// <param name="nodeId">The GUID of the node to retrieve details from.</param>
        /// <param name="entityFields">A ITypeDescriptorCollection object that contains the fields to retrieve for each node.</param>
        /// <returns></returns>
        public byte[] GetNodeAcl(string repositoryName, Guid domainId, Guid rootMapId, Guid mapId, Guid nodeId, ITypeDescriptorCollection entityFields)
        {
            GlymaSearchLogger.WriteTrace(LogCategoryId.Connector, TraceSeverity.Verbose, "GetNodeAcl(" + repositoryName + ", " + domainId + ", " + rootMapId + ", " + mapId + ", " + nodeId + ")");

            byte[] nodeAcl = null;

            if (IsSecurityEnabled)
            {
                nodeAcl = SecurityManager.GetNodeAcl(MapRepository.GetDatabaseName(), repositoryName, domainId, rootMapId);
            }
            else
            {
                nodeAcl = SecurityManager.GetAllowAllNodeAcl(repositoryName, domainId, rootMapId);
            }

            return(nodeAcl);
        }
Beispiel #8
0
        /// <summary>
        /// Gets the root map nodes from a Glyma repository.
        /// </summary>
        /// <param name="entityFields">A ITypeDescriptorCollection object that contains the fields to retrieve for each node.</param>
        /// <returns>A collection of DynamicType objects containing details of the nodes retrieved from a Glyma repository.</returns>
        /// <remarks>This is intended to be used as a Finder method in a BCS model.</remarks>
        public List <DynamicType> GetRooMaps(ITypeDescriptorCollection entityFields)
        {
            GlymaSearchLogger.WriteTrace(LogCategoryId.Connector, TraceSeverity.Verbose, "GetRootMaps");

            Uri  startUrl = new Uri(StartAddress);
            Guid domainId = Guid.Empty;

            if (startUrl.Segments.Length == 2)
            {
                domainId = new Guid(startUrl.Segments[1].TrimEnd('/'));
            }

            List <DynamicType> nodes = MapRepository.GetRootMaps(RepositoryName, domainId, entityFields);

            nodes.RemoveAll(node => !CrawlRules.Apply(node, MapRepository));

            return(nodes);
        }
        protected List <SpUserDetail> GetAllowedUsers(string mapDatabaseName, string repositoryName, Guid domainId, Guid rootMapId)
        {
            List <SpUserDetail> allowedUsers = new List <SpUserDetail>();

            // Get the non-admninistrator users defined in the security database.
            List <SpFarmGroupIdentifier> allowedGroupIdentifiers = _securityRepository.GetAllowedGroups(repositoryName, domainId, rootMapId);

            foreach (SpFarmGroupIdentifier groupIdentifier in allowedGroupIdentifiers)
            {
                try
                {
                    SpSiteCollectionRepository        siteCollectionRepository = new SpSiteCollectionRepository(groupIdentifier.SiteCollectionId);
                    Dictionary <string, SpUserDetail> users = siteCollectionRepository.GetUsersInGroup(groupIdentifier.GroupId);
                    allowedUsers = allowedUsers.Union(users.Values).ToList();
                }
                catch (FileNotFoundException currentException)
                {
                    GlymaSearchLogger.WriteTrace(LogCategoryId.Security, TraceSeverity.Medium, "Unable to connect to the site collection with ID, " + groupIdentifier.SiteCollectionId + " : " + currentException.ToString());
                }
            }

            // Get the administators for the site collections that are associated with the map database.
            List <Guid> siteCollectionIds = _securityRepository.GetSiteCollectionAssociations(mapDatabaseName);

            foreach (Guid siteCollectionId in siteCollectionIds)
            {
                try
                {
                    SpSiteCollectionRepository        siteCollectionRepository     = new SpSiteCollectionRepository(siteCollectionId);
                    Dictionary <string, SpUserDetail> siteCollectionAdministrators = siteCollectionRepository.GetSiteCollectionAdministrators();
                    allowedUsers = allowedUsers.Union(siteCollectionAdministrators.Values).ToList();
                }
                catch (FileNotFoundException currentException)
                {
                    GlymaSearchLogger.WriteTrace(LogCategoryId.Security, TraceSeverity.Medium, "Unable to connect to the site collection with ID, " + siteCollectionId + " : " + currentException.ToString());
                }
            }

            return(allowedUsers);
        }
        /// <summary>
        /// Executes a MethodInstance in the model against the specified external system instance with given parameters.
        /// </summary>
        /// <param name="methodInstance">The method instance being executed.</param>
        /// <param name="lobSystemInstance">The external system instance which the method instance is being executed against.</param>
        /// <param name="args">Parameters of the method. The size of the parameter array is equal to the number of parameter objects in the method definition in the BCS model file, and the values are passed in order. Out and return parameters will be a null reference.</param>
        /// <param name="context">ExecutionContext in which this execution is happening. This value will be a null reference if ExecutionContext is not created.</param>
        /// <remarks>
        /// This method is executed in a separate thread.
        /// </remarks>
        public override void ExecuteStatic(Microsoft.BusinessData.MetadataModel.IMethodInstance methodInstance, Microsoft.BusinessData.MetadataModel.ILobSystemInstance lobSystemInstance, object[] args, Microsoft.BusinessData.Runtime.IExecutionContext context)
        {
            // Modify the execution behaviour for the method instance types that are used in the Glyma repository model and revert to the base class implementation
            // for all other method instance types (until a better understanding is developed on how the other method instance types are used).
            switch (methodInstance.MethodInstanceType)
            {
            case MethodInstanceType.Finder:
            case MethodInstanceType.SpecificFinder:
            case MethodInstanceType.AssociationNavigator:
            case MethodInstanceType.ChangedIdEnumerator:
            case MethodInstanceType.DeletedIdEnumerator:
            case MethodInstanceType.BinarySecurityDescriptorAccessor:

                // Validate parameters to ensure all required execution details are available.
                if (methodInstance == null)
                {
                    throw new ArgumentNullException("methodInstance");
                }

                if (lobSystemInstance == null)
                {
                    throw new ArgumentNullException("lobSystemInstance");
                }

                if (args == null)
                {
                    throw new ArgumentNullException("args");
                }

                if (context == null)
                {
                    throw new ArgumentNullException("context");
                }

                IConnectionContext connectionContext = (IConnectionContext)context["ConnectionContext"];
                if (connectionContext == null)
                {
                    throw new ArgumentNullException("The BDC execution context doesn't contain a connection context.");
                }

                // Create the proxy and execute the method.
                GlymaRepositoryProxy proxy = null;
                try
                {
                    proxy = CreateProxy();
                    if (proxy == null)
                    {
                        throw new ArgumentException("The proxy returned from the BDC shim is null.");
                    }

                    GlymaSearchLogger.WriteTrace(LogCategoryId.Connector, TraceSeverity.Verbose, "Configuring proxy to execute " + methodInstance.MethodInstanceType.ToString() + " method for: " + connectionContext.Path.OriginalString);
                    SetGlobalSettings(proxy, lobSystemInstance.GetLobSystem().GetProperties());
                    SetStartAddress(proxy, connectionContext.Path.OriginalString);
                    SetRepositoryName(proxy, lobSystemInstance.Name);
                    SetMapConnectionString(proxy, lobSystemInstance.GetProperties(), lobSystemInstance.Name);

                    // Get the definition of the fields for the entity that will be returned by the proxy method.  This enables the connector to build entities
                    // based on the definitions in the model file instead of having entities with fixed pre-defined properties.
                    ITypeDescriptorCollection entityFields = GetEntityFields(methodInstance);

                    GlymaSearchLogger.WriteTrace(LogCategoryId.Connector, TraceSeverity.Verbose, "Executing " + methodInstance.MethodInstanceType.ToString() + " proxy method for: " + connectionContext.Path.OriginalString);
                    ExecuteProxyMethod(proxy, methodInstance, args, entityFields);
                    GlymaSearchLogger.WriteTrace(LogCategoryId.Connector, TraceSeverity.Verbose, "Completed execution of " + methodInstance.MethodInstanceType.ToString() + " proxy method for: " + connectionContext.Path.OriginalString);
                }
                catch (Exception currentException)
                {
                    GlymaSearchLogger.WriteTrace(LogCategoryId.Connector, TraceSeverity.Unexpected, currentException.ToString());
                    throw;
                }
                finally
                {
                    if (proxy != null)
                    {
                        DisposeProxy(proxy);
                        proxy = null;
                    }
                }
                break;

            default:
                base.ExecuteStatic(methodInstance, lobSystemInstance, args, context);
                break;
            }
        }