2009
09.09
Para descargar el plugin sigue éste enlace http://www.4shared.com/file/131400156/e521c155/seguridad.html
El plugin se instala en la carpeta /app/plugins/
El uso de este plugin es simple, primero debemos crear dos tablas en nuestra base de datos.
| 01 | |
| 02 | SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; |
| 03 | SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; |
| 04 | SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL'; |
| 05 | |
| 06 | CREATE TABLE IF NOT EXISTS `perfil` ( |
| 07 | `id` INT NOT NULL AUTO_INCREMENT , |
| 08 | `nombre` VARCHAR(45) NULL , |
| 09 | PRIMARY KEY (`id`) ) |
| 10 | ENGINE = InnoDB; |
| 11 | |
| 12 | CREATE TABLE IF NOT EXISTS `permiso` ( |
| 13 | `id` INT NOT NULL AUTO_INCREMENT , |
| 14 | `autorizado` TINYINT(1) NULL , |
| 15 | `perfil_id` INT NULL , |
| 16 | `controlador` VARCHAR(45) NULL , |
| 17 | `accion` VARCHAR(45) NULL , |
| 18 | PRIMARY KEY (`id`) , |
| 19 | INDEX `fk_permiso_perfil1` (`perfil_id` ASC) , |
| 20 | CONSTRAINT `fk_permiso_perfil1` |
| 21 | FOREIGN KEY (`perfil_id` ) |
| 22 | REFERENCES `perfil` (`id` ) |
| 23 | ON DELETE NO ACTION |
| 24 | ON UPDATE NO ACTION) |
| 25 | ENGINE = InnoDB; |
| 26 | |
| 27 | SET SQL_MODE=@OLD_SQL_MODE; |
| 28 | SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; |
| 29 | SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; |
| 30 | |
Luego, configurar en nuestro plugin el archivo app/plugins/seguridad/controllers/components/seguridad.php
| 1 | |
| 2 | var $excepciones = array('Pages'=>array('display'), 'Login'=>array('index', 'logout', 'admin_index', 'admin_logout') ); |
| 3 | |
Aquí debemos poner las acciones y controladores que no deben ser supervisados por el plugin con el formato array(‘Controlador’=>array(‘accion1′, ‘accion2′,…,’accionN’)).
Lo siguiente es añadir el plugin a nuestra aplicación, para esto, ponemos en /app/app_controller.php
| 1 | |
| 2 | var $components = array('Seguridad.Seguridad'); |
| 3 | |
y la función:
| 01 | |
| 02 | public function beforeFilter(){ |
| 03 | $controlador = $this->params['controller']; |
| 04 | $accion = $this->params['action']; |
| 05 | if($this->Seguridad->isException($controlador, $accion)){ |
| 06 | return true; |
| 07 | exit(); |
| 08 | } |
| 09 | if($this->Seguridad->checkAuth($controlador, $accion, $perfil['id'])){ |
| 10 | return true; |
| 11 | exit(); |
| 12 | } |
| 13 | $this->redirect('/pages/denegado'); |
| 14 | return false; |
| 15 | exit(); |
| 16 | } |
| 17 | |
Ahora vamos a http://nuestro-sitio.com/seguridad/seguridad_perfil y creamos los perfiles necesarios, al editarlos podemos darle la autorización de acceso a la acción correspondiente a cada controlador.
VN:F [1.9.3_1094]
Rating: 9.5/10 (2 votes cast)
Plugin de seguridad para Cake, 9.5 out of 10 based on 2 ratings
[...] Pluggin de Seguridad para CakePHP [...]