security - How does the web container know about the role of the user -
i new web-app development , security , trying understand things around.
everywhere implementing security in webapp ask use declarative
security. example in tomcat can declare roles in tomcat-user.xml
file following one.
<tomcat-users> <user name="tomcat" password="s3cret" roles="manager-gui" /> </tomcat-users>
this part can understand.
now suppose have added of these roles in web-app. user of web-app makes request resource in web-app. want know how container or i know with role user has made request?
thank you.
using tomcat , jsp:
a datasourcerealm can point database containing user , user role tables, using userdatabaserealm (points tomcat-users.xml) works fine well.
if want protect jsp pages in specific folder, add web.xml
<security-constraint> <web-resource-collection> <web-resource-name>folder description</web-resource-name> <url-pattern>/foldername/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>role_admin</role-name> </auth-constraint> </security-constraint>
if want know if user has specific role upon entering page, can use
boolean hasadminrole = request.isuserinrole("role_admin");
Comments
Post a Comment