3 * StatusNet, the distributed open-source microblogging tool
5 * Plugin to enable LDAP Authorization
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Craig Andrews <candrews@integralblue.com>
25 * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
34 class LdapAuthorizationPlugin extends AuthorizationPlugin
36 public $roles_to_groups = array();
37 public $login_group = null;
39 function onInitializePlugin(){
40 if(!isset($this->provider_name)){
41 throw new Exception("provider_name must be set. Use the provider_name from the LDAP Authentication plugin.");
43 if(!isset($this->uniqueMember_attribute)){
44 throw new Exception("uniqueMember_attribute must be set.");
46 $this->ldapCommon = new LdapCommon(get_object_vars($this));
49 function onAutoload($cls)
54 require_once(INSTALLDIR.'/plugins/LdapCommon/LdapCommon.php');
59 //---interface implementation---//
60 function loginAllowed($user) {
61 $user_username = new User_username();
62 $user_username->user_id=$user->id;
63 $user_username->provider_name=$this->provider_name;
64 if($user_username->find() && $user_username->fetch()){
65 $entry = $this->ldapCommon->get_user($user_username->username);
67 if(isset($this->login_group)){
68 if(is_array($this->login_group)){
69 foreach($this->login_group as $group){
70 if($this->ldapCommon->is_dn_member_of_group($entry->dn(),$group)){
75 if($this->ldapCommon->is_dn_member_of_group($entry->dn(),$this->login_group)){
81 //if a user exists, we can assume he's allowed to login
92 function hasRole($profile, $name) {
93 $user_username = new User_username();
94 $user_username->user_id=$profile->id;
95 $user_username->provider_name=$this->provider_name;
96 if($user_username->find() && $user_username->fetch()){
97 $entry = $this->ldapCommon->get_user($user_username->username);
99 if(isset($this->roles_to_groups[$name])){
100 if(is_array($this->roles_to_groups[$name])){
101 foreach($this->roles_to_groups[$name] as $group){
102 if($this->ldapCommon->is_dn_member_of_group($entry->dn(),$group)){
107 if($this->ldapCommon->is_dn_member_of_group($entry->dn(),$this->roles_to_groups[$name])){
117 function onPluginVersion(&$versions)
119 $versions[] = array('name' => 'LDAP Authorization',
120 'version' => STATUSNET_VERSION,
121 'author' => 'Craig Andrews',
122 'homepage' => 'http://status.net/wiki/Plugin:LdapAuthorization',
124 _m('The LDAP Authorization plugin allows for StatusNet to handle authorization through LDAP.'));