Exemplo n.º 1
0
        public static PoseCredentials Deserialize(byte[] buffer)
        {
            PoseCredentials credentials = new PoseCredentials();

            try
            {
                int curPosition = 0;

                // SessionID
                credentials._userNo = BitConverter.ToInt64(buffer, curPosition);
                curPosition        += 8;

                // CertifiedTime
                credentials._expireTime = BitConverter.ToInt64(buffer, curPosition);
                curPosition            += 8;

                // ServiceRoleType
                credentials._serviceRoleType = BitConverter.ToInt32(buffer, curPosition);
                curPosition += 4;

                if (buffer.Length != curPosition)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                ErrorHandler.OccurException(HttpStatusCode.Unauthorized);
            }

            return(credentials);
        }
Exemplo n.º 2
0
        public static PoseCredentials CreateCredentials(long userNo, int serviceRoleType)
        {
            var newCredentials = new PoseCredentials();

            newCredentials._userNo          = userNo;
            newCredentials._serviceRoleType = serviceRoleType;
            newCredentials._expireTime      = LogicTime.GetUnixTimeNow(DateTime.UtcNow.AddMilliseconds(TOKEN_EXPIRE_IN));

            return(newCredentials);
        }
Exemplo n.º 3
0
        public PoseCredentials CheckCredentialValid()
        {
            PoseCredentials credentials = ServerContext.Current.DecryptCredentials();

            credentials.IsAuthenticated = false;

            if (credentials != PoseCredentials.Default &&
                LogicTime.FromUnixTimeStamp(credentials.ExpireTime) > DateTime.UtcNow)
            {
                credentials.IsAuthenticated = true;
            }

            return(credentials);
        }
Exemplo n.º 4
0
        public static byte[] Serialize(PoseCredentials credentials)
        {
            List <byte> buffer = new List <byte>();

            try
            {
                // SessionID
                buffer.AddRange(BitConverter.GetBytes(credentials._userNo));

                // CertifiedTime
                buffer.AddRange(BitConverter.GetBytes(credentials._expireTime));

                // ServiceRoleType
                buffer.AddRange(BitConverter.GetBytes(credentials._serviceRoleType));
            }
            catch (Exception)
            {
                ErrorHandler.OccurException(HttpStatusCode.Unauthorized);
            }

            return(buffer.ToArray());
        }
Exemplo n.º 5
0
        public static byte[] CreateToken(long userNo, int serviceRoleType)
        {
            var newCredentials = PoseCredentials.CreateCredentials(userNo, serviceRoleType);

            return(Singleton.Get <CryptoFacade>().Encrypt_RSA(PoseCredentials.Serialize(newCredentials)));
        }
Exemplo n.º 6
0
 public PosePrincipal(PoseCredentials identity)
 {
     this._identity = identity;
 }