use of io.micronaut.core.value.PropertyResolver in project micronaut-graphql by micronaut-projects.
the class GraphiQLController method replaceParameters.
private String replaceParameters(final String str, final Map<String, String> parameters) {
Map<String, Object> map = new HashMap<>();
map.putAll(parameters);
PropertyResolver propertyResolver = new MapPropertyResolver(map);
PropertyPlaceholderResolver propertyPlaceholderResolver = new DefaultPropertyPlaceholderResolver(propertyResolver, conversionService);
return propertyPlaceholderResolver.resolvePlaceholders(str).get();
}
use of io.micronaut.core.value.PropertyResolver in project micronaut-security by micronaut-projects.
the class AuthenticationModeCondition method matches.
@Override
public boolean matches(ConditionContext context) {
PropertyResolver propertyResolver = context.getBeanContext().getBean(PropertyResolver.class);
final String propertyName = SecurityConfigurationProperties.PREFIX + ".authentication";
if (!propertyResolver.containsProperty(propertyName)) {
if (LOG.isDebugEnabled()) {
LOG.debug("{}} is not fulfilled because {} is not set.", getClass().getSimpleName(), propertyName);
}
return false;
}
Optional<String> propertyValueOptional = propertyResolver.get(propertyName, String.class);
if (!propertyValueOptional.isPresent()) {
if (LOG.isDebugEnabled()) {
LOG.debug("{} is not fulfilled because {} property is not a String.", getClass().getSimpleName(), propertyName);
}
return false;
}
final String propertyvalue = propertyValueOptional.get();
final boolean result = acceptableModes.stream().map(AuthenticationMode::toString).anyMatch(propertyvalue::equals);
if (!result && LOG.isDebugEnabled()) {
LOG.debug("{} is not fulfilled because {} is not one of {}.", getClass().getSimpleName(), propertyName, acceptableModes);
}
return result;
}
use of io.micronaut.core.value.PropertyResolver in project micronaut-core by micronaut-projects.
the class BuildSelfSignedCondition method matches.
@Override
public boolean matches(ConditionContext context) {
BeanContext beanContext = context.getBeanContext();
if (beanContext instanceof PropertyResolver) {
PropertyResolver resolver = (PropertyResolver) beanContext;
boolean deprecated = enabledForPrefix(resolver, SslConfiguration.PREFIX);
boolean server = enabledForPrefix(resolver, ServerSslConfiguration.PREFIX);
return validate(context, deprecated, server);
} else {
context.fail("Bean requires property but BeanContext does not support property resolution");
return false;
}
}
use of io.micronaut.core.value.PropertyResolver in project micronaut-core by micronaut-projects.
the class AbstractInitializableBeanDefinition method getValueForPath.
/**
* Resolve a value for the given field of the given type and path.
*
* @param resolutionContext The resolution context
* @param context The bean context
* @param propertyType The required property type
* @param propertyPath The property path
* @param <T1> The generic type
* @return An optional value
*/
@Internal
@UsedByGeneratedCode
protected final <T1> Optional<T1> getValueForPath(BeanResolutionContext resolutionContext, BeanContext context, Argument<T1> propertyType, String propertyPath) {
if (context instanceof PropertyResolver) {
PropertyResolver propertyResolver = (PropertyResolver) context;
String valString = substituteWildCards(resolutionContext, propertyPath);
return propertyResolver.getProperty(valString, ConversionContext.of(propertyType));
}
return Optional.empty();
}
use of io.micronaut.core.value.PropertyResolver in project micronaut-core by micronaut-projects.
the class AbstractBeanDefinition method getValueForField.
/**
* Obtains a value for the given field from the bean context
* <p>
* Warning: this method is used by internal generated code and should not be called by user code.
*
* @param resolutionContext The resolution context
* @param context The context
* @param fieldIndex The index of the field
* @return The resolved bean
*/
@SuppressWarnings("WeakerAccess")
@Internal
@UsedByGeneratedCode
protected final Object getValueForField(BeanResolutionContext resolutionContext, BeanContext context, int fieldIndex) {
FieldInjectionPoint injectionPoint = fieldInjectionPoints.get(fieldIndex);
BeanResolutionContext.Path path = resolutionContext.getPath();
path.pushFieldResolve(this, injectionPoint);
try {
if (context instanceof PropertyResolver) {
final AnnotationMetadata annotationMetadata = injectionPoint.getAnnotationMetadata();
String valueAnnVal = annotationMetadata.stringValue(Value.class).orElse(null);
Argument<?> fieldArgument = injectionPoint.asArgument();
Argument<?> argumentType;
boolean isCollection = false;
if (Collection.class.isAssignableFrom(injectionPoint.getType())) {
argumentType = fieldArgument.getFirstTypeVariable().orElse(Argument.OBJECT_ARGUMENT);
isCollection = true;
} else {
argumentType = fieldArgument;
}
if (isInnerConfiguration(argumentType, context)) {
Qualifier qualifier = resolveQualifier(resolutionContext, fieldArgument, true);
if (isCollection) {
Collection beans = ((DefaultBeanContext) context).getBeansOfType(resolutionContext, argumentType, qualifier);
return coerceCollectionToCorrectType(fieldArgument.getType(), beans);
} else {
return ((DefaultBeanContext) context).getBean(resolutionContext, argumentType, qualifier);
}
} else {
String valString = resolvePropertyValueName(resolutionContext, injectionPoint, valueAnnVal, annotationMetadata);
ArgumentConversionContext conversionContext = ConversionContext.of(fieldArgument);
Optional value = resolveValue((ApplicationContext) context, conversionContext, valueAnnVal != null, valString);
if (argumentType.isOptional()) {
return resolveOptionalObject(value);
} else {
if (value.isPresent()) {
return value.get();
} else {
if (fieldArgument.isDeclaredNullable()) {
return null;
}
throw new DependencyInjectionException(resolutionContext, injectionPoint, "Error resolving field value [" + valString + "]. Property doesn't exist or cannot be converted");
}
}
}
} else {
throw new DependencyInjectionException(resolutionContext, injectionPoint, "@Value requires a BeanContext that implements PropertyResolver");
}
} finally {
path.pop();
}
}
Aggregations