[HOW-TO] Use Custom Variable to get user HOME dir from LDAP

IMPORTANT NOTIFICATION - FORUM MOVES TO HTTPS://FORUM.PYDIO.COM

Dear Pydio Community,
This forum will be soon made readonly, as we are transitioning to Discourse. To start on a fresh basis, we decided NOT TO MIGRATE the current threads to the new platform.
As a result, please be kind enough to register there and post your messages at the new location, and if you have an open thread, please do re-open it on Discourse!

Thank you and sorry for the inconvenience
Pydio Team

Home Forums Developers [HOW-TO] Use Custom Variable to get user HOME dir from LDAP

This topic contains 10 replies, has 5 voices, and was last updated by Profile photo of Charles Charles 5 months, 4 weeks ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #80595
    Profile photo of buffy
    buffy
    Participant

    Good day,

    I have been chugging away at mapping the LDAP home drive for users that login remotely at our primary school. I have found trying to use the SMB option yields no luck at at all but using the access.fs will allow me to setup a workspace manually to a UNC which is cracking. The problem I am having is getting a custom var (LDAP_HOME) to resolve for access.fs

    I have output below object\array and can see its there but I just cant get access.fs to change the name from LDAP_HOME to the real home.

    Any help would be very appreciated.

    AJXP_Role Object
    (
    [groupPath:protected] =>
    [roleId:protected] => AJXP_USR_/bob
    [roleLabel:protected] =>
    [acls:protected] => Array
    (
    [0] => rw
    [1] => rw
    [ajxp_user] => rw
    [ajxp_conf] => rw
    [fs_template] => rw
    [xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx] => rw
    [xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx] => rw
    [xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx] => rw
    )

    [parameters:protected] => Array
    (
    [AJXP_REPO_SCOPE_ALL] => Array
    (
    [auth.ldap] => Array
    (
    [email] =>
    [AJXP_GROUP_PATH_FLAT] =>
    [LDAP_HOME] => //wil-sr-001/amg
    )

    [core.conf] => Array
    (
    [email] =>
    [avatar] =>
    [USER_DISPLAY_NAME] =>
    [DEFAULT_START_REPOSITORY] => ajxp_user
    [lang] =>
    [country] => uk
    [USER_SHARED_USERS_LIMIT] =>
    )

    [access.fs.] => Array
    (
    [AJXP_GROUP_PATH] =>
    [LDAP_HOME] => //wil-sr-001/amg
    [PATH] =>
    )

    )

    )


    • This topic was modified 3 years, 4 months ago by Profile photo of Charles Charles.
    #80599
    Profile photo of Charles
    Charles
    Keymaster

    @c12simple any suggestion?


    Charles, Pydio author - doing my best to help !
    If you like the software or want to say thanks, pay by a tweet, mention #pydio or follow us

    #80733
    Profile photo of c12simple
    c12simple
    Keymaster

    Hello,

    There are several steps to map an attribute in LDAP to Pydio:
    1.
    Mapping ldap user attribute to user in Pydio
    example: in configuration Authentication plugin with LDAP Instance
    LDAP attribute: homeDirectory
    Mapping Type: Plugin Parameter
    Plugin parameter: core.conf/USER_HOME_DIR
    2.
    Active meta plugin in Workspace Features and configure
    FS Type: cifs
    Sudo: Yes/No
    Remote Path: MOUNT_USER_HOME_DIR
    Mount Point: localPathInServerPydio/share/AJXP_USER
    Mount Options: let be default
    User: blank
    Password: blank
    Session credential: YES
    3.
    Define a customized function in external file .php
    ex: AJXP_INSTALL_PATH/myCode/mapHomeFilter.php

        function myFilter(&$value)
        {
            if ((!is_string($value)) || strcmp($value, "MAP_USER_HOME_DIR") !== 0) return;
            $currentUser = AuthService::getLoggedUser();
            if (is_null(ConfService::getRepository())) return;
            if ($currentUser != null) {
                $repoObject = ConfService::getCurrentRepositoryId();
    
                //-------------------
                // get attribute of ldap user via core.conf/USER_HOME_DIR
                //-------------------
                $custom = $currentUser->mergedRole->filterParameterValue("core.conf", "HOME_DIRECTORY", $repoObject, '');
                if (empty($custom)) return;
                $custom = str_replace("\\", "/", $custom);
    
                //-------------------
                //replace Remote path in configuration of FS Mount by ldap attribute
                //-------------------
             $value = str_replace("MOUNT_USER_HOME_DIR", $custom, $value);
            }
        }
    

    Register new function to system
    Add following line at the end of conf/bootstrap_context.php
    require_once “AJXP_INSTALL_PATH/myCode/mapHomeFilter.php”;
    AJXP_Controller::registerIncludeHook(“vars.filter”, “myFilter”);

    For further information, please visit:
    Access.fs and Meta.mountfs
    https://pyd.io/administrator/workspaces/workspaces-drivers/access-fs-meta-mount/

    Custon variables
    https://pyd.io/defining-custom-variables-in-workspaces/
    https://pyd.io/going-further-with-custom-variables/


    #80749
    Profile photo of buffy
    buffy
    Participant

    First off thanks very much for your response it clear you have put a lot of time and effort into it. I shall attempt to add this into my install later on today or tomorrow. I have been assigned a server install today.


    #80777
    Profile photo of buffy
    buffy
    Participant

    Ok still not quite there, I have fixed this little bit from

    require_once “AJXP_INSTALL_PATH/myCode/mapHomeFilter.php”;

    to

    require_once AJXP_INSTALL_PATH."/myCode/mapHomeFilter.php”;
    

    I have tired to enter the location manually in FS Mount as instead of putting MOUNT_USER_HOME_DIR I have tried \\wil-sr-001\amg which I know works with out the CIFS addon.


    #80791
    Profile photo of buffy
    buffy
    Participant
    strcmp($value, "MAP_USER_HOME_DIR") !== 0)

    Should this be:

    strcmp($value, "MOUNT_USER_HOME_DIR") !== 0)
    $custom = $currentUser->mergedRole->filterParameterValue("core.conf", "HOME_DIRECTORY", $repoObject, '');

    Should this be:

    $custom = $currentUser->mergedRole->filterParameterValue("core.conf", "USER_HOME_DIR", $repoObject, '');

    #80792
    Profile photo of buffy
    buffy
    Participant

    I was getting an error to check that the credentials were being stored in the session. When I enabled store credentials in session I was not able to get past the dashboard with an error of “Internal Server error. You should check what happened.”


    #80795
    Profile photo of buffy
    buffy
    Participant

    Ok ITS WORKING! YAYAYAYAYAYAYAYAY

    Right the FS Mount does not work from a server 2012 system and I suspect its a Linux \ Unix option. Any way Here is my final setup based off TRAN’s suggestions.

    1. Mapping ldap user attribute to user in Pydio
    example: in configuration Authentication plugin with LDAP Instance
    LDAP attribute: homeDirectory
    Mapping Type: Plugin Parameter
    Plugin parameter: core.conf/LDAP_HOME

    2. Create new workspace
    Select “filesystem (standard)”
    Set PATH MOUNT_USER_HOME_DRIVE
    Set READ\WRITE permissions
    Set alias my-documents **WHAT EVER YOU WANT**
    Session Credential: NO

    3. Define a customized function in external file .php
    ex: AJXP_INSTALL_PATH/myCode/mapHomeFilter.php

    <?php
    function myLDAPHOMEFilter(&$value)
        {
            if ((!is_string($value)) || strcmp($value, "MOUNT_USER_HOME_DRIVE") !== 0) return;
            $currentUser = AuthService::getLoggedUser();
            if (is_null(ConfService::getRepository())) return;
            if ($currentUser != null) {
                $repoObject = ConfService::getCurrentRepositoryId();
    
                //-------------------
                // get attribute of ldap user via core.conf/USER_HOME_DIR
                //-------------------
                $custom = $currentUser->mergedRole->filterParameterValue("core.conf", "LDAP_HOME", $repoObject, '');
                if (empty($custom)) return;
                $custom = str_replace("\\", "/", $custom);
                    
                //-------------------
                //replace Remote path in configuration of FS Mount by ldap attribute
                //-------------------
             $value = str_replace("MOUNT_USER_HOME_DRIVE", $custom, $value);
            }
        }
    
    ?>
    

    4. Register new function to system
    Add following line at the end of conf/bootstrap_context.php
    require_once “AJXP_INSTALL_PATH/myCode/mapHomeFilter.php”;
    AJXP_Controller::registerIncludeHook(“vars.filter”, “myFilter”);


    #113375
    Profile photo of mwsteven
    mwsteven
    Participant

    I’ve followed these step pretty much verbatim. Whenever I add my new functions to the end of my bootstrap_context.php file, my server crashes with a http 500 error. I am using php7.0, nginx, and mysql running pydio 8.0 Community edition. Any help?


    #113839
    Profile photo of BossRoss
    BossRoss
    Participant

    I echo the request for help. Looks like these don’t work anymore…
    AJXP_Plugin (Looks like it’s just Plugin now)
    AJXP_Controller
    AuthService::getLoggedUser (see https://pydio.com/forum/f/topic/outdated-documentation/#post-107280)

    I can’t upgrade from 6.4.2 as the register plugin (in bootstrap_plugins.php) causes the update to fail.

    If someone has a solution for parsing UPN login into two variables, I could use some help. Thanks.


    #113964
    Profile photo of Charles
    Charles
    Keymaster

    Hi,
    I just updated https://pydio.com/en/docs/kb/workspaces/custom-variables-workspaces , hope it helps.
    Charles


    Charles, Pydio author - doing my best to help !
    If you like the software or want to say thanks, pay by a tweet, mention #pydio or follow us

Viewing 11 posts - 1 through 11 (of 11 total)

The forum ‘Developers’ is closed to new topics and replies.