Spring Boot JS App wont work after securing rest-api with Spring Security -


i created simple spring boot/ js app. in next step tried implement usermanagement feature handle multiple users.

so implemented usermodel , controller , secured rest-api calls via authentication of spring security.

@configuration @enablewebsecurity @componentscan("package.packagename") public class securityconfig extends websecurityconfigureradapter {  @autowired datasource datasource; @autowired public void configauthentication(authenticationmanagerbuilder auth) throws exception{      auth.jdbcauthentication().datasource(datasource)             .usersbyusernamequery("select email, password, active accounts email=?")             .authoritiesbyusernamequery("select email, role account_roles email=?"); }  @override @order(securityproperties.access_override_order) protected void configure(httpsecurity http) throws exception {         http                 .formlogin().permitall()                 .and()                 .authorizerequests()                 .antmatchers("/index.html",  "/").permitall()                 .anyrequest().authenticated()                 .and()                 .logout();                         } } 

additionally file have securitywebapplicationinitializer

public class securitywebapplicationinitializer     extends abstractsecuritywebapplicationinitializer {  public securitywebapplicationinitializer() {     super(securityconfig.class); } } 

my problem fact, if start application , try access via localhost:8080 face 404 error. app should work without login , seems springsecurity enabled app not able load js stuff in resources/public directory.

reading logs showed following:

no mapping found http request uri [/] in dispatcherservlet name 'dispatcherservlet'

if start app without spring security works without problems.

the securing of api-calls works charm - i'm able login, receive cookie , use cookie authenticate against api-functions secured springsecurity.

i hope can me resolve (hopefully small) problem.

thanks in advance

when use .formlogin() need define login page or use .httpbasic() auth. can use this:

    .formlogin()                               .and()     .httpbasic(); 

or

    .formlogin()         .loginpage("/login.html") 

you can read more here

http://docs.spring.io/spring-security/site/docs/3.2.x/guides/form.html

http://www.baeldung.com/spring-security-login


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -