Jump to content

Roles and permission


shalomd

Recommended Posts

Hello,

When I login to JasperServer with a certain user - how can pass the user role to the report so I can use this in the SQL.

Is there a way to perform something similar in order to show a user only the data they are allowed to see?

Example: if I login as Richard --> I can see only sales department, if I login as Tom --> I can see sales and production departments.

Thanks

Shalom

 

 

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

You can use roles and username in reports without domains, but you have some work to do.

 

In a report define the follwing parameters:

 

<!-- this is passed in automatically by JasperServer -->

  <parameter name="LoggedInUser" class="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/>

<!-- these are dependent parameters -->

  <parameter name="LoggedInUserRoles" class="java.util.Collection">

    <defaultValueExpression><![CDATA[$P{LoggedInUser}.getRoles()]]></defaultValueExpression>

  </parameter>

  <parameter name="LoggedInUserRolesAsStrings" class="java.util.Collection">

    <defaultValueExpression><![CDATA[convert $P{LoggedInUserRoles} to collection of strings - Gtroovy or Java Expression, or scriptlet method call]]></defaultValueExpression>

  </parameter>

 

<!-- use JasperReports $X to get the role name values into an IN clause -->

    <queryString>
        <![CDATA[select * from blah
where $X{IN, role_name, LoggedInUserRolesAsStrings} ]]>
    </queryString>


Sherman

Jaspersoft
 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...