Skip to content

Commit

Permalink
Defining endpoint security through JDL
Browse files Browse the repository at this point in the history
This commit introduces a role-based security feature for the backend, allowing users to define security configurations using JDL clauses. Security can now be specified directly within JDL for various entities, where different roles with specified permissions are mapped to the corresponding Java entity resource files. This mapping auto-generates the requisite `@Secured({})` annotations on the endpoints, ensuring the right level of access control based on roles. Examples of the JDL security clauses include:
```
  secure entity1, entity2, entity3 with roles {
    ROLE_ADMIN allows (get, post, put, delete)
    ROLE_USER allows (get)
  }
```
and
```
  secure all except entity3 with roles {
    ROLE_ADMIN allows (get, post, put, delete)
    ROLE_USER allows (get)
  }
```
which would translate to `@Secured({ "ROLE_ADMIN" })` annotations in the generated Java code for specified endpoints. Additionally, the integration tests have been updated to consider these role-based security configurations.

Moreover, the groundwork for supporting other security types has been laid down through the inclusion of grammar and parser definitions. These additional security types encompass privilege security, organizational security, parent based security, and relation based security, although the code generators for these types are not included in this commit.

Resolves jhipster#19201
  • Loading branch information
SpiralUp committed Oct 4, 2023
1 parent 97f3f90 commit 927949c
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions test-integration/samples/jdl-entities/app-roles-security.jdl
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,8 @@ paginate Operation, JobHistory, Employee with infinite-scroll

service TheLabel, Employee, Department, Region with serviceClass
service BankAccount, Location, Country with serviceImpl
secure all except Country, Region with roles {
secure all with roles {
ROLE_ADMIN allows (get, put, post, delete)
ROLE_USER allows (get, put, post, delete)
}
secure Country,Region with roles {
ROLE_ADMIN allows (get, put, post, delete)
ROLE_USER allows ()
}

0 comments on commit 927949c

Please sign in to comment.