E1.30 Php Symfony Security Step 11: Configure Doctrine for Production Security (Wpf, Xamarin, Angular SPA, Reactjs SPA) - chempkovsky/CS2WPF-and-CS2XAMARIN GitHub Wiki

Open any Security Controller for Doctrine setting

  • Open the "AspnetdashboardViewController.php"-file

picture

At the begining of the file you wil find the following instructions

// ///////////////////////////////////////////////////////////////////////////////
// the generated code expects "config/packages/doctrine.yaml"-file to have the following config parameters
// ///////////////////////////////////////////////////////////////////////////////
// doctrine:
//    dbal:
//       default_connection: here is a name of default connection (for instance, default_connection: aspnetforphpchckdbcontextconnection)
//
//       connections:
//       ...
//          aspnetforphpchckdbcontextconnection:
//                # configure these for your database server 
//                url: '%env(resolve:DATABASE_ASPNETFORPHPCHCKDBCONTEXT_URL)%'
//                # driver: 'pdo_mysql'
//                # server_version: '5.7'
//                # charset: utf8mb4
//    orm:
//       default_entity_manager: here is a name of default manager (for instance, default_entity_manager: aspnetforphpchckdbcontextmanager)
//
//       entity_managers:
//       ...
//          aspnetforphpchckdbcontextmanager:
//              connection: aspnetforphpchckdbcontextconnection
//              mappings:
//                  Aspnetforphpchckdbcontext:
//                      is_bundle: false
//                      type: annotation 
//                      dir: '%kernel.project_dir%/src/Entity'
//                      prefix: 'App\Entity'
//                      alias: aspnetforphpchckdbcontextmanager  
//
// ///////////////////////////////////////////////////////////////////////////////
// "config/packages/doctrine.yaml"-file  expects ".env"-file to have the following config parameters like below
// ///////////////////////////////////////////////////////////////////////////////
// ...
// ### > doctrine/doctrine-bundle ###
// # Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
// # IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
// #
// DATABASE_ASPNETFORPHPCHCKDBCONTEXT_URL="mysql://root:[email protected]:3306/schema_name_here?serverVersion=8.0"
// ### < doctrine/doctrine-bundle ###
// ...
// ///////////////////////////////////////////////////////////////////////////////

  • modify "config/packages/doctrine.yaml"-file according to the instructions:
doctrine:
    dbal:
        default_connection: aspnetforphpchckdbcontextconnection
        connections:
            litdbcontextdeployconnection:
                # configure these for your database server 
                url: '%env(resolve:DATABASE_LITDBCONTEXT_URL)%'
                # driver: 'pdo_mysql'
                # server_version: '5.7'
                # charset: utf8mb4
            litdbcontextconnection:
                # configure these for your database server 
                url: '%env(resolve:DATABASE_LITDBCONTEXT_URL)%'
                # driver: 'pdo_mysql'
                # server_version: '5.7'
                # charset: utf8mb4
            aspnetforphpchckdbcontextdeployconnection:
                # configure these for your database server 
                url: '%env(resolve:DATABASE_ASPNETFORPHPCHCKDBCONTEXT_URL)%'
                # driver: 'pdo_mysql'
                # server_version: '5.7'
                # charset: utf8mb4
          aspnetforphpchckdbcontextconnection:
                # configure these for your database server 
                url: '%env(resolve:DATABASE_ASPNETFORPHPCHCKDBCONTEXT_URL)%'
                # driver: 'pdo_mysql'
                # server_version: '5.7'
                # charset: utf8mb4

    orm:
        default_entity_manager: aspnetforphpchckdbcontextmanager
        entity_managers:
            litdbcontextdeploymanager:
                connection: litdbcontextdeployconnection
                mappings:
                    Litdbcontextdeploy:
                        is_bundle: false
                        type: annotation 
                        dir: '%kernel.project_dir%/src/Deployment/Literature'
                        prefix: 'App\Deployment\Literature'
                        alias: litdbcontextdeploymanager  
            litdbcontextmanager:
                connection: litdbcontextconnection
                mappings:
                    Litdbcontext:
                        is_bundle: false
                        type: annotation 
                        dir: '%kernel.project_dir%/src/Production/Literature/Entity'
                        prefix: 'App\Production\Literature\Entity'
                        alias: litdbcontextmanager  
            aspnetforphpchckdbcontextdeploymanager:
                connection: aspnetforphpchckdbcontextdeployconnection
                mappings:
                    Aspnetforphpchckdbcontextdeploy:
                        is_bundle: false
                        type: annotation 
                        dir: '%kernel.project_dir%/src/Deployment/AspNetSecurity'
                        prefix: 'App\Deployment\AspNetSecurity'
                        alias: aspnetforphpchckdbcontextdeploymanager  
            aspnetforphpchckdbcontextmanager:
                connection: aspnetforphpchckdbcontextconnection
                mappings:
                    Aspnetforphpchckdbcontext:
                        is_bundle: false
                        type: annotation 
                        dir: '%kernel.project_dir%/src/Entity'
                        prefix: 'App\Entity'
                        alias: aspnetforphpchckdbcontextmanager  

Note:

  • Open the file:
    • AspnetuserViewAuthController.php
  • At the beginning of the file we have additional requirements
// ///////////////////////////////////////////////////////////////////////////////
// Important note
//
// aspnetforphpchckdbcontextconnection and aspnetforphpchckdbcontextmanager must be declared as "default_connection" and "default_entity_manager"
//
// ///////////////////////////////////////////////////////////////////////////////
// the generated code expects "config/packages/doctrine.yaml"-file to have the following config parameters
....
  • we set
    • default_connection: aspnetforphpchckdbcontextconnection
    • default_entity_manager: aspnetforphpchckdbcontextmanager

".env"-file:

  • modify ".env"-file according to the instructions:

###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
DATABASE_LITDBCONTEXT_URL="mysql://root:[email protected]:3306/litxamarindemo?serverVersion=8.0"
DATABASE_ASPNETFORPHPCHCKDBCONTEXT_URL="mysql://root:[email protected]:3306/aspnet?serverVersion=8.0"
# DATABASE_URL="postgresql://db_user:[email protected]:5432/db_name?serverVersion=13&charset=utf8"
###< doctrine/doctrine-bundle ###

Note:

With DATABASE_ASPNETFORPHPCHCKDBCONTEXT_URL we defined new schema: aspnet for for the security.