java - Spring Security: anonymousUser blocked from .authenticated() configuration? -


when not logged in spring security, authentication's currentprincipalname anonymoususer , method .authenticated() returns true.

however, configuration asks requests authenticated , anonymoususer denied.

here configuration code:

@override protected void configure(httpsecurity http) throws exception {     characterencodingfilter characterencodingfilter = new characterencodingfilter();     characterencodingfilter.setencoding("utf-8");     characterencodingfilter.setforceencoding(true);     http.addfilterbefore(characterencodingfilter, csrffilter.class);      http     .formlogin()//support form login         .loginpage("/login")     .and()     .authorizerequests()         .antmatchers("/spitter/me").authenticated()         .antmatchers(httpmethod.post, "/spittles").authenticated()         .anyrequest().permitall(); } 

both of 2 antmatchers blocked anonymoususer accessing. there reason why?

edit: why duplicate? asking different question. question "why authenticataed?" , mine "it authenticated, why not treated one?". question's answers not answer question.

full security config source code:

package spittr.config;  import javax.sql.datasource;  import org.springframework.beans.factory.annotation.autowired; import org.springframework.context.annotation.bean; import org.springframework.context.annotation.configuration; import org.springframework.http.httpmethod; import org.springframework.security.config.annotation.authentication.builders.authenticationmanagerbuilder; import org.springframework.security.config.annotation.web.builders.httpsecurity; import org.springframework.security.config.annotation.web.configuration.websecurityconfigureradapter; import org.springframework.security.config.annotation.web.servlet.configuration.enablewebmvcsecurity; import org.springframework.security.crypto.bcrypt.bcryptpasswordencoder; import org.springframework.security.crypto.password.passwordencoder; import org.springframework.security.crypto.password.standardpasswordencoder; import org.springframework.security.web.csrf.csrffilter; import org.springframework.web.filter.characterencodingfilter;  @configuration @enablewebmvcsecurity public class securityconfig extends websecurityconfigureradapter{      static{         system.out.println("securityconfig loaded");     }     @autowired     datasource datasource;        @override     protected void configure(authenticationmanagerbuilder auth) throws exception {         auth.jdbcauthentication()          .datasource(datasource)           .usersbyusernamequery("select username, password, enabled "                 + " spitter username = ?")            .authoritiesbyusernamequery("select username, role "                 + " spitter username =?")            .passwordencoder(passwordencoder());     }      @override     protected void configure(httpsecurity http) throws exception {         characterencodingfilter characterencodingfilter = new characterencodingfilter();         characterencodingfilter.setencoding("utf-8");         characterencodingfilter.setforceencoding(true);         http.addfilterbefore(characterencodingfilter, csrffilter.class);          http         .formlogin()//support form login             .loginpage("/login")         .and()         .authorizerequests()             .antmatchers("/spitters/me").authenticated()             .antmatchers(httpmethod.post, "/spittles").authenticated()             .anyrequest().permitall();     }      @bean     public passwordencoder passwordencoder(){         return new bcryptpasswordencoder();     } } 


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -