java - UserDetailsService is never called(Spring boot security) -


i have springsecurity config

@configuration @enablewebsecurity @enableglobalmethodsecurity(securedenabled = true) public class securityconfig  extends websecurityconfigureradapter {      @autowired     private userdetailsserviceimpl detailsservice;      @autowired     public void registerglobalauthentication(authenticationmanagerbuilder auth) throws exception {         auth.userdetailsservice(detailsservice);     }      @override     protected void configure(httpsecurity http) throws exception {         http.authorizerequests()                 .antmatchers("/", "/index").access("hasrole('user')");         http.userdetailsservice(detailsservice);     } } 

when open index.html page 403 error. because user anonymous. want check user , set role , detail before opened page. write service

@service public class userdetailsserviceimpl implements userdetailsservice {     @autowired     private httpservletrequest request;     @autowired     authservice authservice;     @override     public userdetails loaduserbyusername(string s) throws usernamenotfoundexception {         string ipaddress = request.getremoteaddr();         authlkuser authlkuserbyip = authservice.getauthlkuserbyip(ipaddress);          if (authlkuserbyip == null) return null;          boolean b = authservice.checkauthlkuser(authlkuserbyip);         if (b) return null;         set<grantedauthority> roles = new hashset();         roles.add(new simplegrantedauthority("user"));         userdetails userdetails = new org.springframework.security.core.userdetails.user(authlkuserbyip.getmsisdn(),                         authlkuserbyip.getsubsid(), roles);         return userdetails;     } } 

but service never called.

in spring boot if have custom spring security configuration not use auto configuration spring security.

in spring security configuration haven't given anyway authenticate user. there form based, basic header based, etc authentication available in spring security. should use 1 of authenticate user during authentication userdetailsserviceimpl used load user.

follow post form based login


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 -