File indexing completed on 2025-05-04 05:29:13
0001 <?php 0002 0003 /** 0004 * ocs-webserver 0005 * 0006 * Copyright 2016 by pling GmbH. 0007 * 0008 * This file is part of ocs-webserver. 0009 * 0010 * This program is free software: you can redistribute it and/or modify 0011 * it under the terms of the GNU Affero General Public License as 0012 * published by the Free Software Foundation, either version 3 of the 0013 * License, or (at your option) any later version. 0014 * 0015 * This program is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU Affero General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Affero General Public License 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 * 0023 * Created: 09.12.2016 0024 **/ 0025 class Default_Model_SingleSignOnToken 0026 { 0027 0028 const LOGIN_CACHE_NAME_PREFIX = 'sso_token_login_'; 0029 const LOGOUT_CACHE_NAME_PREFIX = 'sso_token_logout_'; 0030 const SSO_SESSION_NAMESPACE = 'sso_action'; 0031 const ACTION_LOGIN = 'login'; 0032 const ACTION_LOGOUT = 'logout'; 0033 const REMEMBER_ME = true; 0034 0035 /** 0036 * @param $data 0037 * 0038 * @return string 0039 * @throws Zend_Cache_Exception 0040 * @throws Zend_Exception 0041 */ 0042 public function createToken($data) 0043 { 0044 $idToken = substr(Local_Tools_UUID::generateUUID(), 0, 45); 0045 /** @var Zend_Cache_Core $cache */ 0046 $cache = Zend_Registry::get('cache'); 0047 $cache->save($data, $idToken, array(), 120); 0048 0049 return $idToken; 0050 } 0051 0052 /** 0053 * @param $token_id 0054 * 0055 * @return bool 0056 * @throws Zend_Exception 0057 */ 0058 public function isValid($token_id) 0059 { 0060 $token_id = preg_replace('/[^-a-zA-Z0-9_]/', '', $token_id); 0061 /** @var Zend_Cache_Core $cache */ 0062 $cache = Zend_Registry::get('cache'); 0063 0064 return (boolean)$cache->test($token_id); 0065 } 0066 0067 /** 0068 * @param $token_id 0069 * 0070 * @return false|mixed 0071 * @throws Zend_Exception 0072 */ 0073 public function getData($token_id) 0074 { 0075 /** @var Zend_Cache_Core $cache */ 0076 $cache = Zend_Registry::get('cache'); 0077 0078 return $cache->load($token_id); 0079 } 0080 0081 /** 0082 * @param $token_id 0083 * @param $data 0084 * 0085 * @return bool 0086 * @throws Zend_Cache_Exception 0087 * @throws Zend_Exception 0088 */ 0089 public function addData($token_id, $data) 0090 { 0091 /** @var Zend_Cache_Core $cache */ 0092 $cache = Zend_Registry::get('cache'); 0093 $cached_data = $cache->load($token_id); 0094 0095 return $cache->save(array_merge($cached_data, $data), $token_id, array(), 120); 0096 } 0097 0098 }