-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ClientRegistrations RestTemplate not configurable #14176
Comments
@ZIRAKrezovic, thanks for reaching out! In 6.2 (recently released), there is a new feature available (see gh-11783) which allows you to more easily configure a However, regarding
I'm going to close this issue with the above explanation. |
Hi @sjohnr ... the problem here is without this "internal" class, there is no way to support RP initiated logout because the endsession_uri is configured only via the mentioned ClientRegistrations utility class. |
@ZIRAKrezovic, I don't think I follow. You can configure RP-initiated logout as per the documentation.
I don't think this is correct, as the
which can be specified via |
@sjohnr Forgot to add further context. I am using spring-boot + auto configuration. There is no way to do it with spring autoconfigured client registrations + repository. Thanks for the info, I may have to override a bit more than I'd like to. |
It's somewhat a hack, but it works ... in case somebody else needs it import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.context.properties.bind.BindResult;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.ResolvableType;
import org.springframework.core.env.Environment;
import org.springframework.security.oauth2.client.registration.ClientRegistration;
import org.springframework.security.oauth2.client.registration.InMemoryReactiveClientRegistrationRepository;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@Slf4j
public class OidcMetadataBeanPostProcessor
implements BeanPostProcessor, InitializingBean, EnvironmentAware {
private Environment environment;
private Map<String, Map<String, String>> properties;
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) {
if (bean instanceof InMemoryReactiveClientRegistrationRepository repo) {
return replace(repo);
}
return bean;
}
private InMemoryReactiveClientRegistrationRepository replace(
InMemoryReactiveClientRegistrationRepository repo) {
List<ClientRegistration> registrations = new ArrayList<>();
List<ClientRegistration> modifiedRegistrations = new ArrayList<>();
repo.forEach(registrations::add);
Iterator<ClientRegistration> it = registrations.iterator();
while (it.hasNext()) {
var registration = it.next();
if (properties.containsKey(registration.getRegistrationId())) {
var details = registration.getProviderDetails();
Map<String, Object> metadata = new HashMap<>(details.getConfigurationMetadata());
metadata.putAll(properties.get(registration.getRegistrationId()));
modifiedRegistrations.add(
ClientRegistration.withClientRegistration(registration)
.providerConfigurationMetadata(metadata)
.build());
it.remove();
}
}
registrations.addAll(modifiedRegistrations);
if (modifiedRegistrations.isEmpty()) {
return repo;
} else {
log.debug(
"Modified [{}] client registrations with metadata from 'security.oidc-meta-data'",
modifiedRegistrations.size());
return new InMemoryReactiveClientRegistrationRepository(registrations);
}
}
@Override
public void afterPropertiesSet() {
BindResult<Map<String, Map<String, String>>> bind =
Binder.get(environment)
.bind(
"security.oidc-meta-data",
Bindable.of(
ResolvableType.forClassWithGenerics(
Map.class,
ResolvableType.forClass(String.class),
ResolvableType.forClassWithGenerics(
Map.class, String.class, String.class))));
if (bind.isBound()) {
properties = bind.get();
} else {
properties = Collections.emptyMap();
}
}
@Override
public void setEnvironment(Environment environment) {
this.environment = environment;
}
} And application.yaml security:
oidc-meta-data:
keycloak:
first: second |
@ZIRAKrezovic, I would also recommend you look into simply providing your You can of course fetch details from the |
Hi |
Exception occurred in generateToken I/O error on POST request for "https://xyzabc/oauth/client_credential/accesstoken": (certificate_unknown) PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: (certificate_unknown) PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested targetjavax.net.ssl.SSLHandshakeException: (certificate_unknown) PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target |
Describe the bug
When ClientRegistrations is used to obtain meta data from issuer that has an invalid HTTPS certificate (in my case, self-signed), it fails with error
To Reproduce
Minimal application.yml
Dependencies
Configuration bean
Spring Boot 3.2.0-RC2, Spring Security 6.2.0-RC2
Expected behavior
I can override WebClient instances for each service that calls my provider and provide a valid TLS certification path. But I cannot do it for ClientRegistrations.
Sample
A link to a GitHub repository with a minimal, reproducible sample.
Reports that include a sample will take priority over reports that do not.
At times, we may require a sample, so it is good to try and include a sample up front.
The text was updated successfully, but these errors were encountered: