public UserService(IdentityDatabaseContext identityDatabaseContext, IOptions <IdentitySettings> identitySettings, IHttpContextAccessor iHttpContextAccessor)
 {
     _userRepository = new UserRepository(identityDatabaseContext, identitySettings, iHttpContextAccessor);
     _jwtService     = new JwtService(identityDatabaseContext, identitySettings, iHttpContextAccessor);
     //_roleService = new RoleService(identityDatabaseContext);
     _userRoleService = new UserRoleService(identityDatabaseContext, identitySettings, iHttpContextAccessor);
 }
 public UserRolesController(IdentityDatabaseContext identityDatabaseContext, IUserRoleService userRoleService, IUserService userService, IRoleService roleService)
 {
     _identityDatabaseContext = identityDatabaseContext;
     _userRoleService         = userRoleService;
     _userService             = userService;
     _roleService             = roleService;
 }
		public UserStoreTests(string collectionPrefix)
		{
			collectionPrefix = $"{typeof(UserStoreTests).Name}_{collectionPrefix}";

			_databaseFixture = new DatabaseFixture(collectionPrefix);
			_userCollection = _databaseFixture.GetCollection<IdentityUser>();
			_roleCollection = _databaseFixture.GetCollection<IdentityRole>();
			_databaseContext = new IdentityDatabaseContext { UserCollection = _userCollection, RoleCollection = _roleCollection };

			_errorDescriber = new IdentityErrorDescriber();
			_userStore = new UserStore<IdentityUser, IdentityRole>(_databaseContext, null, _errorDescriber);


			_claim1 = new Claim("ClaimType1", "some value");
			_claim2 = new Claim("ClaimType2", "some other value");
			_claim3 = new Claim("other type", "some other value");

			_claim1SameType = new Claim(_claim1.Type, _claim1.Value + " different");

			_identityClaim1 = new IdentityClaim(_claim1);
			_identityClaim2 = new IdentityClaim(_claim2);
			_identityClaim3 = new IdentityClaim(_claim3);

			_identityClaim1SameType = new IdentityClaim(_claim1SameType);
		}
        public UserStoreTests(string collectionPrefix)
        {
            collectionPrefix = $"{typeof(UserStoreTests).Name}_{collectionPrefix}";

            _databaseFixture = new DatabaseFixture(collectionPrefix);
            _userCollection  = _databaseFixture.GetCollection <IdentityUser>();
            _roleCollection  = _databaseFixture.GetCollection <IdentityRole>();
            _databaseContext = new IdentityDatabaseContext {
                UserCollection = _userCollection, RoleCollection = _roleCollection
            };

            _errorDescriber = new IdentityErrorDescriber();
            _userStore      = new UserStore <IdentityUser, IdentityRole>(_databaseContext, null, _errorDescriber);


            _claim1 = new Claim("ClaimType1", "some value");
            _claim2 = new Claim("ClaimType2", "some other value");
            _claim3 = new Claim("other type", "some other value");

            _claim1SameType = new Claim(_claim1.Type, _claim1.Value + " different");

            _identityClaim1 = new IdentityClaim(_claim1);
            _identityClaim2 = new IdentityClaim(_claim2);
            _identityClaim3 = new IdentityClaim(_claim3);

            _identityClaim1SameType = new IdentityClaim(_claim1SameType);
        }
        protected override void Seed(GeographyDatabaseContext context)
        {
            var typesOfRegions = context.Set <TypeOfRegion>();

            var storedTypesOfRegionsNames = new HashSet <string>(typesOfRegions.Select(t => t.Name));

            var regionNames = new HashSet <string>
            {
                "World",
                "Continent",
                "Country",
                "Province (State)",
                "Multi-Region (within a country)",
                "Multi-City (Vicinity)",
                "City",
                "Neighborhood",
                "Point of Interest",
                "Point of Interest Shadow",
                "Airport",
                "Train Station"
            };

            const string userName = "******";

            int creatorId;

            using (var identityContext = new IdentityDatabaseContext())
            {
                var users = identityContext.Set <Model.Identity.User>();
                if (!users.Any(p => p.UserName == userName))
                {
                    users.Add(new Model.Identity.User {
                        UserName = userName
                    });
                    identityContext.SaveChanges();
                }


                var geographyContextUser = identityContext.Users.FirstOrDefault(p => p.UserName == userName);
                if (geographyContextUser == null)
                {
                    throw new NullReferenceException(nameof(geographyContextUser));
                }

                creatorId = geographyContextUser.Id;
            }

            foreach (var regionName in regionNames)
            {
                if (!storedTypesOfRegionsNames.Contains(regionName))
                {
                    context.Set <TypeOfRegion>().Add(new TypeOfRegion {
                        Name = regionName, CreatorId = creatorId
                    });
                }
            }

            context.SaveChanges();
        }
 // The following code creates the database and schema if they don't exist.
 // This is a temporary workaround since deploying database through EF migrations is
 // not yet supported in this release.
 // Please see this http://go.microsoft.com/fwlink/?LinkID=615859 for more information on how to do deploy the database
 // when publishing your application.
 private static void EnsureDatabaseCreated(IdentityDatabaseContext context)
 {
     if (!_databaseChecked)
     {
         _databaseChecked = true;
         context.Database.EnsureCreated();
     }
 }
示例#7
0
        public AuthenticationController()
        {
            var context = new IdentityDatabaseContext();
            var store   = new UserStore <IdentityUser>(context);

            userManager = new UserManager <IdentityUser>(store);
            roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
        }
		public RoleStoreTests(string collectionPrefix)
		{
			collectionPrefix = $"{typeof(RoleStoreTests).Name}_{collectionPrefix}";

			_databaseFixture = new DatabaseFixture(collectionPrefix);
			_userCollection = _databaseFixture.GetCollection<IdentityUser>();
			_roleCollection = _databaseFixture.GetCollection<IdentityRole>();
			_databaseContext = new IdentityDatabaseContext { UserCollection = _userCollection, RoleCollection = _roleCollection };

			_userStore = new UserStore<IdentityUser, IdentityRole>(_databaseContext);
			_roleStore = new RoleStore<IdentityUser, IdentityRole>(_databaseContext);
			_errorDescriber = new IdentityErrorDescriber();
		}
示例#9
0
        public void Instance_Is_IdentityDbContext_Of_User_Comma_Role_Comma_Integer_Comma_UserLogin_Comma_UserRole_Comma_UserClaim()
        {
            //Arrange
            var type =
                typeof(Microsoft.AspNet.Identity.EntityFramework.IdentityDbContext <User, Role, int, UserLogin, Membership,
                                                                                    UserClaim>);

            //Act
            var context = new IdentityDatabaseContext();

            //Assert
            Assert.IsInstanceOf(type, context);
        }
 public AccountController(
     UserManager <ApplicationUser> userManager,
     SignInManager <ApplicationUser> signInManager,
     IEmailSender emailSender,
     ISmsSender smsSender,
     IdentityDatabaseContext applicationDbContext)
 {
     _userManager          = userManager;
     _signInManager        = signInManager;
     _emailSender          = emailSender;
     _smsSender            = smsSender;
     _applicationDbContext = applicationDbContext;
 }
示例#11
0
        public RoleStoreTests(string collectionPrefix)
        {
            collectionPrefix = $"{typeof(RoleStoreTests).Name}_{collectionPrefix}";

            _databaseFixture = new DatabaseFixture(collectionPrefix);
            _userCollection  = _databaseFixture.GetCollection <IdentityUser>();
            _roleCollection  = _databaseFixture.GetCollection <IdentityRole>();
            _databaseContext = new IdentityDatabaseContext {
                UserCollection = _userCollection, RoleCollection = _roleCollection
            };

            _userStore      = new UserStore <IdentityUser, IdentityRole>(_databaseContext);
            _roleStore      = new RoleStore <IdentityUser, IdentityRole>(_databaseContext);
            _errorDescriber = new IdentityErrorDescriber();
        }
        public IdentityDatabaseContextTests(string collectionPrefix)
        {
            RegisterClassMap <IdentityUser, IdentityRole, string> .Init();

            collectionPrefix = $"{typeof(IdentityDatabaseContextTests).Name}_{collectionPrefix}";

            var configuration = new ConfigurationBuilder().AddJsonFile("config.json").Build();

            _databaseContext = new IdentityDatabaseContext
            {
                ConnectionString        = configuration["Data:ConnectionString"],
                DatabaseName            = "Testing",
                EnsureCollectionIndexes = false
            };
            _databaseContext.UserCollectionName = collectionPrefix + "_" + _databaseContext.UserCollectionName;
            _databaseContext.RoleCollectionName = collectionPrefix + "_" + _databaseContext.RoleCollectionName;
        }
示例#13
0
        /// <summary>
        /// Configures the application and HTTP request pipeline. Configure is called after ConfigureServices is
        /// called by the ASP.NET runtime.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <param name="loggerfactory">The logger factory.</param>
        /// <param name="identityContext">The database context for the identity database</param>
        public void Configure(IApplicationBuilder application, ILoggerFactory loggerfactory,
                              IdentityDatabaseContext identityContext)
        {
            //__BEGIN_INITIALIZE_DATABASES_
            if (_hostingEnvironment.IsDevelopment())
            {
                IdentityDatabaseIntializer.InitializeDevelopmentEnvironment(identityContext);
            }
            else
            {
                IdentityDatabaseIntializer.InitializeProductionEnvironment(identityContext);
            }

            //__END_INTIALIZE_DATABASES_

            application
            // Removes the Server HTTP header from the HTTP response for marginally better security and performance.
            .UseNoServerHttpHeader()
            // Require HTTPS to be used across the whole site. Also set a custom port to use for SSL in
            // Development. The port number to use is taken from the launchSettings.json file which Visual
            // Studio uses to start the application.
            .UseRewriter(
                new RewriteOptions().AddRedirectToHttps(StatusCodes.Status301MovedPermanently, _sslPort))
#if (CORS)
            .UseCors(CorsPolicyName.AllowAny)
#endif
            .UseResponseCaching()
            .UseResponseCompression()
            .UseStaticFilesWithCacheControl(_configuration)
            .UseCookiePolicy()
            .UseIfElse(
                _hostingEnvironment.IsDevelopment(),
                x => x
                .UseDebugging()
                .UseDeveloperErrorPages(),
                x => x.UseErrorPages())
            .UseStrictTransportSecurityHttpHeader()
            .UsePublicKeyPinsHttpHeader()
            .UseContentSecurityPolicyHttpHeader(_sslPort, _hostingEnvironment)
            .UseSecurityHttpHeaders()
            .UseAuthentication()
            .UseMvc();
        }
示例#14
0
        public BaseTest()
        {
            // var serviceProvider = new ServiceCollection()
            ////.AddEntityFrameworkSqlServer()
            //.AddEntityFrameworkNpgsql()
            ////.AddTransient<ITestService, TestService>()
            //.BuildServiceProvider();

            DbContextOptionsBuilder <IdentityDatabaseContext> builder = new DbContextOptionsBuilder <IdentityDatabaseContext>();
            var connectionString = "server=localhost;userid=root;password=12345;database=Identity;";

            builder.UseMySql(connectionString);
            //.UseInternalServiceProvider(serviceProvider); //burası postgress ile sıkıntı çıkartmıyor, fakat mysql'de çalışmıyor test esnasında hata veriyor.

            _identityDatabaseContext = new IdentityDatabaseContext(builder.Options);
            //_context.Database.Migrate();

            IdentitySettings _identitySettings = new IdentitySettings()
            {
                FileUploadFolderPath = "c:/"
            };
            IOptions <IdentitySettings> options = Options.Create(_identitySettings);
            IHttpContextAccessor        iHttpContextAccessor = new HttpContextAccessor {
                HttpContext = new DefaultHttpContext()
            };

            _userService           = new UserService(_identityDatabaseContext, options, iHttpContextAccessor);
            _roleService           = new RoleService(_identityDatabaseContext, options, iHttpContextAccessor);
            _jwtService            = new JwtService(_identityDatabaseContext, options, iHttpContextAccessor);
            _permissionService     = new PermissionService(_identityDatabaseContext, options, iHttpContextAccessor);
            _rolePermissionService = new RolePermissionService(_identityDatabaseContext, options, iHttpContextAccessor);
            _userRoleService       = new UserRoleService(_identityDatabaseContext, options, iHttpContextAccessor);
            schemaService          = new SchemaService(_identityDatabaseContext, options, iHttpContextAccessor);


            //Status Services.
            //StatusSettings _statusSettings = new StatusSettings() { FileUploadFolderPath = "c:/" };
            //IOptions<StatusSettings> statusOptions = Options.Create(_statusSettings);
            //_statusService = new StatusService(_statusDatabaseContext, statusOptions, iHttpContextAccessor);
        }
示例#15
0
        private void CreateRolesandUsers()
        {
            var context     = new IdentityDatabaseContext();
            var store       = new UserStore <IdentityUser>(context);
            var userManager = new UserManager <IdentityUser>(store);
            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));

            if (!roleManager.RoleExists("Admin"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);

                var user = new IdentityUser();
                user.UserName = "******";

                string userPWD = "P@ssword1";

                var chkUser = userManager.Create(user, userPWD);

                if (chkUser.Succeeded)
                {
                    var result1 = userManager.AddToRole(user.Id, "Admin");
                }
            }

            if (!roleManager.RoleExists("Manager"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Manager";
                roleManager.Create(role);
            }

            if (!roleManager.RoleExists("Employee"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Employee";
                roleManager.Create(role);
            }
        }
 public SchemaService(IdentityDatabaseContext identityDatabaseContext, IOptions <IdentitySettings> identitySettings, IHttpContextAccessor iHttpContextAccessor)
 {
     _identityDatabaseContext  = identityDatabaseContext;
     _identitySchemaRepository = new IdentitySchemaRepository(_identityDatabaseContext, identitySettings, iHttpContextAccessor);
 }
示例#17
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            IdentityDatabaseContext _identityDatabaseContext = (IdentityDatabaseContext)context.HttpContext.RequestServices.GetService(typeof(IdentityDatabaseContext));
            IJwtService             _jwtService      = (JwtService)context.HttpContext.RequestServices.GetService(typeof(IJwtService));
            IUserService            _userService     = (UserService)context.HttpContext.RequestServices.GetService(typeof(IUserService));
            IRoleService            _roleService     = (RoleService)context.HttpContext.RequestServices.GetService(typeof(IRoleService));
            IUserRoleService        _userRoleService = (UserRoleService)context.HttpContext.RequestServices.GetService(typeof(IUserRoleService));

            context.HttpContext.Request.Headers.TryGetValue("Token", out _Token);
            if (_Token.Count > 0)
            {
                Guid token;
                Jwt  jwt = new Jwt();
                try
                {
                    token = Guid.Parse(_Token.FirstOrDefault());

                    jwt = (Jwt)_jwtService.CheckToken(token).Data;
                    if (jwt == null)
                    {
                        CommonApiResponse <dynamic> response = CommonApiResponse <dynamic> .Create(context.HttpContext.Response, System.Net.HttpStatusCode.OK, false, null, "Token geçersiz.");

                        BadRequestObjectResult badReq = new BadRequestObjectResult(response);
                        context.Result = badReq;
                        return;
                    }
                }
                catch (Exception ex)
                {
                    CommonApiResponse <dynamic> response = CommonApiResponse <dynamic> .Create(context.HttpContext.Response, System.Net.HttpStatusCode.InternalServerError, false, null, ex.Message);

                    BadRequestObjectResult badReq = new BadRequestObjectResult(response);
                    context.Result = badReq;
                    return;
                }

                try
                {
                    var  controller = context.Controller as Controller;
                    User user       = _userService.GetById(jwt.UserId);
                    List <UserRoleView> userRoleViewList = _userRoleService.GetByUserId(jwt.UserId);
                    if (user == null)
                    {
                        CommonApiResponse <dynamic> response = CommonApiResponse <dynamic> .Create(context.HttpContext.Response, System.Net.HttpStatusCode.OK, false, null, "Kullanıcı bulunamadı.");

                        BadRequestObjectResult badReq = new BadRequestObjectResult(response);
                        context.Result = badReq;
                        return;
                    }

                    if (requiredRoleList.Count > 0)
                    {
                        foreach (string requiredRoleName in requiredRoleList)
                        {
                            foreach (var userRole in userRoleViewList)
                            {
                                if (Guid.Parse(requiredRoleName) == userRole.RoleId)
                                {
                                    IsAcces = true;
                                    break;
                                }
                            }
                        }
                        if (!IsAcces)
                        {
                            CommonApiResponse <dynamic> response = CommonApiResponse <dynamic> .Create(context.HttpContext.Response, System.Net.HttpStatusCode.OK, false, null, "Yetkiniz yok.");

                            BadRequestObjectResult badReq = new BadRequestObjectResult(response);
                            context.Result = badReq;
                            return;
                        }
                    }

                    controller.ViewBag.Jwt  = jwt;
                    controller.ViewBag.User = user;
                }
                catch (Exception ex)
                {
                    CommonApiResponse <dynamic> response = CommonApiResponse <dynamic> .Create(context.HttpContext.Response, System.Net.HttpStatusCode.InternalServerError, false, null, ex.Message);

                    BadRequestObjectResult badReq = new BadRequestObjectResult(response);
                    context.Result = badReq;
                    return;
                }
            }
            else
            {
                CommonApiResponse <dynamic> response = CommonApiResponse <dynamic> .Create(context.HttpContext.Response, System.Net.HttpStatusCode.OK, false, null, "Header Token bulunamadı.");

                ObjectResult badReq = new ObjectResult(response);
                context.Result = badReq;
            }
        }
示例#18
0
 public LoginController(IdentityDatabaseContext identityDatabaseContext, IUserService userService)
 {
     _identityDatabaseContext = identityDatabaseContext;
     _userService             = userService;
 }
 public PermissionService(IdentityDatabaseContext identityDatabaseContext, IOptions <IdentitySettings> identitySettings, IHttpContextAccessor iHttpContextAccessor)
 {
     _permissionRepository     = new PermissionRepository(identityDatabaseContext, identitySettings, iHttpContextAccessor);
     _rolePermissionRepository = new RolePermissionRepository(identityDatabaseContext, identitySettings, iHttpContextAccessor);
 }
示例#20
0
 public RolePermissionController(IdentityDatabaseContext identityDatabaseContext, IRolePermissionService rolePermissionService)
 {
     _identityDatabaseContext = identityDatabaseContext;
     _rolePermissionService   = rolePermissionService;
 }
示例#21
0
 public UsersRepository(IdentityDatabaseContext context) : base(context)
 {
 }
示例#22
0
 protected IdentityRepository(IdentityDatabaseContext context) : base(context)
 {
     Context = context;
 }
 public JwtService(IdentityDatabaseContext identityDatabaseContext, IOptions <IdentitySettings> identitySettings, IHttpContextAccessor iHttpContextAccessor)
 {
     _jwtRepository = new JwtRepository(identityDatabaseContext, identitySettings, iHttpContextAccessor);
 }
 public UserService(IdentityUserManager userManager, IdentityDatabaseContext dbContext, BookService bookService)
 {
     this.userManager = userManager;
     this.bookService = bookService;
     this.roles       = dbContext.Roles.Distinct() as IQueryable <CustomRole>;
 }
		public RoleStoreInMemoryTests()
		{
			var databaseContext = new IdentityDatabaseContext();
			_roleStore = new RoleStore<IdentityUser, IdentityRole>(databaseContext);
		}
 public PermissionsController(IdentityDatabaseContext identityDatabaseContext, IPermissionService permissionService)
 {
     _identityDatabaseContext = identityDatabaseContext;
     _permissionService       = permissionService;
 }
示例#27
0
 /// <summary>
 /// Initializes the Identity database if it is not already initialized. If initialized, it binds the database to the application through dependency injection
 /// </summary>
 public static IApplicationBuilder InitializeIdentityDatabase(this IApplicationBuilder application, IHostingEnvironment hostingEnvironment, IdentityDatabaseContext identityContext)
 {
     if (hostingEnvironment.IsDevelopment())
     {
         IdentityDatabaseIntializer.InitializeDevelopmentEnvironment(identityContext);
     }
     else
     {
         IdentityDatabaseIntializer.InitializeProductionEnvironment(identityContext);
     }
     return(application);
 }
        public RoleStoreInMemoryTests()
        {
            var databaseContext = new IdentityDatabaseContext();

            _roleStore = new RoleStore <IdentityUser, IdentityRole>(databaseContext);
        }
示例#29
0
 public UsersController(IdentityDatabaseContext identityDatabaseContext, IUserService testService, IJwtService iJwtService)
 {
     _identityDatabaseContext = identityDatabaseContext;
     _userService             = testService;
     _iJwtService             = iJwtService;
 }
 public ValuesController(IOptions <IdentitySettings> identitySettings, IdentityDatabaseContext identityDatabaseContext)
 {
     _identitySettings        = identitySettings;
     _identityDatabaseContext = identityDatabaseContext;
 }
示例#31
0
        protected override void Seed(PropertyDatabaseContext context)
        {
            var typesOfAttributes = context.Set <TypeOfAttribute>();

            var storedTypesOfAttributesNames = new HashSet <string>(typesOfAttributes.Select(t => t.Name));

            var typesOfAttributesNames = new HashSet <string>
            {
                "Amenity",
                "Policy"
            };

            const string userName = "******";

            int creatorId;

            using (var identityContext = new IdentityDatabaseContext())
            {
                var users = identityContext.Set <Model.Identity.User>();
                if (!users.Any(p => p.UserName == userName))
                {
                    users.Add(new Model.Identity.User {
                        UserName = userName
                    });
                    identityContext.SaveChanges();
                }

                var propertyContextUser = identityContext.Users.FirstOrDefault(p => p.UserName == userName);
                if (propertyContextUser == null)
                {
                    throw new NullReferenceException(nameof(propertyContextUser));
                }

                creatorId = propertyContextUser.Id;
            }

            foreach (var typeOfAttributeName in typesOfAttributesNames)
            {
                if (!storedTypesOfAttributesNames.Contains(typeOfAttributeName))
                {
                    typesOfAttributes.Add(new TypeOfAttribute {
                        Name = typeOfAttributeName, CreatorId = creatorId
                    });
                }
            }
            context.SaveChanges();


            var subTypesOfAttributes            = context.Set <SubTypeOfAttribute>();
            var storedSubTypesOfAttributesNames = new HashSet <string>(subTypesOfAttributes.Select(s => s.Name));

            var subTypesOfAttributesNames = new HashSet <string>
            {
                "AmenityOfAccommodation",
                "AmenityOfRoom",
                "CheckInOut",
                "Other",
                "Payment",
                "Pets"
            };

            foreach (var subTypesOfAttributesName in subTypesOfAttributesNames)
            {
                if (!storedSubTypesOfAttributesNames.Contains(subTypesOfAttributesName))
                {
                    subTypesOfAttributes.Add(new SubTypeOfAttribute()
                    {
                        Name = subTypesOfAttributesName, CreatorId = creatorId
                    });
                }
            }
            context.SaveChanges();
        }
示例#32
0
 public JwtController(IJwtService iJwtService, IdentityDatabaseContext identityDatabaseContext)
 {
     _iJwtService             = iJwtService;
     _identityDatabaseContext = identityDatabaseContext;
 }