Announcement Announcement Module
Collapse
No announcement yet.
generateNewContext throws NullPointerException Page Title Module
Move Remove Collapse
This topic is closed
X
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • generateNewContext throws NullPointerException

    Hi everyone,

    I have been trying to figure out how to get a simple example to work using Tapestry + Spring + Acegi + Hibernate. I have been following the hispacta example, searching this forum, and trying to understand the changes that have been made with the latest version (0.8.2).

    All I am trying to do is to authenciate a user from the database (via Hibernate). Nothing fancy or extra.

    Using Acegi 0.8.2 and Spring 1.2.1, however, I got a NullPointerException when the HttpSessionContextIntegrationFilter.generateNewCon text() method call when I tried to bring up the Home page (the very first page of the app).

    My app server is JBoss 4.0.1sp1.

    Code:
    21:38:52,735 DEBUG [HttpSessionContextIntegrationFilter] No HttpSession currently exists
    21:38:52,735 ERROR [Engine] StandardWrapperValve[core]: Servlet.service() for servlet core threw exception
    java.lang.NullPointerException
            at net.sf.acegisecurity.context.HttpSessionContextIntegrationFilter.generateNewContext(HttpSessionContextIntegrationFilter.
            at net.sf.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:210)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
            at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
            at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
            at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:66)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
            at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:150)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
            at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:54)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
            at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
            at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
            at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
            at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
            at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
            at java.lang.Thread.run(Thread.java:595)
    Below is my web.xml and spring configuration file.

    Code:
    <web-app>
       <display-name>Core Web Application</display-name>
    
       <context-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>
             /WEB-INF/classes/applicationContext.xml
          </param-value>
       </context-param> 
        
    
       <filter>
          <filter-name>Acegi HTTP Session Context Integration Filter</filter-name>
          <filter-class>net.sf.acegisecurity.context.HttpSessionContextIntegrationFilter</filter-class>
       </filter>
    
       <filter>
          <filter-name>Acegi Authentication Processing Filter</filter-name>
          <filter-class>net.sf.acegisecurity.util.FilterToBeanProxy</filter-class>
          <init-param>
             <param-name>targetClass</param-name>
             <param-value>net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilter</param-value>
          </init-param>
       </filter>
          
       <filter-mapping>
          <filter-name>Acegi HTTP Session Context Integration Filter</filter-name>
          <url-pattern>/*</url-pattern>
       </filter-mapping>
    
       <filter-mapping>
          <filter-name>Acegi Authentication Processing Filter</filter-name>
          <url-pattern>/*</url-pattern>
       </filter-mapping>   
       
       <listener>
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
       </listener>   
            
    
       <servlet>
          <servlet-name>core</servlet-name>
          <servlet-class>org.apache.tapestry.ApplicationServlet</servlet-class>
          <load-on-startup>0</load-on-startup>
       </servlet>
    
    
       <servlet-mapping>
          <servlet-name>core</servlet-name>
          <url-pattern>/app</url-pattern>
       </servlet-mapping>
    
    
       <session-config>
          <session-timeout>15</session-timeout>
       </session-config>
    
       <welcome-file-list>
          <welcome-file>index.html</welcome-file>
       </welcome-file-list>
    </web-app>
    and my acegi related configuration:

    Code:
    <beans>
       
       <bean id="authenticationManager" class="net.sf.acegisecurity.providers.ProviderManager">
          <property name="providers">
             <list>
                <ref bean="daoAuthenticationProvider"/>
             </list>
          </property>
       </bean>
       
       <bean id="daoAuthenticationProvider" class="net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider">
          <property name="authenticationDao"><ref bean="gemExUserDao"/></property>
          <property name="passwordEncoder"><ref bean="passwordEncoder"/></property>
       </bean>
          
       <bean id="passwordEncoder" class="net.sf.acegisecurity.providers.encoding.Md5PasswordEncoder">      
       </bean>
       
       <bean id="authenticationProcessingFilter" class="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilter">
          <property name="authenticationManager"><ref bean="authenticationManager"/></property>
          <property name="authenticationFailureUrl"><value>/app?service=page/Login</value></property>
          <property name="defaultTargetUrl"><value>/app</value></property>
          <property name="filterProcessesUrl"><value>/j_acegi_security_check</value></property>
       </bean>
       
       <bean id="httpSessionContextIntegrationFilter" class="net.sf.acegisecurity.context.HttpSessionContextIntegrationFilter" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default">
          <property name="context">
             <value>net.sf.acegisecurity.context.security.SecureContextImpl</value> 
          </property>
       </bean>
              
    </beans>
    Am I missing anything in particular? Any pointers will be greatly appreciated.

    Thanks,
    Ben

  • #2
    What line of HttpSessionContextIntegrationFilter is throwing the exception? Also, are you trying to use JBoss container adapters or the recommended filters-based approach? Have you got an old version of Acegi Security somewhere in the JBoss classloader? Are you using the official 0.8.2 release, or a separately compiled version?

    Comment


    • #3
      Hi Alex,

      I didn't think anyone would replied to my post after 8 days!! I really appreciate your efforts. I initially was trying to have only the minimum setup working (e.g. only a simple authentication without all the other stuff). Since I didn't get any help, I decide to add more to the setup scouring the net for examples and stuff. After a few tries, I finally got it working. Basically, this is now my configuration (in case people are interested):

      As a newcomer, I like to say that the documentation needs some serious work. I had a very hard time figuring out what I need to do to get a basic setup going. I understand this is open source and the work of volunteers, so please understand I am in no way complaining. Just giving some feedback...

      Code:
      <beans>
         
         <bean id="authenticationManager" class="net.sf.acegisecurity.providers.ProviderManager">
            <property name="providers">
               <list>
                  <ref bean="daoAuthenticationProvider"/>
                  <ref local="anonymousAuthenticationProvider"/>
               </list>
            </property>
         </bean>
         
         <bean id="daoAuthenticationProvider" class="net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider">
            <property name="authenticationDao"><ref bean="gemExUserDao"/></property>
            <!-- <property name="passwordEncoder"><ref bean="passwordEncoder"/></property> -->
         </bean>
                  
         <bean id="passwordEncoder" class="net.sf.acegisecurity.providers.encoding.Md5PasswordEncoder">      
         </bean>
         
         <bean id="anonymousAuthenticationProvider" class="net.sf.acegisecurity.providers.anonymous.AnonymousAuthenticationProvider">
            <property name="key"><value>foobar</value></property>
         </bean>
            
         <bean id="filterChainProxy" class="net.sf.acegisecurity.util.FilterChainProxy">
            <property name="filterInvocationDefinitionSource">
               <value>
      		      CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
      		      PATTERN_TYPE_APACHE_ANT
                  /**=httpSessionContextIntegrationFilter,authenticationProcessingFilter,anonymousProcessingFilter,securityEnforcementFilter
               </value>
            </property>
         </bean>
         
         <bean id="httpSessionContextIntegrationFilter" class="net.sf.acegisecurity.context.HttpSessionContextIntegrationFilter" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default">
            <property name="context">
               <value>net.sf.acegisecurity.context.security.SecureContextImpl</value> 
            </property>
         </bean>
                
         <bean id="authenticationProcessingFilter" class="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilter">
            <property name="authenticationManager"><ref bean="authenticationManager"/></property>
            <property name="authenticationFailureUrl"><value>/app?service=page/Login</value></property>
            <property name="defaultTargetUrl"><value>/app?service=page/Home</value></property>
            <property name="alwaysUseDefaultTargetUrl"><value>false</value></property>
            <property name="filterProcessesUrl"><value>/j_acegi_security_check</value></property>
         </bean>
            
         <bean id="anonymousProcessingFilter" class="net.sf.acegisecurity.providers.anonymous.AnonymousProcessingFilter">
            <property name="key"><value>foobar</value></property>
            <property name="userAttribute"><value>anonymousUser,ROLE_ANONYMOUS</value></property>
         </bean>
                  
         <bean id="securityEnforcementFilter" class="net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter">
            <property name="filterSecurityInterceptor"><ref local="filterInvocationInterceptor"/></property>
            <property name="authenticationEntryPoint"><ref local="authenticationProcessingFilterEntryPoint"/></property>
         </bean>
         
         <bean id="authenticationProcessingFilterEntryPoint" class="net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint">
            <property name="loginFormUrl"><value>/app?service=page/Login</value></property>
            <property name="forceHttps"><value>false</value></property>
         </bean>
         
         <bean id="filterInvocationInterceptor" class="net.sf.acegisecurity.intercept.web.FilterSecurityInterceptor">
            <property name="authenticationManager"><ref bean="authenticationManager"/></property>
            <property name="accessDecisionManager"><ref local="httpRequestAccessDecisionManager"/></property>
            <property name="objectDefinitionSource">
               <value>
      	         CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
      		      PATTERN_TYPE_APACHE_ANT
                  /app=ROLE_ANONYMOUS,ROLE_USER
      		      /app?service?page/home=ROLE_ANONYMOUS,ROLE_USER
      		      /app?service?page/login=ROLE_ANONYMOUS
      		      /app**=ROLE_USER
                  /**=ROLE_ANONYMOUS,ROLE_USER
               </value>
            </property>
         </bean>      
         
         <bean id="httpRequestAccessDecisionManager" class="net.sf.acegisecurity.vote.AffirmativeBased">
            <property name="allowIfAllAbstainDecisions"><value>false</value></property>
            <property name="decisionVoters">
               <list>
                  <ref bean="roleVoter"/>
               </list>
            </property>
         </bean>   
         
         <bean id="roleVoter" class="net.sf.acegisecurity.vote.RoleVoter"/>        
         
      </beans>

      Comment

      Working...
      X