-
Notifications
You must be signed in to change notification settings - Fork 8
/
wordpress-cas-client.php
146 lines (132 loc) · 5.68 KB
/
wordpress-cas-client.php
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
140
141
142
143
144
145
146
<?php
/*
Plugin Name: WordPress CAS Client
Description: Integrates WordPress with existing <a href="http://en.wikipedia.org/wiki/Central_Authentication_Service">CAS</a> single sign-on architectures. Additionally this plugin can use a LDAP server (such as Active Directory) for populating user information after the user has successfully logged on to WordPress. This plugin is a fork of the <a href="http://wordpress.org/extend/plugins/wpcas-w-ldap">wpCAS-w-LDAP</a> plugin.
Version: 1.4
Author: Bellevue College
Author URI: http://www.bellevuecollege.edu
License: GNU General Public License v2 or later
Plugin URI: BellevueCollege/wordpress-cas-client
*/
/*
* WordPress CAS Client plugin used to authenticate users against a CAS server
*
* Copyright (C) 2014 Bellevue College
* Copyright (C) 2009 Ioannis C. Yessios
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* This plugin owes a huge debt to
* Casey Bisson's wpCAS, copyright (C) 2008
* and released under GPL. http://wordpress.org/extend/plugins/wpcasldap/
*
* Casey Bisson's plugin owes a huge debt to Stephen Schwink's CAS
* Authentication plugin, copyright (C) 2008 and released under GPL.
* http://wordpress.org/extend/plugins/cas-authentication/
*
* It also borrowed a few lines of code from Jeff Johnson's SoJ CAS/LDAP Login
* plugin. http://wordpress.org/extend/plugins/soj-casldap/
*
* This plugin honors and extends Bisson's and Schwink's work, and is licensed
* under the same terms.
*
* Bellevue College
* Address: 3000 Landerholm Circle SE
* Room N215F
* Bellevue WA 98007-6484
* Phone: +1 425.564.4201
*/
define( 'CAPABILITY', 'edit_themes' );
define( 'CAS_CLIENT_ROOT', dirname( __FILE__ ) );
require_once constant( 'CAS_CLIENT_ROOT' ) . '/includes/admin-option-page-functions.php';
require_once constant( 'CAS_CLIENT_ROOT' ) . '/includes/class-wp-cas-ldap.php';
require_once constant( 'CAS_CLIENT_ROOT' ) . '/includes/update-network-settings.php';
require_once constant( 'CAS_CLIENT_ROOT' ) . '/config.php';
/*
* Configure plugin WordPress Hooks
*/
/*
* This global variable is set to either 'get_option' or 'get_site_option'
* depending on multisite option value.
*/
global $get_options_func;
$get_options_func = 'get_option';
/*
* This global variable is defaulted to 'options.php' , but for network
* setting we want the form to submit to itself, so we will leave it empty.
*/
global $form_action;
$form_action = 'options.php';
if ( is_multisite( ) ) {
update_network_settings( );
add_action( 'network_admin_menu', 'cas_client_settings' );
$get_options_func = 'get_site_option';
$form_action = '';
} elseif ( is_admin( ) ) {
add_action( 'admin_init', 'wp_cas_ldap_register_settings' );
add_action( 'admin_menu', 'wp_cas_ldap_options_page_add' );
}
add_action( 'wp_authenticate', array( 'WP_CAS_LDAP', 'authenticate' ), 10, 2 );
add_action( 'wp_logout', array( 'WP_CAS_LDAP', 'logout' ) );
add_action( 'lost_password', array( 'WP_CAS_LDAP', 'disable_function' ) );
add_action( 'retrieve_password', array( 'WP_CAS_LDAP', 'disable_function' ) );
add_action( 'password_reset', array( 'WP_CAS_LDAP', 'disable_function' ) );
add_filter( 'show_password_fields', array( 'WP_CAS_LDAP', 'show_password_fields' ) );
/*
* Prevent 'Password Changed' email from being sent
*
* Email was introduced in WordPress 4.3, and was sent on every login
* due to password being programatically changed as needed.
*/
add_filter( 'send_password_change_email', '__return_false' );
global $wp_cas_ldap_options;
if ( $wp_cas_ldap_options ) {
if ( ! is_array( $wp_cas_ldap_options ) ) {
$wp_cas_ldap_options = array( );
}
}
$wp_cas_ldap_use_options = wp_cas_ldap_get_options( );
global $cas_configured;
$cas_configured = false;
/*
* Check to see if the phpCAS class exists in our environment. If it doesn't
* then check to see if we have all the configuration variables we need to
* configure phpCAS. If we do then import the phpCAS library and call the
* phpCAS::client() method.
*
* NOTE: This assumes that if the phpCAS class does exist in the environment
* that the method phpCAS::client() has been already called by another
* piece of code elsewhere. If the client method has not been invoked but
* the phpCAS class has been imported into the environment anyway then
* this logic would cause the other phpCAS methods to fail when called
* later in this plugin.
*/
if ( ! class_exists( 'phpCAS' ) ) {
if ( ! empty( $wp_cas_ldap_use_options['include_path'] ) &&
file_exists( $wp_cas_ldap_use_options['include_path'] ) &&
! empty( $wp_cas_ldap_use_options['server_hostname'] ) &&
! empty( $wp_cas_ldap_use_options['server_path'] ) &&
! empty( $wp_cas_ldap_use_options['server_port'] ) ) {
require_once $wp_cas_ldap_use_options['include_path'];
phpCAS::client($wp_cas_ldap_use_options['cas_version'],
$wp_cas_ldap_use_options['server_hostname'],
intval( $wp_cas_ldap_use_options['server_port'] ),
$wp_cas_ldap_use_options['server_path']);
phpCAS::setNoCasServerValidation( );
$cas_configured = true;
}
} else {
$cas_configured = true;
}