Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jun 26 2017 20:07
    @remmeier banned @hibaymj
Remo
@remmeier
@0-Tikaro not as of yet with the built-in filtering. but new FilterOperator can be defined to adress it
Romain LE BARO
@scandinave
HI, I try to integrate CRNK with Spring Boot and Keycloak. My goal is to define authorizations inside keycloak and have CRNK to filter resources base on it. My approache consist of let the keycloak adapter to handle resources filtering and use CRKN to handle field-based and data-bases authorizations. Is it the best approaches? And how can i get the Keycloak token that contains user scopes and use it inside CRNK?
Remo
@remmeier
seems good. if you need access to http header or other thing, spring (boot) means like auto wiring should be om I think? nothing needed on crnk side? HttpRequestContextAware is the crnk mechanism to access headers
Romain LE BARO
@scandinave
I have some doubts with how implement security with CRNK. Another possibility i have, is to retrieve user scope and map it with CRNK security. But i dont know where to define this mapping that need to be process on each request :
Resource-based authorization: Don't know where ?

Field-based authorization: Implementing ResourceFilter as Spring @Component?

Data-based authorization: Inside SecurityConfigurer.config.setDataRoomFilter?
Remo
@remmeier
typically one sets up Spring Security. This will hook into the servlet engine. And crnk can just make use of HttpServletRequest.isUserInRole (built-in default). All that then has to be implemented manually is a SecurityConfigurer that will setup the mapping of Roles to actual resource authorizations (and potentially further dataroom one).
Romain LE BARO
@scandinave
If i do it with isUserInRole my application roles will be hardcoded inside the application and will need a rebuild/redeploy of the app if a role is added no? I need something more dynamic where scope are retrieve from the jwt provided by keycloak (I know how to do that ) and map with the crnk authorizations/querySpec .
Remo
@remmeier
adding a new role usually means changing the application itself, not? whereas adding/removing roles for users (and pass along with JWTs) is quite common. or does it work diffferently in your case?
duncanportelli
@duncanportelli
@remmeier when creating a resource, the JSON:API spec that multiple response codes are supported (https://jsonapi.org/format/#crud-creating-responses). I have a case where I want to return a 202 Accepted instead of a 201 Created. Is this supported with the current functionality in Crnk please?
maarten-cb
@maarten-cb

Hi! Has anyone been able to get an OR filter to work with relationships?
When I filter on two attributes, it works fine and I get results that match both conditions:

/things/thing?filter={
    "OR": [
        {"unassigned": true},
        {"active": true}
    ]
}

But when I add a relationships to the filter, it only returns the records matching the relationship condition. I can have a thousand unassigned records without an assignee relationship, but it will not return them.

/things/thing?filter={
    "OR": [
        {"unassigned": true},
        {"assignee": {"user_id": "13d012e6-57ae-11e9-8647-d663bd873d93"}}
    ]
}

Is there a trick to this, a workaround perhaps? I'm on crnk 3.3

@maarten-cb what kind of repository are you using? maybe jpa where inner joins could be an issue?
maarten-cb
@maarten-cb
@remmeier That's right! I'll log the query and see what's going on there. Thanks.
duncanportelli
@duncanportelli
Thanks @remmeier
maarten-cb
@maarten-cb
@remmeier You were correct. It's doing an inner join on assignees, which eliminates the chance of any records without an assignee relationship to be included. I'm not sure how to influence the query to make it a left join. Any ideas?
Romain LE BARO
@scandinave
@Remo yeah, in my case the role and it's authorisations are provided by a authorisations server ( keycloak ) and can be change without having to rebuild the application. I think I have found a way to do this by exploiting permissions inside token and map it with crkn resource and field filters.
Remo
@remmeier
@maarten-cb I think the jpa repository, its config or the executor allows to change the default join type. potentially we should im prove the strategy and automatically go to outer join for some use cases. this is actually already happening for sorting.
@scandinave if you think you need more flexibility, you can have a closer look at the security module. i thin it already allows reconfiguration at runtime. beyond that there is also the possibility to go a layer deeper and buld an own one. the basic filter api is quite generic and then security module is more of a reasonable default i would say.
Jochen Reinhardt
@JochenReinhardt
I have trouble with HTTP authentication.
I always get a 401, then a subsequent request with credentials included, is OK.
this means the client sends every request twice which is a performance penalty and causes extra-load on the server.
I learned today, that using a client context with the apache http client makes the extra requests disappear.
How would I add a context to the crnk client?
Jochen Reinhardt
@JochenReinhardt

In io.crnk.client.http.apache.HttpClientRequest, the request is executed without HTTP-Context.

@Override
    public HttpAdapterResponse execute() throws IOException {
        listeners.stream().forEach(it -> it.onRequest(this));
        HttpClientResponse response = new HttpClientResponse(impl.execute(requestBase));
        listeners.stream().forEach(it -> it.onResponse(this, response));
        return response;
    }

Is it a viable option to subclass HttpClientRequest and HttpClientAdapter in order to get an invocation with the same HttpContext every time?

maarten-cb
@maarten-cb
@remmeier I made a wrapper for JpaQueryFactory that allows the default JoinType to be overridden. It works! Thanks for your help.
duncanportelli
@duncanportelli
Good morning. I am looking to implement a custom way to return a different HTTP status code upon creating a resource based on the type of the resource. I managed to implement a custom HttpStatusBehavior which extends DefaultHttpStatusBehavior. I am trying to access the ResourceRegistry from within however even though I am implementing the ResourceRegistryAware, the ResourceRegistry is still not being set. Any ideas on how this can be achieved please?
Remo
@remmeier
@JochenReinhardt who is setting the necessary HTTP headers? Shouldnt they be set before making the first request?
@duncanportelli if you make use of spring boot or something similar, you can just inject it with the regular means. Otherwise a need of CrnkBoot/ModuleRegistry might be required to make sure ResourceRegistryAware is honored.
Sebastian Wyrazik
@swyrazik
Hi! Does Crnk support sorting by @Transient Entity fields? It doesn't seem to work out-of-the-box.
For example, I'd like to sort by the sum of two normal attributes.
Mikael Blomström
@mikaelblomstrom
Thank you @remmeier for approving crnk-project/crnk-framework#579 much appreciated!
Remo
@remmeier
thank you for the change! could you rebase to resolve the merge conflict?
@swyrazik what kind of support are you looking in for? in general no, as of yet, it is left to JPA.
Sebastian Wyrazik
@swyrazik

First I'm looking for a way to use transient fields as sort parameters, meaning that Crnk would accept them in the first place. It seems that only actual fields can be used for sorting, unless I'm missing something.

Then there is the problem of translating a transient field to its corresponding JPA query. I wasn't actually expecting that that would work without some kind of customization, but I was wondering if there is some way to tell Crnk how a field is supposed to be mapped to a JPA query. For example, having the following in an Entity:

@Transient
public int getTotal() {
    return a + b;
}

I would want to translate that into order by (o.a + o.b). Maybe Hibernate's @Formula could be used in this case.

Is there any way I could configure Crnk to allow any of the above? Any pointers on where I should look into, without having to modify the Crnk source code?

Martin
@EmDee

Hi there!

I'm trying to use crnk-gen to generate Java models and interfaces for my JSON:API schema.

I've followed the setup described in https://www.crnk.io/releases/stable/documentation/#_openapi, but run into a dependency problem with XML-doclet (https://github.com/MarkusBernhardt/xml-doclet). It complains about not being able to install that dependency, apparently because no repo has been defined.

I then downloaded the example app and added the plugin part in my gradle:

apply plugin: 'crnk-gen'
crnkGen {
    runtime {
        // Gradle classpath configuration to use
        configuration = 'runtime'
    }

    // fork generation into new process to have clean environment
    forked = true

    // specify the package to look for resources
    resourcePackages = ['io.crnk.test']

    openapi {
        // enable OpenAPI generation within Gradle plugin
        enabled = true

        // specify name of openapi template in the build dir to merge onto
        templateName = "openapi-template.yml"

        // specify name of API to display in the generated OpenAPI file
        projectName = "Generated Title"

        // specify version of the API to display in the generated OpenAPI file
        projectVersion = "0.1.0"

        // specify name of openapi template in the build dir to merge onto
        projectDescription = "A generated description of the API."

        // specify location of generated sources
        genDir = file('src/resources')
    }
}
crnkGen.init()

However, I'm getting a Failed to apply plugin [class 'io.crnk.gen.gradle.DocletPlugin'].

Questions:

  1. Does crnk-gen support my use case, i.e. passing a openapi.json scheme and let it generate interfaces and models?
  2. Has anyone ran into above mentioned error?
Martin
@EmDee
Ok, I think I figured out how it works and it is not intended as an OpenAPI code generator.
openapigenerator can be used to generate JSON:API documentation based off defined Crnk APIs and/or models, but can not create models and interfaces from a documentation.
kushal69
@kushal69
Hi,
Is there any example available on how to add headers to crnkClient request.
uhpotter
@uhpotter
Hi, I have a use case where I am intercepting the sql before execution, modifying the query (adding a custom where clause) and then sending it on. In the process, I discovered that when I'm hitting a CRNK endpoint to fetch all records /myResource, CRNK is executing 51 queries in the process of returning my data. A lot of the queries are duplicates of each other as well. Can anyone point me to good ways to help alleviate some of that query overhead and improve performance?
Rehab Reda
@rehab-reda0
Hi,how can I represent true/false in the nested filters
If I want to sayd FilerSpec.and(certainConditions)
and this certain conditions want to add true or false to one of the conditions without having a field name
Remo
@remmeier
@kushal69 yes, there is HttpAdapter with various implementations like for appache and okhttp. You may use that or directly the underlying implementation to add custom logic.
@rehab-reda0 what exactly are you looking for? can you make an example?
@uhpotter why are there that many queries? are there many inclusions? is it a default JPA repository? without inclusion there are typically one or two queries (data and maybe total count). In case you make use of the Jpa repository, you are free to build on top of that implementation, or even better, add a Repository decorator in front of it to do caching. But generally make sure you are not suffering from N+1 issues somewhere.
Remo
@remmeier
@swyrazik sorry, a late reply. you can always intercept and add custom logic to map the transient field to actual JPA fields (also with a decorator or custom implementation of the repository). But for the sake of simplicity I usually try to avoid this things when it comes to JPA. In many cases a DB View may suffice to let the DB take care of those things.
Stepenik
@stepenik

Hi everbody,
I am new in JsonApi and I see this great library crnk.

My question is where to put custom logic written in services.
In standard Spring Boot Rest Api we have controllers -> services -> repositories
but in JsonApi (crnk) we have resources and repositories.
Resources is controllers in standard Rest Api ?
Where I can put custom logic and how.

Remo
@remmeier
Custom logic is all in the repositories. The "lower-level plumbing" is being taken care of by JSON:API as standard and crnk as implementation. That should be fine for 98% of the use cases, and there are hooks for the other 2%.
3 replies
wulfcolin
@wulfcolin
Hi @remmeier can I have a JSONObject (i.e org.json.JSONObject) as attribute type?
Currently I can only use this if the API caller passes the attribute as string and then jackson will parse the json object from string. Is there any other option? Thanks!
2 replies
aroraKom
@aroraKom
Is there any way to generate swagger documentation for Spring boot maven project which is using crnk library
2 replies
kushal69
@kushal69
@remmeier thank you for the the reply. One more question - I am using crnk-gen-openapi lib to generate open api document in that i need to add headers (like Authorization) which we will be consuming at crnk. Can you please suggest on this ?
1 reply
Lasse Immonen
@turtleman

hello! wanting to ask about a PR and possible new releases coming out. the PR is this one: crnk-project/crnk-framework#793. how does it look, is it okay?

how about plans for a new release? anything projected at the moment?