Пример #1
0
        public void LoginTestMethod1()
        {
            Configuration.Configure();
            AccountBussiness accountBussines = new AccountBussiness();
            SignInMessage    msg             = new SignInMessage();

            msg.UserName = "******";
            RSAEncryptionCreator encryption = new RSAEncryptionCreator();

            msg.Password = encryption.PublicEncryption("123");
            msg.ClientId = "1";
            var result = accountBussines.Authenticate(msg);

            Assert.AreNotEqual(result.HasError, true);
            Assert.AreNotEqual(result.IdentityToken.Signature, string.Empty);

            TokenValidator validator       = new TokenValidator();
            var            tokenValidation = validator.ValiateIdentityToken(result.IdentityToken);
            var            strToken        = result.IdentityToken.ToString();
            IdentityToken  cToken          = new IdentityToken(strToken);
            var            strCtoken       = cToken.ToString();

            Assert.AreEqual(strToken, strCtoken);
            Assert.AreEqual(tokenValidation.IsError, true);
        }
Пример #2
0
        public SecurityResourceDtoContainer MenuList(Common.Message.AuthorizationRequest request)
        {
            SecurityResourceDtoContainer container = new SecurityResourceDtoContainer();
            TokenValidator        tokenValidator   = new TokenValidator();
            PermissionTDataAccess permissionDa     = new PermissionTDataAccess();
            var validationResult = tokenValidator.ValiateIdentityToken(request.IdentityToken);

            if (validationResult.IsError)
            {
                container.Response.AddBusinessException(validationResult.Error, Framework.Common.Service.Message.BusinessExceptionEnum.Validation);
                return(container);
            }
            else
            {
                ResourceTDataAccess resource = new ResourceTDataAccess();
                int userId = 0;
                int.TryParse(request.IdentityToken.SubjectId, out userId);

                var menuItemList = resource.GetMenuAccessList(request.AppDomainId, userId);
                //  container.SecurityResourceDtoList.AddRange(menuItemList);

                foreach (var item in menuItemList)
                {
                    permissionDa.AddResources(item, container.SecurityResourceDtoList);
                }
                // container.SecurityResourceDtoList.AddRange(submenuList);
            }
            return(container);
        }
Пример #3
0
        public Common.Message.AuthorizationResult CheckAccess(Common.Message.AuthorizationRequest request)
        {
            AuthorizationResult result         = new AuthorizationResult();
            TokenValidator      tokenValidator = new TokenValidator();

            var validationResult = tokenValidator.ValiateIdentityToken(request.IdentityToken);

            if (validationResult.IsError)
            {
                result.ErrorMessage = validationResult.Error;
                return(result);
            }
            AccessTokenGenerator generator = new AccessTokenGenerator();
            var accessToken = generator.GenerateToken(request.IdentityToken, request.Resource);

            result.AccessToken = accessToken;
            return(result);
        }
Пример #4
0
        public IdentityToken ExpireToken(IdentityToken token)
        {
            SessionBussiness sessionBs = new SessionBussiness();

            TokenValidator tokenValidator   = new TokenValidator();
            var            validationResult = tokenValidator.ValiateIdentityToken(token);

            if (validationResult.IsError)
            {
                return(token);
            }
            if (token.HasLogin)
            {
                sessionBs.ExpireSession(token.SessionId);
                token.HasLogin = false;
                TokenSigner.SignIdentityToken(token);
            }
            return(token);
        }
Пример #5
0
        public SecurityResourceDtoContainer AccessList(Common.Message.AuthorizationRequest request)
        {
            SecurityResourceDtoContainer container = new SecurityResourceDtoContainer();
            TokenValidator tokenValidator          = new TokenValidator();
            var            validationResult        = tokenValidator.ValiateIdentityToken(request.IdentityToken);

            if (validationResult.IsError)
            {
                container.Response.AddBusinessException(validationResult.Error, Framework.Common.Service.Message.BusinessExceptionEnum.Validation);
                return(container);
            }
            else
            {
                ResourceTDataAccess resource = new ResourceTDataAccess();
                int userId = 0;
                int.TryParse(request.IdentityToken.SubjectId, out userId);
                var resourceList = resource.GetResourceAccessList(request.ResourceTypeId, request.AppDomainId, userId);
                container.SecurityResourceDtoList.AddRange(resourceList);
            }
            return(container);
        }
Пример #6
0
        public Common.Message.TokenValidationResult ValidateIdentityToken(Common.Message.IdentityToken token)
        {
            TokenValidator validator = new TokenValidator();

            return(validator.ValiateIdentityToken(token));
        }