Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dynamically switch application context in Spring Security?

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 ?

like image 252
Amit Avatar asked Sep 26 '17 09:09

Amit


1 Answers

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.

like image 143
Andreas Avatar answered Oct 03 '22 00:10

Andreas