Example #1
0
        public static bool Ensure(this ConcurrentDictionary <long, int> claims, int scope, int type, int claimIndex)
        {
            var subjectClaimIndex = new SubjectClaimIndex(scope, type);

            claims.Add(subjectClaimIndex.Value, claimIndex);
            return(true);
        }
Example #2
0
        public static int Remove(this ConcurrentDictionary <long, int> claims, int scope, int type)
        {
            var subjectClaimIndex = new SubjectClaimIndex(scope, type);

            if (claims.Remove(subjectClaimIndex.Value, out int claimIndex))
            {
                return(claimIndex);
            }
            return(-1);
        }
Example #3
0
        public static bool Exist(this Dictionary <long, int> claims, int scope, int type)
        {
            if (claims == null)
            {
                return(false);
            }

            var subjectClaimIndex = new SubjectClaimIndex(scope, type);

            return(claims.ContainsKey(subjectClaimIndex.Value));
        }
Example #4
0
        public static bool GetIndex(this Dictionary <long, int> claims, int scope, int type, out int index)
        {
            index = 0;
            if (claims == null)
            {
                return(false);
            }

            var subjectClaimIndex = new SubjectClaimIndex(scope, type);

            return(claims.TryGetValue(subjectClaimIndex.Value, out index));
        }
Example #5
0
        public static bool Ensure(this Dictionary <long, int> claims, int scope, int type, int claimIndex)
        {
            if (claims == null)
            {
                claims = new Dictionary <long, int>(1);
            }

            var subjectClaimIndex = new SubjectClaimIndex(scope, type);

            if (claims.ContainsKey(subjectClaimIndex.Value))
            {
                return(true);
            }

            claims[subjectClaimIndex.Value] = claimIndex;
            return(true);
        }
Example #6
0
        public void RemoveByIssuer(Claim claim)
        {
            if (!Graph.IssuerIndex.TryGetValue(claim.Issuer.Id, out int issuerIndex))
            {
                return; // No issuer, then no trust!
            }
            var graphIssuer = Graph.Issuers[issuerIndex];

            if (!string.IsNullOrEmpty(claim.Scope))
            {
                int scopeIndex = -1;
                if (!Graph.Scopes.TryGetKey(claim.Scope, out scopeIndex))
                {
                    return; // Scope was not found !
                }
                foreach (var subject in graphIssuer.Subjects.Values)
                {
                    if (subject.Claims == null)
                    {
                        continue;
                    }

                    var list = subject.Claims.Keys.ToList();
                    foreach (var key in list)
                    {
                        var subjectClaimIndex = new SubjectClaimIndex(key);
                        if (subjectClaimIndex.Scope == scopeIndex)
                        {
                            subject.Claims.Remove(subjectClaimIndex.Scope, subjectClaimIndex.Type);
                        }
                    }
                }
            }
            else
            {
                graphIssuer.Subjects = null; // Clear out all subjects with claims.
                // Do not need to remove graphIssuer as it containes no identifying data.
                // Would be created automatically on next reload of graph model anyways if referenced by others.
                // The claims from the issuer will still be in memory until next reboot.
                // Its not possible to identify the uniqe claims belonging to the removed issuer and therefore they will stay there until next reboot.
                // However it is not possible to get the data from the claims anymore unless issued by other issuers.
            }

            // Is it possble to remove the issuer?, as we do not know if any other is referencing to it.
            // There is no backpointer, so this would be a DB query.
        }
Example #7
0
        public static bool Exist(this ConcurrentDictionary <long, int> claims, int scope, int type)
        {
            var subjectClaimIndex = new SubjectClaimIndex(scope, type);

            return(claims.ContainsKey(subjectClaimIndex.Value));
        }
Example #8
0
        public static bool GetIndex(this ConcurrentDictionary <long, int> claims, int scope, int type, out int index)
        {
            var subjectClaimIndex = new SubjectClaimIndex(scope, type);

            return(claims.TryGetValue(subjectClaimIndex.Value, out index));
        }