Exemple #1
0
 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new OC_USER_CAS();
     }
     return self::$instance;
 }
Exemple #2
0
 public static function InitCAS()
 {
     if (!self::$_InitCAS) {
         $aliasName = OCP\Config::getAppValue('user_cas', 'cas_aliasName', '');
         $casVersion = OCP\Config::getAppValue('user_cas', 'cas_server_version', '2.0');
         $casHostname = OCP\Config::getAppValue('user_cas', 'cas_server_hostname', 'ident.domain.fr');
         $casPort = OCP\Config::getAppValue('user_cas', 'cas_server_port', '443');
         $casPath = OCP\Config::getAppValue('user_cas', 'cas_server_path', '/cas');
         phpCAS::client($casVersion, $casHostname, (int) $casPort, $casPath, false);
         if ($aliasName) {
             phpCAS::setFixedServiceURL($aliasName);
         }
         phpCAS::setNoCasServerValidation();
         self::$_InitCAS = true;
     }
     return self::$_InitCAS;
 }
Exemple #3
0
 public static function logout($parameters)
 {
     if (\OC::$server->getConfig()->getAppValue('user_cas', 'cas_disable_logout', false)) {
         return true;
     }
     $casBackend = OC_USER_CAS::getInstance();
     if (phpCAS::isAuthenticated()) {
         phpCAS::logout();
     }
     return true;
 }
Exemple #4
0
 public static function initialized_php_cas()
 {
     if (!self::$_initialized_php_cas) {
         $casVersion = OCP\Config::getAppValue('user_cas', 'cas_server_version', '2.0');
         $casHostname = OCP\Config::getAppValue('user_cas', 'cas_server_hostname', $_SERVER['SERVER_NAME']);
         $casPort = OCP\Config::getAppValue('user_cas', 'cas_server_port', 443);
         $casPath = OCP\Config::getAppValue('user_cas', 'cas_server_path', '/cas');
         $casDebugFile = OCP\Config::getAppValue('user_cas', 'cas_debug_file', '');
         $casCertPath = OCP\Config::getAppValue('user_cas', 'cas_cert_path', '');
         $php_cas_path = OCP\Config::getAppValue('user_cas', 'cas_php_cas_path', 'CAS.php');
         if (!class_exists('phpCAS')) {
             if (empty($php_cas_path)) {
                 $php_cas_path = 'CAS.php';
             }
             OC_Log::write('cas', "Try to load phpCAS library ({$php_cas_path})", OC_Log::DEBUG);
             include_once $php_cas_path;
             if (!class_exists('phpCAS')) {
                 OC_Log::write('cas', 'Fail to load phpCAS library !', OC_Log::ERROR);
                 return false;
             }
         }
         if ($casDebugFile !== '') {
             phpCAS::setDebug($casDebugFile);
         }
         phpCAS::client($casVersion, $casHostname, (int) $casPort, $casPath, false);
         if (!empty($casCertPath)) {
             phpCAS::setCasServerCACert($casCertPath);
         } else {
             phpCAS::setNoCasServerValidation();
         }
         self::$_initialized_php_cas = true;
     }
     return self::$_initialized_php_cas;
 }
Exemple #5
0
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
if (OCP\App::isEnabled('user_cas')) {
    require_once 'user_cas/user_cas.php';
    OCP\App::registerAdmin('user_cas', 'settings');
    // register user backend
    \OC_User::useBackend('CAS');
    OC::$CLASSPATH['OC_USER_CAS_Hooks'] = 'user_cas/lib/hooks.php';
    OCP\Util::connectHook('OC_User', 'post_createUser', 'OC_USER_CAS_Hooks', 'post_createUser');
    OCP\Util::connectHook('OC_User', 'post_login', 'OC_USER_CAS_Hooks', 'post_login');
    OCP\Util::connectHook('OC_User', 'logout', 'OC_USER_CAS_Hooks', 'logout');
    $force_login = shouldEnforceAuthentication();
    if (isset($_GET['app']) && $_GET['app'] == 'user_cas' || $force_login) {
        if (OC_USER_CAS::initialized_php_cas()) {
            phpCAS::forceAuthentication();
            $user = phpCAS::getUser();
            $application = new \OC\Core\Application();
            $loginController = $application->getContainer()->query('LoginController');
            $loginController->tryLogin($user, NULL, NULL);
            if (isset($_SERVER["QUERY_STRING"]) && !empty($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != 'app=user_cas') {
                header('Location: ' . OC::$WEBROOT . '/?' . $_SERVER["QUERY_STRING"]);
                exit;
            }
        }
        OC::$REQUESTEDAPP = '';
        \OC_Util::redirectToDefaultPage();
    }
    if (!phpCAS::isAuthenticated() && !OCP\User::isLoggedIn()) {
        \OC_App::registerLogIn(array('href' => '?app=user_cas', 'name' => 'CAS Login'));
Exemple #6
0
 public static function logout($parameters)
 {
     $casBackend = OC_USER_CAS::getInstance();
     if (phpCAS::isAuthenticated()) {
         phpCAS::logout();
     }
     return true;
 }