model view controller - Spring Security Custom Authfilter doesnt work -


i working in personal project , using spring web mvc , spring security 4, annotation based configs, , custom usernamepasswordauthenticationfilter never reached, losing it, search can solved, if help, 'd grateful, here code

spring initialization

@order(1) public class springmvcinitializer  extends abstractannotationconfigdispatcherservletinitializer  {      @override     protected class<?>[] getrootconfigclasses() {         return new class[]{appconfig.class};     }      @override     protected class<?>[] getservletconfigclasses() {         return null;     }      @override     protected string[] getservletmappings() {         return new string[]{"/"};     }   } 

security initialization

@order(2) public class securityinitializer extends abstractsecuritywebapplicationinitializer {  } 

spring beans declarations , context stuff

@enablewebmvc @configuration @componentscan({"app","server"}) @import({ securitycontext.class }) public class appconfig extends webmvcconfigureradapter {      @override        public void addresourcehandlers(resourcehandlerregistry registry) {            registry.addresourcehandler("/resources/**").addresourcelocations("/meta-inf/resources/");       }     @bean     public internalresourceviewresolver viewresolver(){         internalresourceviewresolver resolver = new  internalresourceviewresolver();         resolver.setsuffix(".jsp");         resolver.setprefix("/web-inf/views/");         resolver.setcontenttype("text/html; charset=utf-8");         resolver.setviewclass(jstlview.class);         return resolver;     }     @bean     public drivermanagerdatasource datasource(){         drivermanagerdatasource driver = new drivermanagerdatasource();         driver.setdriverclassname("com.mysql.jdbc.driver");         driver.seturl("jdbc:mysql://localhost:3306/dberp-1");         driver.setusername("root");         driver.setpassword("123456");         return driver;     }     @bean     public localsessionfactorybean sessionfactory(){         localsessionfactorybean session = new localsessionfactorybean();         session.setdatasource(datasource());         string[] pakages = {"model"};         session.setpackagestoscan(pakages);         properties prop = new properties();         prop.put("dialect", mysqldialect.class);         session.sethibernateproperties(prop);         return session;     }  } 

i sure doing wrong in securitycontext class....

@configuration @enablewebsecurity public class securitycontext extends websecurityconfigureradapter {       @override     protected void configure(httpsecurity  http) throws exception{         http             .exceptionhandling()                  .authenticationentrypoint(authenticationentrypoint())                  .and()             .addfilterbefore(authenticationfilter(), usernamepasswordauthenticationfilter.class)              .authorizerequests()                  .antmatchers("/login","/resources/**").anonymous()                  .antmatchers("/users").hasauthority("admin")                  .antmatchers("/**").hasanyauthority("employee","admin")                  .and()              .logout()                 .logoutsuccessurl("/login")                 .invalidatehttpsession(true)                 .logouturl("/logout")                 .and()              .csrf().disable();      }      @bean        public authenticationentrypoint authenticationentrypoint(){         authenticationentrypoint entryauth = new loginurlauthenticationentrypoint("/login");          return entryauth;     }      @bean(name="customauthenticationmanager")     @override     protected authenticationmanager authenticationmanager() throws exception {         authenticationmanager authmanager = new customauthenticationmanager();         return authmanager;     };     @bean     public usernamepasswordauthenticationfilter authenticationfilter() throws exception{         /*usernamepasswordauthenticationfilter authfilter = new usernamepasswordauthenticationfilter();         authfilter.setauthenticationmanager(authenticationmanager());         authfilter.setauthenticationsuccesshandler(new simpleurlauthenticationsuccesshandler("/home"));         authfilter.setauthenticationfailurehandler(new simpleurlauthenticationfailurehandler("/login?error"));*/         usernamepasswordauthenticationfilter authfilter = new authfilter();         authfilter.setauthenticationmanager(authenticationmanager());         authfilter.setauthenticationsuccesshandler(new simpleurlauthenticationsuccesshandler("/home"));         authfilter.setauthenticationfailurehandler(new simpleurlauthenticationfailurehandler("/login?error"));         authfilter.setrequiresauthenticationrequestmatcher(new antpathrequestmatcher("/login", "post"));          return authfilter;     }   } 


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -