users@glassfish.java.net

Re: how to catch javax.security.auth.login.LoginException ?

From: Kumar Jayanti <Vbkumar.Jayanti_at_Sun.COM>
Date: Mon, 21 Jun 2010 14:12:14 +0530

Dominik Dorn wrote:
> Hi,
>
> I have a servlet filter doing authentication for my webapp.
>
> basically I'm doing the following
>
> public void doFilter(ServletRequest servletRequest,
> ServletResponse servletResponse, FilterChain filterChain) throws
> IOException, ServletException {
> ...
> if (
> servletRequest.getParameter("doLogin") != null &&
> servletRequest.getParameter("username") != null &&
> servletRequest.getParameter("password") != null
> ) {
> String username = (String)
> servletRequest.getParameter("username");
> String password = (String)
> servletRequest.getParameter("password");
>
> /**
> * Clearing the parameter map
> */
>
> try {
> ((HttpServletRequest)
> servletRequest).login(username, password);
>
> ....
> }
> catch(ServletException se)
> {
> ((HttpServletResponse)
> servletResponse).sendRedirect(((HttpServletRequest)
> servletRequest).getRequestURI() + "?setLoggedIn=false");
> }
> catch (Exception e) {
> e.printStackTrace();
> ((HttpServletResponse)
> servletResponse).sendRedirect(((HttpServletRequest)
> servletRequest).getRequestURI() + "?setLoginError=true");
> }
> }
>
> however, I cannot distinguish if the ServletException is from the
> login or from something else, as se.getCause() and se.getRootCause()
> always point to itself... so I never get the
> javax.security.auth.login.LoginException that is thrown somewhere and
> I'm unable to distinguish if an exception got thrown because the
> credentials are
> wrong or because something other threw a servlet exception.
>
> in the server logs the following message is written:
> [#|2010-06-15T14:52:39.276+0200|WARNING|glassfish3.0|javax.enterprise.system.container.web.com.sun.web.security|_ThreadID=25;_ThreadName=http-thread-pool-8080-(2);|Web
> login failed: Login failed: javax.security.auth.login.LoginException:
> Security Exception|#]
>
>
> how can I catch that one?
>
>
We will check if there is some issue here and get back soon.

regards,
kumar

> thanks,
> dominik
> --
> Dominik Dorn
> http://dominikdorn.com
>
> Tausche Deine Lernunterlagen auf http://www.studyguru.eu !
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>
>