Announcement Announcement Module
Collapse
No announcement yet.
AbstractContextSource throws a NullPointerException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AbstractContextSource throws a NullPointerException

    Hi all,

    I'm using Spring LDAP for securing a GWT web-app. Currently I'm trying to make an IBM developer work (available here: http://www.ibm.com/developerworks/java/library/j-saas/) compliant with Spring Security 3.0. I've changed the given JUnit Test in order to test my Spring module but I get the following exception.
    Code:
    java.lang.NullPointerException
    	at java.util.Hashtable.<init>(Unknown Source)
    	at org.springframework.ldap.core.support.AbstractContextSource.getAuthenticatedEnv(AbstractContextSource.java:480)
    	at org.springframework.ldap.core.support.AbstractContextSource.getContext(AbstractContextSource.java:106)
    	at org.springframework.security.ldap.authentication.BindAuthenticator.bindWithDn(BindAuthenticator.java:111)
    	at org.springframework.security.ldap.authentication.BindAuthenticator.authenticate(BindAuthenticator.java:91)
    	at org.springframework.security.ldap.authentication.LdapAuthenticationProvider.authenticate(LdapAuthenticationProvider.java:252)
    	at org.springframework.security.authentication.ProviderManager.doAuthentication(ProviderManager.java:120)
    	at org.springframework.security.authentication.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:48)
    	at org.springframework.security.authentication.ProviderManager.doAuthentication(ProviderManager.java:138)
    	at org.springframework.security.authentication.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:48)
    	at org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter.attemptAuthentication(UsernamePasswordAuthenticationFilter.java:97)
    	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
    	at org.springframework.mock.web.PassThroughFilterChain.doFilter(PassThroughFilterChain.java:78)
    	at security.web.filter.TenantSecurityContextFilter.doFilter(TenantSecurityContextFilter.java:95)
    	at security.test.MultiTenantAuthenticationTest.performUserAuthentication(MultiTenantAuthenticationTest.java:155)
    	at security.test.MultiTenantAuthenticationTest.assertGivenUserCredentialsAreValid(MultiTenantAuthenticationTest.java:106)
    	at security.test.MultiTenantAuthenticationTest.testMultiTenantAuthenticationWorksAsExpected(MultiTenantAuthenticationTest.java:88)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at junit.framework.TestCase.runTest(TestCase.java:164)
    	at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.runManaged(AbstractJUnit38SpringContextTests.java:334)
    	at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.access$0(AbstractJUnit38SpringContextTests.java:326)
    	at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests$1.run(AbstractJUnit38SpringContextTests.java:216)
    	at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.runTest(AbstractJUnit38SpringContextTests.java:296)
    	at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.runTestTimed(AbstractJUnit38SpringContextTests.java:253)
    	at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.runBare(AbstractJUnit38SpringContextTests.java:213)
    	at junit.framework.TestResult$1.protect(TestResult.java:106)
    	at junit.framework.TestResult.runProtected(TestResult.java:124)
    	at junit.framework.TestResult.run(TestResult.java:109)
    	at junit.framework.TestCase.run(TestCase.java:120)
    	at junit.framework.TestSuite.runTest(TestSuite.java:230)
    	at junit.framework.TestSuite.run(TestSuite.java:225)
    	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    I've attached a zip archive containing two directories:
    • src, containing the Java sources file
    • resources, containing the xml context configuration and the LDIF files for creating the partitions contexts and populanting the partitions.
    Could it be a bug or have I made some mistakes?
    Any suggestion is welcome!

    Regards,
    Salvatore

  • #2
    My first impression is that this is the same symptom as when you manually create a ContextSource and forget to call afterPropertiesSet.

    I just had a quick look, but it seems you override afterPropertiesSet in AbstractRoutingLdapSecurityContextSource. Perhaps you should call super.afterPropertiesSet?

    Comment


    • #3
      Thanks for your reply, Ulrik! Your hint was very helpful!
      The NullPointerException was thrown because an instance field of the class AbstractContextSource was not initialized. This initialization is performed during the execution of the method afterPropertiesSet() defined in AbstractContextSource.
      I cannot call it in my overriding method as I am defining a routing LDAP context source that holds a context set and I have to select one of them once the context holder has been set. Currently my - working - work-around is to ovveride the method getContext(String,String) that builds the missing instance field.

      Regards,

      Salvatore

      Comment


      • #4
        Thanks Salvatore for your replies. Can you please upload updated code. I am getting lot of exceptions after adding super.afterPropertiesSet().


        Shirish
        Originally posted by Turiddu View Post
        Thanks for your reply, Ulrik! Your hint was very helpful!
        The NullPointerException was thrown because an instance field of the class AbstractContextSource was not initialized. This initialization is performed during the execution of the method afterPropertiesSet() defined in AbstractContextSource.
        I cannot call it in my overriding method as I am defining a routing LDAP context source that holds a context set and I have to select one of them once the context holder has been set. Currently my - working - work-around is to ovveride the method getContext(String,String) that builds the missing instance field.

        Regards,

        Salvatore

        Comment

        Working...
        X