Source for file Ethna_Plugin_Csrf_Session.php

Documentation is available at Ethna_Plugin_Csrf_Session.php

  1. <?php
  2. // vim: foldmethod=marker
  3. /**
  4.  *  Ethna_Plugin_Csrf_Session.php
  5.  *
  6.  *  @author     Keita Arai <cocoiti@comio.info>
  7.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  8.  *  @package    Ethna
  9.  *  @version    $Id$
  10.  */
  11.  
  12. // {{{ Ethna_Plugin_Csrf_Session
  13. /**
  14.  *  CSRF対策
  15.  *
  16.  *  CSRF対策をトークンを用いて対策するためのコード
  17.  *
  18.  *  @author     Keita Arai <cocoiti@comio.info>
  19.  *  @access     public
  20.  *  @package    Ethna
  21.  */
  22. {
  23.     /**#@+
  24.      *  @access private
  25.      */
  26.  
  27.     /** @var    object  Ethna_Session    セッションオブジェクト */
  28.     var $session;
  29.     
  30.     /**#@-*/
  31.  
  32.  
  33.     /**
  34.      *  Ethna_Plugin_Csrfのコンストラクタ
  35.      *
  36.      *  @access public
  37.      *  @param  object  Ethna_Controller    &$controller    コントローラオブジェクト
  38.      */
  39.     function Ethna_Plugin_Csrf_Session(&$controller)
  40.     {
  41.         parent::Ethna_Plugin_Csrf($controller);
  42.  
  43.         // オブジェクトの設定
  44.         $this->session =$this->controller->getSession();
  45.     }
  46.     
  47.     /**
  48.      *  トークンをViewとローカルファイルにセットする
  49.      *
  50.      *  @access public
  51.      *  @return boolean  成功か失敗か
  52.      */
  53.     function set()
  54.     {
  55.         if ($this->session->isStart()) {
  56.             $this->session->start();
  57.         }
  58.  
  59.         $token $this->session->get($this->token_name);
  60.         if ($token !== null{
  61.             return true;
  62.         }
  63.  
  64.         $key $this->_generateKey();
  65.         $this->session->set($this->token_name$key)
  66.  
  67.         return true;       
  68.     }
  69.  
  70.     /**
  71.      *  トークンIDを取得する
  72.      *
  73.      *  @access public
  74.      *  @return string トークンIDを返す。
  75.      */
  76.     function get()
  77.     {
  78.         if ($this->session->isStart()) {
  79.             $this->session->start();
  80.         }
  81.         
  82.         return $this->session->get($this->token_name);
  83.     }
  84.  
  85.     /**
  86.      *  トークンIDを削除する
  87.      *
  88.      *  @access public
  89.      */
  90.     function remove()
  91.     {
  92.         if ($this->session->isStart()) {
  93.             $this->session->start();
  94.         }
  95.         $this->session->remove($this->token_name);        
  96.     }
  97. }
  98. // }}}
  99. ?>

Documentation generated on Fri, 11 Nov 2011 04:00:09 +0900 by phpDocumentor 1.4.3