You do not have to modify your controllers, just create an event listener and, on each request, do what you want to do.
To get the user, just inject the security context service and get the token. Then you can get the user if the request is behind a firewall.
Here is an example based on the official documentation (not tested and must be modified to fit on your project):
// src/Acme/DemoBundle/EventListener/AcmeRequestListener.php
namespace Acme\DemoBundle\EventListener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\Security\Core\SecurityContextInterface;
class AcmeRequestListener
{
protected $sc;
public function __construct(SecurityContextInterface $sc)
{
$this->sc = $sc;
}
public function onKernelRequest(GetResponseEvent $event)
{
if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) {
// don't do anything if it's not the master request
return;
}
if( null === ($token = $this->sc->getToken()) ) {
// don't do anything if you are not behind a firewall
return;
}
// do anything with $token to get the user and check he is authenticated
$user = $token->getUser();
// Client IP
$ip = $event->getRequest()->getClientIp();
}
}
And you service definition:
<!-- app/config/config.xml -->
<service id="kernel.listener.your_listener_name" class="Acme\DemoBundle\EventListener\AcmeExceptionListener">
<argument type="service" id="security.context" />
<tag name="kernel.event_listener" event="kernel.exception" method="onKernelException" />
</service>