/// <summary>
        /// проверка токена авторизации на клиентской части
        /// </summary>
        /// <param name="user"></param>
        /// <param name="_sc"></param>
        /// <returns></returns>
        public static Guid CheckSessionAuthState(LoggedUser user, AuthorizeServiceClient _sc)
        {
            if (user == null)
            {
                return(Guid.Empty);
            }

            CheckTokenResponse response = _sc.CheckToken(new Guid(user.AuthToken), user.RoleChangeDateTime);

            if (response.Roles != null && response.Roles.Count != 0)
            {
                //пока, выходим из системы
                return(Guid.Empty);

                var claimsUser = (ClaimsIdentity)user.Identity;
                //удаляем текущие роли
                List <Claim> userRoles = claimsUser.FindAll(ClaimTypes.Role).ToList();
                foreach (Claim userRole in userRoles)
                {
                    claimsUser.RemoveClaim(userRole);
                }

                foreach (UserRoles dicUserRole in response.Roles)
                {
                    Claim newRole = new Claim(ClaimTypes.Role, dicUserRole.ToString());
                    claimsUser.AddClaim(newRole);
                }
            }
            if (!response.OK)
            {
                return(Guid.Empty);
            }
            return(new Guid(user.AuthToken));
        }
Exemple #2
0
        public static WebDavClient InitWebDav(Guid token, AuthorizeServiceClient authorizeService)
        {
            UserInfoResponse userInfoResponse = authorizeService.GetUserData(token);

            if (userInfoResponse.Exception == null)
            {
                UserInfo user         = userInfoResponse.User;
                var      webDavClient = new WebDavClient(userInfoResponse.WebDavRootDir, token);

                return(webDavClient);
            }
            throw new Exception("Ошибка получения данных о пользователе", userInfoResponse.Exception);
        }
Exemple #3
0
        public static bool FileExist(string fileUri, Guid token)
        {
            var          _authService = new AuthorizeServiceClient();
            WebDavClient webDavClient = InitWebDav(token, _authService);
            var          fileInfo     = new FileInfo(fileUri);
            bool         result       = true;

            byte[] file = webDavClient.Download(fileUri);
            //List<DirInfo> dirInfos = webDavClient.GetDirectories(fileInfo.Directory.Name);
            //bool result=dirInfos.Any(x => x.IsDirectory == false && x.DisplayName.Equals(fileInfo.Name));
            if (file == null)
            {
                result = false;
            }
            return(result);
        }
Exemple #4
0
        /// <summary>
        ///     инициализация визарда
        /// </summary>
        /// <param name="id"></param>
        /// <param name="cryptxService"></param>
        /// <param name="authService"></param>
        /// <param name="token"></param>
        public WizardModel(Guid id, CryptxServiceClient cryptxService, AuthorizeServiceClient authService, Guid token)
        {
            ProfileSelect            = new ProfileSelect();
            CanBack                  = true;
            CanNext                  = true;
            CanmakeOperation         = false;
            ProfileSelect.UseDefault = false;
            ProfileResponse userDefaultResponse = cryptxService.GetDefaultProfile(token);

            if (userDefaultResponse.Exception == null)
            {
                if (userDefaultResponse.Settings.Id == Guid.Empty)
                {
                    ProfileResponse response = cryptxService.GetBlankProfile();
                    if (response.Exception == null)
                    {
                        ProfileSelect.UseDefault = true;
                        Settings = response.Settings;
                    }
                    else
                    {
                        throw new Exception("Ошибка при получении настроек по умолчанию");
                    }
                }
                else
                {
                    Settings = userDefaultResponse.Settings;
                }
            }
            else
            {
                throw new Exception("Ошибка при получении ваших настроек по умолчанию");
            }
            //зануляем пароли
            Settings._SignatureSettings.KeysetPassword  = "";
            Settings._DecryptionSettings.KeysetPassword = "";

            //Settings = _cryptxService.GetDefaultProfile();// SettingInitializer.InitializeSettings();
            UserInfo = new UserInfoW();
            UserInfoResponse userInfo = authService.GetUserData(token);

            DownloadedFiles        = new List <DownloadedFile>();
            UserInfo.WebDavRootDir = userInfo.WebDavRootDir;
            UserInfo.User          = userInfo.User;
            Id           = id;
            CreationTime = DateTime.Now;
        }
Exemple #5
0
        public MasterInitModel(Guid token, CryptxServiceClient cryptx, AuthorizeServiceClient authorize, string files,
                               OperationType?type)
        {
            UserInfoResponse curUser = authorize.GetUserData(token);

            ProfileResponse      blankProfileResponse = cryptx.GetBlankProfile();
            UserProfilesResponse response             = cryptx.GetUserProfiles(Guid.Empty, token);

            OperationType    = (type == null) ? 0 : (OperationType)type;
            FilesJSON        = string.IsNullOrEmpty(files) ? "[]" : files;
            BlankProfileJSON = JsonConvert.SerializeObject(blankProfileResponse.Settings, Formatting.Indented);

            if (response.UserProfileList.Count == 0)
            {
                response.UserProfileList.Add(new UserProfileListElement
                {
                    Name = "Стандартные"
                });
            }

            SettingsJSON = JsonConvert.SerializeObject(response.UserProfileList, Formatting.Indented);
            UserInfo     = curUser.User;
        }