I am trying to implement a login and welcome page using Angular as the front end and spring boot as the controller .
In my WebSecuirtyConfigureAdapter
@Override
protected void configure(HttpSecurity http) throws Exception
{
http.httpBasic().and()
.authorizeRequests()
.antMatchers("/index.html").permitAll()
.antMatchers("/src/assets/logo.png").permitAll()
.antMatchers("/main.js").permitAll()
.antMatchers("/main.js.map").permitAll()
.antMatchers("/polyfills.js").permitAll()
.antMatchers("/polyfills.js.map").permitAll()
.antMatchers("/styles.js").permitAll()
.antMatchers("/styles.js.map").permitAll()
.antMatchers("/vendor.js").permitAll()
.antMatchers("/vendor.js.map").permitAll()
.antMatchers("/runtime.js.map").permitAll()
.antMatchers("/runtime.js").permitAll()
.antMatchers("/saml/**").permitAll()
.antMatchers("/favicon.ico").permitAll()
.antMatchers("/assets/logo.png").permitAll()
.antMatchers("/oauth/**").permitAll()
.antMatchers("/userinfo").permitAll()
.antMatchers("/").permitAll()
.anyRequest()
.authenticated()
.and()
.formLogin().loginPage("/#/login").permitAll()
.successHandler(this.successHandler)
.failureHandler(this.failureHandler)
.and()
.exceptionHandling()
.authenticationEntryPoint(this.entryPoint)
.and()
.csrf().csrfTokenRepository(csrfTokenRepository()).ignoringAntMatchers("/url5/**")
.and()
.addFilterAfter(filter, BasicAuthenticationFilter.class)
.addFilterBefore(filter, CsrfFilter.class)
.addFilterAfter(this.csrfHeaderFilter(), CsrfFilter.class);
}
I need to re-direct any unauthenticated requests to authenticationEntryPoint but since I had to add "/" to allow Angular to work it is not working as expected . As "/" is permitted every request is permitted and I do not hit the entryPoint which directs me to the login page at /#/login. If I remove the "/" I am able to hit the entryPoint but Angular wouldn't render as spring security would not allow that to load . I need my unauthorized request to go via the entry point as this is a legacy code and it works the parameters which might be sent along with the request. Can you please help me how to achieve the same ?
Try adding a Controller
which will forward to index.html
.
@Controller
public class UiController {
@RequestMapping({
"/",
"/login", //my login page is on /login
})
public String handler() {
return "forward:index.html";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.