예제 #1
2
        public void Setup()
        {
            //Map interfaces for further modifications

            DiMvc.Register();

            Ioc.RegisterType<IUserRepository, UserRepository>();
            Ioc.RegisterType<ICryptoProvider, KeccakCryptoProvider>();
            Ioc.RegisterType<ISaltProvider, RandomSaltProvider>();
            Ioc.RegisterType<RoleProvider, CalendarRoleProvider>();

            _roleProvider = Ioc.Resolve<RoleProvider>();

            var cryptoProvider = Ioc.Resolve<ICryptoProvider>();
            var saltProvider = Ioc.Resolve<ISaltProvider>();

            _userPassword = "******";
            _userSalt = saltProvider.GetSalt(SALT_LENGTH);
            var keccak = cryptoProvider.GetHashWithSalt(_userPassword, _userSalt);

            _user = new User
            {
                Email = "*****@*****.**",
                FirstName = "Sherlock",
                LastName = "Holmes",
                PasswordHash = keccak,
                Role = Roles.Simple
            };

            _repoUnit = Ioc.Resolve<RepoUnit>();
            _repoUnit.User.Save(_user);
        }
 internal static RoleProvider GetDefaultRoleProvider()
 {
     if (defaultRoleProviderSet)
     {
         return defaultRoleProvider;
     }
     Type typeOfRoles = TypeOfRoles;
     RoleProvider provider = null;
     if (typeOfRoles != null)
     {
         try
         {
             if ((bool) typeOfRoles.GetProperty("Enabled").GetValue(null, null))
             {
                 provider = typeOfRoles.GetProperty("Provider").GetValue(null, null) as RoleProvider;
             }
         }
         catch (TargetInvocationException exception)
         {
             if (exception.InnerException != null)
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception.InnerException);
             }
             throw;
         }
     }
     defaultRoleProvider = provider;
     defaultRoleProviderSet = true;
     return provider;
 }
예제 #3
0
파일: Roles.cs 프로젝트: dox0/DotNet471RS3
        private static void InitializeSettings(RoleManagerSection settings)
        {
            if (!s_Initialized)
            {
                s_Providers = new RoleProviderCollection();

                if (HostingEnvironment.IsHosted)
                {
                    ProvidersHelper.InstantiateProviders(settings.Providers, s_Providers, typeof(RoleProvider));
                }
                else
                {
                    foreach (ProviderSettings ps in settings.Providers)
                    {
                        Type t = Type.GetType(ps.Type, true, true);
                        if (!typeof(RoleProvider).IsAssignableFrom(t))
                        {
                            throw new ArgumentException(SR.GetString(SR.Provider_must_implement_type, typeof(RoleProvider).ToString()));
                        }
                        RoleProvider        provider    = (RoleProvider)Activator.CreateInstance(t);
                        NameValueCollection pars        = ps.Parameters;
                        NameValueCollection cloneParams = new NameValueCollection(pars.Count, StringComparer.Ordinal);
                        foreach (string key in pars)
                        {
                            cloneParams[key] = pars[key];
                        }
                        provider.Initialize(ps.Name, cloneParams);
                        s_Providers.Add(provider);
                    }
                }
            }
        }
예제 #4
0
        private static void InitializeDefaultProvider(RoleManagerSection settings)
        {
            bool flag = !HostingEnvironment.IsHosted || (BuildManager.PreStartInitStage == PreStartInitStage.AfterPreStartInit);

            if (!s_InitializedDefaultProvider && flag)
            {
                s_Providers.SetReadOnly();
                if (settings.DefaultProvider == null)
                {
                    s_InitializeException = new ProviderException(System.Web.SR.GetString("Def_role_provider_not_specified"));
                }
                else
                {
                    try
                    {
                        s_Provider = s_Providers[settings.DefaultProvider];
                    }
                    catch
                    {
                    }
                }
                if (s_Provider == null)
                {
                    s_InitializeException = new ConfigurationErrorsException(System.Web.SR.GetString("Def_role_provider_not_found"), settings.ElementInformation.Properties["defaultProvider"].Source, settings.ElementInformation.Properties["defaultProvider"].LineNumber);
                }
                s_InitializedDefaultProvider = true;
            }
        }
        public DefaultProviderSwitcher(
            MembershipProviderAccessor membershipProviderAccessor, 
            RoleProviderAccessor roleProviderAccessor, 
            MembershipProvider provider, 
            RoleProvider roleProvider)
        {
            Condition.Requires(membershipProviderAccessor, "membershipProviderAccessor").IsNotNull();
            Condition.Requires(roleProviderAccessor, "roleProviderAccessor").IsNotNull();
            Condition.Requires(provider, "provider").IsNotNull();
            Condition.Requires(roleProvider, "roleProvider").IsNotNull();

            this.membershipProviderAccessor = membershipProviderAccessor;
            this.roleProviderAccessor = roleProviderAccessor;

            this.originalMembershipInitializedDefault =
                membershipProviderAccessor.SetInitializedDefaultProviderAndReturnOriginalValue(true);
            this.originalMembershipInitialized = membershipProviderAccessor.SetInitializedAndReturnOriginalValue(true);
            this.originalMembershipProvider = membershipProviderAccessor.SetProviderAndReturnOriginalValue(provider);

            this.originalRoleEnabledInitialized = roleProviderAccessor.SetEnabledAndReturnOriginalValue(true);
            this.originalRoleProviders =
                roleProviderAccessor.SetProvidersAndReturnOriginalValue(new RoleProviderCollection());
            this.originalRoleInitializedDefault =
                roleProviderAccessor.SetInitializedDefaultProviderAndReturnOriginalValue(true);
            this.originalRoleInitialized = roleProviderAccessor.SetInitializedAndReturnOriginalValue(true);
            this.originalRoleProvider = roleProviderAccessor.SetProviderAndReturnOriginalValue(roleProvider);
        }
예제 #6
0
 private static void InitializeSettings(RoleManagerSection settings)
 {
     if (!s_Initialized)
     {
         s_Providers = new RoleProviderCollection();
         if (HostingEnvironment.IsHosted)
         {
             ProvidersHelper.InstantiateProviders(settings.Providers, s_Providers, typeof(RoleProvider));
         }
         else
         {
             foreach (ProviderSettings settings2 in settings.Providers)
             {
                 Type c = Type.GetType(settings2.Type, true, true);
                 if (!typeof(RoleProvider).IsAssignableFrom(c))
                 {
                     throw new ArgumentException(System.Web.SR.GetString("Provider_must_implement_type", new object[] { typeof(RoleProvider).ToString() }));
                 }
                 RoleProvider        provider   = (RoleProvider)Activator.CreateInstance(c);
                 NameValueCollection parameters = settings2.Parameters;
                 NameValueCollection config     = new NameValueCollection(parameters.Count, StringComparer.Ordinal);
                 foreach (string str in parameters)
                 {
                     config[str] = parameters[str];
                 }
                 provider.Initialize(settings2.Name, config);
                 s_Providers.Add(provider);
             }
         }
     }
 }
예제 #7
0
        public override IList <string> GetIdentities()
        {
            List <string> list = new List <string>();

            System.Web.Security.RoleProvider roleProvider = this.GetRoleProvider();
            list.AddRange(roleProvider.GetUsersInRole(this.Name));
            return(list);
        }
 private static SimpleRoleProvider CreateDefaultSimpleRoleProvider(string name, RoleProvider currentDefault)
 {
     RoleProvider previousProvider = currentDefault;
     SimpleRoleProvider provider = new SimpleRoleProvider(previousProvider);
     NameValueCollection config = new NameValueCollection();
     provider.Initialize(name, config);
     return provider;
 }
    public FakeRoleProviderTest()
    {
      this.localProvider = Substitute.For<RoleProvider>();
      this.provider = new FakeRoleProvider();
      this.provider.LocalProvider.Value = this.localProvider;

      this.roles = new[] { @"sitecore\Editors", @"sitecore\Authors" };
      this.users = new[] { @"sitecore\John", @"sitecore\Jane" };
    }
        public override IList <string> GetIdentities()
        {
            List <string> identities = new List <string>();

            System.Web.Security.RoleProvider rp = GetRoleProvider();

            identities.AddRange(rp.GetUsersInRole(Name));

            return(identities);
        }
        public ProviderInitializationHttpModule(MembershipProvider membershipProvider, RoleProvider roleProvider)
        {
            MembershipCreateStatus createStatus;

            Roles.CreateRole("Administrator");

            string username = ConfigurationManager.AppSettings["default:username"];
            string password = ConfigurationManager.AppSettings["default:password"];
            string email = ConfigurationManager.AppSettings["default:email"];

            Membership.CreateUser(username, password, email, null, null, true, null, out createStatus);
            Roles.AddUserToRole("admin", "Administrator");
        }
예제 #12
0
 private System.Web.Security.RoleProvider GetRoleProvider()
 {
     if (this.RoleProvider == null)
     {
         return(Roles.Provider);
     }
     System.Web.Security.RoleProvider provider = Roles.Providers[this.RoleProvider];
     if (provider == null)
     {
         throw new ProviderException(SR.GetString("Error_RoleProviderNotAvailableOrEnabled", new object[] { this.RoleProvider }));
     }
     return(provider);
 }
예제 #13
0
        ///<summary>
        ///Initializes the provider.
        ///</summary>
        ///
        ///<param name="config">A collection of the name/value pairs representing the provider-specific 
        /// attributes specified in the configuration for this provider.
        /// The <c>providerId</c> attribute may be used to override the name being used for looking up an object definition.
        /// </param>
        ///<param name="name">The friendly name of the provider.</param>
        ///<exception cref="T:System.ArgumentNullException">The <paramref name="name"/> or <paramref name="config"/> is null.</exception>
        ///<exception cref="T:System.InvalidOperationException">An attempt is made to call <see cref="M:System.Configuration.Provider.ProviderBase.Initialize(System.String,System.Collections.Specialized.NameValueCollection)"></see> on a provider after the provider has already been initialized.</exception>
        ///<exception cref="T:System.ArgumentException">The <paramref name="name"/> has a length of zero or providerId attribute is not set.</exception>      
        public override void Initialize(string name, NameValueCollection config)
        {
            lock (this)
            {
                if (config == null) throw new ArgumentNullException("config");                        
            
                string providerId = config["providerId"];            
                if (String.IsNullOrEmpty(providerId)) 
                    providerId = name;
                config.Remove("providerId");

                this.wrappedProvider = (RoleProvider)WebApplicationContext.GetRootContext().GetObject(providerId);
                this.wrappedProvider.Initialize(name,config);
            }
        }
예제 #14
0
        public void Setup()
        {
            _userBLL = MockRepository.GenerateStub<IUserBLL>();
            _userAuth = MockRepository.GenerateStub<IUserAuth>();
            _delegateBLL = new DelegateBLL(_userAuth, _userBLL);
            _roleProvider = MockRepository.GenerateStub<RoleProvider>();
            _userAuth.RoleProvider = _roleProvider;

            _currentUser.UserName = "******";
            _userBLL.Expect(a => a.GetUser()).Return(_currentUser).Repeat.Any();

            for (int i = 0; i < 3; i++)
            {
                _users.Add(CreateValidEntities.User(i+3));
                //_users[i].Delegate = _users[0];
            }
        }
예제 #15
0
        /// <summary>
        /// 
        /// </summary>
        static Common()
        {
            /* ensure assemblies are loaded
             * this loads assemblies that may not be loaded because they have not direct reference
             * but need to be loaded because they may contain modules and portlets
             */
            EnsureAssembliesAreLoaded();

            _cacheManager = new CacheManager();

            // providers
            _databaseProvider = Databases.Provider as PortalDatabaseProvider;
            _pathProvider = CommunityPaths.Provider;
            _configurationProvider = CommunityConfigurations.Provider;
            _membershipProvider = global::System.Web.Security.Membership.Provider;
            _roleProvider = global::System.Web.Security.Roles.Provider;
        }
예제 #16
0
        protected void DropCollections()
        {
            var roleProvider = new RoleProvider();

            // roles
            var colName = Helper.GenerateCollectionName(_applicationName, RoleProvider.DEFAULT_ROLE_COLLECTION_SUFFIX);
            _db.DropCollection(colName);

            colName = Helper.GenerateCollectionName(_appName2, RoleProvider.DEFAULT_ROLE_COLLECTION_SUFFIX);
            _db.DropCollection(colName);

            // users
            colName = Helper.GenerateCollectionName(_applicationName, MembershipProvider.DEFAULT_USER_COLLECTION_SUFFIX);
            _db.DropCollection(colName);

            colName = Helper.GenerateCollectionName(_appName2, MembershipProvider.DEFAULT_USER_COLLECTION_SUFFIX);
            _db.DropCollection(colName);
        }
        public void Setup()
        {
            RavenDb.InitializeStorage();

            ((RavenDbStorage) RavenDb.Storage).SessionSettings.SetStaleResultsWhait(StaleResultWhaitMode.AllNonStale);

            var repositoryFactory = Substitute.For<IRepositoryFactory>();
            repositoryFactory.CreateUserRepository().Returns(_ => _enableOutsideSession
                                                                      ? new UserRepositoryImpl(_outsideSession)
                                                                      : new UserRepositoryImpl(RavenDb.Storage));
            repositoryFactory.CreateRoleRepository().Returns(_ => _enableOutsideSession
                                                                      ? new RoleRepositoryImpl(_outsideSession)
                                                                      : new RoleRepositoryImpl(RavenDb.Storage));

            RepositoryFactory.Initialize(repositoryFactory);

            _roleProvider = new RoleProvider();
            _membershipProvider = new MembershipProvider();
        }
예제 #18
0
    /// <summary>
    /// The initialize.
    /// </summary>
    /// <param name="name">
    /// The name.
    /// </param>
    /// <param name="config">
    /// The config.
    /// </param>
    /// <exception cref="ProviderException">
    /// </exception>
    public override void Initialize(string name, NameValueCollection config)
    {
      string realProviderName = config["passThru"];


      if (realProviderName == null || realProviderName.Length < 1)
      {
        throw new ProviderException("Pass Thru provider name has not been specified in the web.config");
      }

      // Remove passThru configuration attribute
      config.Remove("passThru");

      // Check for further attributes
      if (config.Count > 0)
      {
        // Throw Provider error as no more attributes were expected
        throw new ProviderException("Unrecognised Attribute on the Roles PassThru Provider");
      }

      // Initialise the "Real" roles provider
      this._realProvider = Roles.Providers[realProviderName];
    }
예제 #19
0
 public void Initialize(RoleProvider provider)
 {
     _Provider = provider;
 }
예제 #20
0
 public AdSecurityRepository(RoleProvider roleProvider) : base(roleProvider){}
예제 #21
0
 /// <summary>
 /// Creates the default simple role provider.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="currentDefault">The current default.</param>
 /// <returns></returns>
 private static SimpleRoleProvider CreateDefaultSimpleRoleProvider(string name, RoleProvider currentDefault)
 {
     var roleProvider = new SimpleRoleProvider(previousProvider: currentDefault);
     var config = new NameValueCollection();
     roleProvider.Initialize(name, config);
     return roleProvider;
 }
        public void SetProvider(string ProviderName)
        {
            OnDebug(this, name + ".SetProvider()");

            try
            {
                if (String.IsNullOrWhiteSpace(ProviderName))
                {
                    InternalProvider = Roles.Provider;
                }
                else
                {
                    InternalProvider = Roles.Providers[ProviderName];
                }

                OnDebug(this, name + ": InternalProvider = " + InternalProvider.Name);
            }
            catch (Exception ex)
            {
                OnError(this, ex);
                InternalProvider = Roles.Provider;
            }
        }
 private static void InitializeDefaultProvider(RoleManagerSection settings)
 {
     bool flag = !HostingEnvironment.IsHosted || (BuildManager.PreStartInitStage == PreStartInitStage.AfterPreStartInit);
     if (!s_InitializedDefaultProvider && flag)
     {
         s_Providers.SetReadOnly();
         if (settings.DefaultProvider == null)
         {
             s_InitializeException = new ProviderException(System.Web.SR.GetString("Def_role_provider_not_specified"));
         }
         else
         {
             try
             {
                 s_Provider = s_Providers[settings.DefaultProvider];
             }
             catch
             {
             }
         }
         if (s_Provider == null)
         {
             s_InitializeException = new ConfigurationErrorsException(System.Web.SR.GetString("Def_role_provider_not_found"), settings.ElementInformation.Properties["defaultProvider"].Source, settings.ElementInformation.Properties["defaultProvider"].LineNumber);
         }
         s_InitializedDefaultProvider = true;
     }
 }
예제 #24
0
 public RightsProvider(RoleProvider roleProvider, IRepository rightsRepository)
 {
     _roleProvider = roleProvider;
     _rightsRepository = rightsRepository;
 }
 public AspNetRoleProviderWrapper(RoleProvider roleProvider)
 {
     _roleProvider = roleProvider;
 }
예제 #26
0
 public AccountMembershipService(MembershipProvider provider, RoleProvider roleProvider)
 {
     _provider = provider ?? Membership.Provider;
     _roleProvider = roleProvider ?? Roles.Provider;
 }
        public override bool IncludesIdentity(string identity)
        {
            System.Web.Security.RoleProvider rp = GetRoleProvider();

            return(rp.IsUserInRole(identity, Name));
        }
예제 #28
0
 public RoleService(RoleProvider roleProvider)
 {
     this.roleProvider = roleProvider;
 }
 public AspRoleAuthorizationCallContextInitializer(RoleProvider roleProvider)
 {
     this.RoleProvider = roleProvider;
 }
예제 #30
0
		public void SetUp() {
			var config = new NameValueCollection();
			config.Add("applicationName", "IntegrationTests");
			config.Add("ldapServer", LdapServerInConfig);
			var ldapProvider = new LdapRoleProvider();

			ldapProvider.Initialize("IntegrationTests", config);

			var enabledField = typeof(Roles).GetField("s_Enabled",
			                                    BindingFlags.NonPublic |
			                                    BindingFlags.Static);

			enabledField.SetValue(typeof(Roles), true);

			var initialized = typeof(Roles).GetField("s_Initialized",
			                                    BindingFlags.NonPublic |
			                                    BindingFlags.Static);

			initialized.SetValue(typeof(Roles), true);

			var providers = new RoleProviderCollection(); 

			var readOnlyField = typeof(Roles).GetField("s_Providers",
			                                                BindingFlags.NonPublic |
			                                                BindingFlags.Static);
			readOnlyField.SetValue(typeof(Roles), providers);

			providers.Add(ldapProvider);

			var registeredProvider = Roles.Providers["IntegrationTests"];

			Assert.IsNotNull(registeredProvider);
			
			provider = registeredProvider;
		}
예제 #31
0
 public SimpleRoleProvider(RoleProvider previousProvider) {
     _previousProvider = previousProvider;
 }
예제 #32
0
        public Dictionary<string, bool> GetRolesForUser(string userName, RoleProvider provider)
        {
            Dictionary<string, bool> roles = new Dictionary<string, bool>();

            var rolesIn = provider.GetRolesForUser(userName);
            var rolesNotIn = provider.GetAllRoles().Except(rolesIn).ToArray();
            foreach (var role in rolesIn)
            {
                roles.Add(role, true);
            }

            foreach (var role in rolesNotIn)
            {
                roles.Add(role, false);
            }

            return roles;
        }
 public AccountRoleService(RoleProvider provider)
 {
     _provider = provider ?? Roles.Provider;
 }
예제 #34
0
 public FormsMembershipService(MembershipProvider provider)
 {
     _provider = provider ?? Membership.Provider;
     _roleProvider = Roles.Provider;
 }
 public AspNetRoleProviderWrapper()
 {
     if (Roles.Enabled)
         _roleProvider = Roles.Provider;
 }
예제 #36
0
 public UserAccountService(MembershipProvider membershipProvider, RoleProvider roleProvider)
 {
   this._membership = membershipProvider ?? Membership.Provider;
   this._roleProvider = roleProvider ?? Roles.Provider;
 }
예제 #37
0
		public void CopyTo (RoleProvider[] array, int index)
		{
			base.CopyTo (array, index);
		}
예제 #38
0
 private RoleProvider()
 {
     _Provider = Roles.Providers["SqlRoleProvider"];
 }