示例#1
0
        public void Is_Unique()
        {
            // Act
            var id1 = new AuthId();
            var id2 = new AuthId();
            var id3 = new AuthId();
            var id4 = new AuthId();

            // Assert
            Assert.NotEqual(id1.ToString(), id2.ToString());
            Assert.NotEqual(id1.GetHashCode(), id2.GetHashCode());
            Assert.NotEqual(id1.ToBytes(), id2.ToBytes());

            Assert.NotEqual(id1.ToString(), id3.ToString());
            Assert.NotEqual(id1.GetHashCode(), id3.GetHashCode());
            Assert.NotEqual(id1.ToBytes(), id3.ToBytes());

            Assert.NotEqual(id1.ToString(), id4.ToString());
            Assert.NotEqual(id1.GetHashCode(), id4.GetHashCode());
            Assert.NotEqual(id1.ToBytes(), id4.ToBytes());


            Assert.NotEqual(id2.ToString(), id3.ToString());
            Assert.NotEqual(id2.GetHashCode(), id3.GetHashCode());
            Assert.NotEqual(id2.ToBytes(), id3.ToBytes());

            Assert.NotEqual(id2.ToString(), id4.ToString());
            Assert.NotEqual(id2.GetHashCode(), id4.GetHashCode());
            Assert.NotEqual(id2.ToBytes(), id4.ToBytes());


            Assert.NotEqual(id3.ToString(), id4.ToString());
            Assert.NotEqual(id3.GetHashCode(), id4.GetHashCode());
            Assert.NotEqual(id3.ToBytes(), id4.ToBytes());
        }
示例#2
0
        public void Is_Bootable(string startValue)
        {
            // Act
            var id = new AuthId(startValue);

            // Assert
            Assert.Equal(id.ToString(), startValue);
        }
示例#3
0
        internal void AddAuthentication(QueryStringParameters nvc)
        {
            if (IdType == AuthIdType.MainId)
            {
                nvc["auth-id"] = AuthId.ToString();
            }
            if (IdType == AuthIdType.SubId)
            {
                nvc["sub-auth-id"] = AuthId.ToString();
            }

            nvc["auth-password"] = AuthPassword;
        }
示例#4
0
 internal OracleProgramMetadata(ProgramType type, OracleProgramIdentifier identifier, bool isAnalytic, bool isAggregate, bool isPipelined, bool isOffloadable, bool parallelSupport, bool isDeterministic, int?metadataMinimumArguments, int?metadataMaximumArguments, AuthId authId, string displayType, bool isBuiltIn)
 {
     Type                      = type;
     Identifier                = identifier;
     IsAnalytic                = isAnalytic;
     IsAggregate               = isAggregate;
     IsPipelined               = isPipelined;
     IsOffloadable             = isOffloadable;
     ParallelSupport           = parallelSupport;
     IsDeterministic           = isDeterministic;
     _metadataMinimumArguments = metadataMinimumArguments;
     _metadataMaximumArguments = metadataMaximumArguments;
     AuthId                    = authId;
     DisplayType               = displayType;
     IsBuiltIn                 = isBuiltIn;
 }
示例#5
0
        public async Task <ClaimsIdentity> GenerateUserIdentityAsync(UserManager <ApplicationUser> manager, string authenticationType)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);

            // Add custom user claims here
            TechDispatchContext db = new TechDispatchContext();

            userIdentity.AddClaim(new Claim("UserRole", db.TechDispatchRoles.FirstAsync(x => x.TechDispatchRoleId == TechDispatchRoleId).Result.Name));

            //to-do: Custom authorization. For now though, we simply add the authorization codes based on role.
            MyClaims = db.TechDispatchRoles.FirstAsync(x => x.TechDispatchRoleId >= TechDispatchRoleId).Result.AccessClaims;

            MyClaims.ForEach(d =>
                             userIdentity.AddClaim(new Claim(d.ClaimName, d.ClaimValue))
                             );

            userIdentity.AddClaim(new Claim("Name", Name == null ? Email : Name));
            userIdentity.AddClaim(new Claim("Email", Email));
            userIdentity.AddClaim(new Claim("AuthId", AuthId.ToString()));

            return(userIdentity);
        }
        public byte[] GetBytes()
        {
            using (MemoryStream headerStream = new MemoryStream(), dataStream = new MemoryStream())
            {
                BinaryWriter headerBaos = new BinaryWriter(headerStream);
                BinaryWriter dataBaos   = new BinaryWriter(dataStream);

                try
                {
                    // Version
                    headerBaos.Write(ByteUtils.ShortToBytes(_version));

                    // Id
                    int len = Id.GetLengthOrZero();
                    headerBaos.Write((byte)(len & 0xff));
                    if (len > 0)
                    {
                        dataBaos.Write(Id.GetBytesOrEmptyArray());
                    }

                    // Tag
                    len = Tag.GetLengthOrZero();
                    headerBaos.Write(ByteUtils.ShortToBytes((short)(len & 0xffff)));
                    if (len > 0)
                    {
                        dataBaos.Write(Tag.GetBytesOrEmptyArray());
                    }

                    // GroupId
                    len = GroupId.GetLengthOrZero();
                    headerBaos.Write((byte)(len & 0xff));
                    if (len > 0)
                    {
                        dataBaos.Write(GroupId.GetBytesOrEmptyArray());
                    }

                    // SequenceNumber
                    if (SequenceNumber == 0)
                    {
                        headerBaos.Write((byte)0);
                    }
                    else
                    {
                        headerBaos.Write((byte)4);
                        dataBaos.Write(ByteUtils.IntegerToBytes(SequenceNumber));
                    }

                    // SequenceTotal
                    if (SequenceTotal == 0)
                    {
                        headerBaos.Write((byte)0);
                    }
                    else
                    {
                        headerBaos.Write((byte)4);
                        dataBaos.Write(ByteUtils.IntegerToBytes(SequenceTotal));
                    }

                    // Priority
                    if (Priority == 0)
                    {
                        headerBaos.Write((byte)0);
                    }
                    else
                    {
                        headerBaos.Write((byte)1);
                        dataBaos.Write(Priority);
                    }

                    //Timestamp
                    if (Timestamp == 0)
                    {
                        headerBaos.Write((byte)0);
                    }
                    else
                    {
                        headerBaos.Write((byte)8);
                        dataBaos.Write(ByteUtils.LongToBytes(Timestamp));
                    }

                    // Publisher
                    len = Publisher.GetLengthOrZero();
                    headerBaos.Write((byte)(len & 0xff));
                    if (len > 0)
                    {
                        dataBaos.Write(Publisher.GetBytesOrEmptyArray());
                    }

                    // AuthId
                    len = AuthId.GetLengthOrZero();
                    headerBaos.Write(ByteUtils.ShortToBytes((short)(len & 0xffff)));
                    if (len > 0)
                    {
                        dataBaos.Write(AuthId.GetBytesOrEmptyArray());
                    }

                    // AuthGroup
                    len = AuthGroup.GetLengthOrZero();
                    headerBaos.Write(ByteUtils.ShortToBytes((short)(len & 0xffff)));
                    if (len > 0)
                    {
                        dataBaos.Write(AuthGroup.GetBytesOrEmptyArray());
                    }

                    // ChainPosition
                    if (ChainPosition == 0)
                    {
                        headerBaos.Write((byte)0);
                    }
                    else
                    {
                        headerBaos.Write((byte)8);
                        dataBaos.Write(ByteUtils.LongToBytes(ChainPosition));
                    }

                    // Hash
                    len = Hash.GetLengthOrZero();
                    headerBaos.Write(ByteUtils.ShortToBytes((short)(len & 0xffff)));
                    if (len > 0)
                    {
                        dataBaos.Write(Hash.GetBytesOrEmptyArray());
                    }

                    // PreviousHash
                    len = PreviousHash.GetLengthOrZero();
                    headerBaos.Write(ByteUtils.ShortToBytes((short)(len & 0xffff)));
                    if (len > 0)
                    {
                        dataBaos.Write(PreviousHash.GetBytesOrEmptyArray());
                    }

                    // Nonce
                    len = Nonce.GetLengthOrZero();
                    headerBaos.Write(ByteUtils.ShortToBytes((short)(len & 0xffff)));
                    if (len > 0)
                    {
                        dataBaos.Write(Nonce.GetBytesOrEmptyArray());
                    }

                    // DifficultyTarget
                    if (DifficultyTarget == 0)
                    {
                        headerBaos.Write((byte)0);
                    }
                    else
                    {
                        headerBaos.Write((byte)4);
                        dataBaos.Write(ByteUtils.IntegerToBytes(DifficultyTarget));
                    }

                    // InfoType
                    len = InfoType.GetLengthOrZero();
                    headerBaos.Write((byte)(len & 0xff));
                    if (len > 0)
                    {
                        dataBaos.Write(InfoType.GetBytesOrEmptyArray());
                    }

                    // InfoFormat
                    len = InfoFormat.GetLengthOrZero();
                    headerBaos.Write((byte)(len & 0xff));
                    if (len > 0)
                    {
                        dataBaos.Write(InfoFormat.GetBytesOrEmptyArray());
                    }

                    // ContextData
                    if (ContextData == null)
                    {
                        headerBaos.Write((byte)0);
                    }
                    else
                    {
                        headerBaos.Write(ByteUtils.IntegerToBytes(ContextData.Length));
                        dataBaos.Write(ContextData, 0, ContextData.Length);
                    }

                    // ContentData
                    if (ContentData == null)
                    {
                        headerBaos.Write(ByteUtils.IntegerToBytes(0));
                    }
                    else
                    {
                        headerBaos.Write(ByteUtils.IntegerToBytes(ContentData.Length));
                        dataBaos.Write(ContentData, 0, ContentData.Length);
                    }

                    var headerBytes = headerStream.ToArray();
                    var dataBytes   = dataStream.ToArray();

                    var result = new byte[headerBytes.Length + dataBytes.Length];
                    Array.Copy(headerBytes, 0, result, 0, headerBytes.Length);
                    Array.Copy(dataBytes, 0, result, headerBytes.Length, dataBytes.Length);

                    return(result);
                }
                catch (Exception)
                {
                    //TODO: log
                }
                finally
                {
                    try
                    {
                        headerBaos.Dispose();
                        dataBaos.Dispose();
                    }
                    catch (Exception)
                    {
                        // TODO: log("Error when closing byte arrays streams");
                    }
                }
            }

            return(new byte[0]);
        }
示例#7
0
        public async Task <IActionResult> Classify(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "v1/classify")] HttpRequest req,
            [Table("ClassifyResult")] ICollector <ResponseTableEntity> tableCollector,
            [Queue("ClassifyResultCreate")] ICollector <string> queueCollector,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            var body    = JsonConvert.DeserializeObject <Request>(await req.ReadAsStringAsync());
            var authId  = AuthId.From(req);
            var isLocal = String.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID"));

            if (isLocal)
            {
                authId.PrincipalIdp  = "local";
                authId.PrincipalId   = "local-id";
                authId.PrincipalName = "local-name";
            }
            if (!authId.IsLogin)
            {
                return(new UnauthorizedResult());
            }

            log.LogInformation(string.Join(",\n", req.Headers.Select(x => x.ToString())));
            log.LogInformation(JsonConvert.SerializeObject(authId));

            // XXX 追跡用のIDあった気がするのでそちらを取りたい -> 見当たらない
            var id     = Guid.NewGuid();
            var result = _service.Execute(new TextInput(id.ToString(), body.Text), new Config()
            {
                ClassifierName = body.ClassifierName,
                TranslatorName = body.TranslatorName,
                NormalizerName = "", // XXX
            });

            var rowKey   = string.Format("{0:x16}", DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks) + "-" + id.ToString();
            var response = new Response()
            {
                Id             = rowKey,
                Categories     = result.Categories.ToList(),
                TranslatedText = result.TranslatedText,
                HasError       = result.HasError,
                Request        = body,
            };

            var jsonResponse = JsonConvert.SerializeObject(response);
            var tableEntity  = new ResponseTableEntity()
            {
                PartitionKey = "ja-en",
                RowKey       = rowKey,
                AuthIdp      = authId.PrincipalIdp,
                AuthId       = authId.PrincipalId,
                AuthName     = authId.PrincipalName,
                ResponseData = jsonResponse,
            };

            tableCollector.Add(tableEntity);
            queueCollector.Add(rowKey);

            log.LogInformation(jsonResponse);

            return(new OkObjectResult(response));
        }