public void Remove(AuthorizationContextKey key) { if (Exists(key)) { string stringKey = key; database.KeyDelete(stringKey); } }
public bool Set(AuthorizationContextKey key, ISet <PermissionCode> value, TimeSpan?expiresIn = null) { var serializedValue = SerializeValue(value); string stringKey = key; return(expiresIn.HasValue ? database.StringSet(stringKey, serializedValue, expiresIn) : database.StringSet(stringKey, serializedValue)); }
private AuthorizationContextKey GetKey(IEnumerable <Claim> claims) { var isAnonymous = claims == null || (!claims.Any(UserId) || !claims.Any(TenantId)); if (isAnonymous) { return(AuthorizationContextKey.Anonymous()); } return(AuthorizationContextKey.Create(claims.First(UserId).Value, claims.First(TenantId).Value)); }
//Thanking R# for the timesaver public bool Equals(AuthorizationContextKey other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Equals(other.UserId, UserId) && Equals(other.TenantId, TenantId)); }
public ImmutableHashSet <PermissionCode> Get(AuthorizationContextKey key) { string stringKey = key; var entry = database.StringGet(stringKey); if (entry.IsNull) { return(new HashSet <PermissionCode>().ToImmutableHashSet()); } return(((ISet <PermissionCode>)serializer.Deserialize(entry)).ToImmutableHashSet()); }
public ImmutableHashSet <PermissionCode> GetEffectivePermissionSet(AuthorizationContextKey key) { if (!cache.Exists(key)) { var roles = roleRepository.Get(key.TenantId, key.UserId); var permissions = repository.GetPermissions(roles.Select(r => r.Id)); cache.Set(key, new HashSet <PermissionCode>(permissions.Select(p => p.Code))); return(permissions.Select(p => p.Code).ToImmutableHashSet()); } var codes = cache.Get(key); return(codes); }
public void Clear(AuthorizationContextKey key) { cache.Remove(key); }
public bool Exists(AuthorizationContextKey key) { string stringKey = key; return(database.KeyExists(stringKey)); }