使用Olingo和JPA进行授权 [英] Authorization Using Olingo and JPA

查看:122
本文介绍了使用Olingo和JPA进行授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将JPA和Olingo用于某些REST服务.我能够获得与我的实体相似的基本实现,类似于此处的示例: JPA Olingo Web应用程序.

但是,现在我试图在加入访问表的地方添加授权,然后相应地过滤结果.我只是想知道是否有一种不必重写默认行为的好方法.我在用于EDM的注释处理器中看到了注释处理器,但似乎不合适我们的模型很好.

我的问题是:是否有一种简单的方法可以更改Olingo JPA处理器以默认情况下联接表和过滤器实体以实现授权?这将要求我能够传递帐户进行过滤并限制所有结果.

我还尝试了此处所述的预处理和后处理. 自定义JPA处理器但是,过滤操作需要在查询中完成返回结果后,因为JPA查询将返回太多结果,并且转换成千上万的对象耗时又长.

到目前为止,我已经实现了CustomODataJPAProcessor.但是,这将要求我现在重写并重写org.apache.olingo.odata2.jpa.processor.core.access.data.JPAProcessorImpl#processmethod并使用所需的功能修改JPA查询.您会看到我实现了一个新的JPAProcessor,在其中调用process并发送我的帐户.这是我的CustomODataJPAProcessor的readEntitySet方法中的代码:

    /* Pre Process Step */
    preprocess( );
    List<String> accounts = new ArrayList<>();

    //This is what the original readEntitySet does
    //ODataJPAFactory.createFactory().getODataJPAAccessFactory().getODataJPAResponseBuilder(oDataJPAContext);

    //Using custom JPA Processor that I added
    jpaProcessor = new CustomJPAProcessor(this.oDataJPAContext);
    CustomJPAProcessor customJPAProcessor = (CustomJPAProcessor)jpaProcessor;
    List<Object> jpaEntities = customJPAProcessor.process(uriParserResultView, accounts);

    //What the docs want you to do http://olingo.apache.org/doc/odata2/tutorials/CustomODataJPAProcessor.html
    //java.util.List<Object> jpaEntities = jpaProcessor.process(uriParserResultView);

   /* Post Process Step */
    postProcess( );

解决方案

我不知道您是否还在为此工作. 我现在正在解决这个问题. Olingo提供了ODataJPAQueryExtensionEntityListener,此侦听器由JPAQueryBuilder执行,在执行buildQuery之前的第一步.

使用此无状态侦听器,您可以替换buildQuery方法,以便访问和更改包含JPQL查询的字符串jpqlStatement.toString().

我认为比原生SQL更好

再见 多梅尼科

I'm using JPA and Olingo for some REST services. I was able to get the basic implementation working with my entities similar to the example here: JPA Olingo Web App.

However Now I'm trying to add authorization where I join to access tables and then filter the results accordingly. I'm just wondering if there is a good way of doing this without having to override default behavior. I have seen the annotation processor here Annotation Processor for EDM but it doesn't seem to fit our model very well.

My question is this: Is there an easy way to change the Olingo JPA Processor to join tables and filter entities by default in order to implement authorization? This will require me to be able to pass in accounts to filter and also limit all results.

I have also tried pre-processing and post-processing as described here. Custom JPA Processor However, the filtering needs to be done in the query not after returning the results because the JPA query will return too many results and is long and costly to convert thousands of objects.

So far I've implemented a CustomODataJPAProcessor. However, it will require me to now rewrite and override the org.apache.olingo.odata2.jpa.processor.core.access.data.JPAProcessorImpl#processmethod and modify the JPA Query with my desired functionality. You'll see that I implemented a new JPAProcessor where I call process and send in my accounts. Here's what my code looks like in the readEntitySet method of my CustomODataJPAProcessor:

    /* Pre Process Step */
    preprocess( );
    List<String> accounts = new ArrayList<>();

    //This is what the original readEntitySet does
    //ODataJPAFactory.createFactory().getODataJPAAccessFactory().getODataJPAResponseBuilder(oDataJPAContext);

    //Using custom JPA Processor that I added
    jpaProcessor = new CustomJPAProcessor(this.oDataJPAContext);
    CustomJPAProcessor customJPAProcessor = (CustomJPAProcessor)jpaProcessor;
    List<Object> jpaEntities = customJPAProcessor.process(uriParserResultView, accounts);

    //What the docs want you to do http://olingo.apache.org/doc/odata2/tutorials/CustomODataJPAProcessor.html
    //java.util.List<Object> jpaEntities = jpaProcessor.process(uriParserResultView);

   /* Post Process Step */
    postProcess( );

解决方案

I do not know if you are stil working on it. I am working on this problem right now. Olingo provide the ODataJPAQueryExtensionEntityListener this listener is execute by JPAQueryBuilder one step before the execution of the buildQuery.

With this stateless listener you can replace the buildQuery methods so you can access and change the string jpqlStatement.toString() that contain the JPQL query.

I think is better then the native SQL

bye Domenico

这篇关于使用Olingo和JPA进行授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆