Skip to content

Instantly share code, notes, and snippets.

@jagedn
Last active September 28, 2016 07:35
Show Gist options
  • Save jagedn/2cc530514c57dd67d3142dd87e56b135 to your computer and use it in GitHub Desktop.
Save jagedn/2cc530514c57dd67d3142dd87e56b135 to your computer and use it in GitHub Desktop.
Listener from cloud configuration changes and do something
@Component
@ConfigurationProperties(prefix="authorization")
class CloudConfiguration {
String secretKey
boolean dirty = true
@Autowired
SignedJwtTokenGenerator tokenGenerator
@EventListener
public void handleContextRefresh(ApplicationEvent event) {
if( event instanceof EnvironmentChangeEvent) {
dirty = event.keys.find { it == 'authorization.secretKey' }
}
if( event instanceof RefreshScopeRefreshedEvent && dirty ) {
println "secretKey has been updated, refresh tokenGenerator "
tokenGenerator.jwtSecret = secretKey
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment