use of io.micronaut.security.oauth2.configuration.endpoints.AuthorizationEndpointConfiguration in project micronaut-security by micronaut-projects.
the class OpenIdClientCondition 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));
OpenIdClientConfiguration openIdClientConfiguration = clientConfiguration.getOpenid().get();
String failureMessagePrefix = "Skipped OpenID client creation for provider [" + name;
if (clientConfiguration.isEnabled()) {
if (openIdClientConfiguration.getIssuer().isPresent() || endpointsManuallyConfigured(openIdClientConfiguration)) {
if (clientConfiguration.getGrantType() == GrantType.AUTHORIZATION_CODE) {
Optional<AuthorizationEndpointConfiguration> authorization = openIdClientConfiguration.getAuthorization();
if (!authorization.isPresent() || authorization.get().getResponseType() == ResponseType.CODE) {
return true;
} else {
context.fail(failureMessagePrefix + "] because the response type is not 'code'");
}
} else {
context.fail(failureMessagePrefix + "] because the grant type is not 'authorization-code'");
}
} else {
context.fail(failureMessagePrefix + "] because no issuer is configured");
}
} else {
context.fail(failureMessagePrefix + "] because the configuration is disabled");
}
return false;
}
}
return true;
}
Aggregations