source: sandbox/workflow/branches/609/lib/security/Security.php @ 2222

Revision 2222, 2.5 KB checked in by pedroerp, 14 years ago (diff)

Ticket #609 - Atualizando comentários para seguir o padrão phpdoc.

  • Property svn:executable set to *
Line 
1<?php
2/**************************************************************************\
3* eGroupWare                                                               *
4* http://www.egroupware.org                                                *
5* --------------------------------------------                             *
6*  This program is free software; you can redistribute it and/or modify it *
7*  under the terms of the GNU General Public License as published by the   *
8*  Free Software Foundation; either version 2 of the License, or (at your  *
9*  option) any later version.                                              *
10\**************************************************************************/
11
12/**
13 * Security class for Workflow module.
14 * You should never forget to call 'enable'
15 * public method to enable security before
16 * executing process code.
17 *
18 * @package Factory
19 * @license http://www.gnu.org/copyleft/gpl.html GPL
20 * @author Pedro Eugênio Rocha - pedro.eugenio.rocha@gmail.com
21 */
22class Security {
23
24        /**
25         * @var boolean $_protection Stores the current security mode.
26         * @access private
27         * @static
28         */
29        private static $_protection = false;
30
31
32        /**
33         * Disallow the instantiation of this class.
34         * @access public
35         * @return void
36         */
37        public function __construct() {
38                throw new Exception("Oops! Static only class.");
39        }
40
41
42        /**
43         * Returns the current security mode.
44         * @access public
45         * @return boolean
46         */
47        public static function isEnabled() {
48                return self::$_protection;
49        }
50
51
52        /**
53         * Change to secured mode.
54         * @access public
55         * @return boolean
56         * @static
57         */
58        public static function enable() {
59
60                if (self::_isAllowed())
61                        self::$_protection = true;
62                else
63                        throw new Exception('You are not allowed to change security mode.');
64                return true;
65        }
66
67        /**
68         * Change to unsecured mode.
69         * @access public
70         * @return boolean
71         * @static
72         */
73        public static function disable() {
74
75                if (self::_isAllowed())
76                        self::$_protection = false;
77                else
78                        throw new Exception('You are not allowed to change security mode.');
79                return true;
80        }
81
82
83        /**
84         * This function do all the security stuff.
85         * Here we must define in which files we are able
86         * to change the security mode.
87         *
88         * @access private
89         * @return boolean
90         * @static
91         */
92        private static function _isAllowed() {
93                $backtrace = debug_backtrace();
94
95                /* TODO - These are not definitive validations */
96                /* $backtrace[1] specifies the imediate antecessor function */
97                $basedir = dirname($backtrace[1]['file']);
98
99                if ($basedir == dirname(__FILE__))
100                        return true;
101                return false;
102        }
103}
104
105?>
Note: See TracBrowser for help on using the repository browser.