Last active
August 13, 2023 02:37
-
-
Save sandipchitale/54f335637d54c22b0742e1bfa75ce64f to your computer and use it in GitHub Desktop.
Sample BeanProcessor to modify a configuration property bean #springboot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class OAuth2ClientPropertiesSchemeAdjusterBeanPostProcessor implements BeanPostProcessor, EnvironmentAware { | |
private Environment environment; | |
@Override | |
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { | |
if (bean instanceof OAuth2ClientProperties oAuth2ClientProperties) { | |
String tokenUri = oAuth2ClientProperties.getProvider().get("as").getTokenUri(); | |
if ("true".equals(environment.getProperty("server.ssl.enabled"))) { | |
tokenUri = tokenUri.replace("http://", "https://"); | |
} else { | |
tokenUri = tokenUri.replace("https://", "http://"); | |
} | |
oAuth2ClientProperties.getProvider().get("as").setTokenUri(tokenUri); | |
} | |
return bean; | |
} | |
@Override | |
public void setEnvironment(Environment environment) { | |
this.environment = environment; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment