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?

asked 06.08.2009 at 07:02

Benedict%20Groppe's gravatar image

Benedict Groppe
(suspended)
accept rate: 50%


You can use the PublicAPI to do so:

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);

If you want to check for the user that is currently logged in, it is even more simple:

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);
link

answered 10.08.2009 at 05:14

Christian%20Strebel's gravatar image

Christian St... ♦
3.2k31338
accept rate: 88%

If you want to use this as a BackingBean it has a slightly different syntax - maybe this helps someone...

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;
    }
}
link

answered 10.04.2014 at 12:38

Nikel%20Weis's gravatar image

Nikel Weis
(suspended)
accept rate: 57%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×40
×26

Asked: 06.08.2009 at 07:02

Seen: 5,690 times

Last updated: 10.04.2014 at 12:38