Unable to override spring boot's (default) security configuration -


i trying secure spring boot rest application using spring security basic authentication.

the default basic authentication works plugging in following dependency

    <dependency>         <groupid>org.springframework.boot</groupid>         <artifactid>spring-boot-starter-security</artifactid>     </dependency> 

the next step override default authentication credentials provided spring boot custom credentials (username, password).

i have tried using:

@configuration @enablewebsecurity @enableglobalmethodsecurity(prepostenabled = true) public class securityconfiguration extends websecurityconfigureradapter {      @override     @autowired     public void configure (authenticationmanagerbuilder authbuilder) throws exception {          authbuilder.inmemoryauthentication()             .withuser("aide").password("aide").roles("user").and()             .withuser("pervacio").password("pervacio").roles("admin");     }      @override     @autowired     protected void configure (httpsecurity http) throws exception {          http.httpbasic().and()             .authorizerequests()                 .antmatchers(httpmethod.post, "/search").hasrole("admin")             .and().csrf().disable();     } } 

here controller:

@restcontroller @springbootapplication public class controller {      // request mappings , other code here      public static void main(string[] args) {         springapplication.run(controller.class, args);     } } 

the problem having unable override default credentials custom ones.

how do this?

other posts on suggest annotating configure methods autowired, , isn't working me.

what doing wrong? tried above approach following official example.

the problem realized location (or package) of securityconfiguration.

@componentscan annotation (included part of @springbootapplication) default scans components in same package defined.

hence, there 2 solutions: a) move configuration same package annotation defined b) configure annotation scan components in package placed configuration

in case, securityconfiguration file above in different package compared application class.

solution a:

include following annotation:

@componentscan({"<security-package-name>"}) 

and plug in name of package has security configuration.

solution b:

move java configuration class same package of application class.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -