Пример #1
0
 /// <summary>
 /// Gets the token.
 /// </summary>
 /// <param name="userName">Name of the user.</param>
 /// <returns></returns>
 public TokenResponse GetToken(TokenRequest tokenRequest)
 {
     //token, 有个Id和User,
     TokenResponse response = new TokenResponse();
     GetTokenBase(tokenRequest, response);
     return response;
 }
Пример #2
0
 /// <summary>
 /// Validates the token.
 /// 在securitylist里面找token.id对应的user
 /// 项目用到的
 /// </summary>
 /// <param name="token">The token.</param>
 /// <returns></returns>
 public TokenResponse ValidateToken(TokenRequest tokenRequest)
 {
     TokenResponse tokenResponse = new TokenResponse();
     ValidateTokenBase(tokenRequest, tokenResponse);
     return tokenResponse;
 }
Пример #3
0
 /// <summary>
 /// Validates the token base.
 /// </summary>
 /// <param name="tokenRequest">The token request.</param>
 /// <param name="tokenResponse">The token response.</param>
 private void ValidateTokenBase(TokenRequest tokenRequest, TokenResponse tokenResponse)
 {
     tokenResponse.User = new User();
     lock (synchronizeObjectCall)
     {
         //tokenRequest.Token , tokenRequest.User = null
         //所以只能用tokenRequest.Token.Id去验证
         if (iPow.Service.SSO.WebService.SecurityTokenService.SecurityTokenList.Contains(tokenRequest.Token.TokenId))
         {
             //存在这个token.id
             SecurityToken securityToken = iPow.Service.SSO.WebService.SecurityTokenService.SecurityTokenList[tokenRequest.Token.TokenId];
             //一个请求token的过期时间
             //如果大于了过期时间的话,也不会有用的
             TimeSpan differenceTime = DateTime.Now - securityToken.CreateTime;
             if (differenceTime <= tokenTimeOut)
             {
                 tokenResponse.User = securityToken.User;
             }
             //token用一欠,就删除
             iPow.Service.SSO.WebService.SecurityTokenService.SecurityTokenList.Remove(securityToken);
         }
     }
 }
Пример #4
0
        /// <summary>
        /// Gets the token base.
        /// </summary>
        /// <param name="tokenRequest">The token request.</param>
        /// <param name="response">The response.</param>
        private void GetTokenBase(TokenRequest tokenRequest, TokenResponse response)
        {
            response.Token = new Token();
            lock (synchronizeObjectCall)
            {
                //通过user是否登陆,去判断是否登陆了,如果登陆了才发放,token.id
                var userIsOnline = iPow.Service.SSO.WebService.OnLineUserService.OnLineUserList
                    .Where(e => e.id == tokenRequest.User.id && e.username == tokenRequest.User.username)
                    .FirstOrDefault();

                if (userIsOnline != null)
                {
                    SecurityToken securityToken = new SecurityToken()
                    {
                        User = tokenRequest.User,
                        TokenId = response.Token.TokenId,
                        CreateTime = DateTime.Now
                    };
                    iPow.Service.SSO.WebService.SecurityTokenService.SecurityTokenList.Add(securityToken);

                    //发放token.id
                  //  response.Token.TokenId = iPow.Service.SSO.WebService.TokenBuilderService.BuilderTokenId();
                }
            }
        }