Spring Boot URL mapping for static HTML -
my spring boot appliation consist of 2 main "modules":
- a "web" module consists of static html pages, available public (unauthenticated/anonymouse users); and
- an "app" module consists of number of dynamic pages, each of require (spring security-based) authentication access
the basic app structure is:
index.html
: homepage, mappedhttp://localhost:8080/
about.html
: page, mappedhttp://localhost:8080/about
contact.html
: contact page, mappedhttp://localhost:8080/contact
login.html
: login page, mappedhttp://localhost:8080/login
dashboard.html
: dashboard/landing page after logging in, mappedhttp://localhost:8080/account
- all other pages under
http://localhost:8080/account/*
mvc/dynamic pages typical@requestmapping
mappings
what not clear me is, static ("public web") html pages, i:
- just use standard controller-based
@requestmappings
render thymeleaf/handlebars template (which has no data model since content static)? or i: - treat these pages static content (same css/js) , serve them static content spring boot prescribes? if correct option, how achieve correct url mappings (so, example, users can go
http://localhost:8080/contact
instead ofhttp://localhost:8080/contact.html
)?
okey first need map views via mvc resolver :
@configuration public class webmvcconfig extends webmvcconfigureradapter { @override public void addviewcontrollers(viewcontrollerregistry registry) { registry.addviewcontroller("/login").setviewname("login"); registry.addviewcontroller("/contact").setviewname("contact"); } }
after mapping views need add views /login
in antmatchers
assuming configuration method looks :
@override protected void configure(httpsecurity http) throws exception { http .csrf().disable() .authorizerequests() .antmatchers("/contact","/about", ...).permitall() //add static pages here ( public pages ) .anyrequest() .authenticated() .and() .formlogin() .loginpage("/login") .permitall() .successhandler(successhandler) // don't think you'll needing it's redirect user if it's admin or simple user .and() // logout .logout() .invalidatehttpsession(true) .logouturl("/logout") .permitall(); }
after adding view map in antmatchers
spring security wont handle authentification pages , solves problem
Comments
Post a Comment