5

I am using Spring security in my web application and I am using Javaconfig for it. Recently we have also added Spring SAML authentication in the application and finally got it working after some hurdles. Inside the WebApplicationInitializer's onStartUp() I am loading SpringSecurity configuration or SpringSaml configuration based on some pre condition.

Now how can I do this dynamically ? Actually I will introduce a button and once admin clicks on this button admin and all users will be logged out and context should be reloaded. At this point of time its ok if system is inaccessible for sometime and it re initializes application context (which is actually my goal) ?

In other words how can I call the onStartUp() method of WebApplicationInitializer ?

Amit
  • 13,134
  • 17
  • 77
  • 148
  • 1
    I think it can be done without reloading the spring application context. Even if you context is refreshed, you may face other side effects. [This question](https://stackoverflow.com/questions/27545846/spring-integration-getting-exception-on-refreshing-application-context-2nd-time) give the way to refresh the application context from controller but ended up in different issues. If you can share some of your configuration code, that can be helpful to provide better answers. – skadya Oct 02 '17 at 22:01

1 Answers1

6

You use Spring Environment Profiles to control which security configuration is loaded.

To switch profile, you then update the configuration file listing the active profiles, and reload the app.

See Spring Boot Reference Guide - 25. Profiles.

Andreas
  • 154,647
  • 11
  • 152
  • 247
  • Thanks for the answer Andreas. Can you share how to programmatically "reload the app." ? – Amit Sep 26 '17 at 09:23
  • @aProgrammer If you use `spring-boot-devtools`, updating the configuration file will automatically trigger a LiveReload: See [Spring Boot Reference Guide - 83. Hot swapping](https://docs.spring.io/spring-boot/docs/current/reference/html/howto-hotswapping.html). – Andreas Oct 04 '17 at 14:50