imports:
    - { resource: controllers.yml }

services:
    oro_user.manager:
        class: Oro\Bundle\UserBundle\Entity\UserManager
        public: true
        arguments:
            - '@oro_user.security.user_loader'
            - '@doctrine'
            - '@security.encoder_factory'
            - '@oro_entity_extend.enum_value_provider'
            - '@oro_user.manager.mailer_processor_link'

    oro_user.manager.mailer_processor_link:
        tags:
            - { name: oro_service_link, service: oro_user.mailer.processor }

    oro_user.manager.api:
        class: Oro\Bundle\SoapBundle\Entity\Manager\ApiEntityManager
        public: true
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - 'Oro\Bundle\UserBundle\Entity\User'
            - '@doctrine.orm.entity_manager'

    oro_user.permission_manager.api:
        class: Oro\Bundle\UserBundle\Entity\Manager\UserPermissionApiEntityManager
        public: true
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - 'Oro\Bundle\UserBundle\Entity\User'
            - '@doctrine.orm.entity_manager'
            - '@security.authorization_checker'
            - '@security.token_storage'
            - '@oro_security.acl.extension_selector'

    oro_user.listener.password_changed_listener:
        class: Oro\Bundle\UserBundle\EventListener\PasswordChangedListener
        arguments:
            - '@oro_entity_extend.enum_value_provider'
        tags:
            - { name: doctrine.orm.entity_listener, entity: Oro\Bundle\UserBundle\Entity\User, event: prePersist}
            - { name: doctrine.orm.entity_listener, entity: Oro\Bundle\UserBundle\Entity\User, event: preUpdate}

    oro_user.security.user_loader:
        class: Oro\Bundle\UserBundle\Security\UserLoader
        arguments:
            - '@doctrine'
            - '@oro_config.manager'

    oro_user.security.provider:
        class: Oro\Bundle\UserBundle\Security\UserProvider
        arguments:
            - '@oro_user.security.user_loader'
            - '@doctrine'

    oro_user.security.login:
        class: Oro\Bundle\UserBundle\EventListener\LoginSubscriber
        arguments:
            - "@oro_user.manager"
        tags:
            - { name: kernel.event_listener, event: security.interactive_login, method: onLogin }

    oro_user.security.login_attempts_log_listener:
        class: Oro\Bundle\UserBundle\EventListener\LoginAttemptsLogListener
        arguments:
            - '@oro_user.security.login_attempts_handler'
        tags:
            - { name: kernel.event_listener, event: security.interactive_login, method: onInteractiveLogin }
            - { name: kernel.event_listener, event: security.authentication.failure, method: onAuthenticationFailure }

    oro_user.security.login_attempts_handler:
        class: Oro\Bundle\UserBundle\Security\LoginAttemptsHandler
        arguments:
            - '@oro_user.manager'
            - '@oro_user.logger.user_login_attempt'
            - '@oro_user.security.skipped_log_attempts_firewalls_provider'
            - !tagged_iterator oro_security.login_source_provider.success
            - !tagged_iterator oro_security.login_source_provider.fail

    oro_user.security.skipped_log_attempts_firewalls_provider:
        class: Oro\Bundle\UserBundle\Security\SkippedLogAttemptsFirewallsProvider

    oro_user.security.impersonation_login_source_provider:
        class: Oro\Bundle\UserBundle\Security\ImpersonationLoginSourceProvider
        tags:
            - { name: oro_security.login_source_provider.success }
            - { name: oro_security.login_source_provider.fail }

    oro_user.user_menu:
        class: Oro\Bundle\UserBundle\Menu\UserMenuBuilder
        tags:
            - { name: oro_menu.builder, alias: usermenu }

    oro_user.role.listener:
        class: Oro\Bundle\UserBundle\EventListener\RoleListener
        arguments:
            - '@oro_security.acl.sid_manager'
        tags:
            - { name: doctrine.orm.entity_listener, entity: Oro\Bundle\UserBundle\Entity\Role, event: prePersist}
            - { name: doctrine.orm.entity_listener, entity: Oro\Bundle\UserBundle\Entity\Role, event: preUpdate}

    oro_user.twig.user_extension:
        class: Oro\Bundle\UserBundle\Twig\OroUserExtension
        arguments:
            - '@oro_platform.twig.service_locator'
        tags:
            - { name: twig.extension }

    oro_user.topic.outdated_user_page:
        class: Oro\Bundle\SyncBundle\Topic\BroadcastTopic
        arguments:
            - 'oro_user.outdated_user_page'
        tags:
            - { name: gos_web_socket.topic }

    oro_user.access_rule.anonymous_role:
        class: Oro\Bundle\UserBundle\Acl\AccessRule\AnonymousRoleAccessRule
        tags:
            - { name: oro_security.access_rule, entityClass: Oro\Bundle\UserBundle\Entity\Role }

    oro_user.role_manager:
        class: Oro\Bundle\UserBundle\Entity\Manager\RoleManager
        arguments:
            - "@doctrine.orm.entity_manager"

    oro_user.role_manager.api:
        class: Oro\Bundle\SoapBundle\Entity\Manager\ApiEntityManager
        public: true
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - 'Oro\Bundle\UserBundle\Entity\Role'
            - '@doctrine.orm.entity_manager'

    oro_user.group_manager:
        class: Oro\Bundle\UserBundle\Entity\Manager\GroupManager
        arguments:
            - "@doctrine.orm.entity_manager"

    oro_user.group_manager.api:
        class: Oro\Bundle\SoapBundle\Entity\Manager\ApiEntityManager
        public: true
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - 'Oro\Bundle\UserBundle\Entity\Group'
            - '@doctrine.orm.entity_manager'

    oro_user.impersonation_authenticator:
        class: Oro\Bundle\UserBundle\Security\ImpersonationAuthenticator
        arguments:
            - '@doctrine'
            - '@oro_user.security.factory.impersonation_username_password_organization'
            - '@oro_security.authentication.organization_guesser'
            - '@event_dispatcher'
            - '@router'

    oro_user.event_listener.impersonation_success_listener:
        class: Oro\Bundle\UserBundle\EventListener\ImpersonationSuccessListener
        arguments:
            - '@oro_user.mailer.processor'
            - '@session.flash_bag'
            - '@logger'
        tags:
            - { name: kernel.event_listener, event: oro_user.impersonation_success, method: onImpersonationSuccess }

    oro_user.autocomplete.user.search_acl_handler:
        class: Oro\Bundle\UserBundle\Autocomplete\UserAclHandler
        arguments:
            - '@doctrine'
            - '@oro_attachment.provider.picture_sources'
            - '@security.authorization_checker'
            - '@oro_security.token_accessor'
            - '@oro_security.ownership_tree_provider'
            - '@oro_entity.routing_helper'
            - '@oro_entity.entity_name_resolver'
            - '@security.acl.voter.basic_permissions'
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: acl_users }

    oro_user.autocomplete.user.search_handler:
        class: Oro\Bundle\UserBundle\Autocomplete\UserSearchHandler
        parent: oro_form.autocomplete.full_name.search_handler
        arguments:
            - '@oro_attachment.provider.picture_sources'
            - 'Oro\Bundle\UserBundle\Entity\User'
            - ['username', 'namePrefix', 'firstName', 'middleName', 'lastName', 'nameSuffix', 'email']
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: users, acl_resource: oro_user_user_view }

    oro_user.autocomplete.assigned_to_organization_users.handler:
        class: Oro\Bundle\UserBundle\Autocomplete\AssignedToOrganizationUsersHandler
        parent: oro_form.autocomplete.full_name.search_handler
        arguments:
            - '@oro_attachment.provider.picture_sources'
            - 'Oro\Bundle\UserBundle\Entity\User'
            - ['username', 'namePrefix', 'firstName', 'middleName', 'lastName', 'nameSuffix', 'email']
        calls:
            - [setTokenAccessor, ['@oro_security.token_accessor']]
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: assigned_to_organization_users }

    oro_user.autocomplete.widget_user.search_handler:
        class: Oro\Bundle\UserBundle\Autocomplete\WidgetUserSearchHandler
        parent: oro_form.autocomplete.full_name.search_handler
        arguments:
            - '@translator'
            - '@oro_attachment.provider.picture_sources'
            - 'Oro\Bundle\UserBundle\Entity\User'
            - ['username', 'namePrefix', 'firstName', 'middleName', 'lastName', 'nameSuffix', 'email']
        calls:
            - [setTokenAccessor, ['@oro_security.token_accessor']]
            - [setSearchUserCriteria, ['@oro_user.autocomplete.search_user_criteria']]
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: widget_owner_users, acl_resource: oro_user_user_view }

    oro_user.autocomplete.user.organization_search_handler:
        class: Oro\Bundle\UserBundle\Autocomplete\OrganizationUsersHandler
        parent: oro_user.autocomplete.user.search_handler
        calls:
           - [setTokenAccessor,  ['@oro_security.token_accessor']]
           - [setSearchUserCriteria, ['@oro_user.autocomplete.search_user_criteria']]
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: organization_users, acl_resource: oro_user_user_view }

    oro_user.autocomplete.search_user_criteria:
        class: Oro\Bundle\UserBundle\Autocomplete\QueryCriteria\SearchUserCriteria
        public: true

    oro_user.autocomplete.user.search_without_current_handler:
        class: Oro\Bundle\UserBundle\Autocomplete\UserWithoutCurrentHandler
        parent: oro_form.autocomplete.full_name.search_handler
        arguments:
            - '@oro_security.token_accessor'
            - '@oro_attachment.provider.picture_sources'
            - 'Oro\Bundle\UserBundle\Entity\User'
            - ['username', 'namePrefix', 'firstName', 'middleName', 'lastName', 'nameSuffix', 'email']
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: users_without_current, acl_resource: oro_user_user_view }

    oro_user.autocomplete.role.search_handler:
        class: Oro\Bundle\FormBundle\Autocomplete\SearchHandler
        parent: oro_form.autocomplete.search_handler
        arguments:
            - 'Oro\Bundle\UserBundle\Entity\Role'
            - ['label']
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: roles, acl_resource: oro_user_role_view }

    oro_user.autocomplete.widget_role.search_handler:
        class: Oro\Bundle\UserBundle\Autocomplete\WidgetRoleSearchHandler
        parent: oro_form.autocomplete.search_handler
        arguments:
            - 'Oro\Bundle\UserBundle\Entity\Role'
            - ['label']
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: widget_owner_roles, acl_resource: oro_user_role_view }

    oro_user.autocomplete.role.authenticated_search_handler:
        class: Oro\Bundle\UserBundle\Autocomplete\AuthenticatedRolesHandler
        parent: oro_form.autocomplete.search_handler
        arguments:
            - 'Oro\Bundle\UserBundle\Entity\Role'
            - ['label']
        tags:
            - { name: oro_form.autocomplete.search_handler, alias: roles_authenticated, acl_resource: oro_user_role_view }

    oro_user.gender_provider:
        class: Oro\Bundle\UserBundle\Provider\GenderProvider
        public: true
        arguments:
            - '@translator'

    oro_user.email_recipients_provider:
        class: Oro\Bundle\UserBundle\Provider\EmailRecipientsProvider
        arguments:
            - '@doctrine'
            - '@oro_email.provider.email_recipients.helper'
        tags:
            - { name: oro_email.recipients_provider, priority: 30 }

    oro_user.email.owner.provider:
        class: Oro\Bundle\UserBundle\Entity\Provider\EmailOwnerProvider
        tags:
            - { name: oro_email.owner.provider, order: 1 }

    oro_user.change_password.subscriber:
        class: Oro\Bundle\UserBundle\Form\EventListener\ChangePasswordSubscriber
        arguments:
            - '@form.factory'
            - '@oro_security.token_accessor'

    oro_user.delete_handler_extension.user:
        class: Oro\Bundle\UserBundle\Handler\UserDeleteHandlerExtension
        parent: oro_entity.delete_handler_extension
        arguments:
            - '@oro_security.token_accessor'
            - '@oro_organization.owner_deletion_manager'
        tags:
            - { name: oro_entity.delete_handler_extension, entity: Oro\Bundle\UserBundle\Entity\User }

    oro_user.delete_handler_extension.role:
        class: Oro\Bundle\UserBundle\Handler\RoleDeleteHandlerExtension
        parent: oro_entity.delete_handler_extension
        arguments:
            - '@oro_security.acl.sid_manager'
        tags:
            - { name: oro_entity.delete_handler_extension, entity: Oro\Bundle\UserBundle\Entity\Role }

    Oro\Bundle\UserBundle\Handler\ResetPasswordHandler:
        alias: oro_user.handler.reset_password_handler

    oro_user.handler.reset_password_handler:
        class: Oro\Bundle\UserBundle\Handler\ResetPasswordHandler
        public: true
        lazy: true
        arguments:
            - '@oro_notification.manager.email_notification'
            - '@oro_user.manager'
            - '@logger'

    oro_user.activity_widget_provider:
        class: Oro\Bundle\UIBundle\Provider\TabMenuWidgetProvider
        arguments:
           - '@oro_entity.entity_identifier_accessor'
           - '@oro_ui.twig.tab_extension'
           - 'user_activity_tab_panel'
           - 'Oro\Bundle\UserBundle\Entity\User'
        tags:
           - { name: oro_activity.activity_widget_provider, priority: -10 }

    oro_user.event_listener.owner_user_grid_listener:
        class: Oro\Bundle\UserBundle\EventListener\OwnerUserGridListener
        arguments:
            - '@doctrine'
            - '@security.authorization_checker'
            - '@oro_security.token_accessor'
            - '@oro_security.ownership_tree_provider'
            - '@security.acl.voter.basic_permissions'
        tags:
            - { name: kernel.event_listener, event: oro_datagrid.datagrid.build.before.owner-users-select-grid, method: onBuildBefore }

    oro_user.mailer.processor:
        class: Oro\Bundle\UserBundle\Mailer\Processor
        arguments:
            - '@oro_user.mailer.user_template_email_sender'

    oro_user.mailer.user_template_email_sender:
        class: Oro\Bundle\UserBundle\Mailer\UserTemplateEmailSender
        lazy: true
        arguments:
            - '@oro_notification.model.notification_settings'
            - '@oro_email.manager.template_email'

    oro_user.placeholder.filter:
        class: Oro\Bundle\UserBundle\Placeholder\PlaceholderFilter
        public: true
        arguments:
            - '@oro_security.token_accessor'

    oro_user.password_change.widget_provider.actions:
        parent: oro_ui.widget_provider.action_button.abstract
        arguments:
            - oro_user_password_change_button
            - oro_user_password_change_link
        tags:
            - { name: oro_ui.view_action_provider, group: activity, priority: 100 }
            - { name: oro_ui.update_action_provider, group: activity, priority: 100 }

    security.user_checker:
        class: Oro\Bundle\UserBundle\Security\UserChecker
        arguments:
            - '@security.token_storage'

    oro_user.event_listener.password_change_exception_listener:
        class: Oro\Bundle\UserBundle\EventListener\PasswordChangeExceptionListener
        arguments:
            - '@session'
            - '@translator'
        tags:
            - { name: kernel.event_listener, event: kernel.exception, method: onKernelException, priority: 255 }

    oro_user.role.datagrid_helper:
        class: Oro\Bundle\UserBundle\Datagrid\RoleGridHelper
        public: true
        arguments:
            - '@security.authorization_checker'

    oro_user.provider.filter.user_choice_tree:
        class: Oro\Bundle\UserBundle\Provider\Filter\ChoiceTreeUserProvider
        public: true
        arguments:
            - '@doctrine'
            - '@oro_security.acl_helper'
            - '@oro_locale.dql.formatter.name'

    Oro\Bundle\UserBundle\Provider\RolePrivilegeCategoryProvider:
        alias: oro_user.provider.role_privilege_category_provider

    oro_user.provider.role_privilege_category_provider:
        class: Oro\Bundle\UserBundle\Provider\RolePrivilegeCategoryProvider
        public: true
        arguments:
            - '@oro_user.provider.privilege_category_configuration_provider'
            - '@translator'

    oro_user.provider.privilege_category_configuration_provider:
        class: Oro\Bundle\UserBundle\Configuration\PrivilegeCategoryConfigurationProvider
        parent: oro.static_config_provider.abstract
        arguments:
            - '%kernel.cache_dir%/oro/acl_categories.php'
            - '%kernel.debug%'

    oro_user.provider.role_privilege_capability_provider:
        class: Oro\Bundle\UserBundle\Provider\RolePrivilegeCapabilityProvider
        public: true
        arguments:
            - '@translator'
            - '@oro_user.provider.role_privilege_category_provider'
            - '@oro_user.form.handler.abstract.acl_role'

    oro_user.datagrid.datasource.role_permission_datasource:
        class: Oro\Bundle\UserBundle\Datagrid\RolePermissionDatasource
        arguments:
            - '@translator'
            - '@oro_security.acl.permission_manager'
            - '@oro_user.form.handler.abstract.acl_role'
            - '@oro_user.provider.role_privilege_category_provider'
            - '@oro_entity_config.config_manager'
        tags:
            - { name: oro_datagrid.datasource, type: role-permission-provider }

    oro_user.validator.user_custom_grid_field_validator:
        class: Oro\Bundle\UserBundle\Validator\UserGridFieldValidator
        arguments:
            - '@oro_security.token_accessor'
            - '@property_accessor'
        tags:
            - {name: oro_entity.custom_grid_field_validator, entity_name: Oro_Bundle_UserBundle_Entity_User }

    oro_user.validator.user_authentication_fields:
        class: Oro\Bundle\UserBundle\Validator\Constraints\UserAuthenticationFieldsValidator
        arguments:
            - '@oro_user.manager'
        tags:
            - { name: validator.constraint_validator }

    oro_user.validator.password_complexity_validator:
        class: Oro\Bundle\UserBundle\Validator\Constraints\PasswordComplexityValidator
        arguments:
            - '@oro_user.provider.password_complexity_config_provider'
        tags:
            - { name: validator.constraint_validator }

    oro_user.validator.email_case_insensitive_option:
        class: Oro\Bundle\UserBundle\Validator\Constraints\EmailCaseInsensitiveOptionValidator
        arguments:
            - '@doctrine'
            - '@translator'
            - '@oro_datagrid.helper.route'
        tags:
            - { name: validator.constraint_validator }

    oro_user.validator.unique_user_email_validator:
        class: Oro\Bundle\UserBundle\Validator\Constraints\UniqueUserEmailValidator
        arguments:
            - '@oro_user.manager'
        tags:
            - { name: validator.constraint_validator }

    oro_user.provider.password_complexity_config_provider:
        class: Oro\Bundle\UserBundle\Provider\PasswordComplexityConfigProvider
        arguments:
            - '@oro_config.user'

    oro_user.validator.user_without_role:
        class: Oro\Bundle\UserBundle\Validator\Constraints\UserWithoutRoleValidator
        tags:
            - { name: validator.constraint_validator }

    oro_user.dashboard.owner_helper:
        class: Oro\Bundle\UserBundle\Dashboard\OwnerHelper
        arguments:
          - '@doctrine'
          - '@security.token_storage'
          - '@oro_security.ownership_tree_provider'

    Oro\Bundle\UserBundle\Dashboard\OwnerHelper:
        alias: oro_user.dashboard.owner_helper

    oro_user.listener.choice_tree_filter_load_data_listener:
        class: Oro\Bundle\UserBundle\EventListener\ChoiceTreeFilterLoadDataListener
        arguments:
            - '@doctrine'
        tags:
            - { name: kernel.event_listener, event: oro_filter.choice_tree_filter_load_data, method: fillData }

    oro_user.provider.user_config_form_provider:
        class: Oro\Bundle\UserBundle\Provider\UserConfigurationFormProvider
        parent: oro_config.provider.abstract_provider
        lazy: true

    Oro\Bundle\UserBundle\Provider\UserConfigurationFormProvider:
        alias: oro_user.provider.user_config_form_provider

    oro_user.provider.user_logging_info_provider:
        class: Oro\Bundle\UserBundle\Provider\UserLoggingInfoProvider
        arguments:
            - '@request_stack'

    oro_user.imap_configuration.subscriber:
        class: Oro\Bundle\UserBundle\Form\EventListener\UserImapConfigSubscriber
        arguments:
            - '@doctrine.orm.entity_manager'
            - '@request_stack'
            - '@oro_security.token_accessor'

    oro_user.forced_password_reset.widget_provider.actions:
        parent: oro_ui.widget_provider.action_button.abstract
        arguments:
            - oro_user_force_password_reset_button
            - oro_user_force_password_reset_link
        tags:
            - { name: oro_ui.view_action_provider, group: activity, priority: 120 }

    oro_user.user.datagrid_view_list:
        class: Oro\Bundle\UserBundle\Datagrid\UserViewList
        public: true
        arguments:
            - '@translator'

    oro_user.datagrid.extension.reset_password:
        class: Oro\Bundle\UserBundle\Datagrid\Extension\MassAction\ResetPasswordExtension
        calls:
            - [setRequestStack, ["@request_stack"]]
        shared: false
        tags:
            - { name: oro_datagrid.extension }

    oro_user.security.disabled_login_subscriber:
        class: Oro\Bundle\UserBundle\Security\DisabledLoginSubscriber
        arguments:
            - '@security.token_storage'
        tags:
            - { name: kernel.event_listener, event: kernel.request , method: onKernelRequest}

    oro_user.scope_criteria_provider.user:
        class: Oro\Bundle\UserBundle\Provider\ScopeUserCriteriaProvider
        arguments:
            - "@security.token_storage"

    oro_user.user_scope_cache_key_builder:
        class: Oro\Bundle\UserBundle\Provider\UserScopeCacheKeyBuilder
        decorates: oro_scope.scope_cache_key_builder
        decoration_priority: 100
        arguments:
            - '@.inner'
            - '@security.token_storage'

    oro_user.datagrid.action_checker:
        class: Oro\Bundle\UserBundle\Datagrid\ActionChecker
        public: true
        arguments:
            - '@oro_security.token_accessor'

    oro_user.provider.default_user:
        class: Oro\Bundle\UserBundle\Provider\DefaultUserProvider
        arguments:
            - '@oro_config.manager'
            - '@doctrine'

    oro_user.event_listener.turn_off_caching:
        class: Oro\Bundle\UserBundle\EventListener\TurnOffCachingListener
        arguments:
            - '@security.token_storage'
        tags:
            - { name: kernel.event_listener, event: kernel.response, method: onKernelResponse }

    oro_user.event_listener.authentication_failure:
        class: Oro\Bundle\UserBundle\EventListener\AuthenticationFailureListener
        arguments:
            - 'main'
            - 'oro_user.login.errors.bad_credentials'
        tags:
            - { name: kernel.event_listener, event: security.authentication.failure, method: onAuthenticationFailure, priority: -255 }

    oro_user.provider.user_preferred_localization_provider:
        class: Oro\Bundle\UserBundle\Provider\UserPreferredLocalizationProvider
        arguments:
            - '@oro_config.user'
            - '@oro_locale.manager.localization'
        tags:
            - { name: oro_locale.preferred_localization_provider }

    oro_user.security.factory.impersonation_username_password_organization:
        class: Oro\Bundle\UserBundle\Security\ImpersonationUsernamePasswordOrganizationTokenFactory
        public: true

    oro_user.logger.user_login_attempt:
        class: Oro\Bundle\UserBundle\Security\UserLoginAttemptLogger
        public: true
        arguments:
            - '@doctrine'
            - '@oro_user.provider.user_logging_info_provider'
            - '@translator'
            - '@logger'
            - Oro\Bundle\UserBundle\Entity\UserLoginAttempt
            - '%oro_user.login_sources%'
        tags:
            - { name: monolog.logger, channel: security }

    oro_user.acl.voter.anonymous_role:
        class: Oro\Bundle\UserBundle\Acl\Voter\AnonymousRoleVoter
        tags:
            - { name: security.voter }

    oro_user.acl.search.role_acl_helper_condition:
        class: Oro\Bundle\UserBundle\Acl\Search\RoleSearchAclHelperCondition
        arguments:
            - '@oro_security.orm.ownership_sql_walker_builder'
        tags:
            - { name: oro_security.acl_helper.condition }
