0

ZK and Spring Secutiry, how could I verify if the user has the necessary role from a zul file?

asked 2009-07-03 17:38:51 +0800

fmcypriano gravatar image fmcypriano
612 1 7
http://felipecypriano.com...

Hello,

I'd like to know if is there a way to verify if the user has the necessary roles from a zul file? Just like the spring security plugin for Grails: http://www.grails.org/AcegiSecurity+Plugin+-+Artifacts

It would be nice to do something like this:
<security:ifAllGranted role="ROLE_ADMIN,ROLE_SUPERVISOR">
<button label="Special Button"/>
</security:ifAllGranted>

If those tags doesn't exists, how do you do this kind of authorization? Hide parts of the page that the user doesn't have access.

Regards,
Felipe Cypriano

delete flag offensive retag edit

6 Replies

Sort by ยป oldest newest

answered 2009-07-03 18:49:53 +0800

deved gravatar image deved
114 1

Hi Felipe,
You can use the "if" or the "unless" attributes.

<button label="Special Button" if="${role==ROLE_ADMIN}"/>


Regards,

edgar

link publish delete flag offensive edit

answered 2009-07-03 21:05:45 +0800

madruga0315 gravatar image madruga0315 flag of Brazil
937 2 12

you could register a xel method which calls the method ifAllGranted on the taglib, then use if and unless as pointed by edgar

link publish delete flag offensive edit

answered 2009-07-06 11:41:17 +0800

fmcypriano gravatar image fmcypriano
612 1 7
http://felipecypriano.com...

What is a xel method and how could I register it?

Regards,
Felipe Cypriano

link publish delete flag offensive edit

answered 2009-07-06 12:16:25 +0800

deved gravatar image deved
114 1

Check it here:
http://www.zkoss.org/doc/devref/ch02s02s11.html

link publish delete flag offensive edit

answered 2009-07-06 18:24:58 +0800

fmcypriano gravatar image fmcypriano
612 1 7
http://felipecypriano.com...

Thank you Edgar and madruga.

link publish delete flag offensive edit

answered 2009-07-15 16:51:35 +0800

nicodom gravatar image nicodom
3
http://www.geniusbytes.co...

updated 2009-07-15 16:53:03 +0800

Register this xel method:
<?xel-method prefix="sec" name="userHasAuthority" class="org.springframework.security.util.AuthorityUtils" signature="boolean userHasAuthority(java.lang.String)"?>

Then if you need to show a button only to a certain role, you can use it as following:
<zul:button label="EDIT" if="${sec:userHasAuthority('ROLE_SUPERVISOR')}"/>

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-07-03 17:38:51 +0800

Seen: 379 times

Last updated: Jul 15 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More