7 Replies Latest reply on Oct 18, 2007 12:33 AM by Shane Bryzak

    NPE in SeamSecurity (getCookieValue(Selector.java:59))

    Mariusz Smykula Newbie

      I have simple test:

      new FacesRequest() {
      
       @Override
       protected void updateModelValues() throws Exception {
       setValue("#{identity.username}", "admin");
       setValue("#{identity.password}", "admin");
       }
      
       @Override
       protected void invokeApplication() {
       invokeMethod("#{identity.login}");
       }
      
       @Override
       protected void renderResponse() {
      
      assert getValue("#{identity.loggedIn}").equals(true); }
      
       }.run();



      FAILED: testUserLogin
      java.lang.NullPointerException
       at org.jboss.seam.core.Selector.getCookieValue(Selector.java:59)
       at org.jboss.seam.security.Identity.initCredentialsFromCookie(Identity.java:91)
       at org.jboss.seam.security.Identity.create(Identity.java:85)
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
       at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:102)
       at org.jboss.seam.Component.callComponentMethod(Component.java:1835)
       at org.jboss.seam.Component.callCreateMethod(Component.java:1783)
       at org.jboss.seam.Component.newInstance(Component.java:1772)
       at org.jboss.seam.Component.getInstance(Component.java:1669)
       at org.jboss.seam.Component.getInstance(Component.java:1636)
       at org.jboss.seam.Namespace.get(Namespace.java:42)
       at javax.el.MapELResolver.getValue(MapELResolver.java:157)
       at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:135)
       at com.sun.el.parser.AstValue.getValue(AstValue.java:117)
       at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:192)
       at org.jboss.seam.util.UnifiedELValueBinding.getValue(UnifiedELValueBinding.java:34)
       at org.jboss.seam.core.Expressions$1.getValue(Expressions.java:53)
       at org.jboss.seam.Component.getInstanceFromFactory(Component.java:1710)
       at org.jboss.seam.Component.getInstance(Component.java:1659)
       at org.jboss.seam.Component.getInstance(Component.java:1636)
       at org.jboss.seam.Component.getInstance(Component.java:1630)
       at org.jboss.seam.mock.SeamTest.getInstance(SeamTest.java:112)
       at pl.alternativ.med.admin.LoginTest.access$1(LoginTest.java:1)
       at pl.alternativ.med.admin.LoginTest$5.invokeApplication(LoginTest.java:95)
       at org.jboss.seam.mock.SeamTest$Request.run(SeamTest.java:478)
       at pl.alternativ.med.admin.LoginTest.testUserLogin(LoginTest.java:99)
      ... Removed 25 stack frames


      What is wrong with my test?

        • 1. Re: NPE in SeamSecurity (getCookieValue(Selector.java:59))
          Matt Drees Master

          I'm pretty sure it's because MockExternalContext doesn't handle cookies. I submitted a patch to enable it to do so.

          http://jira.jboss.com/jira/browse/JBSEAM-795

          • 3. Re: NPE in SeamSecurity (getCookieValue(Selector.java:59))
            Mariusz Smykula Newbie

            This is not working in CVS now:

            FAILED: testLogin
            java.lang.NullPointerException
            at org.jboss.seam.mock.MockExternalContext.getRequestCookieMap(MockExternalContext.java:181)
            at org.jboss.seam.core.Selector.getCookieValue(Selector.java:59)
            at org.jboss.seam.security.Identity.initCredentialsFromCookie(Identity.java:91)
            at org.jboss.seam.security.Identity.create(Identity.java:85)
            at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
            at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:102)
            at org.jboss.seam.Component.callComponentMethod(Component.java:1835)
            at org.jboss.seam.Component.callCreateMethod(Component.java:1783)
            at org.jboss.seam.Component.newInstance(Component.java:1772)
            at org.jboss.seam.Component.getInstance(Component.java:1669)
            at org.jboss.seam.Component.getInstance(Component.java:1636)
            at org.jboss.seam.Namespace.get(Namespace.java:42)
            at javax.el.MapELResolver.getValue(MapELResolver.java:157)
            at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:135)
            at com.sun.el.parser.AstValue.getValue(AstValue.java:117)
            at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:192)
            at org.jboss.seam.util.UnifiedELValueBinding.getValue(UnifiedELValueBinding.java:34)
            at org.jboss.seam.core.Expressions$1.getValue(Expressions.java:53)
            at org.jboss.seam.Component.getInstanceFromFactory(Component.java:1710)
            at org.jboss.seam.Component.getInstance(Component.java:1659)
            at org.jboss.seam.Component.getInstance(Component.java:1636)
            at org.jboss.seam.Component.getInstance(Component.java:1630)
            at org.jboss.seam.mock.SeamTest.getInstance(SeamTest.java:115)
            at my.admin.LoginTest.access$1(LoginTest.java:1)
            at my.admin.LoginTest$1.invokeApplication(LoginTest.java:17)
            at org.jboss.seam.mock.SeamTest$Request.run(SeamTest.java:486)
            at my.admin.LoginTest.testLogin(LoginTest.java:21)
            ... Removed 25 stack frames


            Jira: http://jira.jboss.com/jira/browse/JBSEAM-820

            • 5. Re: NPE in SeamSecurity (getCookieValue(Selector.java:59))
              Alexander Merk Newbie

              We are using Seam 1.2.1 GA and we can't switch to Seam 2.0 in our project and we have a similar problem.
              The stacktrace of an "normal" (none JSF-Request) request with the Seam Context Filter:

              2007-09-24 08:05:26,776 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/locmgmt]] Session event listener threw exception
              java.lang.NullPointerException
              at org.jboss.seam.mock.MockExternalContext.getRequestCookieMap(MockExternalContext.java:184)
              at org.jboss.seam.core.Selector.getCookie(Selector.java:61)
              at org.jboss.seam.core.Selector.getCookieValue(Selector.java:72)
              at org.jboss.seam.security.Identity.initCredentialsFromCookie(Identity.java:88)
              at org.jboss.seam.security.Identity.create(Identity.java:83)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:585)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:20)
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:123)
              at org.jboss.seam.Component.callComponentMethod(Component.java:1834)
              at org.jboss.seam.Component.callCreateMethod(Component.java:1757)
              at org.jboss.seam.Component.newInstance(Component.java:1746)
              at org.jboss.seam.contexts.Lifecycle.startup(Lifecycle.java:175)
              at org.jboss.seam.contexts.Lifecycle.beginSession(Lifecycle.java:235)
              at org.jboss.seam.servlet.SeamListener.sessionCreated(SeamListener.java:41)
              at org.apache.catalina.session.StandardSession.tellNew(StandardSession.java:384)
              at org.apache.catalina.session.StandardSession.setId(StandardSession.java:356)
              at org.apache.catalina.session.ManagerBase.createSession(ManagerBase.java:824)
              at org.apache.catalina.session.StandardManager.createSession(StandardManager.java:290)
              at org.apache.catalina.connector.Request.doGetSession(Request.java:2225)
              at org.apache.catalina.connector.Request.getSession(Request.java:2024)
              at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:831)
              at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:215)
              at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:215)
              at org.jboss.seam.web.ContextFilter.doFilter(ContextFilter.java:47)
              at com.agcs.locmgmt.web.seam.TransactionalSeamServletFilter.doFilter(TransactionalSeamServletFilter.java:70)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
              at com.planetj.servlet.filter.compression.CompressingFilter.doFilter(CompressingFilter.java:217)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
              at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:57)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
              at com.agcs.locmgmt.web.seam.CookieMapServletFilter.doFilter(CookieMapServletFilter.java:55)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
              at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
              at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
              at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
              at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
              at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
              at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)
              at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)
              at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
              at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
              at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
              at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
              at java.lang.Thread.run(Thread.java:595)

              I don't understand why the selector using the MockupExternalContext. The Mockup Object is only created on the ExceptionFilter in the "endWebRequestAfterException" method.

              • 6. Re: NPE in SeamSecurity (getCookieValue(Selector.java:59))
                Alexander Merk Newbie

                I found a Bug in Seam and It's not fixed in the Version 2. If the MockFacesContext was created by the ExceptionFilter in the "endWebRequestAfterException" method this faces context is still there after the call FacesContext.getCurrentInstance().release(). If another WebApplication gets this "unclean" thread and ask for a FacesContext he gets the wrong context and the application may crash.
                Please implement in the MockFacesContext the release method as follow:

                @Override
                public void release() {
                setCurrentInstance(null);
                }

                Thanks

                Alex

                • 7. Re: NPE in SeamSecurity (getCookieValue(Selector.java:59))
                  Shane Bryzak Master

                  I've fixed this in CVS, thanks for pointing it out.