angel7170
asked on
Redirect users to index.jsp if they have no access to it.
Hi,
I have an admin.JSP file that I would like to prevent users from accessing in URL directly. Only the admins who has privilege need to access it. If in case they hit that page, I am thinking to redirect them to index.jsp. How can I do that? Please help
I have an admin.JSP file that I would like to prevent users from accessing in URL directly. Only the admins who has privilege need to access it. If in case they hit that page, I am thinking to redirect them to index.jsp. How can I do that? Please help
You need an application server like Tomcat. You can use an in-memory realm to hold your users.Then you need to configure the relevant resources in your web.xml file. And finally you need to write the login.jsp and the index.jsp files. For a step by step guide have a look here.
ASKER
Thanks. Is it possible to do something like below using javascript.
I have a configuration.java file basically returns a boolean value if the user logs in is an admin or not. I am trying to take this value an throw an error for regular users if they are not admins. Here is the function return to check if the user is an admin or not
<script>
var isAdmin = conf.isAdmin();
if ((isAdmin === null) || !isAdmin) {
result.put("reason", "Permission Denied");
throw new UserServletException();
}
</script>
I have a configuration.java file basically returns a boolean value if the user logs in is an admin or not. I am trying to take this value an throw an error for regular users if they are not admins. Here is the function return to check if the user is an admin or not
public boolean isAdmin() {
boolean hasRole = false;
try {
Subject sbj = SecurityUtils.getSubject();
String adminRole = Props.getProperty(ROLE_KEY);
hasRole = sbj.hasRole(adminRole);
} catch (Throwable t) {
log.error(t.getMessage(), t);
}
return hasRole;
}
Thanks. Is it possible to do something like below using javascript.this is not a task for JavaScript.
you must do this test on server side
ASKER
Thanks. Not sure how to do this on server side. could you please help?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.