java - NullPointerException at org.springframework.security.web.FilterChainProxy.getFilters -


i tried use spring-security, , error.

java.lang.nullpointerexception @ org.springframework.security.web.filterchainproxy.getfilters(filterchainproxy.java:223) @ org.springframework.security.web.filterchainproxy.dofilterinternal(filterchainproxy.java:196) @ org.springframework.security.web.filterchainproxy.dofilter(filterchainproxy.java:176) @ org.springframework.web.filter.delegatingfilterproxy.invokedelegate(delegatingfilterproxy.java:344) @ org.springframework.web.filter.delegatingfilterproxy.dofilter(delegatingfilterproxy.java:261) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.springframework.web.filter.characterencodingfilter.dofilterinternal(characterencodingfilter.java:88) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:220) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:122) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:504) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:170) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:103) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:950) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:116) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:421) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1074) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:611) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:314) @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(unknown source) 

i include filter in web.xml

 <?xml version="1.0" encoding="utf-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"          xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"          xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"          version="3.1">  <listener>     <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener>  <filter>     <filter-name>encoding-filter</filter-name>     <filter-class>         org.springframework.web.filter.characterencodingfilter     </filter-class>     <init-param>         <param-name>encoding</param-name>         <param-value>utf-8</param-value>     </init-param>     <init-param>     <param-name>forceencoding</param-name>     <param-value>true</param-value>     </init-param> </filter>  <filter-mapping>     <filter-name>encoding-filter</filter-name>     <url-pattern>/*</url-pattern> </filter-mapping>    <filter>     <filter-name>springsecurityfilterchain</filter-name>     <filter-class>org.springframework.web.filter.delegatingfilterproxy</filter-class> </filter>  <filter-mapping>     <filter-name>springsecurityfilterchain</filter-name>     <url-pattern>/*</url-pattern> </filter-mapping>  <welcome-file-list>     <welcome-file>index.jsp</welcome-file> </welcome-file-list>  <display-name>spring mvc application</display-name>  <context-param>     <param-name>contextconfiglocation</param-name>     <param-value>classpath:applicationcontext.xml</param-value> </context-param>  <servlet>     <servlet-name>mvc-dispatcher</servlet-name>     <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class>     <load-on-startup>0</load-on-startup> </servlet>  <servlet-mapping>     <servlet-name>mvc-dispatcher</servlet-name>     <url-pattern>/</url-pattern> </servlet-mapping> 

and create bean filter in applicationcontext file:

<bean id="springsecurityfilterchain" class="org.springframework.security.web.filterchainproxy"> </bean> 

before register bean in applicationcontext file have error no bean named 'springsecurityfilterchain' defined

i don't use spring-security.xml configuration, , configure security in securityconfig class.

public class securityconfig extends websecurityconfigureradapter {  @autowired private userdetailsserviceimpl userdetailsservice;  @autowired public void registerglobalauthentication(authenticationmanagerbuilder auth) throws exception {     auth             .userdetailsservice(userdetailsservice); }  @override protected void configure(httpsecurity http) throws exception {     http.csrf()             .disable()             .authorizerequests()             .antmatchers("/resources/**", "/**").permitall()             .anyrequest().permitall()             .and();      http.formlogin()             .loginpage("/login")             .loginprocessingurl("/j_spring_security_check")             .failureurl("/login?error")             .usernameparameter("j_username")             .passwordparameter("j_password")             .permitall();      http.logout()             .permitall()             .logouturl("/logout")             .logoutsuccessurl("/login?logout")             .invalidatehttpsession(true);  }    

}

i think problems configuration of spring-security file, can't understand wrong.

i have figured out going on here, think better off sticking java config or xml config rather mixing , matching them in relation integration spring mvc , security.

in xml configuration, springsecurityfilterchain created http namespace in spring-security.xml. refer here. since have switched java config there no springsecurityfilterchain created application complaining about.

to create springsecurityfilterchain in need following 2 steps.

step 1

remove following web.xml

 <filter>         <filter-name>springsecurityfilterchain</filter-name>         <filter-class>org.springframework.web.filter.delegatingfilterproxy</filter-class>     </filter>      <filter-mapping>         <filter-name>springsecurityfilterchain</filter-name>         <url-pattern>/*</url-pattern>     </filter-mapping> 

step 2

create abstractsecuritywebapplicationinitializer create springsecurityfilterchain you.

public class springsecurityinitializer extends         abstractsecuritywebapplicationinitializer { } 

now abstractsecuritywebapplicationinitializer documentation says when used abstractsecuritywebapplicationinitializer(), class typically used in addition subclass of abstractcontextloaderinitializer.

so have create abstractcontextloaderinitializer yourself. have made 2 changes

step 1 :- remove below web.xml

   <listener>         <listener-class>org.springframework.web.context.contextloaderlistener</listener-class>     </listener>     <context-param>         <param-name>contextconfiglocation</param-name>         <param-value>             /web-inf/applicationcontext.xml         </param-value> 

step 2:- create class springannotationwebinitializer , applicationcontextspring have following content

public class springannotationwebinitializer extends         abstractcontextloaderinitializer {      @override     protected webapplicationcontext createrootapplicationcontext() {         annotationconfigwebapplicationcontext applicationcontext = new annotationconfigwebapplicationcontext();         applicationcontext.register(applicationcontextspring.class);         return applicationcontext;     }  } 

and applicationcontextspring be

@configuration @importresource("classpath:applicationcontext.xml") @import(securityconfig.class) public class applicationcontextspring {  } 

like said, better of creating either java or xml config.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -