<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Assign and revoke Role to Session User dynamically</title><link>https://answers.axonivy.com/questions/1703/assign-and-revoke-role-to-session-user-dynamically</link><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I need to assign and revoke Ivy Role dynamically on the session user. If I understand the API documentation well, the following method assigns the given role to the session, the role should be automatically unassigned after logout:
    Ivy.session().assignRole(role);&lt;/p&gt;
&lt;p&gt;Here the API documentation:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;@PublicAPI(value=EXPERT)
Assigns a role to the session. 
Parameters:role The role to assign&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The problem is that I need also to revoke an Ivy Role dynamically, I could not find a method like Ivy.session().revokeRole(IRole role) or Ivy.session().unassignRole(Irole role).
Is there a possibility to do that?&lt;/p&gt;
&lt;p&gt;Thanks a lot in advance.&lt;/p&gt;
&lt;p&gt;Emmanuel&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/1703/assign-and-revoke-role-to-session-user-dynamically" rel="self"></atom:link><language>en</language><lastBuildDate>Fri, 01 Apr 2016 13:44:42 -0400</lastBuildDate><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/1703/assign-and-revoke-role-to-session-user-dynamically/1711</link><description>&lt;p&gt;You can set the assigned role back to it's default value (and behaviour) by assigning the top level role called "everybody". &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;IRole everybody = Ivy.wf().getSecurityContext().getTopLevelRole();
theSession.assignRole(everybody);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Alternatively you can manage the roles on the session user as roland described: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;IUser theUser = Ivy.wf().getSecurityContext().getCurrentSession().getSessionUser();
theUser.addRole(myRole);
theUser.removeRole(myRole);
&lt;/code&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Fri, 01 Apr 2016 13:44:42 -0400</pubDate><guid>https://answers.axonivy.com/questions/1703/assign-and-revoke-role-to-session-user-dynamically/1711</guid></item><item><title>Answer by roland</title><link>https://answers.axonivy.com/questions/1703/assign-and-revoke-role-to-session-user-dynamically/1704</link><description>&lt;p&gt;Hello Emmanuel,&lt;/p&gt;
&lt;p&gt;you could try ivy.session.getSessionUser().removeRole(ch.ivyteam.ivy.security.IRole)
maybe this helps.&lt;/p&gt;
&lt;p&gt;best regards &lt;/p&gt;
&lt;p&gt;Roland&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">roland</dc:creator><pubDate>Thu, 31 Mar 2016 13:34:26 -0400</pubDate><guid>https://answers.axonivy.com/questions/1703/assign-and-revoke-role-to-session-user-dynamically/1704</guid></item></channel></rss>