cancel
Showing results for 
Search instead for 
Did you mean: 

Current autheinticaed user

bargan
Champ in-the-making
Champ in-the-making
Hi,
In my process i have to specify if the current user is a manager or not, so when a user log in activiti-explorer, i have to retry the id of this user.
So  in my  java  class i used:  " String initiator = Authentication.getAuthenticatedUserId(); " to compar this value with a sql query (to know if this user is a manager or not).
My questions:
*1) Is this expression "Authentication.getAuthenticatedUserId()" is all what i need to get this current authentificated user?
    2) Am i right to use sql queries like this one :
   " SELECT manager FROM service INNER JOIN relationship ON service.id_service = relationship.id_service WHERE id_user='" + initiator + "'";  "
   (i tested it in my java class and its working) ?



Please help,

8 REPLIES 8

jbarrez
Star Contributor
Star Contributor
1) yes

2) um. These are NOT activiti tables?

bargan
Champ in-the-making
Champ in-the-making
hi,
Yes you are right, these are not  activiti tables.
Actually i create two additional tables in activiti database, named "service" and "relationship" , the first contains id, names of services and managers id. In the other hand table "relationship" contains id_service and id_user (foreign key of table service and table "act_id_user"), because in the table act_id_user i added somme users ( and each one is a member of a service  and he can be a sample user or a manager)
For example i have i user named "u03" in act_id_user who is a manger of service named " HR" . so i create a foreign key in table relationship for tables "service" and  "act_id_user"

Am i right to add additinnal tables ?

Thank you.

frederikherema1
Star Contributor
Star Contributor
Any additional relationships you have between users is indeed best mapped in separate tables, leaving the ACT_* tables unaffected for future upgrade purposes. You can use any ORM-framework you want, just make sure transactions are shared across the activiti services and your domain services…

bargan
Champ in-the-making
Champ in-the-making
Thank you for response,
like described above i wnat to get current user in activiti-explorer (so like this i can know if this user is a manager or not).

Please guide if i miss something (because when i fixe user  like this :  String initiator ="U03" for example i get my  result but if i use : String initiator="Authentication.getAuthenticatedUserId();"    i get error in explorer :" unknown expression property  ${verifManager.getManager()}  ).

You find my  xml and code below.

Thank you.

frederikherema1
Star Contributor
Star Contributor
First of all, how do you get an instance of "VerifManager" on the process-scope? Do you set it as a variable, or is it registered as a "bean" in the process engine configuration (see user guide, section "beans". If none of the above, it just won't work. The expression-manager won't be able to know what class/instance you mean by just using "VerifManager".

Also, I see that your VerifManager reads the AuthenticationUtil.getAuthenticatedUser() as an initialiser of a private field… This will only be called once (on creation) and seems error-prone. Better to call this in the method that is guaranteed to be called by the engine/expression-manager…

bargan
Champ in-the-making
Champ in-the-making
Thanks for your response,

1) Yes i registered it  in activiti.cfg.xml like this :  <bean id="VerifManager" class="org.conge.VerifManager" ></bean>

bargan
Champ in-the-making
Champ in-the-making
Thank you so much.
I resolved it

heba
Champ in-the-making
Champ in-the-making
how can you resolved it ??