Developed with love by KnpLabs Hire us for your project!
31

DomainUserBundle

by M6Web

User authentication by domain

DomainUserBundle Build Status

DomainUserBundle provides user authentication by subdomain.
It allows firewalling, cache customization, route filtering and data filtering by subdomain.

Dependency

DomainUserBundle requires FirewallBundle.

Installation

Add this line in your composer.json:

{
    "require": {
        "m6web/domain-user-bundle": "~1.0"
    }
}

Update your vendors:

$ composer update m6web/domain-user-bundle

Add to your AppKernel.php:

new M6Web\Bundle\DomainUserBundle\M6WebDomainUserBundle(),
new M6Web\Bundle\FirewallBundle\M6WebFirewallBundle(),

Configuration

Modify your routes to add a parameter in your host requirement:

routes:
    resource: api_routing.yml
    host:     {client}api.example.com
    requirements:
        client: ([a-z0-9]+\.)?
    defaults:
        client ""

Add in your app/config.yml:

m6_web_domain_user:
    default_cache:    300      # Default cache duration
    router_parameter: client   # Parameter in the host requirement
    default_user:     public   # User when the parameter is not found
    users_dir:        %kernel.root_dir%/config/users # Directory containing the user configs
    firewall:
        allow_debug_route: false # Allows or not (default) web debug toolbar routes for the concerned environment

Add a user app/config/users/public.yml:

firewall:
    user_access: # Configure IP restrictions with FirewallBundle
        default_state: false
        lists:
            internal: true

    allow: # Filter routes alllowed to this user
        default: true
        methods:
            delete: false # Override by method
        resources:
            article: false # Override by routes configured with "defaults: {resource: article}"
        route:
            post_comment: false # Override by route name
        allow_debug_route: false # Allows or not (default) web debug toolbar routes for this user

cache:
    defaults: 60 # Override the default cache duration
    routes:
        hello: 86400 # Override by route name

entities:
    article:
        active: true # Arbitrary flag you can use to filter your entities in your repositories
parameters:
    param_name: param_value # Arbitrary parameters

Edit your app/config/security.yml:
```yaml
security:
firewalls:
secured_area:
pattern: ^/
anonymous: false
m6_web_domain_user: true

providers:
    m6_web_domain_user:
        id: m6_web_domain_user.user_provider

## Tests

```shell
$ ./vendor/bin/atoum

Credits

Developped by the Cytron Team of M6 Web.
Tested with atoum.

License

DomainUserBundle is licensed under the MIT license.

The MIT License (MIT)

Copyright (c) 2014 M6Web

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
m6_web_domain_user:
default_user: ~ # Required
default_cache: ~ # Required
router_parameter: ~ # Required
users_dir: ~ # Required
firewall:
allow_debug_route: false
  • Merge pull request #24 from M6Web/feature/use-childDefinition
    By web-flow, 1 year ago
  • use ChildDefinition instead of DefinitionDecorator
    By s_douzima, 1 year ago
  • Merge pull request #23 from M6Web/feature/use-latest-firewallbundle-and-sf4
    By web-flow, 1 year ago
  • use latest firewallbundle and require sf4
    By s_douzima, 1 year ago
  • Merge pull request #22 from M6Web/fix/valid-yaml
    By web-flow, 1 year ago
  • fix typo
    By s_douzima, 1 year ago
  • Merge pull request #21 from jubianchi/update-atoum
    By web-flow, 2 years ago
  • Update to newer atoum versions
    By jubianchi, 2 years ago
  • Merge pull request #20 from M6Web/fix/cache-master-requests-only
    By web-flow, 2 years ago
  • use CacheListener only for master requests + fix strict symfony3.0 requirements
    By Oliboy50, 2 years ago
  • Merge pull request #19 from M6Web/feature/cache-user-config
    By web-flow, 2 years ago
  • use a mandatory cache warmer to create the users config in the sf cache
    By omansour, 2 years ago
  • Merge pull request #17 from M6Web/updateDeps
    By web-flow, 3 years ago
  • Updated dependencies to be really compatible with Symfony 3
    By lolautruche, 3 years ago
  • Merge pull request #16 from lolautruche/patch-1
    By web-flow, 3 years ago
  • Updated .travis.yml to test with most recent version of PHP and Symfony
    By lolautruche, 3 years ago
  • Compatibility with Symfony 3
    By web-flow, 3 years ago
  • Merge pull request #15 from M6Web/feature/allow-profiler-routes
    By jdlabails, 3 years ago
  • Allow profiler routes.
    By jdlabails, 3 years ago
  • Merge pull request #12 from M6Web/fix/bad-user-error
    By mojoLyon, 3 years ago
  • throw AccessDeniedHttpException instead of AccessDeniedException in FirewallListener
    By mojoLyon, 3 years ago
  • Merge pull request #11 from M6Web/feature/compatibility-symfony-2.7
    By fabdsp, 4 years ago
  • Compatibility with Symfony >=27.
    By fabdsp, 4 years ago
  • Merge pull request #9 from M6Web/feature/user-parameters-variable
    By adriensamson, 5 years ago
  • Variables user parameters
    By fabdsp, 5 years ago
  • Merge pull request #8 from M6Web/feature/user-parameters
    By adriensamson, 5 years ago
  • Add parameters to README and fix UserConfiguration
    By Adrien Samson, 5 years ago
  • tests - WIP
    By omansour, 5 years ago
  • add a parameters table on the user
    By omansour, 5 years ago
  • Merge pull request #7 from M6Web/check-token
    By KuiKui, 5 years ago