dongyang9813 2011-08-14 10:24
浏览 33

Symfony2:子域之间的透明授权过程

All!

I just see that symfony2 router doesn't use the host part of the uri. I need to separate COUNTRY as third subdomain and locale as first element in route path

http://{country}.mysite.com/{_locale}/myaction, i.e.

en.mysite.com/en/action --- english companies & english language

de.mysite.com/ru/action --- deutschland companies & russian language

ru.mysite.com/uk/action --- russian companies & ukrainian language

The problem solved with service like below:

-- config.yml

services:
   kernel.listener.subdomain_listener:
       class: Acme\DemoBundle\Listener\SubdomainListener
       tags:
           - { name: kernel.event_listener, event: kernel.request, method: onDomainParse }

-- SubdomainListener.php

<?php

namespace Acme\DemoBundle\Listener;

use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\Event;

class SubdomainListener
{
   public function onDomainParse(Event $event)
   {
       $request = $event->getRequest();
       $session = $request->getSession();

       // todo: parsing subdomain to detect country

       $session->set('subdomain', $request->getHost());
   }
}

BUT... The question is: how It's possIble (right wAy) to implement AUTH process between several subdomains transparently only once ??

  1. user logged via en.mysite.com/{_locale}/...

  2. user going to de.mysite.com/{_locale}/... but system knows about him(her) and doesn't ask the login/password credentials again

Does anybody help me ? Thanks for advance! Certified Senior Oracle Developer/DBA

  • 写回答

1条回答 默认 最新

  • duanbai1027 2011-08-14 18:11
    关注

    You can easily accomplish this by setting the correct cookie domain. That way all subdomains will be able to access the cookie that identifies your users' session.

    What you want to do is set your cookie domain to: .mysite.com (yes, a dot at the beginning).

    To do that, set the following configuration in your config.yml file:

    framework:
        session:
            cookie_domain: .mysite.com
    

    Note: If you're using remember_me from the security component, you'll probably want to set the domain on the remember_me section of your firewall.

    Addendum: In Symfony 2.0, the relevant setting was 'domain'. It was deprecated in 2.1.

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法