Exemple #1
0
 public ProductsController()
 {
     _unitOfWork = new UnitOfWork(new ProjectContext());
     _productRepository = _unitOfWork.Products;
     _categoryRepository = _unitOfWork.Categories;
     _authRepository = _unitOfWork.Users;
 }
        public bool HasAllRoles(IAuthSession session, IAuthRepository authRepo)
        {
            if (session == null)
                return false;

            return this.RequiredRoles.All(x => session.HasRole(x, authRepo));
        }
        /// <summary>
        /// Saves the Auth Tokens for this request. Called in OnAuthenticated(). 
        /// Overrideable, the default behaviour is to call IUserAuthRepository.CreateOrMergeAuthSession().
        /// </summary>
        protected virtual void SaveUserAuth(IServiceBase authService, IAuthSession session, IAuthRepository authRepo, IAuthTokens tokens)
        {
            if (authRepo == null) return;
            if (tokens != null)
            {
                session.UserAuthId = authRepo.CreateOrMergeAuthSession(session, tokens);
            }

            authRepo.LoadUserAuth(session, tokens);

            foreach (var oAuthToken in session.ProviderOAuthAccess)
            {
                var authProvider = AuthenticateService.GetAuthProvider(oAuthToken.Provider);
                if (authProvider == null) continue;
                var userAuthProvider = authProvider as OAuthProvider;
                if (userAuthProvider != null)
                {
                    userAuthProvider.LoadUserOAuthProvider(session, oAuthToken);
                }
            }

            authRepo.SaveUserAuth(session);

            var httpRes = authService.Request.Response as IHttpResponse;
            if (httpRes != null)
            {
                httpRes.Cookies.AddPermanentCookie(HttpHeaders.XUserAuthId, session.UserAuthId);
            }
            OnSaveUserAuth(authService, session);
        }
        public bool HasAllPermissions(IAuthSession session, IAuthRepository authRepo)
        {
            if (session == null)
                return false;

            return this.RequiredPermissions.All(x => session.HasPermission(x, authRepo));
        }
Exemple #5
0
 public UserController(IAuthRepository authRepository, IAccountService accountService, IDataConverter mapper, IUserService userService, ILogService logService)
     : base(mapper)
 {
     _authRepository = authRepository;
     _accountService = accountService;
     _userService = userService;
     _logService = logService;
 }
 public StandingsProvider(IGameRepository gameRepository, IAuthRepository userRepository, ITournamentProvider tournamentProvider)
 {
     if (gameRepository == null) throw new ArgumentNullException(nameof(gameRepository));
     if (userRepository == null) throw new ArgumentNullException(nameof(userRepository));
     if (tournamentProvider == null) throw new ArgumentNullException(nameof(tournamentProvider));
     _gameRepository = gameRepository;
     _userRepository = userRepository;
     _tournamentProvider = tournamentProvider;
 }
        public RequestServiceTest()
        {
            // Initial Setup
            _converter = new JsonConverter();
            _handler = new Mock<IRequestHandler>();
            _service = new RequestService(_handler.Object);
            _boxConfig = new Mock<ICanvasConfig>();

            OAuth2Session session = new OAuth2Session("fakeAccessToken", "fakeRefreshToken", 3600, "bearer");

            _authRepository = new AuthRepository(_boxConfig.Object, _service, _converter, session);
        }
        public bool HasAllRoles(IHttpRequest req, IAuthSession session, IAuthRepository userAuthRepo=null)
        {
            if (HasAllRoles(session)) return true;

            session.UpdateFromUserAuthRepo(req, userAuthRepo);

            if (HasAllRoles(session))
            {
                req.SaveSession(session);
                return true;
            }
            return false;
        }
        public bool HasAllPermissions(IRequest req, IAuthSession session, IAuthRepository authRepo)
        {
            if (HasAllPermissions(session, authRepo)) return true;

            session.UpdateFromUserAuthRepo(req, authRepo);

            if (HasAllPermissions(session, authRepo))
            {
                req.SaveSession(session);
                return true;
            }
            return false;
        }
Exemple #10
0
        public virtual bool HasPermission(string permission, IAuthRepository authRepo)
        {
            if (UserAuthId == null)
                return false;

            if (!FromToken) //If populated from a token it should have the complete list of permissions
            {
                var managesRoles = authRepo as IManageRoles;
                if (managesRoles != null)
                {
                    return managesRoles.HasPermission(this.UserAuthId, permission);
                }
            }

            return this.Permissions != null && this.Permissions.Contains(permission);
        }
Exemple #11
0
        public virtual bool HasRole(string role, IAuthRepository authRepo)
        {
            if (UserAuthId == null)
                return false;

            if (!FromToken) //If populated from a token it should have the complete list of roles
            {
                var managesRoles = authRepo as IManageRoles;
                if (managesRoles != null)
                {
                    return managesRoles.HasRole(this.UserAuthId, role);
                }
            }

            return this.Roles != null && this.Roles.Contains(role);
        }
        public bool HasAllPermissions(IRequest req, IAuthSession session, IAuthRepository userAuthRepo=null)
        {
            if (HasAllPermissions(session)) return true;

            if (userAuthRepo == null) 
                userAuthRepo = req.TryResolve<IAuthRepository>();

            if (userAuthRepo == null) return false;

            var userAuth = userAuthRepo.GetUserAuth(session, null);
            session.UpdateSession(userAuth);

            if (HasAllPermissions(session))
            {
                req.SaveSession(session);
                return true;
            }
            return false;
        }
        public bool HasAnyPermissions(IRequest req, IAuthSession session, IAuthRepository authRepo)
        {
            if (HasAnyPermissions(session, authRepo)) return true;

            if (authRepo == null)
                authRepo = HostContext.AppHost.GetAuthRepository(req);

            if (authRepo == null)
                return false;

            using (authRepo as IDisposable)
            {
                var userAuth = authRepo.GetUserAuth(session, null);
                session.UpdateSession(userAuth);

                if (HasAnyPermissions(session, authRepo))
                {
                    req.SaveSession(session);
                    return true;
                }
                return false;
            }
        }
 public AuthController(IConfiguration configuration, IAuthRepository authRepository)
 {
     _configuration  = configuration;
     _authRepository = authRepository;
 }
Exemple #15
0
 public AuthController(IAuthRepository repository, IConfiguration configuration)
 {
     _configuration = configuration;
     _repository    = repository;
 }
 public RefreshTokensController(ILogger logger, IAuthRepository authRepository)
     : base(logger)
 {
     _authRepository = authRepository;
 }
Exemple #17
0
 public ImageController(IMatsMatRepository repository, IAuthRepository authRepo)
     :base(repository, authRepo)
 {
 }
 public AuthenticationController(IAuthRepository repo, IConfiguration configuration)
 {
     _repo          = repo;
     _configuration = configuration;
 }
 public AccountController(IMatsMatRepository matsMatRepo, IAuthRepository authRepo)
     :base(matsMatRepo, authRepo)
 {
 }
 public AuthController(IAuthRepository repo)
 {
     this._repo = repo;
 }
Exemple #21
0
 public ResourceOwnerPasswordValidator(IAuthRepository authRepository)
 {
     _authRepository = authRepository;
 }
 public AuthService(IAuthRepository authRepository)
 {
     _authRepository = authRepository;
 }
Exemple #23
0
 public AuthService(IAuthRepository repository)
 => (_repository) = (repository);
Exemple #24
0
 public MusteriController(IAppRepository appRepository, IAuthRepository authRepository)
 {
     _authRepository = authRepository;
     _appRepository  = appRepository;
 }
Exemple #25
0
 public TagRepository(IFlickrElement elementProxy, AuthInfo authenticationInformation, IAuthRepository authRepository)
     : base(elementProxy, authenticationInformation, typeof(ITagRepository))
 {
     this.elementProxy = elementProxy;
     this.authRepository = authRepository;
 }
Exemple #26
0
 public AuthController(IAuthRepository authRepository, IConfiguration configuration, IMapper mapper)
 {
     _mapper         = mapper;
     _authRepository = authRepository;
     _configuration  = configuration;
 }
 public AuthorizationServerProvider(IAuthRepository authRepo)
 {
     _authRepo = authRepo;
 }
Exemple #28
0
 public AuthController(IAuthRepository authRepository)
 {
     _authRepo = authRepository;
 }
 public BoxCollectionsManager(IBoxConfig config, IBoxService service, IBoxConverter converter, IAuthRepository auth, string asUser = null, bool? suppressNotifications = null)
     : base(config, service, converter, auth, asUser, suppressNotifications) { }
Exemple #30
0
        /// <summary>
        /// Initializes a new BoxClient with the provided config, converter, service and auth objects.
        /// </summary>
        /// <param name="boxConfig">The config object to use</param>
        /// <param name="boxConverter">The box converter object to use</param>
        /// <param name="requestHandler">The box request handler to use</param>
        /// <param name="boxService">The box service to use</param>
        /// <param name="auth">The auth repository object to use</param>
        /// <param name="asUser">The user ID to set as the 'As-User' header parameter; used to make calls in the context of a user using an admin token</param>
        /// <param name="suppressNotifications">Whether or not to suppress both email and webhook notifications. Typically used for administrative API calls. Your application must have “Manage an Enterprise” scope, and the user making the API calls is a co-admin with the correct "Edit settings for your company" permission.</param>
        public BoxClient(IBoxConfig boxConfig, IBoxConverter boxConverter, IRequestHandler requestHandler, IBoxService boxService, IAuthRepository auth, string asUser = null, bool?suppressNotifications = null)
        {
            Config = boxConfig;

            _asUser = asUser;
            _suppressNotifications = suppressNotifications;

            _handler   = requestHandler;
            _converter = boxConverter;
            _service   = boxService;
            Auth       = auth;

            InitManagers();
        }
Exemple #31
0
        protected virtual IHttpResult ValidateAccount(IServiceBase authService, IAuthRepository authRepo, IAuthSession session, IAuthTokens tokens)
        {
            var userAuth = authRepo.GetUserAuth(session, tokens);
            var isLocked = userAuth != null && userAuth.LockedDate != null;

            if (isLocked)
            {
                session.IsAuthenticated = false;
                authService.SaveSession(session, SessionExpiry);
                return authService.Redirect(session.ReferrerUrl.AddHashParam("f", "AccountLocked"));
            }

            return null;
        }
Exemple #32
0
 /// <summary>
 /// Create a new Boxgroupmanager object.
 /// </summary>
 /// <param name="config"></param>
 /// <param name="service"></param>
 /// <param name="converter"></param>
 /// <param name="auth"></param>
 public BoxGroupsManager(IBoxConfig config, IBoxService service, IBoxConverter converter, IAuthRepository auth, string asUser = null, bool?suppressNotifications = null)
     : base(config, service, converter, auth, asUser, suppressNotifications)
 {
 }
 protected virtual bool IsAccountLocked(IAuthRepository authRepo, IUserAuth userAuth, IAuthTokens tokens=null)
 {
     if (userAuth == null) return false;
     return userAuth.LockedDate != null;
 }
Exemple #34
0
        public async Task <IActionResult> Register(UserForRegistrationDto userForRegistrationDto, [FromServices] IAuthRepository authRepository)
        {
            if (await authRepository.UserExists(userForRegistrationDto.username.ToLower()))
            {
                return(BadRequest("Username already exists"));
            }

            var userToCreate = new User
            {
                Username = userForRegistrationDto.username
            };

            var createdUser = await authRepository.Register(userToCreate, userForRegistrationDto.password);

            return(StatusCode(201));
        }
Exemple #35
0
 public ApiAccessHandler(IHttpContextAccessor contextAccessor, IAuthRepository authRepository)
 {
     _contextAccessor = contextAccessor;
     _authRepository  = authRepository;
 }
 public SampleController(IAuthRepository repo, IConfiguration config)
 {
     _config = config;
     _repo   = repo;
 }
Exemple #37
0
 public AuthController(IAuthRepository authRepository, IConfiguration config, IMapper iMapper)
 {
     mapper        = iMapper;
     configuration = config;
     repository    = authRepository;
 }
Exemple #38
0
 public AuthService(IAuthRepository iRepository, IUnitOfWork iUnitOfWork) : base(iRepository, iUnitOfWork)
 {
     _iRepository = iRepository ?? throw new ArgumentNullException(nameof(iRepository));
     _iUnitOfWork = iUnitOfWork ?? throw new ArgumentNullException(nameof(iUnitOfWork));
 }
 public virtual bool HasAnyPermissions(IAuthSession session, IAuthRepository authRepo)
 {
     return this.RequiredPermissions
         .Any(requiredPermission => session != null
             && session.HasPermission(requiredPermission, authRepo));
 }
Exemple #40
0
 public AuthController(IAuthRepository repo, IConfiguration config)
 {
     this._repo = repo;
     _config    = config;
 }
Exemple #41
0
 public AuthController(IAuthRepository authRepo, IConfiguration config)
 {
     _authRepo = authRepo;
     _config   = config;
 }
Exemple #42
0
 public AuthController(IAuthRepository repository, IConfiguration config)
 {
     _repository = repository;
     _config     = config;
 }
 public AuthController(IAuthRepository repository)
 {
     _repository = repository;
 }
Exemple #44
0
 public AuthController(IAuthRepository repo, IConfiguration config, IEmailSender sender)
 {
     _repo   = repo;
     _config = config;
     _sender = sender;
 }
 public BoxCommentsManager(IBoxConfig config, IBoxService service, IBoxConverter converter, IAuthRepository auth, string asUser = null)
     : base(config, service, converter, auth, asUser) { }
 public AuthController(IAuthRepository repo, IConfiguration config, IMapper mapper)
 {
     _config = config;
     _mapper = mapper;
     _repo   = repo;
 }
 public AnalyticsManager(ICanvasConfig config, IRequestService service, IJsonConverter converter, IAuthRepository auth) : base(config, service, converter, auth)
 {
 }
 public AuthController(IAuthRepository auth, IConfiguration config)
 {
     _config = config;
     _auth   = auth;
 }
 public AccountController(IAuthRepository repo)
 {
     _repo = repo;
 }
 public AuthBusinessLogic(IAuthRepository authRepository, IConfiguration config)
 {
     _authRepository = authRepository;
     _config         = config;
 }
 public RecipesController(IMatsMatRepository repository, IAuthRepository authRepo)
     :base(repository, authRepo)
 {
 }
 public AuthController(IAuthRepository repository, IConfiguration config, IMapper mapper)
 {
     _repository    = repository;
     _configuration = config;
     _mapper        = mapper;
 }
Exemple #53
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Startup"/> class.
 /// </summary>
 public Startup()
 {
     this.authRepository = StructuremapMvc.StructureMapDependencyScope.Container.GetInstance<IAuthRepository>();
     this.crmManagerService = StructuremapMvc.StructureMapDependencyScope.Container.GetInstance<ICRMManagerService>();
 }
 public BoxFilesManager(IBoxConfig config, IBoxService service, IBoxConverter converter, IAuthRepository auth)
     : base(config, service, converter, auth) { }
        protected virtual bool EmailAlreadyExists(IAuthRepository authRepo, IUserAuth userAuth, IAuthTokens tokens = null)
        {
            if (tokens != null && tokens.Email != null)
            {
                var userWithEmail = authRepo.GetUserAuthByUserName(tokens.Email);
                if (userWithEmail == null) 
                    return false;

                var isAnotherUser = userAuth == null || (userAuth.Id != userWithEmail.Id);
                return isAnotherUser;
            }
            return false;
        }
 public AuthController(ISessionManager sessionManager, IAuthRepository <User> repository) : base(sessionManager)
 {
     _repository = repository;
 }
        protected virtual IHttpResult ValidateAccount(IServiceBase authService, IAuthRepository authRepo, IAuthSession session, IAuthTokens tokens)
        {
            var userAuth = authRepo.GetUserAuth(session, tokens);

            var authFeature = HostContext.GetPlugin<AuthFeature>();

            if (authFeature != null && authFeature.ValidateUniqueUserNames && UserNameAlreadyExists(authRepo, userAuth, tokens))
            {
                return authService.Redirect(FailedRedirectUrlFilter(this, GetReferrerUrl(authService, session).SetParam("f", "UserNameAlreadyExists")));
            }

            if (authFeature != null && authFeature.ValidateUniqueEmails && EmailAlreadyExists(authRepo, userAuth, tokens))
            {
                return authService.Redirect(FailedRedirectUrlFilter(this, GetReferrerUrl(authService, session).SetParam("f", "EmailAlreadyExists")));
            }

            if (IsAccountLocked(authRepo, userAuth, tokens))
            {
                return authService.Redirect(FailedRedirectUrlFilter(this, GetReferrerUrl(authService, session).SetParam("f", "AccountLocked")));
            }

            return null;
        }
Exemple #58
0
 public AuthController(IAuthRepository repo, IConfiguration icofig)
 {
     _repo   = repo;
     _icofig = icofig;
 }
Exemple #59
0
 public AuthController(IAuthRepository repo, IConfiguration configuration, IMapper mapper)
 {
     this.mapper        = mapper;
     this.repo          = repo;
     this.configuration = configuration;
 }
Exemple #60
0
 public ResourceOwnerPasswordValidator(IAuthRepository rep)
 {
     this._rep = rep;
 }