I have tried to use security-constraint in web.xml. I gave permission to admin by using role. How to test whether the servlet is secured and be able to access only by the admin?
I have tried to use security-constraint in web.xml. I gave permission to admin by
Share
To test the servlet, you need at least two Google Accounts. One Google Account must be added as at least a Viewer on your Google App Engine Admin Console, the other Google Account must not be added. The Google Account that is not added in the Admin console should not be able to access any servlet where the role is defined as admin.
If for some reason the tests fail, you need to make sure you’ve followed all the steps in the documentation to secure the servlet and implement an authentication schema. Below outlines using Google OAuth and the UserService as an example.
Out of the box, Google App Engine gives you two roles to use within your application: User and Admin.
Admin users are defined as any user that is listed as any one of the three roles on the Google App Engine project, so if you want to grant someone admin access to your servlet, you could add them as a Viewer in the http://appengine.google.com panel.
The UserService class gives you access to the logged in user. You would need to use this to create a login URL for your user, log them in through Google using his or her Google account, redirect him or her to your application, and then use
UserService.isUserAdmin()to determine if that user is indeed an admin user.Using the Users Service describes in detail how to get started using the UserService class.
The Google App Engine Users Java API Overview demonstrates how to handle logging in users on Google App Engine:
Securing the Servlet:
The Deployment Descriptor: Security and Authentication page demonstrates how to modify your web.xml so that only admins can access certain servlets.
In this example, the servlet
/profileis accessible by users with any role, indicated by*, and the/adminservlet is only accessible by users with the roleadmin.While Google App Engine Java does have built-in security, the roles are somewhat limited. If you need finer grain control over the roles of your users, see Luke Taylor’s Post on Spring Security in Google App Engine. The example is old, but if you turn your logging level up to TRACE, you can make it work on the latest versions of Spring and the latest GAE SDK.