btc/auth-bundle

This Symfony 3 Bundle is used for user authentication via ldap.

0.2 2017-01-17 14:47 UTC

README

SensioLabsInsight

Prerequisites

This version of the bundle require Symfony 3.1+.

Installation

Installation is a quick 7 step process:

  1. Download BTC\AuthBundle using composer
  2. Enable the Bundle
  3. Configure your application's security.yml
  4. Configure the BTC\UserBundle
  5. Import BTC\UserBundle routing
  6. Update your database schema
  7. Create default role and admin account

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require btc/auth-bundle dev-master

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new BTC\Bundle\AuthBundle\AuthBundle(),
        );

        // ...
    }

    // ...
}

Step 3: Configure your application's security.yml

Configure your project security by adding the configuration in the app/config/security.yml file of your project:

security:
    encoders:
        BTC\Bundle\AuthBundle\Entity\User:
            id: btc_auth.password_encoder

    role_hierarchy:
        ROLE_ADMIN: [ROLE_MANAGE_USER, ROLE_APP_ADMIN]
        ROLE_APP_ADMIN: [ROLE_USER, ROLE_MANAGE_GUEST]

    providers:
        btc_users:
            entity: { class: BTC\Bundle\AuthBundle\Entity\User, property: email }

    firewalls:
        main:
            anonymous: ~
            guard:
                authenticators:
                    - btc_auth.security.login_form_authenticator

            logout:
                path: /logout

    access_control:
        - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/logout, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin, roles: ROLE_ADMIN }

Step 4: Configure the bundle

Configure the bundle by adding the configuration in the app/config/config.yml file of your project:

auth:
    ldap:
        host : 127.0.0.1
        port : 389
        version : 3
        username: 'cn=ldap_user,dc=domain,dc=com'
        password: 'ldap_p@ssword'
        base_dn : 'dc=domain,dc=com'
        account_filter : '(&(objectClass=inetOrgPerson)(uid=%s))'

Step 5: Import BTC\AuthBundle routing files

Import routing in the app/config/routing.yml file of your project:

btc_auth:
    resource: "@AuthBundle/Controller/"
    type:     annotation

Step 6: Update your database

Run the following command to update your database schema:

php bin/console doctrine:schema:update --force

Step 7: Create default role and admin account

Rune the following command to create default role and admin account

php bin/console auth:configure

You now can log in at http://app.com/app_dev.php/login!