• Resolved Mike Walsh

    (@mpwalsh8)


    Our internal LDAP server has changed so I need to use the wpdirauth_filterquery filter in order to properly validate user logins. I was using the solution in this prior support thread however I cannot get wpdirauth_filterquery to fire.

    I’ve tried modifying my functions.php (I am using TwentyThirteen as my theme) as well as a dedicated plugin. The only thing I’ve been able to get to work is to modify the plugin code itself. For obvious reasons I don’t really want to do that. My preference would be to write a simple plugin so I don’t have to worry about a theme update modifying functions.php either.

    This is what I added to my functions.php:

    function mgcAdjustDirAuthFilter($strCurrentFilter,$strFilter,$strUsername)
    {
         error_log(sprintf("%s::%s\n", basename(__FILE__), __LINE__), 3, "/var/tmp/log.txt"); 
         return "(&(objectClass=user)(objectCategory=person)($strFilter=$strUsername))";
    }
    add_filter(‘wpdirauth_filterquery’,’mgcAdjustDirAuthFilter’,1,3);

    But it never runs. I added error_log() statements within the function to trace execution but the text never appears and the filter is unchanged from the default after apply_filters runs from line 393 of wpDirAuth.php:

    $filterQuery = apply_filters('wpdirauth_filterquery',$filterQuery,$filter,$username);

    Since that didn’t work I tried creating simple plugin:

    <?php
    /**
     * @package MGC-wpDirAuth
     * @version 1.0
     */
    /*
    Plugin Name: MGC-wpDirAuth
    Plugin URI: http://ww.wp.xz.cn/extend/plugins/tbd/
    Description: This plugin defines a filter for the wpDirAuth plugin which configures the querty to work with Mentor's LDAP configuration.
    Author: Mike Walsh
    Version: 1.0
    Author URI: http://michaelwalsh.org/
    */
    
    function mgc_AdjustDirAuthFilter($strCurrentFilter,$strFilter,$strUsername)
    {
        error_log(sprintf("%s::%s\n", basename(__FILE__), __LINE__), 3, "/var/tmp/log.txt");
        return "(&(objectClass=user)(objectCategory=person)($strFilter=$strUsername))";
    }
    
    // Setup the wpdirauth_filterquery hook
    function mgc_wpDirAuth_init() {
        error_log(sprintf("%s::%s\n", basename(__FILE__), __LINE__), 3, "/var/tmp/log.txt");
        add_filter(‘wpdirauth_filterquery’,’mgc_AdjustDirAuthFilter’,1,3);
    }
    
    add_action( 'init', 'mgc_wpDirAuth_init' );
    ?>

    Like the addition to functions.php, the filter never runs. The ‘init’ action does fire and I see the entry in the error log file. I’ve tried various priorities and other hooks (e.g. plugins_loaded and a couple others) but it didn’t make a difference. The site this is running only has one other plugin running which does nothing more than look up information from our LDAP server.

    I assume I am missing something obvious I simply can’t see from staring at it.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Paul Gilzow

    (@gilzow)

    I’m not sure. I just tried it in a single site, and a multisite and it fired correctly. specifically, i added this to my functions file:

    add_filter('wpdirauth_filterquery',function($filterQuery,$filter,$username){
    	__log(func_get_args(),'arguments passed to us',false,array('func'=>__FUNCTION__,'line'=>__LINE__,'file'=>__FILE__));
    	return '(' . $filter . '=foobar)';
    },1,3);

    and in wpDirAuth logged the return from the filter

    In the log, it fired and produced

    [06-Oct-2016 17:28:42 UTC] : At line number 279 inside of function {closure} in file functions.php 
    arguments passed to us
    The variable is a array
    
    array (
      0 => '(samAccountName=myaccount)',
      1 => 'samAccountName',
      2 => 'myaccount',
    )
    
    [06-Oct-2016 17:38:14 UTC] : At line number 394 in file wpDirAuth.php 
    filterQuery after being altered by apply filters
    The variable is a string
    (samAccountName=foobar)
    

    I then removed that and replaced it with your function and in the log I get

    
    [06-Oct-2016 17:43:38 UTC] : At line number 394 in file wpDirAuth.php 
    filterQuery after being altered by apply filters
    The variable is a string
    (&(objectClass=user)(objectCategory=person)(samAccountName=myaccount))
    

    So it is working properly as far as I can tell. Can you give me more info on your specific setup? Multisite/single? WordPress version?

    • This reply was modified 9 years, 8 months ago by Paul Gilzow. Reason: formatting
    • This reply was modified 9 years, 8 months ago by Paul Gilzow.
    Plugin Author Paul Gilzow

    (@gilzow)

    marking resolved as I haven’t heard back from @mpwalsh8 for 3 months.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Can’t get’ is closed to new replies.