use of io.micronaut.context.annotation.EachBean in project micronaut-kafka by micronaut-projects.
the class KafkaStreamsFactory method kafkaStreams.
/**
* Builds the default {@link KafkaStreams} bean from the configuration and the supplied {@link ConfiguredStreamBuilder}.
*
* @param name The configuration name
* @param builder The builder
* @param kStreams The KStream definitions
* @return The {@link KafkaStreams} bean
*/
@EachBean(ConfiguredStreamBuilder.class)
@Context
KafkaStreams kafkaStreams(@Parameter String name, ConfiguredStreamBuilder builder, KStream<?, ?>... kStreams) {
Topology topology = builder.build(builder.getConfiguration());
KafkaStreams kafkaStreams = new KafkaStreams(topology, builder.getConfiguration());
eventPublisher.publishEvent(new BeforeKafkaStreamStart(kafkaStreams, kStreams));
streams.put(kafkaStreams, builder);
if (LOG.isDebugEnabled()) {
LOG.debug("Initializing Application {} with topology:\n{}", name, topology.describe().toString());
}
kafkaStreams.start();
eventPublisher.publishEvent(new AfterKafkaStreamsStart(kafkaStreams, kStreams));
return kafkaStreams;
}
use of io.micronaut.context.annotation.EachBean in project micronaut-security by micronaut-projects.
the class OpenIdClientFactory method openIdConfiguration.
/**
* Retrieves OpenID configuration from the provided issuer.
*
* @param oauthClientConfiguration The client configuration
* @param openIdClientConfiguration The openid client configuration
* @param issuerClient The client to request the metadata
* @return The OpenID configuration
*/
@EachBean(OpenIdClientConfiguration.class)
DefaultOpenIdProviderMetadata openIdConfiguration(@Parameter OauthClientConfiguration oauthClientConfiguration, @Parameter OpenIdClientConfiguration openIdClientConfiguration, @Client HttpClient issuerClient) {
DefaultOpenIdProviderMetadata providerMetadata = openIdClientConfiguration.getIssuer().map(issuer -> {
try {
URL configurationUrl = new URL(issuer, StringUtils.prependUri(issuer.getPath(), openIdClientConfiguration.getConfigurationPath()));
if (LOG.isDebugEnabled()) {
LOG.debug("Sending request for OpenID configuration for provider [{}] to URL [{}]", openIdClientConfiguration.getName(), configurationUrl);
}
// TODO NOSONAR this returns ReadTimeoutException - return issuerClient.toBlocking().retrieve(configurationUrl.toString(), DefaultOpenIdProviderMetadata.class);
String json = issuerClient.toBlocking().retrieve(configurationUrl.toString(), String.class);
return jsonMapper.readValue(json.getBytes(StandardCharsets.UTF_8), Argument.of(DefaultOpenIdProviderMetadata.class));
} catch (HttpClientResponseException e) {
throw new BeanInstantiationException("Failed to retrieve OpenID configuration for " + openIdClientConfiguration.getName(), e);
} catch (MalformedURLException e) {
throw new BeanInstantiationException("Failure parsing issuer URL " + issuer.toString(), e);
} catch (IOException e) {
throw new BeanInstantiationException("JSON Processing Exception parsing issuer URL returned JSON " + issuer.toString(), e);
}
}).orElse(new DefaultOpenIdProviderMetadata());
overrideFromConfig(providerMetadata, openIdClientConfiguration, oauthClientConfiguration);
return providerMetadata;
}
use of io.micronaut.context.annotation.EachBean in project micronaut-security by micronaut-projects.
the class OpenIdClientFactory method openIdClient.
/**
* Creates an {@link OpenIdClient} from the provided parameters.
*
* @param openIdClientConfiguration The openid client configuration
* @param clientConfiguration The client configuration
* @param openIdProviderMetadata The open id provider metadata
* @param authenticationMapper The user details mapper
* @param redirectUrlBuilder The redirect URL builder
* @param authorizationResponseHandler The authorization response handler
* @param endSessionEndpointResolver The end session resolver
* @param endSessionCallbackUrlBuilder The end session callback URL builder
* @return The OpenID client, or null if the client configuration does not allow it
*/
@EachBean(OpenIdClientConfiguration.class)
@Requires(condition = OpenIdClientCondition.class)
@SuppressWarnings("java:S107")
DefaultOpenIdClient openIdClient(@Parameter OpenIdClientConfiguration openIdClientConfiguration, @Parameter OauthClientConfiguration clientConfiguration, @Parameter BeanProvider<DefaultOpenIdProviderMetadata> openIdProviderMetadata, @Parameter @Nullable OpenIdAuthenticationMapper authenticationMapper, AuthorizationRedirectHandler redirectUrlBuilder, OpenIdAuthorizationResponseHandler authorizationResponseHandler, EndSessionEndpointResolver endSessionEndpointResolver, EndSessionCallbackUrlBuilder endSessionCallbackUrlBuilder) {
Supplier<OpenIdProviderMetadata> metadataSupplier = SupplierUtil.memoized(openIdProviderMetadata::get);
EndSessionEndpoint endSessionEndpoint = null;
if (openIdClientConfiguration.getEndSession().isEnabled()) {
endSessionEndpoint = endSessionEndpointResolver.resolve(clientConfiguration, metadataSupplier, endSessionCallbackUrlBuilder).orElse(null);
}
return new DefaultOpenIdClient(clientConfiguration, metadataSupplier, authenticationMapper, redirectUrlBuilder, authorizationResponseHandler, beanContext, endSessionEndpoint);
}
use of io.micronaut.context.annotation.EachBean in project micronaut-security by micronaut-projects.
the class JwksUriSignatureFactory method createJwksUriSignature.
/**
* @param openIdProviderMetadata The open id provider metadata
* @param jwkValidator JWK Validator
* @return a {@link JwksSignature} pointed to the jwks_uri exposed via OpenID configuration
*/
@Requires(property = SecurityConfigurationProperties.PREFIX + ".authentication", value = "idtoken")
@EachBean(DefaultOpenIdProviderMetadata.class)
public JwksSignature createJwksUriSignature(@Parameter BeanProvider<DefaultOpenIdProviderMetadata> openIdProviderMetadata, JwkValidator jwkValidator) {
JwksSignatureConfigurationProperties jwksSignatureConfiguration = new JwksSignatureConfigurationProperties();
jwksSignatureConfiguration.setUrl(openIdProviderMetadata.get().getJwksUri());
return new JwksSignature(jwksSignatureConfiguration, jwkValidator);
}
Aggregations