Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple dynamic firewalls and CAS servers in Symfony2
    primarykey
    data
    text
    <p>I am developing an application in Symfony to manage multiple schools. The application has multiple databases, one for each school, and multiple CAS servers. </p> <p>If I only manage a school, the configuration would be like this:</p> <pre><code># config.yml be_simple_sso_auth: admin_sso: protocol: id: cas version: 2 server: id: cas login_url: https://cas01.example.com/SCHOOLID/login logout_url: https://cas01.example.com/SCHOOL_ID/logout validation_url: https://cas01.example.com/SCHOOL_ID/serviceValidate # security.yml firewalls: school: pattern: ^/school/.*$ trusted_sso: manager: admin_sso login_action: false logout_action: false create_users: true created_users_roles: [ROLE_USER, ROLE_ADMIN] login_path: /school/login check_path: /school/login_check logout: path: /school/logout target: /school </code></pre> <p>With one school everything works fine.</p> <p>Each school accesses the application through the path app.com/school/ID, for example app.com/school/29, app.com/school/54...</p> <p>I wonder if there is way to have multiple dynamic firewall depending on the ID. And use this ID to redirect each CAS URL:</p> <p><a href="https://cas01.example.com/school_29/login" rel="nofollow noreferrer">https://cas01.example.com/school_29/login</a>, <a href="https://cas01.example.com/school_54/login" rel="nofollow noreferrer">https://cas01.example.com/school_54/login</a> ...</p> <p><strong>----------- UPDATED 13/12/12 -----------</strong></p> <p>I created a new file: app/config/cas.php, and I've added some CAS servers settings </p> <pre><code># CAS 14 $container-&gt;loadFromExtension('be_simple_sso_auth', array( 'cas_14' =&gt; array( 'protocol' =&gt; array( 'id' =&gt; 'cas', 'version' =&gt; '2' ), 'server' =&gt; array( 'id' =&gt; 'cas', 'login_url' =&gt; 'https://cas01.example.com/14/login', 'logout_url' =&gt; 'https://cas01.example.com/14/logout', 'validation_url' =&gt; 'https://cas01.example.com/14/serviceValidate', ), ), )); # CAS 15 $container-&gt;loadFromExtension('be_simple_sso_auth', array( 'cas_15' =&gt; array( 'protocol' =&gt; array( 'id' =&gt; 'cas', 'version' =&gt; '2' ), 'server' =&gt; array( 'id' =&gt; 'cas', 'login_url' =&gt; 'https://cas01.example.com/15/login', 'logout_url' =&gt; 'https://cas01.example.com/15/logout', 'validation_url' =&gt; 'https://cas01.example.com/15/serviceValidate', ), ), )); </code></pre> <p>And i import this file in config.yml</p> <pre><code>imports: - { resource: parameters.yml } - { resource: cas.php } - { resource: security.yml } </code></pre> <p>And i add a new firewall for each school:</p> <pre><code>firewalls: backend_14: pattern: ^/backend/school/14/.*$ trusted_sso: manager: cas_14 login_action: false #BeSimpleSsoAuthBundle:TrustedSso:login logout_action: false #BeSimpleSsoAuthBundle:TrustedSso:logout create_users: true created_users_roles: [ROLE_USER, ROLE_ADMIN] login_path: /backend/school/14/login check_path: /backend/school/14/login_check logout: path: /backend/school/logout target: /backend backend_15: pattern: ^/backend/school/15/.*$ trusted_sso: manager: cas_15 login_action: false #BeSimpleSsoAuthBundle:TrustedSso:login logout_action: false #BeSimpleSsoAuthBundle:TrustedSso:logout create_users: true created_users_roles: [ROLE_USER, ROLE_ADMIN] login_path: /backend/school/15/login check_path: /backend/school/15/login_check logout: path: /backend/school/logout target: /backend </code></pre> <p>And all goes right!</p> <p>Now I'm trying to generate all cas.php configuration dynamic from the Entity School. First i try creating a method in SchoolController</p> <pre><code>public function loadCasConfig() { $em = $this-&gt;getDoctrine()-&gt;getManager(); $schools= $em-&gt;getRepository('SchoolBundle:School') -&gt;findBy(array(), array('name'=&gt; 'ASC')); foreach ($schools as $school) { $cas_name = 'cas_'.$school-&gt;getId(); $container-&gt;loadFromExtension('be_simple_sso_auth', array( "$cas_name" =&gt; array( 'protocol' =&gt; array( 'id' =&gt; 'cas', 'version' =&gt; '2' ), 'server' =&gt; array( 'id' =&gt; 'cas', 'login_url' =&gt; "https://cas01.example.com/$school-&gt;getId()/login", 'logout_url' =&gt; "https://cas01.example.com/$school-&gt;getId()/logout", 'validation_url' =&gt; "https://cas01.example.com/$school-&gt;getId()/serviceValidate", ), ), )); } } </code></pre> <p>and call it on cas.php file</p> <pre><code>&lt;?php use Comp\BackendBundle\Controller\SchoolController; SchoolController::loadCasConfig(); </code></pre> <p>but i have this Exception:</p> <pre><code>FileLoaderLoadException: Cannot import resource "C:\wamp\www\comp\app/config\cas.php" from "C:\wamp\www\comp\app/config\config.yml". (Runtime Notice: Non-static method Comp\BackendBundle\Controller\SchoolController::loadCasConfig() should not be called statically, assuming $this from incompatible context in C:\wamp\www\comp\app\config\cas.php line 5) </code></pre> <p>:(. Then i try to insert the method code in the cas.php file:</p> <pre><code>use Doctrine\ORM\EntityManager; use Comp\SchoolBundle\Entity\School; $em = $this-&gt;getDoctrine()-&gt;getManager(); $schools= $em-&gt;getRepository('SchoolBundle:School') -&gt;findBy(array(), array('name'=&gt; 'ASC')); foreach ($schools as $school) { $cas_name = 'cas_'.$school-&gt;getId(); $container-&gt;loadFromExtension('be_simple_sso_auth', array( "$cas_name" =&gt; array( 'protocol' =&gt; array( 'id' =&gt; 'cas', 'version' =&gt; '2' ), 'server' =&gt; array( 'id' =&gt; 'cas', 'login_url' =&gt; "https://cas01.example.com/$school-&gt;getId()/login", 'logout_url' =&gt; "https://cas01.example.com/$school-&gt;getId()/logout", 'validation_url' =&gt; "https://cas01.example.com/$school-&gt;getId()/serviceValidate", ), ), )); } </code></pre> <p>and now i have:</p> <pre><code>FatalErrorException: Error: Call to undefined method Symfony\Component\DependencyInjection\Loader\PhpFileLoader::getDoctrine() in C:\wamp\www\comp\app\config\cas.php line 11 </code></pre> <p>I'd like to know how I can dynamically generate the file cas.php, getting data from the database.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload