- Обобщите проблему
Я хочу использовать orika для сопоставления bean-компонента java, и я создаю фильтр orika, код:
@Slf4j
@Configuration
public class OrikaMapperConfig implements ApplicationContextAware {
@Bean
public MapperFactory init(ApplicationContext applicationContext) {
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
mapperFactory.registerFilter(new CustomFilter<Object, Object>() {
@Override
public boolean filtersSource() {
return true;
}
@Override
public boolean filtersDestination() {
return true;
}
@Override
public <S, D> boolean shouldMap(Type<S> sourceType, String sourceName, S source, Type<D> destType, String destName, D dest, MappingContext mappingContext) {
return true;
}
@Override
public <D> D filterDestination(D destinationValue, Type<?> sourceType, String sourceName, Type<D> destType, String destName, MappingContext mappingContext) {
//how to get login User here with springfluxsecurity?
//I want to modify the destinationValue dynamic with login user role
return destinationValue;
}
@Override
public <S> S filterSource(S sourceValue, Type<S> sourceType, String sourceName, Type<?> destType, String destName, MappingContext mappingContext) {
return sourceValue;
}
});
Map<String, IMapper> mappers = applicationContext.getBeansOfType(IMapper.class);
mappers.forEach((key, iMapper) -> iMapper.register(mapperFactory));
return mapperFactory;
}
@Bean
public MapperFacade mapperFacade(MapperFactory mapperFactory) {
return mapperFactory.getMapperFacade();
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
init(applicationContext);
}
}
Опишите, что вы пробовали
методом filterDestination
Я пытаюсь использовать
ReactiveSecurityContextHolder.getContext().map(context -> (User) context.getAuthentication().getPrincipal()).block()
, чтобы получить пользователя для входа, но получаю сообщение об ошибке
java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-tcp-nio-4
Вопрос: Я хочу знать, как это исправить, спасибо за ответ.