Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Security Setup for Symfony2 Without login

I have been trying to get setup with symfony2 for a while now and it has been going well for quite a while, but I've hit a bit of a snag. I can't figure out how to get my security setup. At our institution, we have a installation of cas (single sign on) and a static class that deals with all of the authentication stuff. It is called gatekeeper. Gatekeeper does all of the role checking and username login stuff. I want to be able to use the authorization stuff of symfony2, but none of the authentication stuff. Is this possible? I have read the documentation but it seems like those things are too tightly bound to be separated. Does anyone have any insights on this topic?

like image 655
Patrick James McDougle Avatar asked Apr 19 '26 05:04

Patrick James McDougle


1 Answers

If you are using your Gatekeeper class for authentication before the request hits the firewall you can create a "pre-authenticated" (i.e. authentication happens before the firewall) listener by extending AbstractPreAuthenticatedListener and implementing getPreAuthenticatedData():

class GatekeeperListener extends AbstractPreAuthenticatedListener
{
    protected function getPreAuthenticatedData(Request $request)
    {
        return array(
            Gatekeeper::getCurrentUsername(), // username
            '',                               // credentials
        );
    }
}

You will need to create a security factory in order to introduce a new authentication listener to the system. This process is described in this cookbook article:

How to create a custom Authentication Provider: The Factory

Your security.yml should look something like this:

security:
    factories:
        - "%kernel.root_dir%/../src/Acme/DemoBundle/Resources/config/security_factories.yml"

    firewalls:
        main:
            pattern: .
            gatekeeper: true
like image 200
Kris Wallsmith Avatar answered Apr 20 '26 19:04

Kris Wallsmith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!