Re: Denying access to a JSP page directly



On Oct 3, 3:27 am, Sameer <dolph...@xxxxxxxxx> wrote:
Dear All,
My login page is index.html.
It accepts username/password there.
Validates it using validate.jsp and redirect it to main.jsp for
further processing.
But i noted that without using index.html, one can go directly to
main.jsp using address bar.
To avoid this i have done this.
I have added this code to validate.jsp

{
%>
<jsp:forward page="main.jsp">
<jsp:param name="security" value="secured" />
</jsp:forward>
<%
response.sendRedirect("main.jsp");}

%>

As the validate.jsp do not submit any form i have to use the forward
tag.
Now i check this at the start of main.jsp.
<%
try {
String is_secure = request.getParameter("security");}

catch (NullPointerException npe)
{
response.sendRedirect("secure.html");}

%>

If the user directly goes to main.jsp then this code will throw the
NullPointerException.
The code throws the exception (as seen on the console) but it do not
redirect it to secure.html.
Why this may be?
Is this the right approach? Any suggestions?

Thanks in advance.

This is often achieved via a Servlet Filter. Add a filter, and check
for a session variable and/or a cookie that indicates a successful
auth. If no auth, redirect the user to login page, if auth'd, let him
pass. I am sure you'd find a lot of examples by Googling around on
usage of Servlet Filters to check authentication.

-cheers,
Manish

.



Relevant Pages

  • Re: Default.aspx - newbie Q`
    ... > If you have the AUTH setup in the web.config to not allow access to this ... > page it should redirect to the login page specified in the web.config. ... > proper authentication have it redirect back to the URL specified in the ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Default.aspx - newbie Q`
    ... > If you have the AUTH setup in the web.config to not allow access to this ... > page it should redirect to the login page specified in the web.config. ... > proper authentication have it redirect back to the URL specified in the ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Default.aspx - newbie Q`
    ... check and redirect to the ReturnURL or Selected.aspx depending on the case. ... > and replace it with something that takes then straight to the login page. ... >> Curt Christianson ... >>> authentication ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Default.aspx - newbie Q`
    ... check and redirect to the ReturnURL or Selected.aspx depending on the case. ... > and replace it with something that takes then straight to the login page. ... >> Curt Christianson ... >>> authentication ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: doesnt redirect
    ... Look under the Security tab. ... One of them is called the Internet zone and probably the one you are using. ... or better explain what you mean by>> redirect ... I think there are 2 interstitchal pages after submitting those login credentials before you get to the mailbox web page. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)