<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Add Role permanently to User programmatically</title><link>https://answers.axonivy.com/questions/1854/add-role-permanently-to-user-programmatically</link><description>&lt;p&gt;Hi
I want to assign a role to a user permanently in my software. And i need to this programmatically.
Can anyone help me out? I tried the addRole function in IUsers but this is just temporary i think.
Best regards
Florian&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/1854/add-role-permanently-to-user-programmatically" rel="self"></atom:link><language>en</language><lastBuildDate>Fri, 01 Jul 2016 10:46:06 -0400</lastBuildDate><item><title>Answer by Reto Weiss</title><link>https://answers.axonivy.com/questions/1854/add-role-permanently-to-user-programmatically/1855</link><description>&lt;p&gt;Hi &lt;/p&gt;
&lt;p&gt;You can asign a role to a user by executing the following script:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import ch.ivyteam.ivy.security.ISecurityContext;
import ch.ivyteam.ivy.security.IUser;
import ch.ivyteam.ivy.security.IRole;

ISecurityContext securityContext = ivy.wf.getApplication().getSecurityContext();
IUser user = securityContext.findUser("myUser");
IRole role = securityContext.findRole("myRole");
user.addRole(role);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will assign the role permanantely to the user. &lt;/p&gt;
&lt;p&gt;Note that the role assignment is not forwarded automatically to sessions of the user. The user has to log out and login again so that he can act as the role. &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reto Weiss</dc:creator><pubDate>Fri, 01 Jul 2016 10:46:06 -0400</pubDate><guid>https://answers.axonivy.com/questions/1854/add-role-permanently-to-user-programmatically/1855</guid></item></channel></rss>