Link to home
Start Free TrialLog in
Avatar of angel7170
angel7170Flag for United States of America

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
Avatar of girionis
girionis
Flag of Greece image

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.
Avatar of angel7170

ASKER

Thanks. Is it possible to do something like below using javascript.
<script>
    var isAdmin = conf.isAdmin();
    if ((isAdmin === null) || !isAdmin) {
                result.put("reason", "Permission Denied");
                throw new UserServletException();
            }
    </script>

Open in new window


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;
    }

Open in new window

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
Thanks. Not sure how to do this on server side. could you please help?
ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial