This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Spring and the fly likes [Spring Security] Restrict access to fields in a page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "[Spring Security] Restrict access to fields in a page" Watch "[Spring Security] Restrict access to fields in a page" New topic
Author

[Spring Security] Restrict access to fields in a page

Celinio Fernandes
Ranch Hand

Joined: Jun 28, 2003
Posts: 547

Hi,
here is a quick question from someone who knows Spring core but has not played much with Spring Security.
I am wondering about the possibilities offered by the framework.

I guess Spring Security allows to restrict access to methods, objects and so on in the business layer.
What about fields in pages in the presentation layer ?

If for instance i have a JSP page with 3 fields (field1, field2, field3).
I want user1 with role1 to be able to fill all fields.
I want user2 with role2 to be able to fill field1 and field2 only. So field3 must be read-only or disabled.

Does Spring Security offer some options/features for that ?

Thanks for helping.


SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCBCD 5
Visit my blog
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Hey,

Have you checked out the Spring Security tag library? Using the <authorize/> tag you should be able to do something like you are wanting.

Sean


I love this place!
Celinio Fernandes
Ranch Hand

Joined: Jun 28, 2003
Posts: 547

OK, thanks.
So i can use the <authorize /> to decide whether to display or not display a field, a block of code etc... if the user does not have the required role/profile.

What if i still want to display the fields and just want to make them read-only, non editable... ?
What's the recommended way to do that ?

Thanks.
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Hey,

I'm not sure what the recommended way to do it is, you could use the tags to say if priv1 do this if not priv1 do that or something similar. You do end up duplicating code though. You could also create your own tags with this logic security logic.

Sean
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: [Spring Security] Restrict access to fields in a page