spring security - Why doesn't my implementation of AuthenticationProvider with Java Config work? -


i tried connect custom authenticationprovider spring security configuration below:

@configuration @enablewebmvcsecurity public class websecurityconfig extends websecurityconfigureradapter {      @autowired     private customauthenticationprovider customauthenticationprovider;      @override     protected void configure(authenticationmanagerbuilder auth) throws exception {         auth.authenticationprovider(customauthenticationprovider);     }      @override     protected void configure(httpsecurity http) throws exception {         http.authorizerequests().antmatchers("/", "/signup", "/resources/**", "/home").permitall()                 .antmatchers("/user").hasrole("user").anyrequest().authenticated()                 .and()                 .formlogin().loginpage("/login").loginprocessingurl("/login").permitall()                 .and().logout().permitall();     }  } 

here customauthenticationprovider class:

@component public class customauthenticationprovider implements authenticationprovider {  @autowired private userservice userservice;  @override public authentication authenticate(authentication auth) throws authenticationexception {      string email = (string) auth.getprincipal();     string password = (string) auth.getcredentials();      system.out.println("[customauthenticationprovider] authentication try [" + email +"]");      user user = (user) userservice.findbyemail(email);     if (user == null) {         throw new badcredentialsexception("[customauthenticationprovider] authentication failed!!! reason: user not exist: [" + email + "]");     }      if (user.getpassword().equals(password)) {         system.out.println("[customauthenticationprovider] - authentication success!!!");          list<grantedauthority> roles = new arraylist<grantedauthority>();         roles.add(new simplegrantedauthority("role_user"));          usernamepasswordauthenticationtoken result = new usernamepasswordauthenticationtoken(email, password, roles);             result.setdetails(user);             return result;         } else {             throw new badcredentialsexception("[customauthenticationprovider] authentication failed!!! reason: wrong password");         }     }      @override     public boolean supports(class<?> auth) {         return auth.equals(usernamepasswordauthenticationtoken.class);     } } 

i opened browser , connected url: "localhost:8080/login" can see login page, , input id/pw. after click "login" button, expected find log output customauthenticationprovider. there no log output. means customauthenticationprovider not working.

i checked google , stackoverflow, cannot find resolution.

before this, used xml configuration like:

<security:authentication-manager>     <security:authentication-provider ref="customauthenticationprovider" /> </security:authentication-manager> 

that code works fine, trying moving code xml java configuration.

i using spring boot ver 1.27. here relevant portion of pom:

<dependencies>     <dependency>         <groupid>org.springframework.boot</groupid>         <artifactid>spring-boot-starter-thymeleaf</artifactid>     </dependency>     <dependency>         <groupid>org.springframework.boot</groupid>         <artifactid>spring-boot-starter-security</artifactid>     </dependency>     <dependency>         <groupid>org.springframework.boot</groupid>         <artifactid>spring-boot-starter-web</artifactid>     </dependency>      <dependency>         <groupid>org.springframework.boot</groupid>         <artifactid>spring-boot-starter-test</artifactid>         <scope>test</scope>     </dependency>     <dependency>         <groupid>javax.servlet</groupid>         <artifactid>jstl</artifactid>     </dependency>     <dependency>         <groupid>org.springframework.hateoas</groupid>         <artifactid>spring-hateoas</artifactid>     </dependency> </dependencies> 


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -