请问如何在没有登录的情况下使用datamanager查询数据

我想在系统登录之前用dataManager去查询另外数据源的数据,发现没有权限?该如何设置才可行?

如何写的代码?出现的是什么错误?

RdbmStore的122行判断权限如下:

        if (isAuthorizationRequired(context) && !isEntityOpPermitted(metaClass, EntityOp.READ)) {
            log.debug("reading of {} not permitted, returning null", metaClass);
            return null;
        }

由于没有登录,所以没有实体的权限

你的代码对通过什么方式在登录前执行的?

在LoadContext找到了一个setAuthorizationRequired,试试看。之前用的FluentLoader上没有开放这个设置,建议也开放一下哦

用的dataManager.load

是不是需要用TrustedClientService 。类似这种:

    TrustedClientService trustedClientService = (TrustedClientService) AppBeans.get(TrustedClientService.NAME);
    UserSession systemSession = null;
    try{
        systemSession = trustedClientService.getSystemSession(AppBeans.get(Configuration.class).getConfig(WebAuthConfig.class).getTrustedClientPassword());
    }catch (LoginException e){
        logger.error("Unable to obtain system session", e);
    }
    AppContext.withSecurityContext(new SecurityContext(systemSession), () ->{
        ......
    });

https://www.cuba-platform.com/discuss/t/working-with-data-from-custom-spring-mvc-controller/9370/2

另外DataManager是带权限检查的,EntityManager不带。

谢谢,我设置了setAuthorizationRequired为false就解决了