Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Brandon Vulaj bvulaj

🏠
Working from home
View GitHub Profile
@bvulaj
bvulaj / AppConfig.java
Last active Mar 14, 2018
Third Party Injection
View AppConfig.java
@Configuration
public class AppConfig {
@Bean
@ConfigurationProperties("provider")
public ProviderInfo providerInfo() {
return new ProviderInfo();
}
}
@bvulaj
bvulaj / AppConfig.java
Last active Mar 14, 2018
Simple Field Injection w/ @value
View AppConfig.java
@Configuration
public class AppConfig {
// Using SpEL
@Value("#{providerInfo.name ?: 'bar'}")
private String providerName;
// Injecting a Duration w/ a default
@Value("${timeout:500ms}")
private Duration timeout;
}
@bvulaj
bvulaj / ProviderInfo.java
Created Mar 14, 2018
Basic Type Safe Injection
View ProviderInfo.java
@Component
@ConfigurationProperties("provider")
public class ProviderInfo {
private String name;
private boolean enabled;
private List<String> roles;
}
View ConfigurePrincipalExtractor.java
@Autowired
private PrincipalExtractor principalExtractor;
private Filter ssoFilter() {
OAuth2ClientAuthenticationProcessingFilter facebookFilter = new OAuth2ClientAuthenticationProcessingFilter("/login/facebook");
OAuth2RestTemplate facebookTemplate = new OAuth2RestTemplate(facebook(), oauth2ClientContext);
facebookFilter.setRestTemplate(facebookTemplate);
UserInfoTokenServices tokenServices = new UserInfoTokenServices(facebookResource().getUserInfoUri(), facebook().getClientId());
tokenServices.setRestTemplate(facebookTemplate);
tokenServices.setPrincipalExtractor(principalExtractor);
@bvulaj
bvulaj / SecurityConfiguration.java
Last active Dec 15, 2020
Multiple Oauth2 Providers in Spring Security
View SecurityConfiguration.java
@Autowired
private FacebookPrincipalExtractor facebookPrincipalExtractor;
@Autowired
private FacebookAuthoritiesExtractor facebookAuthoritiesExtractor;
@Autowired
private GooglePrincipalExtractor googlePrincipalExtractor;
@Autowired
private GoogleAuthoritiesExtractor googleAuthoritiesExtractor;
@Bean