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

Revision 2206, 1.7 KB checked in by pedroerp, 14 years ago (diff)

Ticket #609 - Versão inicial das classes de segurança e fábricas.

  • Property svn:executable set to *
Line 
1<?php
2
3/**
4 * Security class for Workflow module.
5 *
6 * @author Pedro Eugênio Rocha
7 * @package Security
8 * @static
9 */
10class Security {
11
12        /**
13         * @var boolean $_protection Stores the current security mode.
14         * @access private
15         * @static
16         */
17        private static $_protection = false;
18
19
20        /**
21         * Disallow the instantiation of this class.
22         * @access public
23         * @return void
24         */
25        public function __construct() {
26                throw new Exception("Oops! Static only class.");
27        }
28
29
30        /**
31         * Returns the current security mode.
32         * @access public
33         * @return boolean
34         */
35        public static function isEnabled() {
36                return self::$_protection;
37        }
38
39
40        /**
41         * Change to secured mode.
42         * @access public
43         * @return boolean
44         * @static
45         */
46        public static function enable() {
47
48                if (self::_isAllowed())
49                        self::$_protection = true;
50                else
51                        throw new Exception('You are not allowed to change security mode.');
52                return true;
53        }
54
55        /**
56         * Change to unsecured mode.
57         * @access public
58         * @return boolean
59         * @static
60         */
61        public static function disable() {
62
63                if (self::_isAllowed())
64                        self::$_protection = false;
65                else
66                        throw new Exception('You are not allowed to change security mode.');
67                return true;
68        }
69
70
71        /**
72         * This function do all the security stuff.
73         * Here we must define in which files we are able
74         * to change the security mode.
75         *
76         * @access private
77         * @return boolean
78         * @static
79         */
80        private static function _isAllowed() {
81                $backtrace = debug_backtrace();
82
83                /* TODO - These are not definitive validations */
84                /* $backtrace[1] specifies the imediate antecessor function */
85                $basedir = dirname($backtrace[1]['file']);
86
87                if ($basedir == dirname(__FILE__))
88                        return true;
89                return false;
90        }
91}
92
93?>
Note: See TracBrowser for help on using the repository browser.