# forcing to use custom-attribute

frant
54 1

Hello again,

we're using custom-attributes in each zul to check wether the user has the permission (role) to use this page, like this:

<custom-attributes menuName="person.persons (login)"


Now I try to force the usage of this custom-attribute -
So everytime when I create a zul file (with some exceptions),
there has to be a custom-attribute with roles in it, otherwise there should be an error-message
given when I try to open the zul without declaring these custom attributes.
Or is there even a way to throw an error into console?

How and where could I do this? (security-config.xml?)

delete retag edit

## 3 Replies

frant
54 1

...help? anyone? :S

background-information:
Of course I could easily write in every zul-file simply the code from above with the respective roles etc.
But I am not the only one working on this project, and there are some functions that some people aren't allowed to see/execute.
If a devel forgot by accident to add these custom-attributes with roles, you know.. wouldn't be funny.

gganassin
540 6
http://www.hybris.com/

To achieve this, we used Spring Security.
So you can map each resource path to a list of roles and that's it.
http://books.zkoss.org/wiki/Small_Talks/2010/April/Making_Spring_Security_Work_with_ZK

if you can't adopt Spring Security, you can self implement something similiar with System-level Initiator following this:
http://books.zkoss.org/wiki/ZK_Developer's_Reference/UI_Patterns/Page_Initialization

Cheers
Giovanni

frant
54 1

We're using it as well... but I'm a newbie, so I didn't knew how to solve this :/ (practical semester,studying IT)
I found what I was looking for!
Since the custom attributes belongs to a window, I just needed to call a simple windowId.getAttribute() in the Controller for accessing these.
But this would have been too much work - I had to check it that way in EVERY controller!
And checking it in the superclasses would only work if the method in the superclass would be called as well..
phew, but I'm traversing now with a unit test in order to check the war file if it has been built correctly.

Thank you very, very much, gganassin!
Cheers :)

[hide preview]