<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Does a user have a specific role?</title><link>https://answers.axonivy.com/questions/293/does-a-user-have-a-specific-role</link><description>&lt;p&gt;I need some insights in the role system of Ivy. I currently check whether a user does have a role by checking whether the current user does have a role with the ID of that role I am interested in. One problem is that I have to hard code the ID's, another problem that the ID's are hard to retrieve and they are different on Designer and Server. Is there a more simple way to find out whether a specific user does have a specific role?&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/293/does-a-user-have-a-specific-role" rel="self"></atom:link><language>en</language><lastBuildDate>Thu, 10 Apr 2014 12:38:03 -0400</lastBuildDate><item><title>Answer by Nikel Weis</title><link>https://answers.axonivy.com/questions/293/does-a-user-have-a-specific-role/624</link><description>&lt;p&gt;If you want to use this as a BackingBean it has a slightly different syntax - maybe this helps someone...&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import ch.ivyteam.ivy.security.IRole;
import ch.ivyteam.ivy.environment.Ivy;

@ManagedBean(name = "roleCheckerBean")
@RequestScoped

public class RoleCheckerBean {
    public Boolean isUserSalesPerson() {

        IRole sales = Ivy.request().getApplication().getSecurityContext().findRole("sales");
        boolean sessionUserHasSalesRole = Ivy.session().hasRole(sales, false);

        return sessionUserHasSalesRole;
    }
}
&lt;/code&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Nikel Weis</dc:creator><pubDate>Thu, 10 Apr 2014 12:38:03 -0400</pubDate><guid>https://answers.axonivy.com/questions/293/does-a-user-have-a-specific-role/624</guid></item><item><title>Answer by Christian Strebel</title><link>https://answers.axonivy.com/questions/293/does-a-user-have-a-specific-role/294</link><description>&lt;p&gt;You can use the PublicAPI to do so: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import ch.ivyteam.ivy.security.IRole;
import ch.ivyteam.ivy.security.IUser;

IRole myRole = ivy.request.getApplication().getSecurityContext().findRole("My Role");
IUser myUser = ivy.request.getApplication().getSecurityContext().findUser("My User");

boolean myUserHasMyRole = myUser.getUserToken().hasRole(myRole, false);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you want to check for the user that is currently logged in, it is even more simple: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import ch.ivyteam.ivy.security.IRole;
import ch.ivyteam.ivy.security.IUser;

IRole myRole = ivy.request.getApplication().getSecurityContext().findRole("My Role");
boolean sessionUserHasMyRole = ivy.session.hasRole(myRole, false);
&lt;/code&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Christian Strebel</dc:creator><pubDate>Mon, 10 Aug 2009 05:14:01 -0400</pubDate><guid>https://answers.axonivy.com/questions/293/does-a-user-have-a-specific-role/294</guid></item></channel></rss>