<commit_before><?php
/**
 * Jailson for CakePHP
 *   Access Control Plugin
 * 
 * @category CakePHP
 * @author <NAME> <<EMAIL>>
 * @package plugins.jailson
 * @subpackage plugins.jailson.components
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
 * @link http://github.com/m3nt0r/cakephp-jailson Repository/Docs
 * @copyright (c) 2010, <NAME> (http://cakealot.com)
 */
/**
 * Jailson - Acl Auth Component
 * 
 * @category CakePHP
 * @author <NAME> <<EMAIL>>
 * @package plugins.jailson
 * @subpackage plugins.jailson.components
 */
class AclAuthComponent extends Object {
	
	/**
	 * AuthComponent reference
	 */
	protected $_Auth;
	
	/**
	 * Controller reference
	 */
	protected $_Controller;
	
	/**
	 * Deny rules
	 */
	public $deny = array();
	
	/**
	 * Allow rules
	 */
	public $allow = array();
	
	/**
	 * Keep parent settings
	 */
	private $__settings = array();
	
	/**
	 * Name of CakePHP AuthComponent 
	 *   In case you subclassed it..
	 * 
	 * @var string
	 */
	public $authClass = 'Auth';
	
	/**
	 * Initialize the ACL Component
	 * 
	 * - Import and configure the AuthComponent or throw error if missing
	 * - Import the user model from Auth
	 * - Normalize deny/allow $settings
	 * - Store reference to current controller
	 */
	public function initialize(&$controller, $settings) {
		$this->_set($settings);
		$this->__settings = $settings;
		
		// Import controller
		$this->_Controller =& $controller;
		
		// Import and modify AuthComponent
		if (isset($controller->{$this->authClass})) {
			$this->_Auth =& $controller->{$this->authClass};
			$this->_Auth->authorize = 'object';
			$this->_Auth->object = $this;
		} else {
			trigger_error(__("Could not find {$this->authClass}Component. Please include {$this->authClass} in Controller::\$components.", true), E_USER_WARNING);
		}
	}
	
	
	/**
	 * Called by AuthComponent
	 * 
	 * @param 	mixed 	$user 		The user to check the authorization of
	 * @param 	string 	$controller	Name of the controller to check
	 * @param 	string	$action 	Name of the action to check
	 * 
	 * @return boolean True if $user is authorized, otherwise false
	 */
	public function isAuthorized($user, $controller, $action) {
		$userModel = $this->_Auth->getModel();
		$userModel->id = $user[$this->_Auth->userModel]['id'];
		
		if (!is_array($userModel->actsAs) || (!array_key_exists('Jailson.Inmate', $userModel->actsAs) && !in_array('Jailson.Inmate', $userModel->actsAs))) {
			trigger_error(__("Looks like your userModel is missing the behavior. Please include 'Jailson.Inmate' in {$userModel->name}::\$actsAs.", true), E_USER_WARNING);
		}
		
		if (!empty($this->__settings['deny'])) {
			$this->deny = $this->_normalizePermissions($this->deny, $this->__settings['deny']);
		}
		if (!empty($this->__settings['allow'])) {
			$this->allow = $this->_normalizePermissions($this->allow, $this->__settings['allow']);
		}
		
		$currentPath = $controller .'/'. $action;
		
		if (array_key_exists("{$controller}/*", $this->allow)) {
			return true; // the entire controller is allowed
		}
		if (array_key_exists("{$controller}/*", $this->deny)) {
			return false; // the entire controller is denied
		}
		
		$allowAll = false;
		$denyAll = false;
		
		$permissions = array(<commit_msg>added workaround for my trigger_error when running group test<commit_after><?php
/**
 * Jailson for CakePHP
 *   Access Control Plugin
 * 
 * @category CakePHP
 * @author <NAME> <<EMAIL>>
 * @package plugins.jailson
 * @subpackage plugins.jailson.components
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
 * @link http://github.com/m3nt0r/cakephp-jailson Repository/Docs
 * @copyright (c) 2010, <NAME> (http://cakealot.com)
 */
/**
 * Jailson - Acl Auth Component
 * 
 * @category CakePHP
 * @author <NAME> <<EMAIL>>
 * @package plugins.jailson
 * @subpackage plugins.jailson.components
 */
class AclAuthComponent extends Object {
	
	/**
	 * AuthComponent reference
	 */
	protected $_Auth;
	
	/**
	 * Controller reference
	 */
	protected $_Controller;
	
	/**
	 * Deny rules
	 */
	public $deny = array();
	
	/**
	 * Allow rules
	 */
	public $allow = array();
	
	/**
	 * Keep parent settings
	 */
	private $__settings = array();
	
	/**
	 * Name of CakePHP AuthComponent 
	 *   In case you subclassed it..
	 * 
	 * @var string
	 */
	public $authClass = 'Auth';
	
	/**
	 * Initialize the ACL Component
	 * 
	 * - Import and configure the AuthComponent or throw error if missing
	 * - Import the user model from Auth
	 * - Normalize deny/allow $settings
	 * - Store reference to current controller
	 */
	public function initialize(&$controller, $settings) {
		$this->_set($settings);
		$this->__settings = $settings;
		
		// Import controller
		$this->_Controller =& $controller;
		
		// Import and modify AuthComponent
		if (isset($controller->{$this->authClass})) {
			$this->_Auth =& $controller->{$this->authClass};
			$this->_Auth->authorize = 'object';
			$this->_Auth->object = $this;
		} else {
			trigger_error(__("Could not find {$this->authClass}Component. Please include {$this->authClass} in Controller::\$components.", true), E_USER_WARNING);
		}
	}
	
	
	/**
	 * Called by AuthComponent
	 * 
	 * @param 	mixed 	$user 		The user to check the authorization of
	 * @param 	string 	$controller	Name of the controller to check
	 * @param 	string	$action 	Name of the action to check
	 * 
	 * @return boolean True if $user is authorized, otherwise false
	 */
	public function isAuthorized($user, $controller, $action) {
		$userModel = $this->_Auth->getModel();
		$userModel->id = $user[$this->_Auth->userModel]['id'];
		
		if (!is_array($userModel->actsAs) || (!array_key_exists('Jailson.Inmate', $userModel->actsAs) && !in_array('Jailson.Inmate', $userModel->actsAs))) {
			if (basename($_SERVER['SCRIPT_NAME']) != 'test.php')
				trigger_error(__("Looks like your userModel is missing the behavior. Please include 'Jailson.Inmate' in {$userModel->name}::\$actsAs.", true), E_USER_WARNING);
		}
		
		if (!empty($this->__settings['deny'])) {
			$this->deny = $this->_normalizePermissions($this->deny, $this->__settings['deny']);
		}
		if (!empty($this->__settings['allow'])) {
			$this->allow = $this->_normalizePermissions($this->allow, $this->__settings['allow']);
		}
		
		$currentPath = $controller .'/'. $action;
		
		if (array_key_exists("{$controller}/*", $this->allow)) {
			return true; // the entire controller is allowed
		}
		if (array_key_exists("{$controller}/*", $this->deny)) {
			return false; // the entire controller is denied
		}
		
		$allowAll = false;
		$denyAll = false;
		
		$permissions = array(
{'fraction_non_alphanumeric': 0.1605817300409029, 'fraction_numerical': 0.0018179063778215423, 'mean_word_length': 3.6624293785310735, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2996904', 'n_tokens_mistral': 2300, 'n_tokens_neox': 2009, 'n_words': 520}