Ejemplo n.º 1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="configuration"></param>
 /// <param name="authorization"></param>
 /// <param name="webExecute"></param>
 /// <param name="logger"></param>
 public Transaction(IConfiguration configuration, IAuthorization authorization, IExecutorWeb webExecute, ILog logger)
 {
     _configuration = configuration;
     _authorization = authorization;
     _webExecute = webExecute;
     _logger = logger;
 }
Ejemplo n.º 2
0
        private int runCount = 0; // number of times run has been called

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="Bot"/> class.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="userInteraction">The user interaction manager..</param>
        /// <param name="console">The console.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="listener">The listener.</param>
        /// <param name="pluginHandler">The plugin handler.</param>
        /// <param name="moduleLoader">The module loader.</param>
        /// <param name="authorization">The authorization manager.</param>
        public Bot(
            Client client, 
            IUserInteraction userInteraction, 
            IConsole console, 
            IBotSettings settings, 
            IListener listener, 
            IPluginHandler pluginHandler,
            IModuleLoader moduleLoader,
            IAuthorization authorization)
        {
            Guard.Against(client.IsNull(), "client");
            Guard.Against(userInteraction.IsNull(), "userInteraction");
            Guard.Against(console.IsNull(), "console");
            Guard.Against(settings.IsNull(), "settings");
            Guard.Against(listener.IsNull(), "listener");
            Guard.Against(pluginHandler.IsNull(), "pluginHandler");
            Guard.Against(moduleLoader.IsNull(), "moduleLoader");
            Guard.Against(authorization.IsNull(), "authorization");

            this.client = client;
            this.userInteraction = userInteraction;
            this.console = console;
            this.settings = settings;
            this.listener = listener;
            this.pluginHandler = pluginHandler;
            this.moduleLoader = moduleLoader;
            this.authorization = authorization;
            this.SessionStart = DateTime.Now;
        }
Ejemplo n.º 3
0
    protected override void OnInit(EventArgs e)
    {
        try
        {
            _authorization = new Authorization(User.Identity.Name);
        }
        catch { }

        base.OnInit(e);
    }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PluginContext"/> class.
 /// Is marked as internal so external clients cannot instantiate.
 /// </summary>
 /// <param name="client">The client.</param>
 /// <param name="console">The console.</param>
 /// <param name="authorizer">The authorizer.</param>
 /// <param name="chatrooms">The chatrooms.</param>
 /// <param name="listener">The listener.</param>
 /// <param name="botSettings">The bot settings.</param>
 /// <param name="pluginHandler">The plugin handler.</param>
 /// <param name="dispatcher">The system dispatcher.</param>
 /// <param name="packet">The current packet to be processed.</param>
 /// <param name="chatHelper">The chat helper.</param>
 public PluginContext(Client client, IConsole console,
     IAuthorization authorizer, IChatRoomContainer chatrooms,
     IListener listener, IBotSettings botSettings, 
     IPluginHandler pluginHandler, IDispatcher dispatcher, 
     EventPacket packet, IChatHelper chatHelper)
 {
     this.Client = client;
     this.Console = console;
     this.Authorizer = authorizer;
     this.ChatRooms = chatrooms;
     this.Listener = listener;
     this.BotSettings = botSettings;
     this.Plugins = pluginHandler;
     this.Dispatcher = dispatcher;
     this.ThisRoom = chatHelper;
 }
        public void CreateServiceAuthorizationStruct(IAuthorization authorization, string serviceName)
        {
            if (authorization == null) throw new ArgumentNullException("authorization");

            foreach (Structure structure in _dbContext.Structures)
            {
                var structureContext = structure;
                var containers =
                    _dbContext.Containers.Where((c) => c.ContainerPrototype.StructureId == structureContext.Id);

                foreach (Container container in containers)
                {
                    CreateGroups(authorization, structure.Id, container.Id);

                    foreach (WorkSpaceType workSpaceType in container.ContainerPrototype.WorkSpaceTypes)
                    {
                        var containerContext = container;
                        var workSpaceTypeContext = workSpaceType;

                        var rootName = authorization.GetContainerName(structure.Id, container.Id, workSpaceType.Name);

                        authorization.CreateContainer(rootName);

                        var roles = _dbContext.Roles.Where(
                            (r) =>
                            r.ContainerPrototypeStructureId == structureContext.Id &&
                            r.WorkSpaceTypeStructureId == structureContext.Id &&
                            r.WorkSpaceTypeName == workSpaceTypeContext.Name &&
                            r.ContainerPrototypeName == containerContext.ContainerPrototype.Name
                            );

                        SetCurrentAndParentRoleTypes(authorization, structure, container, rootName, serviceName, roles);

                        SetChildsRoleTypes(authorization, structure, container, rootName, serviceName, roles);
                    }
                }
            }

            authorization.Dispose();
        }
        private void CreateGroups(IAuthorization authorization, long structure, long container)
        {
            var roletypes = _dbContext.Enrolls.Where(
                (c) => c.ContainerId == container
                ).Select(
                    (c) => c.RoleType
                ).Distinct();

            foreach (RoleType roletype in roletypes)
            {
                var roletypeContext = roletype;
                var users = _dbContext.Enrolls.Where(
                    (cu) =>
                    cu.ContainerId == container &&
                    cu.RoleTypeName == roletypeContext.Name &&
                    cu.RoleTypeStructureId == structure
                    ).Select(
                        (cu) =>
                        cu.User.Name
                    );

                authorization.AddGroup(authorization.GetGroupName(structure, container, roletype.Name), users);
            }
        }
Ejemplo n.º 7
0
 public AuthController(UserContext UserContext, ILogger <AuthController> log, IAuthorization authorization)
 {
     this.authorization = authorization;
     this.UserContext   = UserContext;
     this.logger        = log;
 }
Ejemplo n.º 8
0
 public WopiHandler(WopiUserRequest wopiUser)
 {
     _userRequest   = wopiUser;
     _errHandler    = new ErrorHandler();
     _authorization = new Authorization();
 }
 public AuthorizationBehavior(IAuthorization authorization)
 {
     this.authorization = authorization;
 }
Ejemplo n.º 10
0
 public MyService(IAuthorization auth)
 {
     _auth = auth;
 }
Ejemplo n.º 11
0
 public CustomerFinderImpl(IRepository repository, IAuditor auditor, IAuthorization authorization)
 {
     this.repository = repository;
     this.auditor = auditor;
     this.authorization = authorization;
 }
Ejemplo n.º 12
0
 public MainManager(AppDBContext context, IEncryptor encryptor, IKPSService kPSService, IMailSender mailSender, IMemoryCache cache, IAuthorization authenticator)
 {
     this.context       = context;
     this.encryptor     = encryptor;
     this.kPSService    = kPSService;
     this.mailSender    = mailSender;
     this.cache         = cache;
     this.authenticator = authenticator;
 }
Ejemplo n.º 13
0
        public static AuthorizedKey ForMetadata(
            ISshKey key,
            string preferredUsername,
            bool useInstanceKeySet,
            IAuthorization authorization)
        {
            Utilities.ThrowIfNull(key, nameof(key));

            if (preferredUsername != null)
            {
                if (!IsValidUsername(preferredUsername))
                {
                    throw new ArgumentException(
                              $"The username '{preferredUsername}' is not a valid username");
                }
                else
                {
                    //
                    // Use the preferred username.
                    //
                    return(new AuthorizedKey(
                               key,
                               useInstanceKeySet
                            ? AuthorizeKeyMethods.InstanceMetadata
                            : AuthorizeKeyMethods.ProjectMetadata,
                               preferredUsername));
                }
            }
            else
            {
                Utilities.ThrowIfNull(authorization, nameof(authorization));

                //
                // No preferred username provided, so derive one
                // from the user's email address:
                //
                // 1. Remove all characters following and including '@'.
                // 2. Lowercase all alpha characters.
                // 3. Replace all non-alphanum characters with '_'.
                //
                var username = new string(authorization.Email
                                          .Split('@')[0]
                                          .ToLower()
                                          .Select(c => IsAsciiLetterOrNumber(c) ? c : '_')
                                          .ToArray());

                //
                // 4. Prepend with 'g' if the username does not start with an alpha character.
                //
                if (!IsAsciiLetter(username[0]))
                {
                    username = "******" + username;
                }

                //
                // 5. Truncate the username to 32 characters.
                //
                username = username.Substring(0, Math.Min(MaxUsernameLength, username.Length));

                return(new AuthorizedKey(
                           key,
                           useInstanceKeySet
                        ? AuthorizeKeyMethods.InstanceMetadata
                        : AuthorizeKeyMethods.ProjectMetadata,
                           username));
            }
        }
Ejemplo n.º 14
0
 public ArtistController(IAuthorization authorization, IRepository artistRepository)
 {
     Authorization = authorization;
     Repository    = artistRepository;
 }
Ejemplo n.º 15
0
 public AuthorizationBehavior(IAuthorization authorization)
 {
     this.authorization = authorization;
 }
Ejemplo n.º 16
0
 public AuthorizationServiceBefore()
 {
     // Возникает проблема в том что авторизация может быть только через mail
     // и чтобы сменить тип авторизации нужно будет лезть в код
     _authorization = new MailAuthorization();
 }
 public TwitterEngineConfiguration(TwitterAuthorization authorization)
 {
     this.authorization = authorization;
 }
        private void SetCurrentAndParentRoleTypes(
            IAuthorization authorization,
            Structure structure,
            Container rootContainer,
            string rootName,
            string service,
            IEnumerable<Role> roles
            )
        {
            Container current = rootContainer;

            do
            {
                foreach (var role in roles)
                    if (ContainsRoleType(structure, current, role.RoleType))
                    {
                        var permissions = role.Rule.Permissions.Where(
                            (sp) =>
                            sp.ServiceName == service
                            ).Select(
                                (sp) =>
                                sp.Name
                            );

                        authorization.AddGroupPermission(
                            rootName,
                            authorization.GetGroupName(structure.Id, current.Id, role.RoleTypeName),
                            permissions
                            );
                    }

                current = current.ParentContainer;
            } while (current != null);
        }
        private void SetChildsRoleTypes(
            IAuthorization authorization,
            Structure structure,
            Container rootContainer,
            string rootName,
            string service,
            IEnumerable<Role> roles
            )
        {
            if (rootContainer.Childs == null) return;

            foreach (var child in rootContainer.Childs)
            {
                SetChildsRoleTypes(authorization, structure, child, service, rootName, roles);

                foreach (var role in roles)
                    if (ContainsRoleType(structure, child, role.RoleType))
                    {
                        var permissions = role.Rule.Permissions.Where(
                            (sp) =>
                            sp.ServiceName == service
                            ).Select(
                                (sp) => sp.Name
                            );

                        authorization.AddGroupPermission(
                            rootName,
                            authorization.GetGroupName(structure.Id, child.Id, role.RoleTypeName),
                            permissions
                            );
                    }
            }
        }
Ejemplo n.º 20
0
        public virtual void Logoff()
        {
            IAuthorization authorization = (IAuthorization)this.GetService <IPermissionsProvider>();

            authorization.Logoff();
        }
Ejemplo n.º 21
0
 public AuthorizeController(IAuthorization authorization)
 {
     _authorization = authorization;
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Initializes a new instance of <see cref="ProductBlo"/> (Business Controller)
 /// </summary>
 /// <param name="authorization">Security information access object to be used by this instance</param>
 /// <param name="dataAccess">Application Request's data access object to be used by this instance</param>
 public ProductBlo(IProductDao dataAccess, IAuthorization authorization, ILogger logger, IMultimediaBlo multimediaBLO) : base(dataAccess, authorization, logger)
 {
     MultimediaBLO = multimediaBLO;
 }
Ejemplo n.º 23
0
 public WopiProcessor(IAuthorization authorization, IErrorHandler errorHandler, HttpListenerResponse response)
 {
     _authorization = authorization;
     _errorHandler  = errorHandler;
     _response      = response;
 }
Ejemplo n.º 24
0
        public async Task <AddDancerPayload> AddDancerAsync(
            AddDancerInput input,
            [ScopedService] DatabaseContext context,
            [Service] IFileStorage fileStorage,
            [Service] IAuthorization authorization,
            CancellationToken cancellationToken)
        {
            var authId = authorization.GetUserId();

            if (authId == null)
            {
                return(new AddDancerPayload(
                           new []
                {
                    new UserError("Cannot find auth id.", CommonErrorCodes.ACT_AGAINST_INVALID_SUBJECT)
                }));
            }

            if (context.Dancers.Any(d => d.AuthenticationId == authId))
            {
                return(new AddDancerPayload(
                           new []
                {
                    new UserError("Auth id already has associated dancer.", CommonErrorCodes.ACT_AGAINST_INVALID_SUBJECT)
                }));
            }

            var dancer = new Dancer
            {
                DdrCode = input.DdrCode,
                DdrName = input.DdrName,
                State   = input.State,
                PrimaryMachineLocation = input.PrimaryMachineLocation,
                AuthenticationId       = authId
            };

            if (input.ProfilePicture != null)
            {
                dancer.ProfilePictureTimestamp = DateTime.UtcNow;
                try
                {
                    using var profileImage = await Image.LoadAsync(input.ProfilePicture.OpenReadStream());

                    var image = await Images.ImageToPngMemoryStreamFactor(profileImage, 256, 256);

                    var destinationKey = $"profile/picture/{dancer.Id}.{(dancer.ProfilePictureTimestamp?.Ticks - 621355968000000000) / 10000000}.png";
                    await fileStorage.UploadFileFromStream(image, destinationKey);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return(new AddDancerPayload(
                               new []
                    {
                        new UserError("Failed to upload profile picture.", CommonErrorCodes.IMAGE_UPLOAD_FAILED)
                    }));
                }
            }

            await context.Dancers.AddAsync(dancer, cancellationToken);

            await context.SaveChangesAsync(cancellationToken);

            return(new AddDancerPayload(dancer));
        }
Ejemplo n.º 25
0
 public async Task InvokeAsync(HttpContext context, IAuthorization authorization)
 {
     _authorization = authorization;
     await _next.Invoke(context);
 }
Ejemplo n.º 26
0
        public virtual void testInvalidCreateAuthorization()
        {
            TestResource resource1 = new TestResource("resource1", 100);

            // case 1: no user id & no group id ////////////

            IAuthorization authorization = authorizationService.CreateNewAuthorization(AuthorizationFields.AuthTypeGrant);

            //authorization.Resource = resource1;

            try
            {
                authorizationService.SaveAuthorization(authorization);
                Assert.Fail("exception expected");
            }
            catch (ProcessEngineException e)
            {
                Assert.True(e.Message.Contains("IAuthorization must either have a 'userId' or a 'groupId'."));
            }

            // case 2: both user id & group id ////////////

            authorization         = authorizationService.CreateNewAuthorization(AuthorizationFields.AuthTypeGrant);
            authorization.GroupId = "someId";
            authorization.UserId  = "someOtherId";
            //authorization.Resource = resource1;

            try
            {
                authorizationService.SaveAuthorization(authorization);
                Assert.Fail("exception expected");
            }
            catch (ProcessEngineException e)
            {
                AssertTextPresent("IAuthorization must either have a 'userId' or a 'groupId'.", e.Message);
            }

            // case 3: no resourceType ////////////

            authorization        = authorizationService.CreateNewAuthorization(AuthorizationFields.AuthTypeGrant);
            authorization.UserId = "someId";

            try
            {
                authorizationService.SaveAuthorization(authorization);
                Assert.Fail("exception expected");
            }
            catch (ProcessEngineException e)
            {
                Assert.True(e.Message.Contains("IAuthorization 'resourceType' cannot be null."));
            }

            // case 4: no permissions /////////////////

            authorization        = authorizationService.CreateNewAuthorization(AuthorizationFields.AuthTypeRevoke);
            authorization.UserId = "someId";

            try
            {
                authorizationService.SaveAuthorization(authorization);
                Assert.Fail("exception expected");
            }
            catch (ProcessEngineException e)
            {
                Assert.True(e.Message.Contains("IAuthorization 'resourceType' cannot be null."));
            }
        }
 public AcmeProcessingWorkflow()
 {
     _authorizationRules = ApplicationRoot.Context.Resolve <IAuthorization>();
     _repository         = ApplicationRoot.Context.Resolve <IRepository>();
 }
Ejemplo n.º 28
0
        public AuthController(IAuthorization repo, IConfiguration config)
        {
            _config = config;

            _repo = repo;
        }
Ejemplo n.º 29
0
 public CustomerFinderImpl(IRepository repository, IAuditor auditor, IAuthorization authorization)
 {
     this.repository    = repository;
     this.auditor       = auditor;
     this.authorization = authorization;
 }
Ejemplo n.º 30
0
 public BaseService(TBusinessLogicObject businessLogic, IHttpContextAccessor httpContextAccessor, IMapper mapper, IAuthorization authorization)
 {
     BusinessLogic = businessLogic;
     Request       = httpContextAccessor.HttpContext.Request;
     Mapper        = mapper;
     Authorization = authorization;
 }
Ejemplo n.º 31
0
 public ListingsService(IProductBlo businessLogic, IHttpContextAccessor httpContextAccessor, IMapper mapper, IAuthorization authorization) : base(businessLogic, httpContextAccessor, mapper, authorization)
 {
 }
Ejemplo n.º 32
0
 public void AuthorizeUsing(IAuthorization authorizationRules)
 {
     Console.WriteLine("Authorizing Stop with " + authorizationRules);
 }
Ejemplo n.º 33
0
 public TrackController(IAuthorization auth, IRepository repository)
 {
     Authorization = auth;
     Repository = repository;
 }
Ejemplo n.º 34
0
 public BookPersonManager(IAuthorization authorization)
 {
     Authorizator = authorization;
 }
Ejemplo n.º 35
0
 public AuthorizationController(IAuthorization authorization)
 {
     _authorization = authorization;
 }
 public AuthorizeTagHelper(IAuthorization authorization)
 {
     Authorization = authorization;
 }
Ejemplo n.º 37
0
 protected ServerObject()
 {
     captcha       = IoC.GetService <ICaptcha>();
     authorization = IoC.GetService <IAuthorization>();
 }
Ejemplo n.º 38
0
 public PersonalAreaController(ILogger <PersonalAreaController> log, UserContext user, IPersonalArea personalArea, IAuthorization authorization)
 {
     this.personalAreaService = personalArea;
     this.logger        = log;
     this.authorization = authorization;
 }
Ejemplo n.º 39
0
 public AdminPanelFilms(UnitOfWork unitOfWork, IAuthorization authorization)
 {
     _unitOfWork    = unitOfWork;
     _authorization = authorization;
 }
Ejemplo n.º 40
0
        public virtual void Logon(ISecurityUser user)
        {
            IAuthorization authorization = (IAuthorization)this.GetService <IPermissionsProvider>();

            authorization.Logon(user);
        }
Ejemplo n.º 41
0
 public void AuthorizeUsing(IAuthorization authorizationRules)
 {
 }
 public FacebookEngineConfiguration(IAuthorization authorization)
 {
     this.authorization = authorization;
 }
Ejemplo n.º 43
0
 public SettingController(UserContext user, ILogger <SettingController> logger, IAuthorization authorization)
 {
     this.settingService = new SettingService(user);
     this.authorization  = authorization;
     this.logger         = logger;
 }
Ejemplo n.º 44
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PluginHandler"/> class.
        /// </summary>        
        /// <param name="pluginLoader">The plugin loader.</param>
        /// <param name="authorizer">The authorizer.</param>        
        /// <param name="serviceFactory">The service factory.</param>
        public PluginHandler(IPluginLoader pluginLoader, IAuthorization authorizer, IServiceHostFactory serviceFactory)
        {
            Guard.Against(pluginLoader == null, "pluginLoader");
            Guard.Against(authorizer == null, "authorizer");
            Guard.Against(serviceFactory == null, "serviceFactory");

            this.pluginDirectory = pluginLoader.PluginDirectory;
            this.pluginLoader = pluginLoader;
            this.authorizer = authorizer;
            this.serviceFactory = serviceFactory;
        }
 public GooglePlusEngineConfiguration(IAuthorization authorization)
 {
     this.authorization = authorization;
 }