/**
 * Get/set the controller this authorize object will be working with. Also checks that isAuthorized is implemented.
 *
 * @param Controller $controller null to get, a controller to set.
 * @return mixed
 * @throws CakeException
 */
	public function controller(Controller $controller = null) {
		if ($controller) {
			if (!method_exists($controller, 'isAuthorized')) {
				throw new CakeException(__d('cake_dev', '$controller does not implement an isAuthorized() method.'));
			}
		}
		return parent::controller($controller);
	}
 /**
  * TinyAuthorize::__construct()
  *
  * @param ComponentCollection $Collection
  * @param array $config
  */
 public function __construct(ComponentCollection $Collection, $config = [])
 {
     $config += $this->_defaultConfig;
     parent::__construct($Collection, $config);
     if (Cache::config($config['cache']) === false) {
         throw new CakeException(sprintf('TinyAuth could not find `%s` cache - expects at least a `default` cache', $config['cache']));
     }
 }
 public function __construct(ComponentCollection $Collection, $settings = array())
 {
     $settings = am($this->_defaults, $settings);
     parent::__construct($Collection, $settings);
     if (Cache::config($settings['cache']) === false) {
         throw new CakeException(__('TinyAuth could not find `%s` cache - expects at least a `default` cache', $settings['cache']));
     }
     $this->_matchArray = $this->_getRoles();
 }
 /**
  * Get the action path for a given request.
  *
  * @see BaseAuthorize::action()
  */
 public function action(CakeRequest $request, $path = '/:plugin/:controller/:action')
 {
     $apiPath = Configure::read('Croogo.Api.path');
     if (!$request->is('api')) {
         $path = str_replace(array($apiPath, ':prefix/'), array(null, null), $path);
         return parent::action($request, $path);
     }
     $api = isset($request['api']) ? $apiPath : null;
     if (isset($request['prefix'])) {
         $prefix = $request['prefix'];
         $action = str_replace($request['prefix'] . '_', '', $request['action']);
     } else {
         $prefix = null;
         $action = $request['action'];
     }
     $plugin = empty($request['plugin']) ? null : Inflector::camelize($request['plugin']);
     $controller = Inflector::camelize($request['controller']);
     $path = str_replace(array($apiPath, ':prefix', ':plugin', ':controller', ':action'), array($api, $prefix, $plugin, $controller, $action), $this->settings['actionPath'] . $path);
     $path = str_replace('//', '/', $path);
     return trim($path, '/');
 }
 /**
  * Sets up additional actionMap values that match the configured `Routing.prefixes`.
  *
  * @param ComponentCollection $collection The component collection from the controller.
  * @param string $settings An array of settings.  This class does not use any settings.
  */
 public function __construct(ComponentCollection $collection, $settings = array())
 {
     parent::__construct($collection, $settings);
     $this->_setPrefixMappings();
 }
 /**
  * Check if the provided user is authorized for the request.
  *
  * Uses the configured Authorization adapters to check whether or not a user is authorized.
  * Each adapter will be checked in sequence, if any of them return true, then the user will
  * be authorized for the request.
  *
  * @param array $user The user to check the authorization of. If empty the user in the session will be used.
  * @param CakeRequest $request The request to authenticate for. If empty, the current request will be used.
  * @return bool True if $user is authorized, otherwise false
  */
 public function isAuthorized($user = null, CakeRequest $request = null)
 {
     if (empty($user) && !$this->user()) {
         return false;
     }
     if (empty($user)) {
         $user = $this->user();
     }
     if (empty($request)) {
         $request = $this->request;
     }
     if ($this->authorizeObject->authorize($user, $request) === true) {
         return true;
     }
     return false;
 }
 public function __construct(\ComponentCollection $collection, $settings = array())
 {
     $this->settings['Apis'] = $collection->getController()->Apis;
     parent::__construct($collection, $settings);
 }