forked from NetCommons3/NetCommons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccessCtrlComponent.php
More file actions
74 lines (63 loc) · 1.83 KB
/
AccessCtrlComponent.php
File metadata and controls
74 lines (63 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* アクセス制御 Component
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('Component', 'Controller');
App::uses('NetCommonsSecurity', 'NetCommons.Utility');
/**
* アクセス制御 Component
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\SiteManager\Controller\Component
*/
class AccessCtrlComponent extends Component {
/**
* Called before the Controller::beforeFilter().
*
* @param Controller $controller Controller with components to initialize
* @return void
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::initialize
*/
public function initialize(Controller $controller) {
parent::initialize($controller);
$this->controller = $controller;
}
/**
* アクセスチェック
*
* @return void
* @throws ForbiddenException
* @throws BadRequestException
*/
public function allowAccess() {
$controller = $this->controller;
if (! Configure::read('NetCommons.installed')) {
return true;
}
$netCommonsSecurity = new NetCommonsSecurity();
//不正IPアドレスチェック
if (! $netCommonsSecurity->enableBadIps()) {
throw new BadRequestException('Bad ip address');
}
//IP変動の禁止チェック
if (! $netCommonsSecurity->denyIpMove()) {
throw new BadRequestException('Bad ip address');
}
//サイト閉鎖のチェック
if ($netCommonsSecurity->isCloseSite($controller->request)) {
if ($controller->Auth->user()) {
throw new ForbiddenException('Under maintenance');
} else {
$controller->redirect('/net_commons/site_close/index');
return false;
}
}
return true;
}
}