use of io.micronaut.security.oauth2.client.clientcredentials.ClientCredentialsConfiguration in project micronaut-security by micronaut-projects.
the class ClientCredentialsHeaderPropagatorEnabled method matches.
@Override
public boolean matches(ConditionContext context) {
AnnotationMetadataProvider component = context.getComponent();
BeanContext beanContext = context.getBeanContext();
if (beanContext instanceof ApplicationContext && component instanceof ValueResolver) {
Optional<String> optional = ((ValueResolver) component).get(Named.class.getName(), String.class);
if (optional.isPresent()) {
String name = optional.get();
OauthClientConfiguration clientConfiguration = beanContext.getBean(OauthClientConfiguration.class, Qualifiers.byName(name));
Optional<ClientCredentialsHeaderTokenPropagatorConfiguration> headerTokenConfiguration = clientConfiguration.getClientCredentials().flatMap(ClientCredentialsConfiguration::getHeaderPropagation);
if (headerTokenConfiguration.isPresent()) {
if (headerTokenConfiguration.get().isEnabled()) {
return true;
} else {
context.fail("Client credentials header token handler is disabled");
return false;
}
} else {
context.fail("Client credentials header token handler disabled due to a lack of configuration");
return false;
}
}
}
return true;
}
use of io.micronaut.security.oauth2.client.clientcredentials.ClientCredentialsConfiguration in project micronaut-security by micronaut-projects.
the class ClientCredentialsEnabled method matches.
@Override
public boolean matches(ConditionContext context) {
AnnotationMetadataProvider component = context.getComponent();
BeanContext beanContext = context.getBeanContext();
if (beanContext instanceof ApplicationContext && component instanceof ValueResolver) {
Optional<String> optional = ((ValueResolver) component).get(Named.class.getName(), String.class);
if (optional.isPresent()) {
String name = optional.get();
OauthClientConfiguration clientConfiguration = beanContext.getBean(OauthClientConfiguration.class, Qualifiers.byName(name));
String failureMessage = "Client credentials is disabled for the client [" + name + "]";
if (clientConfiguration.isEnabled()) {
Optional<ClientCredentialsConfiguration> clientCredentialsConfiguration = clientConfiguration.getClientCredentials();
if (!clientCredentialsConfiguration.isPresent() || clientCredentialsConfiguration.get().isEnabled()) {
return true;
} else {
context.fail(failureMessage);
return false;
}
} else {
context.fail(failureMessage);
return false;
}
}
}
return true;
}
Aggregations