Create a new environment variable using LDAP parameters

English! place to talk about development, programming and coding
Post Reply
ahauser
OTRS newbie
Posts: 11
Joined: 19 May 2017, 10:09
OTRS Version?: ITSM5S

Create a new environment variable using LDAP parameters

Post by ahauser »

Hi,

I would like to get a LDAP parameter from the currently connected user and define it into an environment variable.
The idea would be to be able to call something from a template similar to [% Data.CurrentUserID %] but containing a specific LDAP attribute of the connected user, not just it's ID, and being able to call it from any page (an environment variable seems to be the solution for that, right ?)

I found out that it was possible to modify Layout.pm to create a new environment variable.

For example, it's possible to create a new variable called "New Variable" :
$Self->{NewVariable} = $ConfigObject->Get('DefaultTheme');

And call it inside a .tt template file using :
[% Env('NewVariable') %]


The LDAP attribute I'd like to use is defined in Config.pm as "UserEntity", which is an attribute we currently display on a ticket. What should I do to create a new variable containing it's value concerning the currently connected user ?

It seems it's not contained inside a ConfigObject but somewhere else...

Regards
Alexis

root
Moderator
Posts: 2478
Joined: 18 Dec 2007, 12:23
OTRS Version?: 4/5/6 and Znuny LTS
Real Name: Roy Kaldung
Company: Znuny
Contact:

Re: Create a new environment variable using LDAP parameters

Post by root »

Hi,

Usually, you should be able to access all attributes from the mapping in as long as the ticket data is pushed into the template. Did you checked this? In which module do you need this?

- Roy
Znuny LTS and ((OTRS) Community Edition CentOS / RHEL / Debian / SLES / MySQL / PostgreSQL / Oracle / OpenLDAP / Active Directory / SSO

Do you need professional services? Check out https://www.znuny.com/

Do you want to contribute or want to know why ?

ahauser
OTRS newbie
Posts: 11
Joined: 19 May 2017, 10:09
OTRS Version?: ITSM5S

Re: Create a new environment variable using LDAP parameters

Post by ahauser »

Hi Roy,


I'm trying to access it from the different overviews in the Agent interface.
I'm not trying to get the ticket data, but the data from the currently connected Agent viewing the page. (who also exist as a user with all the LDAP attributes)

The mapping we use for this in Config.pm is like this :

[ 'UserEntity', 'Entity', 'aNameFromOurLDAP', 1, 0, 'var', 'https://ourwebsite.com/script?dept=[% Data.UserEntity | uri %]', 0 ],

I can't access is from the templates using [% UserEntity %] or [% Entity %] or [% Data.UserEntity %] or [% Data.Entity %]

This is why the only solution I have in mind is to add it to the Layout.pm to be able to access it in that way : [% Env(''UserEntity") %]
But maybe there would be another way ?


Alexis

ahauser
OTRS newbie
Posts: 11
Joined: 19 May 2017, 10:09
OTRS Version?: ITSM5S

Re: Create a new environment variable using LDAP parameters

Post by ahauser »

Maybe adding a new field in the Agent informations and fill it with the mapping would make more sense ?
Then would it be accessible from any page ?

skullz
OTRS wizard
Posts: 359
Joined: 24 Feb 2012, 03:58
OTRS Version?: OTRS 6
Real Name: Skullz
Contact:

Re: Create a new environment variable using LDAP parameters

Post by skullz »

You are looking for agent details while the AD mapping that you show is for the customer user..

Additionally, back in the day by default, we cant sync additional info from AD to agent profile..not sure on the latest version either can do this or not..

If can be sync, the variable may be access by [% Env("UserEntity") %], for example.

ahauser
OTRS newbie
Posts: 11
Joined: 19 May 2017, 10:09
OTRS Version?: ITSM5S

Re: Create a new environment variable using LDAP parameters

Post by ahauser »

Then I'm thinking about another solution :
All our agents also exists as customer users which contain the right attributes.

Would it be possible to perform a search on a User with the same ID than the Agent, get a specific attribute and store it into an environment variable in order to use that on any page ?

skullz
OTRS wizard
Posts: 359
Joined: 24 Feb 2012, 03:58
OTRS Version?: OTRS 6
Real Name: Skullz
Contact:

Re: Create a new environment variable using LDAP parameters

Post by skullz »

Just tested..

look like additional LDAP attributes can be pull from LDAP to Agent profile..
for example phone number..

Code: Select all

 $Self->{'AuthSyncModule::LDAP::UserSyncMap2'} = {
       # DB -> LDAP
      UserFirstname => 'givenName',
      UserLastname  => 'sn',
      UserEmail     => 'mail',
      UserPhoneNumber => 'telephonenumber',
  };
then you can access it by [% Env("UserPhoneNumber") | html %] in template file..
Capture.PNG

and, of course you have to create the agent preferences field first to store this value.
viewtopic.php?t=19936
You do not have the required permissions to view the files attached to this post.

root
Moderator
Posts: 2478
Joined: 18 Dec 2007, 12:23
OTRS Version?: 4/5/6 and Znuny LTS
Real Name: Roy Kaldung
Company: Znuny
Contact:

Re: Create a new environment variable using LDAP parameters

Post by root »

skullz wrote:
21 Aug 2020, 16:22
look like additional LDAP attributes can be pull from LDAP to Agent profile..
Hi,

JFI, this feature is available since vrsion 6.

- Roy
Znuny LTS and ((OTRS) Community Edition CentOS / RHEL / Debian / SLES / MySQL / PostgreSQL / Oracle / OpenLDAP / Active Directory / SSO

Do you need professional services? Check out https://www.znuny.com/

Do you want to contribute or want to know why ?

ahauser
OTRS newbie
Posts: 11
Joined: 19 May 2017, 10:09
OTRS Version?: ITSM5S

Re: Create a new environment variable using LDAP parameters

Post by ahauser »

skullz wrote:
21 Aug 2020, 16:22

Code: Select all

 $Self->{'AuthSyncModule::LDAP::UserSyncMap2'} = {
       # DB -> LDAP
      UserFirstname => 'givenName',
      UserLastname  => 'sn',
      UserEmail     => 'mail',
      UserPhoneNumber => 'telephonenumber',
  };
Did you write a new Module in Custom/Kernel/ adding a modification of System/Auth/Sync/LDAP.pm ?
What did you change from the original AuthSyncModule::LDAP::UserSyncMap ?

Regards
Alexis

skullz
OTRS wizard
Posts: 359
Joined: 24 Feb 2012, 03:58
OTRS Version?: OTRS 6
Real Name: Skullz
Contact:

Re: Create a new environment variable using LDAP parameters

Post by skullz »

ahauser wrote:
28 Aug 2020, 11:53
skullz wrote:
21 Aug 2020, 16:22

Code: Select all

 $Self->{'AuthSyncModule::LDAP::UserSyncMap2'} = {
       # DB -> LDAP
      UserFirstname => 'givenName',
      UserLastname  => 'sn',
      UserEmail     => 'mail',
      UserPhoneNumber => 'telephonenumber',
  };
Did you write a new Module in Custom/Kernel/ adding a modification of System/Auth/Sync/LDAP.pm ?
What did you change from the original AuthSyncModule::LDAP::UserSyncMap ?

Regards
Alexisdetai
No need to change anything at core code level..
Normally, AD connection details are define in Config.pm.

So in Config.pm, within $Self->{'AuthSyncModule::LDAP::UserSyncMap'} block, add

Code: Select all

UserPhoneNumber => 'telephonenumber',

ahauser
OTRS newbie
Posts: 11
Joined: 19 May 2017, 10:09
OTRS Version?: ITSM5S

Re: Create a new environment variable using LDAP parameters

Post by ahauser »

Actually it seems I was missing the part with :

Code: Select all

$Self->{'AuthSyncModule'} = 'Kernel::System::Auth::Sync::LDAP';
$Self->{'AuthSyncModule::LDAP::XXX'} = 
I don't get it : it works with your example, I can display the phone number on the page using UserPhoneNumber, but if I try wih something else it doesn't...

Example, I created a new agent preference field. I can see it appears correctly in the Sysconfig :

Code: Select all

    <Setting Name="PreferencesGroups###AgentEntity" Required="0" Valid="1">
        <Description Translatable="1">A longer discription that describes what this field does</Description>
        <Navigation>Frontend::Agent::View::Preferences</Navigation>
        <Value>
            <Hash>
                <Item Key="Module">Kernel::Output::HTML::Preferences::Generic</Item>
                <Item Key="PreferenceGroup">Miscellaneous</Item>
                <Item Key="Label" Translatable="1">AgentEntity</Item>
                <Item Key="Desc" Translatable="1">Something that describes what this field is about.</Item>
                <Item Key="Key" Translatable="1"></Item>
                <Item Key="Prio">2345</Item>
                <Item Key="Active">1</Item>
            </Hash>
        </Value>
    </Setting>
I added it in the mapping in Config.pm, with a simple attribute first : mail :

Code: Select all

 $Self->{'AuthSyncModule::LDAP::UserSyncMap'} = {
##       # DB -> LDAP
        UserPhoneNumber => 'telephoneNumber',
        AgentEntity => 'mail',
  };
Then I added it in the AgentTicketZoom.tt :

Code: Select all

 [% Env("UserPhoneNumber") | html %]
 [% Env("AgentEntity") | html %]
But nothing... Only the phone number of your example displays... Maybe I missed something ?

skullz
OTRS wizard
Posts: 359
Joined: 24 Feb 2012, 03:58
OTRS Version?: OTRS 6
Real Name: Skullz
Contact:

Re: Create a new environment variable using LDAP parameters

Post by skullz »

1. Just tested it..look like must used the prefix 'User'

So instead of

Code: Select all

AgentEntity => 'mail',
Use

Code: Select all

UserEntity => 'mail', 


2. XML should look like this

Code: Select all

    <Setting Name="PreferencesGroups###Entity" Required="0" Valid="1">
        <Description Translatable="1">Defines the config parameters of this item, to be shown in the preferences view. Please note: setting 'Active' to 0 will only prevent agents from editing settings of this group in their personal preferences, but will still allow administrators to edit the settings of another user's behalf. Use 'PreferenceGroup' to control in which area these settings should be shown in the user interface.</Description>
        <Navigation>Frontend::Agent::View::Preferences</Navigation>
        <Value>
            <Hash>
                <Item Key="Module">Kernel::Output::HTML::Preferences::Generic</Item>
                <Item Key="PreferenceGroup">Miscellaneous</Item>
                <Item Key="Label" Translatable="1">Entity</Item>
                <Item Key="Desc" Translatable="1">This is a Description for Entity</Item>
                <Item Key="Key" Translatable="1">Entity</Item>
                <Item Key="Block">Input</Item>
                <Item Key="Data">[% Env("UserEntity") %]</Item>
                <Item Key="PrefKey">UserEntity</Item>
                <Item Key="Prio">7000</Item>
                <Item Key="Active">1</Item>
            </Hash>
        </Value>
    </Setting>

ahauser
OTRS newbie
Posts: 11
Joined: 19 May 2017, 10:09
OTRS Version?: ITSM5S

Re: Create a new environment variable using LDAP parameters

Post by ahauser »

Thanks a lot, it works !

However, on one of the development server we're using, the password is removed everytime after login.
I don't see any other differences except this server doesn't have a SSO login configured.
Could it be related ?
Any ideas ?

gerald2545
OTRS newbie
Posts: 22
Joined: 19 Jul 2019, 16:31
OTRS Version?: 6.0.14
Real Name: Gerald
Company: INRA

Re: Create a new environment variable using LDAP parameters

Post by gerald2545 »

Hi,
do you know how we can use this field in the signature?
I tried adding
$Env{"UserEntity"}

in the signature, but it is not interpreted...

thank you for your help

Gérald
OTRS : 6.0.29, with FAQ extension, on centOS7
Agent auth against local database (postgresql 9)

ahauser
OTRS newbie
Posts: 11
Joined: 19 May 2017, 10:09
OTRS Version?: ITSM5S

Re: Create a new environment variable using LDAP parameters

Post by ahauser »

For me this works :

<OTRS_CURRENT_UserCity>

root
Moderator
Posts: 2478
Joined: 18 Dec 2007, 12:23
OTRS Version?: 4/5/6 and Znuny LTS
Real Name: Roy Kaldung
Company: Znuny
Contact:

Re: Create a new environment variable using LDAP parameters

Post by root »

Hi,

It should be <OTRS_OWNER_UserEntity> / <OTRS_CURRENT_UserEntity> / <OTRS_RESPONSIBLE_UserEntity>

- Roy
Znuny LTS and ((OTRS) Community Edition CentOS / RHEL / Debian / SLES / MySQL / PostgreSQL / Oracle / OpenLDAP / Active Directory / SSO

Do you need professional services? Check out https://www.znuny.com/

Do you want to contribute or want to know why ?

gerald2545
OTRS newbie
Posts: 22
Joined: 19 Jul 2019, 16:31
OTRS Version?: 6.0.14
Real Name: Gerald
Company: INRA

Re: Create a new environment variable using LDAP parameters

Post by gerald2545 »

wonderful!!
thank you very much
OTRS : 6.0.29, with FAQ extension, on centOS7
Agent auth against local database (postgresql 9)

ahauser
OTRS newbie
Posts: 11
Joined: 19 May 2017, 10:09
OTRS Version?: ITSM5S

[Solved] Re: Create a new environment variable using LDAP parameters

Post by ahauser »

As my initial question is solved, I will create new posts for other related questions.

Post Reply