-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthShibbolethController.php
More file actions
139 lines (121 loc) · 3.49 KB
/
AuthShibbolethController.php
File metadata and controls
139 lines (121 loc) · 3.49 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/**
* AuthShibboleth Controller
*
* @author Mitsuru Mutaguchi <mutaguchi@opensource-workshop.jp>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('AuthShibbolethAppController', 'AuthShibboleth.Controller');
/**
* AuthShibboleth Controller
*
* @author Mitsuru Mutaguchi <mutaguchi@opensource-workshop.jp>
* @package NetCommons\AuthShibboleth\Controller
*/
class AuthShibbolethController extends AuthShibbolethAppController {
/**
* use component
*
* @var array
*/
public $components = array(
'AuthShibboleth.AuthShibboleth',
);
/**
* beforeFilter
*
* @return void
**/
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('secure', 'discovery', 'mapping');
}
/**
* 学認Embedded DS表示(URLで直接開く)
* https://example.com/auth_shibboleth/auth_shibboleth/discovery
*
* @return void
**/
public function discovery() {
$this->view = 'AuthShibboleth.AuthShibboleth/ds';
}
/**
* 初期処理
*
* @return CakeResponse
**/
public function secure() {
// ベースURL(認証後のURLを開いた後のリダイレクトに利用します)
$baseUrl = SiteSettingUtil::read('AuthShibboleth.base_url');
// 外部認証のID関連付けログイン、仮登録画面、関連付け画面への遷移先別けはexloginで行う
$redirect = $baseUrl . 'auth_shibboleth/auth_shibboleth/exlogin';
$this->Session->delete('AuthShibbolethTmp.wayfAutoLogin');
// IdPのユーザ情報 セット
$this->AuthShibboleth->setIdpUserData();
// IdPによる個人識別番号 or persistentId の存在チェック
if ($this->AuthShibboleth->isIdpUserid()) {
// リダイレクト
return $this->redirect($redirect);
}
// 必要な属性情報が得られない時は、DSの自動ログインをOFFにする
$this->Session->write('AuthShibbolethTmp.wayfAutoLogin', false);
$returnUrl = $baseUrl . 'auth/login';
$redirect = $baseUrl . 'Shibboleth.sso/Logout?return=' . $returnUrl;
// メッセージ表示
$this->NetCommons->setFlashNotification(
__d('auth', 'Auth.exlogin.failure'),
array(
'class' => 'danger',
'interval' => NetCommonsComponent::ALERT_VALIDATE_ERROR_INTERVAL,
),
400
);
// リダイレクト
return $this->redirect($redirect);
}
/**
* 「他サービスを用いたログイン処理」後の処理・画面遷移先
* (外部認証系プラグインのコントローラでオーバーライトして実装)
*
* @return string リダイレクト先
**/
protected function _exLoginRedirect() {
return $this->AuthShibboleth->exLoginRedirect();
}
/**
* ID関連付け
* (オーバーライト)
*
* @return void
**/
public function mapping() {
// IdPによる個人識別番号 or persistentId の存在チェック
if (! $this->AuthShibboleth->isIdpUserid()) {
return $this->throwBadRequest();
}
parent::mapping();
}
/**
* IdPによる個人識別番号 取得
* (オーバーライト)
*
* @return string idpUserid or persistentId
**/
protected function _getIdpUserid() {
return $this->AuthShibboleth->getIdpUserid();
}
/**
* _exLogin()でログイン後の追加処理
* (オーバーライト)
*
* @return void
**/
protected function _exLoggedin() {
// ログイン関連付け
$this->AuthShibboleth->saveUserMapping($this->Auth->user('id'));
// shibbolethのセッション初期化
$this->Session->delete('AuthShibboleth');
}
}