use of java.beans.IntrospectionException in project CzechIdMng by bcvsolutions.
the class IdentityMonitoredFieldsProcessor method process.
@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
List<String> fields = getCommaSeparatedValues((String) this.getConfigurationMap().get(PROPERTY_MONITORED_FIELDS));
String recipientsRole = (String) this.getConfigurationMap().get(PROPERTY_RECIPIENTS_ROLE);
if (CollectionUtils.isEmpty(fields)) {
LOG.debug("None monitored fields found in configuration.");
return new DefaultEventResult<>(event, this);
}
List<IdmIdentityDto> recipients = service.findAllByRoleName(recipientsRole);
if (CollectionUtils.isEmpty(recipients)) {
LOG.debug("None recievers found in configuration.");
return new DefaultEventResult<>(event, this);
}
IdmIdentityDto newIdentity = event.getContent();
IdmIdentityDto identity = event.getOriginalSource();
List<ChangedField> changedFields = new ArrayList<>();
// Check monitored fields on some changes
fields.forEach(field -> {
try {
Object value = EntityUtils.getEntityValue(identity, field);
Object newValue = EntityUtils.getEntityValue(newIdentity, field);
if (value == null && newValue == null) {
return;
}
if (value != null && !value.equals(newValue)) {
changedFields.add(new ChangedField(field, value.toString(), newValue == null ? null : newValue.toString()));
return;
}
if (newValue != null && !newValue.equals(value)) {
changedFields.add(new ChangedField(field, value == null ? null : value.toString(), newValue.toString()));
return;
}
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | IntrospectionException e) {
throw new ResultCodeException(CoreResultCode.BAD_REQUEST, e);
}
});
if (!changedFields.isEmpty()) {
IdmMessageDto message = new IdmMessageDto.Builder(NotificationLevel.WARNING).addParameter("fullName", service.getNiceLabel(identity)).addParameter("identity", identity).addParameter("changedFields", changedFields).addParameter("url", configurationService.getFrontendUrl(String.format("identity/%s/profile", identity.getId()))).build();
notificationManager.send(String.format("core:%s", TOPIC), message, recipients);
}
return new DefaultEventResult<>(event, this);
}
use of java.beans.IntrospectionException in project CzechIdMng by bcvsolutions.
the class EntityUtils method setEntityValue.
/**
* Get value from given entity field.
* If is first parameter in write method String and value is not String, then will be value converted to String.
*
* @param entity
* @param propertyName
* @param value
* @return
* @throws IntrospectionException
* @throws IllegalAccessException
* @throws IllegalArgumentException
* @throws InvocationTargetException
*/
public static Object setEntityValue(Object entity, String propertyName, Object value) throws IntrospectionException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Optional<PropertyDescriptor> propertyDescriptionOptional = Arrays.asList(Introspector.getBeanInfo(entity.getClass()).getPropertyDescriptors()).stream().filter(propertyDescriptor -> {
return propertyName.equals(propertyDescriptor.getName());
}).findFirst();
if (!propertyDescriptionOptional.isPresent()) {
throw new IllegalAccessException("Field " + propertyName + " not found!");
}
PropertyDescriptor propertyDescriptor = propertyDescriptionOptional.get();
Class<?> parameterClass = propertyDescriptor.getWriteMethod().getParameterTypes()[0];
if (value != null && String.class.equals(parameterClass) && !(value instanceof String)) {
value = String.valueOf(value);
}
if (value != null && !parameterClass.isAssignableFrom(value.getClass()) && !(value.getClass().isPrimitive() || parameterClass.isPrimitive())) {
throw new IllegalAccessException(MessageFormat.format("Wrong type of value [{0}]. Value must be instance of [{1}] type, but has type [{2}]!", value, parameterClass, value.getClass()));
}
return propertyDescriptor.getWriteMethod().invoke(entity, value);
}
use of java.beans.IntrospectionException in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method fillEntity.
/**
* Fill entity with attributes from IC module (by mapped attributes).
*
* @param mappedAttributes
* @param uid
* @param icAttributes
* @param entity
* @param create
* (is create or update entity situation)
* @param context
* @return
*/
protected DTO fillEntity(List<SysSystemAttributeMappingDto> mappedAttributes, String uid, List<IcAttribute> icAttributes, DTO dto, boolean create, SynchronizationContext context) {
mappedAttributes.stream().filter(attribute -> {
// Skip disabled attributes
// Skip extended attributes (we need update/ create entity first)
// Skip confidential attributes (we need update/ create entity
// first)
boolean fastResult = !attribute.isDisabledAttribute() && attribute.isEntityAttribute() && !attribute.isConfidentialAttribute();
if (!fastResult) {
return false;
}
// Can be value set by attribute strategy?
return this.canSetValue(uid, attribute, dto, create);
}).forEach(attribute -> {
String attributeProperty = attribute.getIdmPropertyName();
Object transformedValue = getValueByMappedAttribute(attribute, icAttributes, context);
// Set transformed value from target system to entity
try {
EntityUtils.setEntityValue(dto, attributeProperty, transformedValue);
} catch (IntrospectionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | ProvisioningException e) {
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IDM_FIELD_NOT_SET, ImmutableMap.of("property", attributeProperty, "uid", uid), e);
}
});
return dto;
}
use of java.beans.IntrospectionException in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemAttributeMappingService method getAttributeValue.
/**
* Find value for this mapped attribute by property name. Returned value can be list of objects. Returns transformed value.
*
* @param uid - Account identifier
* @param entity
* @param attributeHandling
* @param idmValue
* @return
* @throws IntrospectionException
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
@Override
public Object getAttributeValue(String uid, AbstractDto entity, AttributeMapping attributeHandling) {
Object idmValue = null;
//
SysSchemaAttributeDto schemaAttributeDto = getSchemaAttribute(attributeHandling);
//
if (attributeHandling.isExtendedAttribute() && entity != null && formService.isFormable(entity.getClass())) {
List<IdmFormValueDto> formValues = formService.getValues(entity, attributeHandling.getIdmPropertyName());
if (formValues.isEmpty()) {
idmValue = null;
} else if (schemaAttributeDto.isMultivalued()) {
// Multiple value extended attribute
List<Object> values = new ArrayList<>();
formValues.stream().forEachOrdered(formValue -> {
values.add(formValue.getValue());
});
idmValue = values;
} else {
// Single value extended attribute
IdmFormValueDto formValue = formValues.get(0);
if (formValue.isConfidential()) {
Object confidentialValue = formService.getConfidentialPersistentValue(formValue);
// If is confidential value String and schema attribute is GuardedString type, then convert to GuardedString will be did.
if (confidentialValue instanceof String && schemaAttributeDto.getClassType().equals(GuardedString.class.getName())) {
idmValue = new GuardedString((String) confidentialValue);
} else {
idmValue = confidentialValue;
}
} else {
idmValue = formValue.getValue();
}
}
} else // Find value from entity
if (attributeHandling.isEntityAttribute()) {
if (attributeHandling.isConfidentialAttribute()) {
// If is attribute isConfidential, then we will find value in
// secured storage
idmValue = confidentialStorage.getGuardedString(entity.getId(), entity.getClass(), attributeHandling.getIdmPropertyName());
} else {
try {
// We will search value directly in entity by property name
idmValue = EntityUtils.getEntityValue(entity, attributeHandling.getIdmPropertyName());
} catch (IntrospectionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | ProvisioningException o_O) {
throw new ProvisioningException(AccResultCode.PROVISIONING_IDM_FIELD_NOT_FOUND, ImmutableMap.of("property", attributeHandling.getIdmPropertyName(), "entityType", entity.getClass()), o_O);
}
}
} else {
// If Attribute value is not in entity nor in extended attribute, then idmValue is null.
// It means attribute is static ... we will call transformation to resource.
}
return this.transformValueToResource(uid, idmValue, attributeHandling, entity);
}
use of java.beans.IntrospectionException in project CzechIdMng by bcvsolutions.
the class CzechIdMIcConvertUtil method convertIcConnectorConfiguration.
public static ConfigurationClass convertIcConnectorConfiguration(IcConnectorConfiguration configuration, Class<? extends ConfigurationClass> configurationClass) {
if (configuration == null || configuration.getConfigurationProperties() == null || configuration.getConfigurationProperties().getProperties() == null) {
return null;
}
List<IcConfigurationProperty> properties = configuration.getConfigurationProperties().getProperties();
try {
ConfigurationClass configurationClassInstance = configurationClass.newInstance();
PropertyDescriptor[] descriptors;
descriptors = Introspector.getBeanInfo(configurationClass).getPropertyDescriptors();
Lists.newArrayList(descriptors).stream().forEach(descriptor -> {
String propertyName = descriptor.getName();
Method writeMethod = descriptor.getWriteMethod();
IcConfigurationProperty propertyToConvert = properties.stream().filter(property -> propertyName.equals(property.getName())).findFirst().orElse(null);
if (propertyToConvert == null) {
return;
}
try {
writeMethod.invoke(configurationClassInstance, propertyToConvert.getValue());
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new IcException(e);
}
});
return configurationClassInstance;
} catch (IntrospectionException | InstantiationException | IllegalAccessException e) {
throw new IcException(e);
}
}
Aggregations