Exemplo n.º 1
0
        /// <summary>
        /// If not using windows authentication, might want to try running under elevated permissions and giving the farm account write access to the SSS.
        /// </summary>
        /// <param name="providerTypeName"></param>
        /// <param name="applicationId"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        public static void WriteCredentialsToSecureStore(string providerTypeName, string applicationId, string userName, string password)
        {
            SPServiceContext context = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default);

            SecureStoreServiceProxy ssp = new SecureStoreServiceProxy();
            ISecureStore            iss = ssp.GetSecureStore(context);

            IList <TargetApplicationField> applicationFields = iss.GetUserApplicationFields(applicationId);

            IList <ISecureStoreCredential> creds =
                new List <ISecureStoreCredential>(applicationFields.Count);

            foreach (TargetApplicationField taf in applicationFields)
            {
                switch (taf.CredentialType)
                {
                case SecureStoreCredentialType.UserName:
                case SecureStoreCredentialType.WindowsUserName:
                    creds.Add(new SecureStoreCredential(MakeSecureString(userName), taf.CredentialType));
                    break;

                case SecureStoreCredentialType.Password:
                case SecureStoreCredentialType.WindowsPassword:
                    creds.Add(new SecureStoreCredential(MakeSecureString(password), taf.CredentialType));
                    break;
                }
            }

            using (SecureStoreCredentialCollection credentials = new SecureStoreCredentialCollection(creds))
            {
                iss.SetCredentials(applicationId, credentials);
            }
        }
Exemplo n.º 2
0
 public StudentHomeWorkDataService()
 {
     this._studentHomeWorkRepository = (IStudentHomeWorkRepository)Mvx.get_IoCProvider().Resolve <IStudentHomeWorkRepository>();
     this._lessonDataService         = (ILessonDataService)Mvx.get_IoCProvider().Resolve <ILessonDataService>();
     this._secureStore = (ISecureStore)Mvx.get_IoCProvider().Resolve <ISecureStore>();
     this._mobileApi   = (IMobileApi)Mvx.get_IoCProvider().Resolve <IMobileApi>();
 }
        private void DeployDefinition(object modelHost, ISecureStore hostSecureStore, TargetApplicationDefinition definition)
        {
            var currentObject = GetCurrentObject(hostSecureStore, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = currentObject,
                ObjectType       = typeof(TargetApplication),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });

            if (currentObject == null)
            {
                currentObject = CreateOject(modelHost, hostSecureStore, definition);
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = currentObject,
                ObjectType       = typeof(TargetApplication),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });
        }
Exemplo n.º 4
0
 public LessonDbDataService()
 {
     this._lessonRepository    = (ILessonDbRepository)Mvx.get_IoCProvider().Resolve <ILessonDbRepository>();
     this._settingsDataService = (ISettingsDataService)Mvx.get_IoCProvider().Resolve <ISettingsDataService>();
     this._secureStore         = (ISecureStore)Mvx.get_IoCProvider().Resolve <ISecureStore>();
     this._mobileApi           = (IMobileApi)Mvx.get_IoCProvider().Resolve <IMobileApi>();
 }
Exemplo n.º 5
0
        public UserDataStore(ISecureStore secureStore, ILogger <UserDataStore> logger)
        {
            this.semaphoreSlim = new SemaphoreSlim(1);

            this.secureStore = secureStore ?? throw new ArgumentNullException(nameof(secureStore));
            this.logger      = logger ?? NullLogger <UserDataStore> .Instance;
        }
Exemplo n.º 6
0
 private bool EnsureSecureStoreTargetApplication(bool forceCreate, out ISecureStore store, out string applicationId)
 {
     store         = GetSecureStore(this.Adapter.Site);
     applicationId = GetSecureStoreTargetApplicationID();
     try {
         store.GetApplication(applicationId);
         return(true);
     } catch (SecureStoreServiceTargetApplicationNotFoundException) {
         if (forceCreate)
         {
             using (BypassValidateFormDigest()) {
                 store.CreateApplication(new TargetApplication(
                                             applicationId: applicationId,
                                             friendlyName: String.Concat(this.Key, " (", this.Adapter.Web.Lists[this.Adapter.ListId].RootFolder.Url, ")"),
                                             contactEmail: "",
                                             ticketTimeoutInMinutes: 30,
                                             type: TargetApplicationType.Individual,
                                             credentialManagementUrl: new Uri("http://tempuri.org")),
                                         new[] { new TargetApplicationField("Password", true, SecureStoreCredentialType.Password) },
                                         new TargetApplicationClaims(GetServiceAccounts(), new SecureStoreServiceClaim[0], new SecureStoreServiceClaim[0]));
             }
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 7
0
        public static void DeleteExtentrixWindowsCredentials(Page page, LogLocationEnum LogLocation, SPUser user)
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                    {
                        using (SPWeb web = site.OpenWeb())
                        {
                            SPServiceContext context = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default);

                            SecureStoreServiceProxy ssp = new SecureStoreServiceProxy();
                            ISecureStore iss            = ssp.GetSecureStore(context);

                            SPContext.Current.Web.AllowUnsafeUpdates = true;
                            //SPUtility.ValidateFormDigest();

                            iss.DeleteUserCredentials(Constants.TargetAppID, GetSSClaim(user));
                            SPContext.Current.Web.AllowUnsafeUpdates = false;
                        }
                    }
                });
            }
            catch (SecureStoreServiceCredentialsNotFoundException ex)
            {
                Logger.Default.Error(LogLocation, ex.Message, ex);
            }
            catch (Exception ex)
            {
                Logger.Default.Info(LogLocation, "SecureStore: Exception delete Windows Credentials");
                Logger.Default.Error(LogLocation, ex.Message, ex);
            }
        }
        private void DeployDefinition(object modelHost, ISecureStore hostSecureStore, TargetApplicationDefinition definition)
        {
            var currentObject = GetCurrentObject(hostSecureStore, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioning,
                Object = currentObject,
                ObjectType = typeof(TargetApplication),
                ObjectDefinition = definition,
                ModelHost = modelHost
            });

            if (currentObject == null)
                currentObject = CreateOject(modelHost, hostSecureStore, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioned,
                Object = currentObject,
                ObjectType = typeof(TargetApplication),
                ObjectDefinition = definition,
                ModelHost = modelHost
            });
        }
Exemplo n.º 9
0
        public BasePartition(LeoEngineConfiguration engineConfig, long partitionId, ItemConfiguration config, Func <Task <IEncryptor> > encryptorFactory, IMemoryCache cache, string cachePrefix)
        {
            _store        = new SecureStore(engineConfig.BaseStore, engineConfig.BackupQueue, engineConfig.IndexQueue, engineConfig.Compressor);
            _partitionId  = partitionId;
            _config       = config;
            _engineConfig = engineConfig;

            _options = SecureStoreOptions.KeepDeletes;
            if (config.DoBackup)
            {
                _options = _options | SecureStoreOptions.Backup;
            }
            if (config.Indexer != null)
            {
                _options = _options | SecureStoreOptions.Index;
            }
            if (config.DoCompress)
            {
                _options = _options | SecureStoreOptions.Compress;
            }

            _encryptor = new Lazy <Task <IEncryptor> >(async() => config.DoEncrypt ? await encryptorFactory().ConfigureAwait(false) : null, true);

            string container = partitionId.ToString(CultureInfo.InvariantCulture);

            _luceneIndex = new Lazy <LuceneIndex>(() => engineConfig.IndexStore == null ? null : new LuceneIndex(new SecureStore(engineConfig.IndexStore, null, null, engineConfig.Compressor), container, config.BasePath, _encryptor, cache, $"{cachePrefix}::{partitionId}"), true);
        }
Exemplo n.º 10
0
 public StudentDbDataService()
 {
     this._studentRepository     = (IStudentDbRepository)Mvx.get_IoCProvider().Resolve <IStudentDbRepository>();
     this._formteacherRepository = (IFormTeacherDbRepository)Mvx.get_IoCProvider().Resolve <IFormTeacherDbRepository>();
     this._tutelaryRepository    = (ITutelaryDbRepository)Mvx.get_IoCProvider().Resolve <ITutelaryDbRepository>();
     this._secureStore           = (ISecureStore)Mvx.get_IoCProvider().Resolve <ISecureStore>();
     this._mobileApi             = (IDbMobileApi)Mvx.get_IoCProvider().Resolve <IDbMobileApi>();
 }
Exemplo n.º 11
0
        /// <summary>
        /// Create a lucene index over the top of a secure store, using an encrypted file cache and english analyzer
        /// Only one instance should be used for both indexing and searching (on any number of threads) for best results
        /// </summary>
        /// <param name="store">Store to have the Indexer on top of</param>
        /// <param name="container">Container to put the index</param>
        /// <param name="basePath">The path to namespace this index in</param>
        /// <param name="encryptor">The encryptor to encryt any records being saved</param>
        /// <param name="cache">Use the specified memory cache to store files in memory</param>
        /// <param name="cachePrefix">Caching namespace for memory files</param>
        public LuceneIndex(ISecureStore store, string container, string basePath, Lazy <Task <IEncryptor> > encryptor, IMemoryCache cache = null, string cachePrefix = null)
        {
            encryptor = encryptor ?? new Lazy <Task <IEncryptor> >(() => Task.FromResult((IEncryptor)null));

            _directory = new SecureStoreDirectory(store, container, basePath, encryptor, cache, cachePrefix);
            _analyzer  = new EnglishAnalyzer();

            _reader = new Lazy <SearcherManager>(() => BuildSearcherManagerReader(_directory, _analyzer), true);
        }
Exemplo n.º 12
0
        internal override void Migrate(ISettings appSettings, ISecureStore secureStore = null)
        {
            string valueOrDefault          = appSettings.GetValueOrDefault("settings_profiles_key", (string)null, (string)null);
            IEnumerable <Profile> profiles = string.IsNullOrEmpty(valueOrDefault) ? (IEnumerable <Profile>) new List <Profile>() : (IEnumerable <Profile>)JsonConvert.DeserializeObject <IEnumerable <Profile> >(valueOrDefault);

            foreach (Profile profile in profiles)
            {
                profile.NewItems = (IDictionary <string, List <NewsItem> >) new Dictionary <string, List <NewsItem> >();
            }
            appSettings.AddOrUpdateValue("settings_profiles_key", JsonConvert.SerializeObject((object)profiles), (string)null);
        }
Exemplo n.º 13
0
 public ProfileDataService()
 {
     this._profileRepository      = (IProfileRepository)Mvx.get_IoCProvider().Resolve <IProfileRepository>();
     this._tokenInfoRepository    = (ITokenInfoRepository)Mvx.get_IoCProvider().Resolve <ITokenInfoRepository>();
     this._pushSettingsRepository = (IPushSettingsRepository)Mvx.get_IoCProvider().Resolve <IPushSettingsRepository>();
     this._secureStore            = (ISecureStore)Mvx.get_IoCProvider().Resolve <ISecureStore>();
     this._globalMobileApi        = (IGlobalMobileApi)Mvx.get_IoCProvider().Resolve <IGlobalMobileApi>();
     this._mobileApi = (IMobileApi)Mvx.get_IoCProvider().Resolve <IMobileApi>();
     this._pushNotificationHandler = (IPushNotificationHandler)Mvx.get_IoCProvider().Resolve <IPushNotificationHandler>();
     this._pushNotificationPlatformSpecificService = (IPushNotificationPlatformSpecificService)Mvx.get_IoCProvider().Resolve <IPushNotificationPlatformSpecificService>();
 }
Exemplo n.º 14
0
        internal override void Migrate(ISettings appSettings, ISecureStore secureStore = null)
        {
            JsonSerializerSettings serializerSettings1 = new JsonSerializerSettings();

            serializerSettings1.set_Error((EventHandler <ErrorEventArgs>)((sender, args) => args.get_ErrorContext().set_Handled(true)));
            JsonSerializerSettings serializerSettings2 = serializerSettings1;
            string valueOrDefault          = appSettings.GetValueOrDefault("settings_profiles_key", (string)null, (string)null);
            IEnumerable <Profile> profiles = string.IsNullOrEmpty(valueOrDefault) ? (IEnumerable <Profile>) new List <Profile>() : (IEnumerable <Profile>)JsonConvert.DeserializeObject <IEnumerable <Profile> >(valueOrDefault, serializerSettings2);

            appSettings.AddOrUpdateValue("settings_profiles_key", JsonConvert.SerializeObject((object)profiles), (string)null);
        }
Exemplo n.º 15
0
 public AuthMessageHandler(
     IMobileApi mobileApi,
     ISecureStore secureStore,
     Profile profile,
     HttpMessageHandler handler)
     : base(handler)
 {
     this._mobileApi   = mobileApi;
     this._secureStore = secureStore;
     this._profile     = profile;
 }
Exemplo n.º 16
0
        internal override void Migrate(ISettings appSettings, ISecureStore secureStore = null)
        {
            string valueOrDefault          = appSettings.GetValueOrDefault("settings_profiles_key", (string)null, (string)null);
            IEnumerable <Profile> profiles = string.IsNullOrEmpty(valueOrDefault) ? (IEnumerable <Profile>) new List <Profile>() : (IEnumerable <Profile>)JsonConvert.DeserializeObject <IEnumerable <Profile> >(valueOrDefault);

            foreach (Profile profile in profiles)
            {
                profile.Student.TanuloAktualisOktatasNevelesiKategoriaja = StudentEducationCategory.Alapkepzes;
            }
            appSettings.AddOrUpdateValue("settings_profiles_key", JsonConvert.SerializeObject((object)profiles), (string)null);
        }
Exemplo n.º 17
0
 public UzenetDataService()
 {
     this._secureStore             = (ISecureStore)Mvx.get_IoCProvider().Resolve <ISecureStore>();
     this._eugyintezesApi          = (IEugyintezesApi)Mvx.get_IoCProvider().Resolve <IEugyintezesApi>();
     this._postaladaElemRepository = (IPostaladaElemRepository)Mvx.get_IoCProvider().Resolve <IPostaladaElemRepository>();
     this._uzenetRepository        = (IUzenetRepository)Mvx.get_IoCProvider().Resolve <IUzenetRepository>();
     this._csatolmanyRepository    = (ICsatolmanyRepository)Mvx.get_IoCProvider().Resolve <ICsatolmanyRepository>();
     this._cimzettRepository       = (ICimzettRepository)Mvx.get_IoCProvider().Resolve <ICimzettRepository>();
     this._dataViewer        = (IDataViewer)Mvx.get_IoCProvider().Resolve <IDataViewer>();
     this._permissionManager = (IPermissionManager)Mvx.get_IoCProvider().Resolve <IPermissionManager>();
 }
Exemplo n.º 18
0
 public EugyintezesApi(
     ISecureStore secureStore,
     IMobileApi mobileApi,
     IUserAgentService userAgentData,
     IDataViewer dataViewer)
 {
     this._secureStore         = secureStore;
     this._mobileApi           = mobileApi;
     this._userAgentData       = userAgentData;
     this._dataViewer          = dataViewer;
     this._deviceSpecification = (IDeviceSpecification)Mvx.get_IoCProvider().Resolve <IDeviceSpecification>();
 }
 public AuthDbMessageHandler(
     IDbMobileApi mobileApi,
     ISecureStore secureStore,
     ProfileRealm profile,
     HttpMessageHandler handler)
     : base(handler)
 {
     this._mobileApi           = mobileApi;
     this._secureStore         = secureStore;
     this._profile             = profile;
     this._tokenInfoRepository = (ITokenInfoDbRepository)Mvx.get_IoCProvider().Resolve <ITokenInfoDbRepository>();
 }
Exemplo n.º 20
0
        public static Credentials GetExtentrixWindowsCredentials(Page page, LogLocationEnum LogLocation, SPUser user)
        {
            WindowsCredentials extentrixCredentials = null;

            SecureStoreCredentialCollection ssCreds = null;
            SPServiceContext context = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default);

            SecureStoreServiceProxy ssp = new SecureStoreServiceProxy();
            ISecureStore            iss = ssp.GetSecureStore(context);

            try
            {
                ssCreds = iss.GetCredentials(Constants.TargetAppID);

                if (ssCreds != null && ssCreds.Count() > 0)
                {
                    extentrixCredentials = new WindowsCredentials();
                    IList <TargetApplicationField> applicationFields = GetTargetApplicationFields(Constants.TargetAppID);

                    foreach (TargetApplicationField taf in applicationFields)
                    {
                        switch (taf.Name)
                        {
                        case "Windows User Name":
                            extentrixCredentials.UserName =
                                ReadSecureString(ssCreds[applicationFields.IndexOf(taf)].Credential);
                            break;

                        case "Windows Password":
                            extentrixCredentials.Password =
                                ReadSecureString(ssCreds[applicationFields.IndexOf(taf)].Credential);
                            break;

                        case "Domain":
                            extentrixCredentials.Domain =
                                ReadSecureString(ssCreds[applicationFields.IndexOf(taf)].Credential);
                            break;
                        }
                    }
                }
            }
            catch (SecureStoreServiceCredentialsNotFoundException ex)
            {
                Logger.Default.Error(LogLocation, ex.Message, ex);
            }
            catch (Exception ex)
            {
                Logger.Default.Info(LogLocation, "SecureStore: Exception getting Windows Credentials");
                Logger.Default.Error(LogLocation, ex.Message, ex);
            }

            return(extentrixCredentials);
        }
Exemplo n.º 21
0
        public static void SetExtentrixWindowsCredentials(LogLocationEnum LogLocation, SPUser user, WindowsCredentials extentrixCredentials)
        {
            try
            {
                IList <TargetApplicationField> applicationFields = GetTargetApplicationFields(Constants.TargetAppID);
                IList <ISecureStoreCredential> creds             = new List <ISecureStoreCredential>(applicationFields.Count);

                using (SecureStoreCredentialCollection credentials = new SecureStoreCredentialCollection(creds))
                {
                    foreach (TargetApplicationField taf in applicationFields)
                    {
                        switch (taf.Name)
                        {
                        case "Windows User Name":
                            creds.Add(new SecureStoreCredential(MakeSecureString(extentrixCredentials.UserName),
                                                                SecureStoreCredentialType.WindowsUserName));
                            break;

                        case "Windows Password":
                            creds.Add(new SecureStoreCredential(MakeSecureString(extentrixCredentials.Password),
                                                                SecureStoreCredentialType.WindowsPassword));
                            break;

                        case "Domain":
                            creds.Add(new SecureStoreCredential(MakeSecureString(extentrixCredentials.Domain)
                                                                , SecureStoreCredentialType.Generic));
                            break;
                        }
                    }

                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                        {
                            using (SPWeb web = site.OpenWeb())
                            {
                                SPServiceContext context    = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default);
                                SecureStoreServiceProxy ssp = new SecureStoreServiceProxy();
                                ISecureStore iss            = ssp.GetSecureStore(context);

                                iss.SetUserCredentials(Constants.TargetAppID, GetSSClaim(user), credentials);
                            }
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.Default.Info(LogLocation, "SecureStore: Exception setting windows credentials");
                Logger.Default.Error(LogLocation, ex.Message, ex);
            }
        }
Exemplo n.º 22
0
        internal override void Migrate(ISettings appSettings, ISecureStore secureStore = null)
        {
            string valueOrDefault = appSettings.GetValueOrDefault("settings_profiles_key", (string)null, (string)null);

            foreach (Profile profile in string.IsNullOrEmpty(valueOrDefault) ? (IEnumerable <Profile>) new List <Profile>() : (IEnumerable <Profile>)JsonConvert.DeserializeObject <IEnumerable <Profile> >(valueOrDefault))
            {
                if (profile.IsActive)
                {
                    appSettings.AddOrUpdateValue("settings_active_profile_guid", profile.Id.ToString(), (string)null);
                    break;
                }
            }
        }
Exemplo n.º 23
0
        public CredentialRealmRepository()
        {
            this._mapper = (IRealmMapper <Ekreta.Mobile.Core.Models.Credentials, CredentialRealm>) new CredentialRealmMappers();
            ISecureStore       secureStore        = (ISecureStore)Mvx.get_IoCProvider().Resolve <ISecureStore>();
            RealmConfiguration realmConfiguration = new RealmConfiguration("kretaellenorzo.cr.realm");

            ((RealmConfigurationBase)realmConfiguration).set_EncryptionKey(secureStore.GetEncryptionKey());
            ((RealmConfigurationBase)realmConfiguration).set_SchemaVersion(1UL);
            ((RealmConfigurationBase)realmConfiguration).set_ObjectClasses(new Type[1]
            {
                typeof(CredentialRealm)
            });
            this._realmConfiguration = realmConfiguration;
        }
Exemplo n.º 24
0
        public SecureStoreDirectory(Directory cache, ISecureStore store, string container, string basePath, Lazy<Task<IEncryptor>> encryptor)
        {
            _container = container;
            _basePath = basePath ?? string.Empty;
            _cache = cache;
            _store = store;
            _encryptor = encryptor ?? new Lazy<Task<IEncryptor>>(() => Task.FromResult((IEncryptor)null));

            _options = SecureStoreOptions.None;
            if (_store.CanCompress)
            {
                _options = _options | SecureStoreOptions.Compress;
            }

            store.CreateContainerIfNotExists(container).WaitAndWrap();
        }
Exemplo n.º 25
0
        public SecureStoreIndexInput(SecureStoreDirectory directory, Directory cache, ISecureStore store, IEncryptor encryptor, StoreLocation location, string cachePath)
        {
            _directory = directory;
            _cache = cache;
            _name = cachePath;

            _fileMutex = BlobMutexManager.GrabMutex(_name);
            _fileMutex.WaitOne();
            try
            {
                InitialiseFile(store, encryptor, location).WaitAndWrap();
            }
            finally
            {
                _fileMutex.ReleaseMutex();
            }
        }
Exemplo n.º 26
0
        public void TestInitialize()
        {
            _client        = Substitute.For <ISecretServerClient>();
            _clientFactory = Substitute.For <ISecretServerClientFactory>();
            _context       = new SecretServerContext
            {
                SecretServerUrl = "https://testsecretserver.fakedomain",
                RuleName        = "uipath-rule",
                RuleKey         = "abc-123",
                ResetToken      = "reset",
                UsernameField   = "username",
                PasswordField   = "password",
            };

            _secretSecureStore = new SecretServerSecureStore(_clientFactory);
            _serializedContext = JsonConvert.SerializeObject(_context);
        }
Exemplo n.º 27
0
 public int Migrate(ISettings settings, ISecureStore secureStore, int currentVersion)
 {
     this._settings       = settings;
     this._secureStore    = secureStore;
     this._currentVersion = currentVersion;
     while (this._currentVersion < this._actions.Count - 2)
     {
         try
         {
             this._currentVersion = this._actions[this._currentVersion + 2]();
         }
         catch (Exception ex)
         {
             CrossMobileAnalytics.Current.TrackException(ex, (IDictionary <string, string>)null, nameof(Migrate), "/Users/admin/myagent/macMiniBlack3/_work/2/s/eKreta.Mobile/eKreta.Mobile.Core.Standard/Helpers/Migration.cs", 57);
         }
     }
     return(this._currentVersion);
 }
Exemplo n.º 28
0
        /// <summary>
        /// Create a lucene index over the top of a secure store, using an encrypted file cache and english analyzer
        /// Only one instance should be used for both indexing and searching (on any number of threads) for best results
        /// </summary>
        /// <param name="store">Store to have the Indexer on top of</param>
        /// <param name="container">Container to put the index</param>
        /// <param name="RAMSizeMb">The max amount of memory to use before flushing when writing</param>
        /// <param name="basePath">The path to namespace this index in</param>
        /// <param name="encryptor">The encryptor to encryt any records being saved</param>
        /// <param name="fileBasedPath">If not null, will build lucene file cache at this location (instead of an in-memory one)</param>
        /// <param name="secsTillReaderRefresh">This is the amount of time to cache the reader before updating it</param>
        public LuceneIndex(ISecureStore store, string container, string basePath, Lazy<Task<IEncryptor>> encryptor, string fileBasedPath = null, double RAMSizeMb = 20, int secsTillReaderRefresh = 10)
        {
            encryptor = encryptor ?? new Lazy<Task<IEncryptor>>(() => Task.FromResult((IEncryptor)null));

            if (string.IsNullOrWhiteSpace(fileBasedPath))
            {
                _cacheDirectory = new RAMDirectory();
            }
            else
            {
                var path = IO.Path.Combine(fileBasedPath, container, basePath);
                _cacheDirectory = new MMapDirectory(new System.IO.DirectoryInfo(path));
            }
            
            _directory = new SecureStoreDirectory(_cacheDirectory, store, container, basePath, encryptor);
            _analyzer = new EnglishAnalyzer();
            _RAMSizeMb = RAMSizeMb;
        }
Exemplo n.º 29
0
        public SecureStoreDirectory(ISecureStore store, string container, string basePath, Lazy <Task <IEncryptor> > encryptor, IMemoryCache memoryCache = null, string cachePrefix = null)
        {
            _container   = container;
            _memoryCache = memoryCache ?? new MemoryCache(new MemoryCacheOptions());
            _cachePrefix = cachePrefix ?? "Lucene";
            _basePath    = basePath ?? string.Empty;
            _store       = store;
            _encryptor   = encryptor ?? new Lazy <Task <IEncryptor> >(() => Task.FromResult((IEncryptor)null));

            _lockFactory = new SecureLockFactory(store, GetLocation);

            _options = SecureStoreOptions.None;
            if (_store.CanCompress)
            {
                _options = _options | SecureStoreOptions.Compress;
            }

            SafeTask.SafeWait(() => store.CreateContainerIfNotExists(container));
        }
Exemplo n.º 30
0
        public static IList <TargetApplicationField> GetTargetApplicationFields(string targetApplicationID)
        {
            IList <TargetApplicationField> applicationFields = null;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPServiceContext context = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default);

                        SecureStoreServiceProxy ssp = new SecureStoreServiceProxy();
                        ISecureStore iss            = ssp.GetSecureStore(context);
                        applicationFields           = iss.GetUserApplicationFields(targetApplicationID);
                    }
                }
            });

            return(applicationFields);
        }
Exemplo n.º 31
0
 public AuthDbDataService()
 {
     this._mobileApi                  = (IDbMobileApi)Mvx.get_IoCProvider().Resolve <IDbMobileApi>();
     this._tokenValidator             = (ITokenValidatorDb)Mvx.get_IoCProvider().Resolve <ITokenValidatorDb>();
     this._messenger                  = (IMvxMessenger)Mvx.get_IoCProvider().Resolve <IMvxMessenger>();
     this._secureStore                = (ISecureStore)Mvx.get_IoCProvider().Resolve <ISecureStore>();
     this._profileDataService         = (IProfileDbDataService)Mvx.get_IoCProvider().Resolve <IProfileDbDataService>();
     this._absenceDataService         = (IAbsenceDbDataService)Mvx.get_IoCProvider().Resolve <IAbsenceDbDataService>();
     this._evaluationDataService      = (IEvaluationDataService)Mvx.get_IoCProvider().Resolve <IEvaluationDataService>();
     this._noteDataService            = (INoteDbDataService)Mvx.get_IoCProvider().Resolve <INoteDbDataService>();
     this._lessonDataService          = (ILessonDataService)Mvx.get_IoCProvider().Resolve <ILessonDataService>();
     this._subjectAverageDataService  = (ISubjectAverageDataService)Mvx.get_IoCProvider().Resolve <ISubjectAverageDataService>();
     this._studentDataService         = (IStudentDataService)Mvx.get_IoCProvider().Resolve <IStudentDataService>();
     this._eventDataService           = (IEventDataService)Mvx.get_IoCProvider().Resolve <IEventDataService>();
     this._teacherHomeWorkDataService = (ITeacherHomeWorkDataService)Mvx.get_IoCProvider().Resolve <ITeacherHomeWorkDataService>();
     this._studentHomeWorkDataService = (IStudentHomeWorkDataService)Mvx.get_IoCProvider().Resolve <IStudentHomeWorkDataService>();
     this._cacheDataService           = (ICacheDataService)Mvx.get_IoCProvider().Resolve <ICacheDataService>();
     this._uzenetDataService          = (IUzenetDataService)Mvx.get_IoCProvider().Resolve <IUzenetDataService>();
     this._examDataService            = (IExamDataService)Mvx.get_IoCProvider().Resolve <IExamDataService>();
     this._instituteDataService       = (IInstituteDataService)Mvx.get_IoCProvider().Resolve <IInstituteDataService>();
 }
Exemplo n.º 32
0
        private static void AddAccessTokenToHttpHeader <T>(
            HttpRequestMessage httpMessage,
            string profileId)
            where T : class
        {
            ISecureStore        secureStore        = (ISecureStore)Mvx.get_IoCProvider().Resolve <ISecureStore>();
            IProfileDataService profileDataService = (IProfileDataService)Mvx.get_IoCProvider().Resolve <IProfileDataService>();
            Profile             profile            = profileId != null?profileDataService.GetProfile(profileId) : profileDataService.GetActiveProfile();

            if (profile == null)
            {
                return;
            }
            TokenData tokenData = secureStore.GetTokenData(profile.Id);

            if (tokenData == null)
            {
                return;
            }
            httpMessage.Headers.Add("Authorization", "bearer " + tokenData.AccessToken);
        }
        protected TargetApplication GetCurrentObject(ISecureStore secureStore, TargetApplicationDefinition definition)
        {
            var apps = secureStore.GetApplications();

            if (!string.IsNullOrEmpty(definition.ApplicationId))
            {
                return apps.FirstOrDefault(app => app.ApplicationId.ToUpper() == definition.ApplicationId.ToUpper());
            }
            else if (!string.IsNullOrEmpty(definition.Name))
            {
                return apps.FirstOrDefault(app => app.Name.ToUpper() == definition.FriendlyName.ToUpper());
            }
            else if (!string.IsNullOrEmpty(definition.FriendlyName))
            {
                return apps.FirstOrDefault(app => app.FriendlyName.ToUpper() == definition.FriendlyName.ToUpper());
            }
            else
            {
                throw new SPMeta2Exception("ApplicationId/Name/FriendlyName needs to be defined.");
            }
        }
        protected TargetApplication GetCurrentObject(ISecureStore secureStore, TargetApplicationDefinition definition)
        {
            var apps = secureStore.GetApplications();

            if (!string.IsNullOrEmpty(definition.ApplicationId))
            {
                return(apps.FirstOrDefault(app => app.ApplicationId.ToUpper() == definition.ApplicationId.ToUpper()));
            }
            else if (!string.IsNullOrEmpty(definition.Name))
            {
                return(apps.FirstOrDefault(app => app.Name.ToUpper() == definition.FriendlyName.ToUpper()));
            }
            else if (!string.IsNullOrEmpty(definition.FriendlyName))
            {
                return(apps.FirstOrDefault(app => app.FriendlyName.ToUpper() == definition.FriendlyName.ToUpper()));
            }
            else
            {
                throw new SPMeta2Exception("ApplicationId/Name/FriendlyName needs to be defined.");
            }
        }
        private TargetApplication CreateOject(object modelHost, ISecureStore hostSecureStore, TargetApplicationDefinition definition)
        {
            var appType = (TargetApplicationType)Enum.Parse(typeof(TargetApplicationType), definition.Type);

            var secureStoreClaimns = new List <SecureStoreServiceClaim>();

            foreach (var claim in definition.TargetApplicationClams)
            {
                secureStoreClaimns.Add(GetSecureStoreClaim(claim));
            }

            var appClaims = new TargetApplicationClaims(secureStoreClaimns, null, null);
            var appFields = GetFields(definition);

            hostSecureStore.CreateApplication(
                new TargetApplication(definition.ApplicationId, definition.FriendlyName, definition.ContactEmail,
                                      definition.TicketTimeout,
                                      appType,
                                      new Uri(definition.CredentialManagementUrl)),
                appFields, appClaims);

            return(GetCurrentObject(hostSecureStore, definition));
        }
Exemplo n.º 36
0
        private async Task InitialiseFile(ISecureStore store, IEncryptor encryptor, StoreLocation location)
        {
            bool fFileNeeded = false;
            if (!_cache.FileExists(_name))
            {
                fFileNeeded = true;
            }
            else
            {
                long cachedLength = _cache.FileLength(_name);

                var metadata = await store.GetMetadata(location).ConfigureAwait(false);
                if (metadata == null)
                {
                    throw new System.IO.FileNotFoundException(_name);
                }

                var blobLength = metadata.ContentLength ?? 0;
                var blobLastModifiedUTC = metadata.LastModified ?? DateTime.UtcNow;

                if (cachedLength != blobLength)
                {
                    fFileNeeded = true;
                }
                else
                {
                    // there seems to be an error of 1 tick which happens every once in a while 
                    // for now we will say that if they are within 1 tick of each other and same length 
                    var elapsed = _cache.FileModified(_name);

                    // normalize RAMDirectory and FSDirectory times
                    if (elapsed > ticks1970)
                    {
                        elapsed -= ticks1970;
                    }

                    var cachedLastModifiedUTC = new DateTime(elapsed, DateTimeKind.Local).ToUniversalTime();
                    if (cachedLastModifiedUTC != blobLastModifiedUTC)
                    {
                        var timeSpan = blobLastModifiedUTC.Subtract(cachedLastModifiedUTC);
                        if (timeSpan.TotalSeconds > 1)
                        {
                            fFileNeeded = true;
                        }
                    }
                }
            }

            // if the file does not exist
            // or if it exists and it is older then the lastmodified time in the blobproperties (which always comes from the blob storage)
            if (fFileNeeded)
            {
                using (StreamOutput fileStream = _directory.CreateCachedOutputAsStream(_name))
                {
                    var data = await store.LoadData(location, null, encryptor).ConfigureAwait(false);
                    if (data == null)
                    {
                        throw new System.IO.FileNotFoundException(_name);
                    }
                    await data.Stream.CopyToStream(fileStream, CancellationToken.None).ConfigureAwait(false);
                }

                // and open it as an input 
                _indexInput = _cache.OpenInput(_name);
            }
            else
            {
                // open the file in read only mode
                _indexInput = _cache.OpenInput(_name);
            }
        }
Exemplo n.º 37
0
 public SecureStoreLock(ISecureStore store, StoreLocation location)
 {
     _store = store;
     _location = location;
 }
        private TargetApplication CreateOject(object modelHost, ISecureStore hostSecureStore, TargetApplicationDefinition definition)
        {
            var appType = (TargetApplicationType)Enum.Parse(typeof(TargetApplicationType), definition.Type);

            var secureStoreClaimns = new List<SecureStoreServiceClaim>();

            foreach (var claim in definition.TargetApplicationClams)
                secureStoreClaimns.Add(GetSecureStoreClaim(claim));

            var appClaims = new TargetApplicationClaims(secureStoreClaimns, null, null);
            var appFields = GetFields(definition);

            hostSecureStore.CreateApplication(
                new TargetApplication(definition.ApplicationId, definition.FriendlyName, definition.ContactEmail,
                    definition.TicketTimeout,
                    appType,
                    new Uri(definition.CredentialManagementUrl)),
                appFields, appClaims);

            return GetCurrentObject(hostSecureStore, definition);
        }