示例#1
0
 /**
  * Apply the behavior that corresponds to the configure 
  * authentication method (basic or digest) to $identity
  * 
  * @param CUserIdentity $identity
  * @throws Exception when extension is configured with an unsupported authMethod
  */
 public static function apply($identity)
 {
     //handle different authentication methods
     switch (Yii::app()->apiAuth->protocol) {
         //basic
         case ApiAuth::AUTH_BASIC:
             $identity->attachBehavior(self::behaviorName, new AIdentityBehaviorBasic());
             break;
             //digest
         //digest
         case ApiAuth::AUTH_DIGEST:
             $identity->attachBehavior(self::behaviorName, new AIdentityBehaviorDigest());
             break;
         default:
             //do not allow authentication methods other than the ones specified above.
             throw new Exception("Behavior not implemented for authentication method: " . Yii::app()->apiAuth->protocol);
             break;
     }
 }