123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
- }
- class LdapAuthorizationPlugin extends AuthorizationPlugin
- {
- const PLUGIN_VERSION = '2.0.0';
- public $roles_to_groups = array();
- public $login_group = null;
- function onInitializePlugin(){
- if(!isset($this->provider_name)){
-
- throw new Exception(_m('provider_name must be set. Use the provider_name from the LDAP Authentication plugin.'));
- }
- if(!isset($this->uniqueMember_attribute)){
-
- throw new Exception(_m('uniqueMember_attribute must be set.'));
- }
- $this->ldapCommon = new LdapCommon(get_object_vars($this));
- }
- function onAutoload($cls)
- {
- switch ($cls)
- {
- case 'LdapCommon':
- require_once(INSTALLDIR.'/plugins/LdapCommon/LdapCommon.php');
- return false;
- }
- return parent::onAutoload($cls);
- }
-
- function loginAllowed($user) {
- $user_username = new User_username();
- $user_username->user_id=$user->id;
- $user_username->provider_name=$this->provider_name;
- if($user_username->find() && $user_username->fetch()){
- $entry = $this->ldapCommon->get_user($user_username->username);
- if($entry){
- if(isset($this->login_group)){
- if(is_array($this->login_group)){
- foreach($this->login_group as $group){
- if($this->ldapCommon->is_dn_member_of_group($entry->dn(),$group)){
- return true;
- }
- }
- }else{
- if($this->ldapCommon->is_dn_member_of_group($entry->dn(),$this->login_group)){
- return true;
- }
- }
- return null;
- }else{
-
- return true;
- }
- }else{
- return null;
- }
- }else{
- return null;
- }
- }
- function hasRole($profile, $name) {
- $user_username = new User_username();
- $user_username->user_id=$profile->id;
- $user_username->provider_name=$this->provider_name;
- if($user_username->find() && $user_username->fetch()){
- $entry = $this->ldapCommon->get_user($user_username->username);
- if($entry){
- if(isset($this->roles_to_groups[$name])){
- if(is_array($this->roles_to_groups[$name])){
- foreach($this->roles_to_groups[$name] as $group){
- if($this->ldapCommon->is_dn_member_of_group($entry->dn(),$group)){
- return true;
- }
- }
- }else{
- if($this->ldapCommon->is_dn_member_of_group($entry->dn(),$this->roles_to_groups[$name])){
- return true;
- }
- }
- }
- }
- }
- return false;
- }
- public function onPluginVersion(array &$versions): bool
- {
- $versions[] = array('name' => 'LDAP Authorization',
- 'version' => self::PLUGIN_VERSION,
- 'author' => 'Craig Andrews',
- 'homepage' => GNUSOCIAL_ENGINE_REPO_URL . 'tree/master/plugins/LdapAuthorization',
- 'rawdescription' =>
-
- _m('The LDAP Authorization plugin allows for StatusNet to handle authorization through LDAP.'));
- return true;
- }
- }
|