From 8e4a18091fc122b4ec81a99d461a393e686c01cd Mon Sep 17 00:00:00 2001 From: Marcelo Boveto Shima Date: Tue, 23 Jan 2024 12:27:23 -0300 Subject: [PATCH 1/2] generate authority domain and rest layers --- generators/app/README.md | 22 +- .../support/prepare-entity.ts | 4 + generators/base-application/types/entity.d.ts | 3 + .../bootstrap-application-base/utils.js | 6 +- .../bootstrap-application/generator.spec.ts | 9 + .../java/__snapshots__/generator.spec.ts.snap | 9 + .../domain/_persistClass_.java.jhi.ejs | 7 + .../domain/_persistClass_Test.java.ejs | 14 +- .../__snapshots__/generator.spec.js.snap | 12 ++ generators/server/files.js | 2 +- generators/server/generator.js | 7 + .../__snapshots__/needles.spec.ts.snap | 12 ++ .../web/rest/_entityClass_Resource.java.ejs | 62 +++++- .../java/_package_/domain/Authority.java.ejs | 143 ------------- .../web/rest/PublicUserResource.java.ejs | 9 - .../web/rest/_entityClass_ResourceIT.java.ejs | 16 +- .../web/rest/PublicUserResourceIT.java.ejs | 29 --- .../web/rest/UserResourceIT.java.ejs | 26 --- generators/server/types.d.ts | 2 + .../__snapshots__/generator.spec.ts.snap | 36 ++++ .../__snapshots__/generator.spec.ts.snap | 24 +++ .../__snapshots__/generator.spec.ts.snap | 36 ++++ .../__snapshots__/generator.spec.ts.snap | 36 ++++ ...rsistClass_.java.jhi.spring_data_neo4j.ejs | 4 +- .../__snapshots__/generator.spec.ts.snap | 195 ++++++++++++++++++ .../__snapshots__/sql-entities.spec.ts.snap | 48 +++++ ...lass_.java.jhi.spring_data_persistable.ejs | 2 +- 27 files changed, 549 insertions(+), 226 deletions(-) delete mode 100644 generators/server/templates/src/main/java/_package_/domain/Authority.java.ejs diff --git a/generators/app/README.md b/generators/app/README.md index ec988e69d4f3..3f02ffd35270 100644 --- a/generators/app/README.md +++ b/generators/app/README.md @@ -67,6 +67,26 @@ entity Company {} `female` variant is supported by `pt-br` locale. +##### Authority + +Secure the entity with the authority. + +``` +@EntityAuthority(ROLE_ADMIN) +@EntityReadAuthority(ROLE_USER) +entity Department {} +``` + +##### Admin Entity + +Declare the entity as an admin entity like User and Authority. +The entity is added to the admin menu and secured with ROLE_ADMIN authority. + +``` +@AdminEntity +entity Department {} +``` + ### Fields #### Notable customizations @@ -87,7 +107,7 @@ entity Company { ##### Label ```jdl -relationship ManyToOnly { +relationship ManyToOne { @RelationshipNameHumanized('Company user') Company{user} to User } ``` diff --git a/generators/base-application/support/prepare-entity.ts b/generators/base-application/support/prepare-entity.ts index 3c3ce3e66711..a3382fe4be52 100644 --- a/generators/base-application/support/prepare-entity.ts +++ b/generators/base-application/support/prepare-entity.ts @@ -74,6 +74,9 @@ const BASE_TEMPLATE_DATA = { existingEnum: false, searchEngine: NO_SEARCH_ENGINE, microserviceName: undefined, + entityAuthority: undefined, + entityReadAuthority: undefined, + adminEntity: undefined, requiresPersistableImplementation: false, updatableEntity: undefined, @@ -171,6 +174,7 @@ export default function prepareEntity(entityWithConfig, generator, application) entityInstance: lowerFirst(entityName), entityTableName: hibernateSnakeCase(entityName), entityNamePlural: pluralize(entityName), + entityAuthority: entityWithConfig.adminEntity ? 'ROLE_ADMIN' : undefined, }); const dto = entityWithConfig.dto && entityWithConfig.dto !== NO_DTO; diff --git a/generators/base-application/types/entity.d.ts b/generators/base-application/types/entity.d.ts index 0354a94c1181..6e2479b45e20 100644 --- a/generators/base-application/types/entity.d.ts +++ b/generators/base-application/types/entity.d.ts @@ -42,6 +42,9 @@ type Entity = Required & builtInUser?: boolean; builtInAuthority?: boolean; microserviceName?: string; + adminEntity?: boolean; + entityAuthority?: string; + entityReadAuthority?: string; entityNameCapitalized: string; entityClass: string; diff --git a/generators/bootstrap-application-base/utils.js b/generators/bootstrap-application-base/utils.js index 9eca185d0034..cfaaf2d98b02 100644 --- a/generators/bootstrap-application-base/utils.js +++ b/generators/bootstrap-application-base/utils.js @@ -120,7 +120,7 @@ export function createAuthorityEntity(customAuthorityData = {}, application) { name: authorityEntityName, entitySuffix: '', builtIn: true, - fluentMethods: false, + adminEntity: true, entityTableName: `${application.jhiTablePrefix}_authority`, relationships: [], fields: entityDefinition ? entityDefinition.fields || [] : [], @@ -130,9 +130,9 @@ export function createAuthorityEntity(customAuthorityData = {}, application) { service: 'no', dto: 'no', skipDbChangelog: true, - entityDomainLayer: false, + entityDomainLayer: application.backendTypeSpringBoot, entityPersistenceLayer: false, - entityRestLayer: false, + entityRestLayer: application.backendTypeSpringBoot, ...customAuthorityData, }; diff --git a/generators/bootstrap-application/generator.spec.ts b/generators/bootstrap-application/generator.spec.ts index fc7115767854..79749eb46aae 100644 --- a/generators/bootstrap-application/generator.spec.ts +++ b/generators/bootstrap-application/generator.spec.ts @@ -173,6 +173,7 @@ describe(`generator - ${generator}`, () => { expectedEntity(entity), ` { + "adminEntity": undefined, "adminUserDto": "AdminUserDTO", "allReferences": Any, "annotations": { @@ -222,6 +223,7 @@ describe(`generator - ${generator}`, () => { "entityApi": "", "entityApiDescription": undefined, "entityApiUrl": "users", + "entityAuthority": undefined, "entityClass": "User", "entityClassHumanized": "User", "entityClassPlural": "Users", @@ -246,6 +248,7 @@ describe(`generator - ${generator}`, () => { "entityPersistenceLayer": false, "entityPluralFileName": "usersundefined", "entityReactName": "User", + "entityReadAuthority": undefined, "entityRestLayer": false, "entitySearchLayer": false, "entityServiceFileName": "user", @@ -699,6 +702,7 @@ describe(`generator - ${generator}`, () => { expectedEntity(entity), ` { + "adminEntity": undefined, "allReferences": Any, "annotations": { "changelogDate": "20220129025419", @@ -743,6 +747,7 @@ describe(`generator - ${generator}`, () => { "entityApi": "", "entityApiDescription": undefined, "entityApiUrl": "entity-as", + "entityAuthority": undefined, "entityClass": "EntityA", "entityClassHumanized": "Entity A", "entityClassPlural": "EntityAS", @@ -765,6 +770,7 @@ describe(`generator - ${generator}`, () => { "entityParentPathAddition": "", "entityPluralFileName": "entity-asundefined", "entityReactName": "EntityA", + "entityReadAuthority": undefined, "entityServiceFileName": "entity-a", "entityStateName": "entity-a", "entitySuffix": "", @@ -1031,6 +1037,7 @@ describe(`generator - ${generator}`, () => { expectedEntity(entity), ` { + "adminEntity": undefined, "allReferences": Any, "annotations": { "changelogDate": "20220129025419", @@ -1075,6 +1082,7 @@ describe(`generator - ${generator}`, () => { "entityApi": "", "entityApiDescription": undefined, "entityApiUrl": "entity-as", + "entityAuthority": undefined, "entityClass": "EntityA", "entityClassHumanized": "Entity A", "entityClassPlural": "EntityAS", @@ -1097,6 +1105,7 @@ describe(`generator - ${generator}`, () => { "entityParentPathAddition": "", "entityPluralFileName": "entity-asundefined", "entityReactName": "EntityA", + "entityReadAuthority": undefined, "entityServiceFileName": "entity-a", "entityStateName": "entity-a", "entitySuffix": "", diff --git a/generators/java/__snapshots__/generator.spec.ts.snap b/generators/java/__snapshots__/generator.spec.ts.snap index 49f389117b89..019c71737ac6 100644 --- a/generators/java/__snapshots__/generator.spec.ts.snap +++ b/generators/java/__snapshots__/generator.spec.ts.snap @@ -14,6 +14,9 @@ exports[`generator - java with default config should match files snapshot 1`] = "src/main/java/com/mycompany/myapp/GeneratedByJHipster.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/myapp/domain/Authority.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/myapp/domain/Bar.java": { "stateCleared": "modified", }, @@ -32,6 +35,12 @@ exports[`generator - java with default config should match files snapshot 1`] = "src/main/java/com/mycompany/myapp/package-info.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/myapp/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/myapp/domain/BarTest.java": { "stateCleared": "modified", }, diff --git a/generators/java/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.ejs b/generators/java/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.ejs index dbf0efb31995..3582acd37fce 100644 --- a/generators/java/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.ejs +++ b/generators/java/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.ejs @@ -80,6 +80,9 @@ Object.keys(uniqueEnums).forEach(function(element) { _%> import <%= entityAbsolutePackage %>.domain.enumeration.<%= element %>; <%_ }); _%> +<%_ if (!updatableEntity) { _%> +import java.util.Objects; +<%_ } _%> <%_ for (const otherEntity of otherEntities.filter(otherEntity => otherEntity.entityPackage !== entityPackage)) { _%> import <%= otherEntity.entityAbsoluteClass %>; @@ -347,8 +350,12 @@ _%> @Override public int hashCode() { +<%_ if (updatableEntity) { _%> // see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/ return getClass().hashCode(); +<%_ } else { _%> + return Objects.hashCode(get<%= primaryKey.nameCapitalized %>()); +<%_ } _%> } // prettier-ignore diff --git a/generators/java/templates/src/test/java/_package_/_entityPackage_/domain/_persistClass_Test.java.ejs b/generators/java/templates/src/test/java/_package_/_entityPackage_/domain/_persistClass_Test.java.ejs index 3f859698a6ad..7201fea06bf2 100644 --- a/generators/java/templates/src/test/java/_package_/_entityPackage_/domain/_persistClass_Test.java.ejs +++ b/generators/java/templates/src/test/java/_package_/_entityPackage_/domain/_persistClass_Test.java.ejs @@ -48,8 +48,20 @@ class <%= persistClass %>Test { <%= persistInstance %>2 = get<%= persistClass %>Sample2(); assertThat(<%= persistInstance %>1).isNotEqualTo(<%= persistInstance %>2); -<%_} _%> +<%_ } _%> } +<%_if (!updatableEntity) { _%> + + @Test + void hashCodeVerifier() throws Exception { + <%= persistClass %> <%= persistInstance %> = new <%= persistClass %>(); + assertThat(<%= persistInstance %>.hashCode()).isZero(); + + <%= persistClass %> <%= persistInstance %>1 = get<%= persistClass %>Sample1(); + <%= persistInstance %>.set<%= primaryKey.nameCapitalized %>(<%= persistInstance %>1.get<%= primaryKey.nameCapitalized %>()); + assertThat(<%= persistInstance %>).hasSameHashCodeAs(<%= persistInstance %>1); + } +<%_ } _%> <%_ for (const relationship of relationships.filter(relationship => !relationship.otherEntity.builtIn)) { _%> @Test diff --git a/generators/server/__snapshots__/generator.spec.js.snap b/generators/server/__snapshots__/generator.spec.js.snap index c9c90b65f0ce..2c16f6d3aafe 100644 --- a/generators/server/__snapshots__/generator.spec.js.snap +++ b/generators/server/__snapshots__/generator.spec.js.snap @@ -965,6 +965,9 @@ exports[`generator - server with entities should match files snapshot 1`] = ` "src/main/java/com/mycompany/myapp/web/rest/AuthenticateController.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/myapp/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/myapp/web/rest/BarResource.java": { "stateCleared": "modified", }, @@ -1118,6 +1121,12 @@ exports[`generator - server with entities should match files snapshot 1`] = ` "src/test/java/com/mycompany/myapp/config/timezone/HibernateTimeZoneIT.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/myapp/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/myapp/domain/BarTest.java": { "stateCleared": "modified", }, @@ -1178,6 +1187,9 @@ exports[`generator - server with entities should match files snapshot 1`] = ` "src/test/java/com/mycompany/myapp/web/rest/AuthenticateControllerIT.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/myapp/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/myapp/web/rest/BarResourceIT.java": { "stateCleared": "modified", }, diff --git a/generators/server/files.js b/generators/server/files.js index bdce109c6621..73f44549f835 100644 --- a/generators/server/files.js +++ b/generators/server/files.js @@ -542,7 +542,7 @@ export const baseServerFiles = { condition: generator => generator.generateBuiltInAuthorityEntity, path: `${SERVER_MAIN_SRC_DIR}_package_/`, renameTo: moveToJavaPackageSrcDir, - templates: ['domain/Authority.java', 'repository/AuthorityRepository.java'], + templates: ['repository/AuthorityRepository.java'], }, { condition: generator => diff --git a/generators/server/generator.js b/generators/server/generator.js index 05b57a492001..b855fee07ba2 100644 --- a/generators/server/generator.js +++ b/generators/server/generator.js @@ -634,9 +634,16 @@ export default class JHipsterServerGenerator extends BaseApplicationGenerator { get preparingEachEntity() { return this.asPreparingEachEntityTaskGroup({ prepareEntity({ entity }) { + const hasAnyAuthority = authorities => + authorities.length > 0 ? `hasAnyAuthority(${authorities.map(auth => `'${auth}'`).join(',')})` : undefined; mutateData(entity, { entityPersistenceLayer: true, entityRestLayer: true, + entitySpringPreAuthorize: hasAnyAuthority(entity.entityAuthority?.split(',') ?? []), + entitySpringReadPreAuthorize: hasAnyAuthority([ + ...(entity.entityAuthority?.split(',') ?? []), + ...(entity.entityReadAuthority?.split(',') ?? []), + ]), }); }, }); diff --git a/generators/server/support/__snapshots__/needles.spec.ts.snap b/generators/server/support/__snapshots__/needles.spec.ts.snap index 9056441f215e..cdd8d18f3077 100644 --- a/generators/server/support/__snapshots__/needles.spec.ts.snap +++ b/generators/server/support/__snapshots__/needles.spec.ts.snap @@ -236,6 +236,9 @@ exports[`generator - server - support - needles generated project should match s "src/main/java/com/mycompany/myapp/web/rest/AuthenticateController.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/myapp/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/myapp/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -371,6 +374,12 @@ exports[`generator - server - support - needles generated project should match s "src/test/java/com/mycompany/myapp/config/timezone/HibernateTimeZoneIT.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/myapp/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/myapp/management/SecurityMetersServiceTests.java": { "stateCleared": "modified", }, @@ -416,6 +425,9 @@ exports[`generator - server - support - needles generated project should match s "src/test/java/com/mycompany/myapp/web/rest/AuthenticateControllerIT.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/myapp/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/myapp/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, diff --git a/generators/server/templates/src/main/java/_package_/_entityPackage_/web/rest/_entityClass_Resource.java.ejs b/generators/server/templates/src/main/java/_package_/_entityPackage_/web/rest/_entityClass_Resource.java.ejs index e65a659bfd61..7143ac5536ee 100644 --- a/generators/server/templates/src/main/java/_package_/_entityPackage_/web/rest/_entityClass_Resource.java.ejs +++ b/generators/server/templates/src/main/java/_package_/_entityPackage_/web/rest/_entityClass_Resource.java.ejs @@ -63,6 +63,9 @@ import tech.jhipster.web.util.<% if (reactive) { %>reactive.<% } %>ResponseUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; +<%_ if (entitySpringPreAuthorize) { _%> +import org.springframework.security.access.prepost.PreAuthorize; +<%_ } _%> <%_ if (!paginationNo) { _%> import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -164,11 +167,20 @@ public class <%= entityClass %>Resource { * @throws URISyntaxException if the Location URI syntax is incorrect. */ @PostMapping("") + <%_ if (entitySpringPreAuthorize) { _%> + @PreAuthorize("<%- entitySpringPreAuthorize %>") + <%_ } _%> public <% if (reactive) { %>Mono<<% } %>ResponseEntity<<%= instanceType %>><% if (reactive) { %>><% } %> create<%= entityClass %>(<% if (anyPropertyHasValidation) { %>@Valid <% } %>@RequestBody <%= instanceType %> <%= instanceName %>) throws URISyntaxException { log.debug("REST request to save <%= entityClass %> : {}", <%= instanceName %>); + <%_ if (primaryKey.autoGenerate) { _%> if (<%= instanceName %>.get<%= primaryKey.nameCapitalized %>() != null) { throw new BadRequestAlertException("A new <%= entityInstance %> cannot already have an ID", ENTITY_NAME, "idexists"); } + <%_ } else if (!reactive) { _%> + if (<%= entityInstance %>Repository.existsById(<%- instanceName %>.get<%= primaryKey.nameCapitalized %>())) { + throw new BadRequestAlertException("<%- entityInstance %> already exists", ENTITY_NAME, "idexists"); + } + <%_ } _%> <%_ if (isUsingMapsId) { _%> if (Objects.isNull(<%= instanceName %>.get<%= mapsIdAssoc.relationshipNameCapitalized %>())) { throw new BadRequestAlertException("Invalid association value provided", ENTITY_NAME, "null"); @@ -194,6 +206,14 @@ public class <%= entityClass %>Resource { <%= instanceName %>.set<%= field.fieldNameCapitalized %>(UUID.randomUUID()); <%_ } _%> <%_ } _%> + <%_ if (!primaryKey.autoGenerate && reactive) { _%> + return <%= entityInstance %>Repository + .existsById(<%- instanceName %>.get<%= primaryKey.nameCapitalized %>()) + .flatMap(exists -> { + if (exists) { + return Mono.error(new BadRequestAlertException("<%- entityInstance %> already exists", ENTITY_NAME, "idexists")); + } + <%_ } _%> <%_ if (serviceNo) { _%> <%- include('/_global_partials_entity_/save_template', {saveNewEntityOperation: true, returnDirectly: false}); -%> <%_ } _%> @@ -211,6 +231,9 @@ public class <%= entityClass %>Resource { throw new RuntimeException(e); } }); + <%_ if (!primaryKey.autoGenerate) { _%> + }); + <%_ } _%> <%_ } else { _%> <%_ if (!serviceNo) { _%> <%- restInstance %> = <%= entityInstance %>Service.save(<%= instanceName %>); @@ -234,6 +257,9 @@ public class <%= entityClass %>Resource { * @throws URISyntaxException if the Location URI syntax is incorrect. */ @PutMapping("/{<%= primaryKey.name %>}") + <%_ if (entitySpringPreAuthorize) { _%> + @PreAuthorize("<%- entitySpringPreAuthorize %>") + <%_ } _%> public <% if (reactive) { %>Mono<<% } %>ResponseEntity<<%= instanceType %>><% if (reactive) { %>><% } %> update<%= entityClass %>( @PathVariable(value = "<%= primaryKey.name %>", required = false) final <%= primaryKey.type %> <%= primaryKey.name %>, <% if (anyPropertyHasValidation) { %>@Valid <% } %>@RequestBody <%= restClass %> <%= restInstance %> @@ -247,10 +273,12 @@ public class <%= entityClass %>Resource { } <%_ if (reactive) { _%> - return <%= entityInstance %>Repository.existsById(<%= primaryKey.name %>).flatMap(exists -> { - if (!exists) { - return Mono.error(new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound")); - } + return <%= entityInstance %>Repository + .existsById(<%= primaryKey.name %>) + .flatMap(exists -> { + if (!exists) { + return Mono.error(new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound")); + } <%_ } else { _%> if (!<%= entityInstance %>Repository.existsById(<%= primaryKey.name %>)) { throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound"); @@ -309,9 +337,13 @@ public class <%= entityClass %>Resource { * @throws URISyntaxException if the Location URI syntax is incorrect. */ @PatchMapping(value = "/{<%= primaryKey.name %>}", consumes = {"application/json", "application/merge-patch+json"}) + <%_ if (entitySpringPreAuthorize) { _%> + @PreAuthorize("<%- entitySpringPreAuthorize %>") + <%_ } _%> public <% if (reactive) { %>Mono<<% } %>ResponseEntity<<%= instanceType %>><% if (reactive) { %>><% } %> partialUpdate<%= entityClass %>( - @PathVariable(value = "<%= primaryKey.name %>", required = false) final <%= primaryKey.type %> <%= primaryKey.name %>, - <% if (anyPropertyHasValidation) { %>@NotNull <% } %>@RequestBody <%= instanceType %> <%= instanceName %>) throws URISyntaxException { + @PathVariable(value = "<%= primaryKey.name %>", required = false) final <%= primaryKey.type %> <%= primaryKey.name %>, + <% if (anyPropertyHasValidation) { %>@NotNull <% } %>@RequestBody <%= instanceType %> <%= instanceName %> + ) throws URISyntaxException { log.debug("REST request to partial update <%= entityClass %> partially : {}, {}", <%= primaryKey.name %>, <%= instanceName %>); if (<%= instanceName %>.get<%= primaryKey.nameCapitalized %>() == null) { throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull"); @@ -392,6 +424,9 @@ public class <%= entityClass %>Resource { <%_ if (databaseTypeSql && isUsingMapsId && !viaService) { _%> @Transactional(readOnly = true) <%_ } _%> +<%_ if (entitySpringReadPreAuthorize) { _%> + @PreAuthorize("<%- entitySpringReadPreAuthorize %>") +<%_ } _%> <%- include('../../_partials_entity_/get_all_template', {viaService}); -%> <%_ if (!jpaMetamodelFiltering && reactive && paginationNo) { _%> @@ -403,6 +438,9 @@ public class <%= entityClass %>Resource { <%_ if (databaseTypeSql && isUsingMapsId && !viaService) { _%> @Transactional(readOnly = true) <%_ } _%> +<%_ if (entitySpringReadPreAuthorize) { _%> + @PreAuthorize("<%- entitySpringReadPreAuthorize %>") +<%_ } _%> public Flux<<%= instanceType %>> getAll<%= entityClassPlural %>AsStream() { log.debug("REST request to get all <%= entityClassPlural %> as a stream"); <%_ if (viaService) { _%> @@ -422,6 +460,9 @@ public class <%= entityClass %>Resource { @GetMapping("/{id}") <%_ if (databaseTypeSql && isUsingMapsId && !viaService) { _%> @Transactional(readOnly = true) +<%_ } _%> +<%_ if (entitySpringReadPreAuthorize) { _%> + @PreAuthorize("<%- entitySpringReadPreAuthorize %>") <%_ } _%> public <% if (reactive) { %>Mono<<% } %>ResponseEntity<<%= instanceType %>><% if (reactive) { %>><% } %> get<%= entityClass %>(@PathVariable("id") <%= primaryKey.type %> id) { log.debug("REST request to get <%= entityClass %> : {}", id);<%- include('../../_partials_entity_/get_template', {viaService, returnDirectly:false, implementsEagerLoadApis}); -%> @@ -436,6 +477,9 @@ public class <%= entityClass %>Resource { * @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}. */ @DeleteMapping("/{id}") + <%_ if (entitySpringPreAuthorize) { _%> + @PreAuthorize("<%- entitySpringPreAuthorize %>") + <%_ } _%> public <% if (reactive) { %>Mono<<% } %>ResponseEntity<% if (reactive) { %>><% } %> delete<%= entityClass %>(@PathVariable("id") <%= primaryKey.type %> id) { log.debug("REST request to delete <%= entityClass %> : {}", id); <%- include('../../_partials_entity_/delete_template', {viaService: viaService, fromResource: true}); -%> @@ -469,6 +513,10 @@ public class <%= entityClass %>Resource { <%_ } _%> * @return the result of the search. */ - @GetMapping("/_search")<%- include('../../_partials_entity_/search_template', {viaService}); -%> + @GetMapping("/_search") + <%_ if (entitySpringReadPreAuthorize) { _%> + @PreAuthorize("<%- entitySpringReadPreAuthorize %>") + <%_ } _%> +<%- include('../../_partials_entity_/search_template', {viaService}); -%> <%_ } _%> } diff --git a/generators/server/templates/src/main/java/_package_/domain/Authority.java.ejs b/generators/server/templates/src/main/java/_package_/domain/Authority.java.ejs deleted file mode 100644 index 533675621d33..000000000000 --- a/generators/server/templates/src/main/java/_package_/domain/Authority.java.ejs +++ /dev/null @@ -1,143 +0,0 @@ -<%# - Copyright 2013-2024 the original author or authors from the JHipster project. - - This file is part of the JHipster project, see https://www.jhipster.tech/ - for more information. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --%> -package <%= packageName %>.domain; - -<%_ if (enableHibernateCache) { _%> -import org.hibernate.annotations.Cache; -import org.hibernate.annotations.CacheConcurrencyStrategy; -<%_ } _%> -<%_ if (databaseTypeMongodb || databaseTypeCouchbase) { _%> -import org.springframework.data.annotation.Id; -import org.springframework.data.<%= databaseType %>.core.mapping.Document; -<%_ } _%> -<%_ if (databaseTypeCouchbase) { _%> -import org.springframework.data.annotation.TypeAlias; -import org.springframework.data.couchbase.repository.Collection; -import static <%= packageName %>.domain.Authority.TYPE_NAME; -<%_ } _%> -<%_ if (databaseTypeNeo4j) { _%> -import org.springframework.data.neo4j.core.schema.Id; -import org.springframework.data.neo4j.core.schema.Node; -<%_ } _%> -<%_ if (databaseTypeSql) { _%> - <%_ if (reactive) { _%> -import org.springframework.data.annotation.Id; -import org.springframework.data.domain.Persistable; -import org.springframework.data.relational.core.mapping.Table; - <%_ } else { _%> -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; -import jakarta.persistence.Column; - - <%_ } _%> -<%_ } _%> -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Size; -import java.io.Serializable; -import java.util.Objects; - -/** - * An authority (a security role) used by Spring Security. - */ -<%_ if (databaseTypeSql && !reactive) { _%> -@Entity -@Table(name = "<%= jhiTablePrefix %>_authority") - <%_ if (enableHibernateCache) { _%> - <%_ if (cacheProviderInfinispan) { _%> -@Cache(usage = CacheConcurrencyStrategy.READ_WRITE) - <%_ } else { _%> -@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) - <%_ } _%> - <%_ } _%> -<%_ } _%> -<%_ if (databaseTypeSql && reactive) { _%> -@Table("<%= jhiTablePrefix %>_authority") -<%_ } _%> -<%_ if (databaseTypeMongodb) { _%> -@Document(collection = "<%= jhiTablePrefix %>_authority") -<%_ } _%> -<%_ if (databaseTypeNeo4j) { _%> -@Node("<%= jhiTablePrefix %>_authority") -<%_ } _%> -<%_ if (databaseTypeCouchbase) { _%> -@Document -@TypeAlias(TYPE_NAME) -@Collection(TYPE_NAME) -<%_ } _%> -public class Authority implements Serializable<% if (databaseTypeSql && reactive) { %>, Persistable<% } %> { - - private static final long serialVersionUID = 1L; - -<%_ if (databaseTypeCouchbase) { _%> - public static final String TYPE_NAME = "authority"; -<%_ } _%> - - @NotNull - @Size(max = 50) - @Id -<%_ if (databaseTypeSql && !reactive) { _%> - @Column(length = 50) -<%_ } _%> - private String name; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof Authority)) { - return false; - } - return Objects.equals(name, ((Authority) o).name); - } - - @Override - public int hashCode() { - return Objects.hashCode(name); - } - - // prettier-ignore - @Override - public String toString() { - return "Authority{" + - "name='" + name + '\'' + - "}"; - } -<%_ if (databaseTypeSql && reactive) { _%> - - @Override - public String getId() { - return name; - } - - @Override - public boolean isNew() { - return true; - } -<%_ } _%> -} diff --git a/generators/server/templates/src/main/java/_package_/web/rest/PublicUserResource.java.ejs b/generators/server/templates/src/main/java/_package_/web/rest/PublicUserResource.java.ejs index c8e9321bb633..ea3e3a1f6348 100644 --- a/generators/server/templates/src/main/java/_package_/web/rest/PublicUserResource.java.ejs +++ b/generators/server/templates/src/main/java/_package_/web/rest/PublicUserResource.java.ejs @@ -156,15 +156,6 @@ public class PublicUserResource { } <%_ } _%> - /** - * Gets a list of all roles. - * @return a string list of all roles. - */ - @GetMapping("/authorities") - public <% if (reactive) { %>Mono><% } else { %>List<% } %> getAuthorities() { - return userService.getAuthorities()<% if (reactive) { %>.collectList()<% } %>; - } - <%_ } else { /* Cassandra */ _%> public <% if (reactive) { %>Flux<% } else { %>List<% } %><<%= user.dtoClass %>> getAllPublicUsers() { return userService.getAllPublicUsers(); diff --git a/generators/server/templates/src/test/java/_package_/_entityPackage_/web/rest/_entityClass_ResourceIT.java.ejs b/generators/server/templates/src/test/java/_package_/_entityPackage_/web/rest/_entityClass_ResourceIT.java.ejs index e8cb11573ad5..f1db55b5a25a 100644 --- a/generators/server/templates/src/test/java/_package_/_entityPackage_/web/rest/_entityClass_ResourceIT.java.ejs +++ b/generators/server/templates/src/test/java/_package_/_entityPackage_/web/rest/_entityClass_ResourceIT.java.ejs @@ -260,7 +260,7 @@ import <%= entityAbsolutePackage %>.domain.enumeration.<%= field.fieldType %>; <%_ } else { _%> @AutoConfigureMockMvc <%_ } _%> -@WithMockUser +@WithMockUser<% if (entityAuthority) { %>(authorities = {"<%- entityAuthority %>"})<% } %> class <%= entityClass %>ResourceIT { <%_ for (field of fieldsToTest) { @@ -512,9 +512,14 @@ filterTestableRelationships.forEach((relationship) => { _%> */ public static <%= persistClass %> create<% if (fieldStatus === 'UPDATED_') { _%>Updated<%_ } %>Entity(<% if (databaseTypeSql) { %>EntityManager em<% } %>) { <%_ if (fluentMethods) { _%> - <%= persistClass %> <%= persistInstance %> = new <%= persistClass %>()<%_ if (reactive && databaseTypeSql && primaryKey.typeUUID && !isUsingMapsId) { _%> + <%= persistClass %> <%= persistInstance %> = new <%= persistClass %>() + <%_ if (reactive && databaseTypeSql && primaryKey.typeUUID && !isUsingMapsId) { _%> .<%= primaryKey.name %>(UUID.randomUUID()) - <%_ } _%><% for (field of fieldsToTest) { %> + <%_ } _%> + <%_ if (primaryKey.typeString && !isUsingMapsId && !primaryKey.autoGenerate) { _%> + .<%= primaryKey.name %>(UUID.randomUUID().toString()) + <%_ } _%> + <% for (field of fieldsToTest) { %> .<%= field.fieldName %>(<%= fieldStatus + field.fieldNameUnderscored.toUpperCase() %>)<% if (field.fieldTypeBinary && !field.blobContentTypeText) { %> .<%= field.fieldName %>ContentType(<%= fieldStatus + field.fieldNameUnderscored.toUpperCase() %>_CONTENT_TYPE)<% } %><% } %>; <%_ } else { _%> @@ -522,6 +527,9 @@ filterTestableRelationships.forEach((relationship) => { _%> <%_ if (reactive && databaseTypeSql && primaryKey.typeUUID && !isUsingMapsId) { _%> <%= persistInstance %>.set<%= primaryKey.fields[0].fieldInJavaBeanMethod %>(UUID.randomUUID()); <%_ } _%> + <%_ if (primaryKey.typeString && !isUsingMapsId && !primaryKey.autoGenerate) { _%> + <%= persistInstance %>.set<%= primaryKey.fields[0].fieldInJavaBeanMethod %>(UUID.randomUUID().toString()); + <%_ } _%> <%_ for (field of fieldsToTest) { _%> <%= persistInstance %>.set<%= field.fieldInJavaBeanMethod %>(<%= fieldStatus + field.fieldNameUnderscored.toUpperCase() %>); <%_ if (field.fieldTypeBinary && !field.blobContentTypeText) { _%> @@ -703,7 +711,7 @@ _%> @Test<%= transactionalAnnotation %> void create<%= entityClass %>WithExistingId() throws Exception { // Create the <%= entityClass %> with an existing ID - <%_ if (primaryKey.typeUUID && databaseTypeSql) { _%> + <%_ if ((primaryKey.typeUUID && databaseTypeSql) || !primaryKey.autoGenerate) { _%> <%= entityInstance %>Repository.<%= saveMethod %>(<%= persistInstance %>)<%= callBlock %>; <%_ } else { _%> <%= persistInstance %>.set<%= primaryKey.nameCapitalized %>(<% if (primaryKey.typeUUID) { %>UUID.randomUUID()<% } else if (primaryKey.typeLong) { %>1L<% } else if (primaryKey.typeInteger) { %>1<% } else { %>"existing_id"<% } %>); diff --git a/generators/server/templates/src/test/java/_package_/web/rest/PublicUserResourceIT.java.ejs b/generators/server/templates/src/test/java/_package_/web/rest/PublicUserResourceIT.java.ejs index 426721615493..3dc29ec2855c 100644 --- a/generators/server/templates/src/test/java/_package_/web/rest/PublicUserResourceIT.java.ejs +++ b/generators/server/templates/src/test/java/_package_/web/rest/PublicUserResourceIT.java.ejs @@ -203,35 +203,6 @@ class PublicUserResourceIT { <% } _%> } -<%_ if ((databaseTypeSql || databaseTypeMongodb || databaseTypeNeo4j || databaseTypeCouchbase) - && (!(authenticationTypeOauth2 && applicationTypeMicroservice))) { _%> - @Test - <%_ if (databaseTypeSql && !reactive) { _%> - @Transactional - <%_ } _%> - void getAllAuthorities()<% if (!reactive) { %> throws Exception<% } %> { - <%_ if (reactive) { _%> - webTestClient.get().uri("/api/authorities") - .accept(MediaType.APPLICATION_JSON) - .exchange() - .expectStatus().isOk() - .expectHeader().contentType(MediaType.APPLICATION_JSON_VALUE) - .expectBody() - .jsonPath("$").isArray() - .jsonPath("$[?(@=='" + AuthoritiesConstants.ADMIN + "')]").hasJsonPath() - .jsonPath("$[?(@=='" + AuthoritiesConstants.USER + "')]").hasJsonPath(); - <%_ } else { _%> - restUserMockMvc.perform(get("/api/authorities") - .accept(MediaType.APPLICATION_JSON) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) - .andExpect(jsonPath("$").isArray()) - .andExpect(jsonPath("$").value(hasItems(AuthoritiesConstants.USER, AuthoritiesConstants.ADMIN))); - <%_ } _%> - } -<%_ } _%> - <%_ if (databaseTypeSql && !authenticationTypeOauth2) { _%> @Test <%_ if (!reactive) { _%> diff --git a/generators/server/templates/src/test/java/_package_/web/rest/UserResourceIT.java.ejs b/generators/server/templates/src/test/java/_package_/web/rest/UserResourceIT.java.ejs index 7b25be38d94c..fc218d92c801 100644 --- a/generators/server/templates/src/test/java/_package_/web/rest/UserResourceIT.java.ejs +++ b/generators/server/templates/src/test/java/_package_/web/rest/UserResourceIT.java.ejs @@ -1025,32 +1025,6 @@ class UserResourceIT { assertThat(userDTO.getAuthorities()).containsExactly(AuthoritiesConstants.USER); assertThat(userDTO.toString()).isNotNull(); } -<%_ if (databaseTypeSql || databaseTypeMongodb || databaseTypeNeo4j) { _%> - - @Test - void testAuthorityEquals() { - Authority authorityA = new Authority(); - assertThat(authorityA) - .isNotEqualTo(null) - .isNotEqualTo(new Object()); - assertThat(authorityA.hashCode()).isZero(); - assertThat(authorityA.toString()).isNotNull(); - - Authority authorityB = new Authority(); - assertThat(authorityA).isEqualTo(authorityB); - - authorityB.setName(AuthoritiesConstants.ADMIN); - assertThat(authorityA).isNotEqualTo(authorityB); - - authorityA.setName(AuthoritiesConstants.USER); - assertThat(authorityA).isNotEqualTo(authorityB); - - authorityB.setName(AuthoritiesConstants.USER); - assertThat(authorityA) - .isEqualTo(authorityB) - .hasSameHashCodeAs(authorityB); - } -<%_ } _%> private void assertPersistedUsers(Consumer>> userAssertion) { <%_ if (databaseTypeCouchbase) { _%> diff --git a/generators/server/types.d.ts b/generators/server/types.d.ts index ed22facf3e3a..ed533ea3e8d9 100644 --- a/generators/server/types.d.ts +++ b/generators/server/types.d.ts @@ -13,6 +13,8 @@ export type SpringEntity = { entityPersistenceLayer?: boolean; /* Generate entity's Rest Api */ entityRestLayer?: boolean; + entitySpringPreAuthorize?: string; + entitySpringReadPreAuthorize?: string; }; export type SpringBootSourceType = GradleSourceType & diff --git a/generators/spring-data-couchbase/__snapshots__/generator.spec.ts.snap b/generators/spring-data-couchbase/__snapshots__/generator.spec.ts.snap index b237deb0072b..f6693895556b 100644 --- a/generators/spring-data-couchbase/__snapshots__/generator.spec.ts.snap +++ b/generators/spring-data-couchbase/__snapshots__/generator.spec.ts.snap @@ -254,6 +254,9 @@ exports[`generator - couchbase gateway-jwt-gradle-enableTranslation(true)-com.my "src/main/java/com/mycompany/web/rest/AuthenticateController.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -398,6 +401,12 @@ exports[`generator - couchbase gateway-jwt-gradle-enableTranslation(true)-com.my "src/test/java/com/mycompany/domain/AnotherSimpleTestSamples.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/domain/SimpleTest.java": { "stateCleared": "modified", }, @@ -458,6 +467,9 @@ exports[`generator - couchbase gateway-jwt-gradle-enableTranslation(true)-com.my "src/test/java/com/mycompany/web/rest/AuthenticateControllerIT.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, @@ -1753,6 +1765,9 @@ exports[`generator - couchbase monolith-jwt-reactive(false)-maven-enableTranslat "src/main/java/tech/jhipster/web/rest/AuthenticateController.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -1906,6 +1921,12 @@ exports[`generator - couchbase monolith-jwt-reactive(false)-maven-enableTranslat "src/test/java/tech/jhipster/domain/AnotherSimpleEntityTestSamples.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/tech/jhipster/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/domain/SimpleEntityTest.java": { "stateCleared": "modified", }, @@ -1960,6 +1981,9 @@ exports[`generator - couchbase monolith-jwt-reactive(false)-maven-enableTranslat "src/test/java/tech/jhipster/web/rest/AuthenticateControllerIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, @@ -3363,6 +3387,9 @@ exports[`generator - couchbase monolith-session-reactive(false)-maven-enableTran "src/main/java/tech/jhipster/web/rest/AnotherSimpleResource.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -3507,6 +3534,12 @@ exports[`generator - couchbase monolith-session-reactive(false)-maven-enableTran "src/test/java/tech/jhipster/domain/AnotherSimpleEntityTestSamples.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/tech/jhipster/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/domain/SimpleEntityTest.java": { "stateCleared": "modified", }, @@ -3543,6 +3576,9 @@ exports[`generator - couchbase monolith-session-reactive(false)-maven-enableTran "src/test/java/tech/jhipster/web/rest/AnotherSimpleResourceIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, diff --git a/generators/spring-data-elasticsearch/__snapshots__/generator.spec.ts.snap b/generators/spring-data-elasticsearch/__snapshots__/generator.spec.ts.snap index 66ccd8e7491f..50fb0e98ff82 100644 --- a/generators/spring-data-elasticsearch/__snapshots__/generator.spec.ts.snap +++ b/generators/spring-data-elasticsearch/__snapshots__/generator.spec.ts.snap @@ -278,6 +278,9 @@ exports[`generator - elasticsearch gateway-jwt-gradle-enableTranslation(true)-co "src/main/java/com/mycompany/web/rest/AuthenticateController.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -410,6 +413,12 @@ exports[`generator - elasticsearch gateway-jwt-gradle-enableTranslation(true)-co "src/test/java/com/mycompany/domain/AnotherSimpleTestSamples.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/domain/SimpleTest.java": { "stateCleared": "modified", }, @@ -467,6 +476,9 @@ exports[`generator - elasticsearch gateway-jwt-gradle-enableTranslation(true)-co "src/test/java/com/mycompany/web/rest/AuthenticateControllerIT.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, @@ -3738,6 +3750,9 @@ exports[`generator - elasticsearch monolith-session-reactive(false)-maven-enable "src/main/java/tech/jhipster/web/rest/AnotherSimpleResource.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/web/rest/MicroserviceResource.java": { "stateCleared": "modified", }, @@ -3879,6 +3894,12 @@ exports[`generator - elasticsearch monolith-session-reactive(false)-maven-enable "src/test/java/tech/jhipster/domain/AnotherSimpleEntityTestSamples.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/tech/jhipster/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/domain/MicroserviceEntityTest.java": { "stateCleared": "modified", }, @@ -3921,6 +3942,9 @@ exports[`generator - elasticsearch monolith-session-reactive(false)-maven-enable "src/test/java/tech/jhipster/web/rest/AnotherSimpleResourceIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/web/rest/MicroserviceResourceIT.java": { "stateCleared": "modified", }, diff --git a/generators/spring-data-mongodb/__snapshots__/generator.spec.ts.snap b/generators/spring-data-mongodb/__snapshots__/generator.spec.ts.snap index 73399f73d98e..04b8dde41752 100644 --- a/generators/spring-data-mongodb/__snapshots__/generator.spec.ts.snap +++ b/generators/spring-data-mongodb/__snapshots__/generator.spec.ts.snap @@ -254,6 +254,9 @@ exports[`generator - mongodb gateway-jwt-gradle-enableTranslation(true)-com.myco "src/main/java/com/mycompany/web/rest/AuthenticateController.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -368,6 +371,12 @@ exports[`generator - mongodb gateway-jwt-gradle-enableTranslation(true)-com.myco "src/test/java/com/mycompany/domain/AnotherSimpleTestSamples.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/domain/SimpleTest.java": { "stateCleared": "modified", }, @@ -425,6 +434,9 @@ exports[`generator - mongodb gateway-jwt-gradle-enableTranslation(true)-com.myco "src/test/java/com/mycompany/web/rest/AuthenticateControllerIT.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, @@ -1684,6 +1696,9 @@ exports[`generator - mongodb monolith-jwt-reactive(false)-maven-enableTranslatio "src/main/java/tech/jhipster/web/rest/AuthenticateController.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -1813,6 +1828,12 @@ exports[`generator - mongodb monolith-jwt-reactive(false)-maven-enableTranslatio "src/test/java/tech/jhipster/domain/AnotherSimpleEntityTestSamples.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/tech/jhipster/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/domain/SimpleEntityTest.java": { "stateCleared": "modified", }, @@ -1867,6 +1888,9 @@ exports[`generator - mongodb monolith-jwt-reactive(false)-maven-enableTranslatio "src/test/java/tech/jhipster/web/rest/AuthenticateControllerIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, @@ -3222,6 +3246,9 @@ exports[`generator - mongodb monolith-session-reactive(false)-maven-enableTransl "src/main/java/tech/jhipster/web/rest/AnotherSimpleResource.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -3342,6 +3369,12 @@ exports[`generator - mongodb monolith-session-reactive(false)-maven-enableTransl "src/test/java/tech/jhipster/domain/AnotherSimpleEntityTestSamples.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/tech/jhipster/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/domain/SimpleEntityTest.java": { "stateCleared": "modified", }, @@ -3378,6 +3411,9 @@ exports[`generator - mongodb monolith-session-reactive(false)-maven-enableTransl "src/test/java/tech/jhipster/web/rest/AnotherSimpleResourceIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, diff --git a/generators/spring-data-neo4j/__snapshots__/generator.spec.ts.snap b/generators/spring-data-neo4j/__snapshots__/generator.spec.ts.snap index 37a5ca6a837b..782018676b11 100644 --- a/generators/spring-data-neo4j/__snapshots__/generator.spec.ts.snap +++ b/generators/spring-data-neo4j/__snapshots__/generator.spec.ts.snap @@ -254,6 +254,9 @@ exports[`generator - neo4j gateway-jwt-gradle-enableTranslation(true)-com.mycomp "src/main/java/com/mycompany/web/rest/AuthenticateController.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -374,6 +377,12 @@ exports[`generator - neo4j gateway-jwt-gradle-enableTranslation(true)-com.mycomp "src/test/java/com/mycompany/domain/AnotherSimpleTestSamples.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/domain/SimpleTest.java": { "stateCleared": "modified", }, @@ -431,6 +440,9 @@ exports[`generator - neo4j gateway-jwt-gradle-enableTranslation(true)-com.mycomp "src/test/java/com/mycompany/web/rest/AuthenticateControllerIT.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, @@ -1678,6 +1690,9 @@ exports[`generator - neo4j monolith-jwt-reactive(false)-maven-enableTranslation( "src/main/java/tech/jhipster/web/rest/AuthenticateController.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -1813,6 +1828,12 @@ exports[`generator - neo4j monolith-jwt-reactive(false)-maven-enableTranslation( "src/test/java/tech/jhipster/domain/AnotherSimpleEntityTestSamples.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/tech/jhipster/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/domain/SimpleEntityTest.java": { "stateCleared": "modified", }, @@ -1867,6 +1888,9 @@ exports[`generator - neo4j monolith-jwt-reactive(false)-maven-enableTranslation( "src/test/java/tech/jhipster/web/rest/AuthenticateControllerIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, @@ -3213,6 +3237,9 @@ exports[`generator - neo4j monolith-session-reactive(false)-maven-enableTranslat "src/main/java/tech/jhipster/web/rest/AnotherSimpleResource.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -3339,6 +3366,12 @@ exports[`generator - neo4j monolith-session-reactive(false)-maven-enableTranslat "src/test/java/tech/jhipster/domain/AnotherSimpleEntityTestSamples.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/tech/jhipster/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/domain/SimpleEntityTest.java": { "stateCleared": "modified", }, @@ -3375,6 +3408,9 @@ exports[`generator - neo4j monolith-session-reactive(false)-maven-enableTranslat "src/test/java/tech/jhipster/web/rest/AnotherSimpleResourceIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, diff --git a/generators/spring-data-neo4j/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.spring_data_neo4j.ejs b/generators/spring-data-neo4j/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.spring_data_neo4j.ejs index cc1d9b89eb71..adff9b25f15e 100644 --- a/generators/spring-data-neo4j/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.spring_data_neo4j.ejs +++ b/generators/spring-data-neo4j/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.spring_data_neo4j.ejs @@ -32,14 +32,16 @@ import org.springframework.data.neo4j.core.schema.Relationship; <&_ } -&> <&_ if (fragment.annotationSection) { -&> -@Node +@Node("<%- entityTableName %>") <&_ } -&> <%_ for (const field of fields) { _%> <&_ if (fragment.field<%- field.fieldNameCapitalized %>AnnotationSection) { -&> <%_ if (field.id && !embedded) { _%> @Id + <%_ if (field.autoGenerate) { _%> @GeneratedValue(UUIDStringGenerator.class) + <%_ } _%> <%_ } else { _%> @Property("<%=field.fieldNameUnderscored %>") <%_ } _%> diff --git a/generators/spring-data-relational/__snapshots__/generator.spec.ts.snap b/generators/spring-data-relational/__snapshots__/generator.spec.ts.snap index 6182433348d3..1e5f87399796 100644 --- a/generators/spring-data-relational/__snapshots__/generator.spec.ts.snap +++ b/generators/spring-data-relational/__snapshots__/generator.spec.ts.snap @@ -116,6 +116,9 @@ exports[`generator - sql gateway-jwt-mysql-gradle-enableTranslation(true)-com.my "src/main/java/com/mycompany/domain/Authority.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/domain/AuthorityCallback.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/domain/UserEntity.java": { "stateCleared": "modified", }, @@ -227,6 +230,9 @@ exports[`generator - sql gateway-jwt-mysql-gradle-enableTranslation(true)-com.my "src/main/java/com/mycompany/web/rest/AuthenticateController.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/web/rest/GatewayResource.java": { "stateCleared": "modified", }, @@ -350,6 +356,12 @@ exports[`generator - sql gateway-jwt-mysql-gradle-enableTranslation(true)-com.my "src/test/java/com/mycompany/config/SqlTestContainersSpringContextCustomizerFactory.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/management/SecurityMetersServiceTests.java": { "stateCleared": "modified", }, @@ -395,6 +407,9 @@ exports[`generator - sql gateway-jwt-mysql-gradle-enableTranslation(true)-com.my "src/test/java/com/mycompany/web/rest/AuthenticateControllerIT.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, @@ -568,6 +583,9 @@ exports[`generator - sql gateway-jwt-oracle-gradle-enableTranslation(true)-com.m "src/main/java/com/mycompany/domain/Authority.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/domain/AuthorityCallback.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/domain/UserEntity.java": { "stateCleared": "modified", }, @@ -679,6 +697,9 @@ exports[`generator - sql gateway-jwt-oracle-gradle-enableTranslation(true)-com.m "src/main/java/com/mycompany/web/rest/AuthenticateController.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/web/rest/GatewayResource.java": { "stateCleared": "modified", }, @@ -799,6 +820,12 @@ exports[`generator - sql gateway-jwt-oracle-gradle-enableTranslation(true)-com.m "src/test/java/com/mycompany/config/SqlTestContainersSpringContextCustomizerFactory.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/management/SecurityMetersServiceTests.java": { "stateCleared": "modified", }, @@ -844,6 +871,9 @@ exports[`generator - sql gateway-jwt-oracle-gradle-enableTranslation(true)-com.m "src/test/java/com/mycompany/web/rest/AuthenticateControllerIT.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, @@ -1014,6 +1044,9 @@ exports[`generator - sql gateway-jwt-postgresql-gradle-enableTranslation(true)-c "src/main/java/com/mycompany/domain/Authority.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/domain/AuthorityCallback.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/domain/UserEntity.java": { "stateCleared": "modified", }, @@ -1122,6 +1155,9 @@ exports[`generator - sql gateway-jwt-postgresql-gradle-enableTranslation(true)-c "src/main/java/com/mycompany/web/rest/AuthenticateController.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -1233,6 +1269,12 @@ exports[`generator - sql gateway-jwt-postgresql-gradle-enableTranslation(true)-c "src/test/java/com/mycompany/config/SqlTestContainersSpringContextCustomizerFactory.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/management/SecurityMetersServiceTests.java": { "stateCleared": "modified", }, @@ -1275,6 +1317,9 @@ exports[`generator - sql gateway-jwt-postgresql-gradle-enableTranslation(true)-c "src/test/java/com/mycompany/web/rest/AuthenticateControllerIT.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, @@ -1439,6 +1484,9 @@ exports[`generator - sql gateway-oauth2-mariadb-gradle-enableTranslation(true)-c "src/main/java/com/mycompany/domain/Authority.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/domain/AuthorityCallback.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/domain/UserEntity.java": { "stateCleared": "modified", }, @@ -1532,6 +1580,9 @@ exports[`generator - sql gateway-oauth2-mariadb-gradle-enableTranslation(true)-c "src/main/java/com/mycompany/web/rest/AuthInfoResource.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/web/rest/GatewayResource.java": { "stateCleared": "modified", }, @@ -1631,6 +1682,12 @@ exports[`generator - sql gateway-oauth2-mariadb-gradle-enableTranslation(true)-c "src/test/java/com/mycompany/config/TestSecurityConfiguration.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/security/SecurityUtilsUnitTest.java": { "stateCleared": "modified", }, @@ -1658,6 +1715,9 @@ exports[`generator - sql gateway-oauth2-mariadb-gradle-enableTranslation(true)-c "src/test/java/com/mycompany/web/rest/AccountResourceIT.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/web/rest/LogoutResourceIT.java": { "stateCleared": "modified", }, @@ -1819,6 +1879,9 @@ exports[`generator - sql gateway-oauth2-mssql-gradle-enableTranslation(true)-com "src/main/java/com/mycompany/domain/Authority.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/domain/AuthorityCallback.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/domain/UserEntity.java": { "stateCleared": "modified", }, @@ -1912,6 +1975,9 @@ exports[`generator - sql gateway-oauth2-mssql-gradle-enableTranslation(true)-com "src/main/java/com/mycompany/web/rest/AuthInfoResource.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/web/rest/GatewayResource.java": { "stateCleared": "modified", }, @@ -2011,6 +2077,12 @@ exports[`generator - sql gateway-oauth2-mssql-gradle-enableTranslation(true)-com "src/test/java/com/mycompany/config/TestSecurityConfiguration.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/security/SecurityUtilsUnitTest.java": { "stateCleared": "modified", }, @@ -2038,6 +2110,9 @@ exports[`generator - sql gateway-oauth2-mssql-gradle-enableTranslation(true)-com "src/test/java/com/mycompany/web/rest/AccountResourceIT.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/web/rest/LogoutResourceIT.java": { "stateCleared": "modified", }, @@ -6204,6 +6279,9 @@ exports[`generator - sql monolith-jwt-mariadb-reactive(false)-maven-enableTransl "src/main/java/tech/jhipster/web/rest/AuthenticateController.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -6327,6 +6405,12 @@ exports[`generator - sql monolith-jwt-mariadb-reactive(false)-maven-enableTransl "src/test/java/tech/jhipster/config/timezone/HibernateTimeZoneIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/tech/jhipster/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/management/SecurityMetersServiceTests.java": { "stateCleared": "modified", }, @@ -6372,6 +6456,9 @@ exports[`generator - sql monolith-jwt-mariadb-reactive(false)-maven-enableTransl "src/test/java/tech/jhipster/web/rest/AuthenticateControllerIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, @@ -6925,6 +7012,9 @@ exports[`generator - sql monolith-jwt-mssql-reactive(false)-maven-enableTranslat "src/main/java/tech/jhipster/web/rest/AuthenticateController.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -7054,6 +7144,12 @@ exports[`generator - sql monolith-jwt-mssql-reactive(false)-maven-enableTranslat "src/test/java/tech/jhipster/config/timezone/HibernateTimeZoneIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/tech/jhipster/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/management/SecurityMetersServiceTests.java": { "stateCleared": "modified", }, @@ -7099,6 +7195,9 @@ exports[`generator - sql monolith-jwt-mssql-reactive(false)-maven-enableTranslat "src/test/java/tech/jhipster/web/rest/AuthenticateControllerIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, @@ -7649,6 +7748,9 @@ exports[`generator - sql monolith-jwt-mysql-reactive(false)-maven-enableTranslat "src/main/java/tech/jhipster/web/rest/AuthenticateController.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -7778,6 +7880,12 @@ exports[`generator - sql monolith-jwt-mysql-reactive(false)-maven-enableTranslat "src/test/java/tech/jhipster/config/timezone/HibernateTimeZoneIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/tech/jhipster/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/management/SecurityMetersServiceTests.java": { "stateCleared": "modified", }, @@ -7823,6 +7931,9 @@ exports[`generator - sql monolith-jwt-mysql-reactive(false)-maven-enableTranslat "src/test/java/tech/jhipster/web/rest/AuthenticateControllerIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, @@ -8364,6 +8475,9 @@ exports[`generator - sql monolith-jwt-oracle-reactive(false)-maven-enableTransla "src/main/java/tech/jhipster/web/rest/AuthenticateController.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -8484,6 +8598,12 @@ exports[`generator - sql monolith-jwt-oracle-reactive(false)-maven-enableTransla "src/test/java/tech/jhipster/config/timezone/HibernateTimeZoneIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/tech/jhipster/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/management/SecurityMetersServiceTests.java": { "stateCleared": "modified", }, @@ -8529,6 +8649,9 @@ exports[`generator - sql monolith-jwt-oracle-reactive(false)-maven-enableTransla "src/test/java/tech/jhipster/web/rest/AuthenticateControllerIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, @@ -9079,6 +9202,9 @@ exports[`generator - sql monolith-jwt-postgresql-reactive(false)-maven-enableTra "src/main/java/tech/jhipster/web/rest/AuthenticateController.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -9208,6 +9334,12 @@ exports[`generator - sql monolith-jwt-postgresql-reactive(false)-maven-enableTra "src/test/java/tech/jhipster/config/timezone/HibernateTimeZoneIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/tech/jhipster/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/management/SecurityMetersServiceTests.java": { "stateCleared": "modified", }, @@ -9253,6 +9385,9 @@ exports[`generator - sql monolith-jwt-postgresql-reactive(false)-maven-enableTra "src/test/java/tech/jhipster/web/rest/AuthenticateControllerIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, @@ -12787,6 +12922,9 @@ exports[`generator - sql monolith-session-mariadb-reactive(false)-maven-enableTr "src/main/java/tech/jhipster/web/rest/AccountResource.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -12907,6 +13045,12 @@ exports[`generator - sql monolith-session-mariadb-reactive(false)-maven-enableTr "src/test/java/tech/jhipster/config/timezone/HibernateTimeZoneIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/tech/jhipster/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/repository/timezone/DateTimeWrapper.java": { "stateCleared": "modified", }, @@ -12934,6 +13078,9 @@ exports[`generator - sql monolith-session-mariadb-reactive(false)-maven-enableTr "src/test/java/tech/jhipster/web/rest/AccountResourceIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, @@ -13445,6 +13592,9 @@ exports[`generator - sql monolith-session-mssql-reactive(false)-maven-enableTran "src/main/java/tech/jhipster/web/rest/AccountResource.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -13565,6 +13715,12 @@ exports[`generator - sql monolith-session-mssql-reactive(false)-maven-enableTran "src/test/java/tech/jhipster/config/timezone/HibernateTimeZoneIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/tech/jhipster/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/repository/timezone/DateTimeWrapper.java": { "stateCleared": "modified", }, @@ -13592,6 +13748,9 @@ exports[`generator - sql monolith-session-mssql-reactive(false)-maven-enableTran "src/test/java/tech/jhipster/web/rest/AccountResourceIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, @@ -14103,6 +14262,9 @@ exports[`generator - sql monolith-session-mysql-reactive(false)-maven-enableTran "src/main/java/tech/jhipster/web/rest/AccountResource.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -14223,6 +14385,12 @@ exports[`generator - sql monolith-session-mysql-reactive(false)-maven-enableTran "src/test/java/tech/jhipster/config/timezone/HibernateTimeZoneIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/tech/jhipster/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/repository/timezone/DateTimeWrapper.java": { "stateCleared": "modified", }, @@ -14250,6 +14418,9 @@ exports[`generator - sql monolith-session-mysql-reactive(false)-maven-enableTran "src/test/java/tech/jhipster/web/rest/AccountResourceIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, @@ -14761,6 +14932,9 @@ exports[`generator - sql monolith-session-oracle-reactive(false)-maven-enableTra "src/main/java/tech/jhipster/web/rest/AccountResource.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -14878,6 +15052,12 @@ exports[`generator - sql monolith-session-oracle-reactive(false)-maven-enableTra "src/test/java/tech/jhipster/config/timezone/HibernateTimeZoneIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/tech/jhipster/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/repository/timezone/DateTimeWrapper.java": { "stateCleared": "modified", }, @@ -14905,6 +15085,9 @@ exports[`generator - sql monolith-session-oracle-reactive(false)-maven-enableTra "src/test/java/tech/jhipster/web/rest/AccountResourceIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, @@ -15413,6 +15596,9 @@ exports[`generator - sql monolith-session-postgresql-reactive(false)-maven-enabl "src/main/java/tech/jhipster/web/rest/AccountResource.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -15533,6 +15719,12 @@ exports[`generator - sql monolith-session-postgresql-reactive(false)-maven-enabl "src/test/java/tech/jhipster/config/timezone/HibernateTimeZoneIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/tech/jhipster/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/repository/timezone/DateTimeWrapper.java": { "stateCleared": "modified", }, @@ -15560,6 +15752,9 @@ exports[`generator - sql monolith-session-postgresql-reactive(false)-maven-enabl "src/test/java/tech/jhipster/web/rest/AccountResourceIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, diff --git a/generators/spring-data-relational/__snapshots__/sql-entities.spec.ts.snap b/generators/spring-data-relational/__snapshots__/sql-entities.spec.ts.snap index 9ce3f85b4a25..707b649d0bd8 100644 --- a/generators/spring-data-relational/__snapshots__/sql-entities.spec.ts.snap +++ b/generators/spring-data-relational/__snapshots__/sql-entities.spec.ts.snap @@ -56,6 +56,12 @@ exports[`generator - sql - entities gateway-jwt-gradle-enableTranslation(true)-c "src/main/java/com/mycompany/domain/AnotherSimple.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/domain/Authority.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/domain/AuthorityCallback.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/domain/Simple.java": { "stateCleared": "modified", }, @@ -146,6 +152,9 @@ exports[`generator - sql - entities gateway-jwt-gradle-enableTranslation(true)-c "src/main/java/com/mycompany/web/rest/AnotherSimpleResource.java": { "stateCleared": "modified", }, + "src/main/java/com/mycompany/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/com/mycompany/web/rest/PublicUserResource.java": { "stateCleared": "modified", }, @@ -170,6 +179,12 @@ exports[`generator - sql - entities gateway-jwt-gradle-enableTranslation(true)-c "src/test/java/com/mycompany/domain/AnotherSimpleTestSamples.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/domain/SimpleTest.java": { "stateCleared": "modified", }, @@ -191,6 +206,9 @@ exports[`generator - sql - entities gateway-jwt-gradle-enableTranslation(true)-c "src/test/java/com/mycompany/web/rest/AnotherSimpleResourceIT.java": { "stateCleared": "modified", }, + "src/test/java/com/mycompany/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/com/mycompany/web/rest/PublicUserResourceIT.java": { "stateCleared": "modified", }, @@ -781,6 +799,9 @@ exports[`generator - sql - entities monolith-jwt-reactive(false)-maven-enableTra "src/main/java/tech/jhipster/domain/AnotherSimpleEntity.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/domain/Authority.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/domain/MicroserviceEntity.java": { "stateCleared": "modified", }, @@ -859,6 +880,9 @@ exports[`generator - sql - entities monolith-jwt-reactive(false)-maven-enableTra "src/main/java/tech/jhipster/web/rest/AnotherSimpleResource.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/web/rest/MicroserviceResource.java": { "stateCleared": "modified", }, @@ -886,6 +910,12 @@ exports[`generator - sql - entities monolith-jwt-reactive(false)-maven-enableTra "src/test/java/tech/jhipster/domain/AnotherSimpleEntityTestSamples.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/tech/jhipster/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/domain/MicroserviceEntityTest.java": { "stateCleared": "modified", }, @@ -913,6 +943,9 @@ exports[`generator - sql - entities monolith-jwt-reactive(false)-maven-enableTra "src/test/java/tech/jhipster/web/rest/AnotherSimpleResourceIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/web/rest/MicroserviceResourceIT.java": { "stateCleared": "modified", }, @@ -1506,6 +1539,9 @@ exports[`generator - sql - entities monolith-session-reactive(false)-maven-enabl "src/main/java/tech/jhipster/domain/AnotherSimpleEntity.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/domain/Authority.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/domain/MicroserviceEntity.java": { "stateCleared": "modified", }, @@ -1584,6 +1620,9 @@ exports[`generator - sql - entities monolith-session-reactive(false)-maven-enabl "src/main/java/tech/jhipster/web/rest/AnotherSimpleResource.java": { "stateCleared": "modified", }, + "src/main/java/tech/jhipster/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, "src/main/java/tech/jhipster/web/rest/MicroserviceResource.java": { "stateCleared": "modified", }, @@ -1611,6 +1650,12 @@ exports[`generator - sql - entities monolith-session-reactive(false)-maven-enabl "src/test/java/tech/jhipster/domain/AnotherSimpleEntityTestSamples.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/tech/jhipster/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/domain/MicroserviceEntityTest.java": { "stateCleared": "modified", }, @@ -1638,6 +1683,9 @@ exports[`generator - sql - entities monolith-session-reactive(false)-maven-enabl "src/test/java/tech/jhipster/web/rest/AnotherSimpleResourceIT.java": { "stateCleared": "modified", }, + "src/test/java/tech/jhipster/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, "src/test/java/tech/jhipster/web/rest/MicroserviceResourceIT.java": { "stateCleared": "modified", }, diff --git a/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.spring_data_persistable.ejs b/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.spring_data_persistable.ejs index e166b5112a1d..5186a2a8d178 100644 --- a/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.spring_data_persistable.ejs +++ b/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.spring_data_persistable.ejs @@ -28,7 +28,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; <&_ } -&> <&_ if (fragment.annotationSection) { -&> -@JsonIgnoreProperties(value = { "new" }) +@JsonIgnoreProperties(value = { "new"<% if (primaryKey.name !== 'id') { %>, "id"<% } %> }) <&_ } -&> <&_ if (fragment.additionalInterfacesSection) { -&> From 07115c8ecbb41c288d5b10c9386cc392fbb5b32b Mon Sep 17 00:00:00 2001 From: Marcelo Boveto Shima Date: Wed, 24 Jan 2024 21:54:52 -0300 Subject: [PATCH 2/2] add initial spring-boot generator --- .../__snapshots__/generator.spec.js.snap | 15 + generators/generator-list.js | 1 + generators/server/generator.js | 13 +- generators/spring-boot/README.md | 20 + .../__snapshots__/generator.spec.ts.snap | 486 ++++++++++++++++++ generators/spring-boot/generator.spec.ts | 33 ++ generators/spring-boot/generator.ts | 53 ++ generators/spring-boot/index.ts | 19 + generators/spring-boot/types-export.d.ts | 1 + test/__snapshots__/api.spec.js.snap | 1 + 10 files changed, 635 insertions(+), 7 deletions(-) create mode 100644 generators/spring-boot/README.md create mode 100644 generators/spring-boot/__snapshots__/generator.spec.ts.snap create mode 100644 generators/spring-boot/generator.spec.ts create mode 100644 generators/spring-boot/generator.ts create mode 100644 generators/spring-boot/index.ts create mode 100644 generators/spring-boot/types-export.d.ts diff --git a/generators/generate-blueprint/__snapshots__/generator.spec.js.snap b/generators/generate-blueprint/__snapshots__/generator.spec.js.snap index 9cdcfb090d3c..ac7f38543a2b 100644 --- a/generators/generate-blueprint/__snapshots__/generator.spec.js.snap +++ b/generators/generate-blueprint/__snapshots__/generator.spec.js.snap @@ -659,6 +659,21 @@ exports[`generator - generate-blueprint with all option should match snapshot 1` "generators/server/templates/template-file-server.ejs": { "stateCleared": "modified", }, + "generators/spring-boot/command.mjs": { + "stateCleared": "modified", + }, + "generators/spring-boot/generator.mjs": { + "stateCleared": "modified", + }, + "generators/spring-boot/generator.spec.mjs": { + "stateCleared": "modified", + }, + "generators/spring-boot/index.mjs": { + "stateCleared": "modified", + }, + "generators/spring-boot/templates/template-file-spring-boot.ejs": { + "stateCleared": "modified", + }, "generators/spring-cache/command.mjs": { "stateCleared": "modified", }, diff --git a/generators/generator-list.js b/generators/generator-list.js index 01764ee1f9ad..da573f204b24 100644 --- a/generators/generator-list.js +++ b/generators/generator-list.js @@ -59,6 +59,7 @@ export const GENERATOR_MAVEN = 'maven'; export const GENERATOR_PROJECT_NAME = 'project-name'; export const GENERATOR_REACT = 'react'; export const GENERATOR_SERVER = 'server'; +export const GENERATOR_SPRING_BOOT = 'spring-boot'; export const GENERATOR_SPRING_CACHE = 'spring-cache'; export const GENERATOR_SPRING_CLOUD_STREAM = 'spring-cloud-stream'; export const GENERATOR_SPRING_DATA_CASSANDRA = 'spring-data-cassandra'; diff --git a/generators/server/generator.js b/generators/server/generator.js index b855fee07ba2..8a21335bd8dd 100644 --- a/generators/server/generator.js +++ b/generators/server/generator.js @@ -54,6 +54,7 @@ import { GENERATOR_SPRING_DATA_MONGODB, GENERATOR_SPRING_DATA_NEO4J, GENERATOR_SERVER, + GENERATOR_SPRING_BOOT, GENERATOR_SPRING_CACHE, GENERATOR_SPRING_WEBSOCKET, GENERATOR_SPRING_DATA_RELATIONAL, @@ -258,6 +259,11 @@ export default class JHipsterServerGenerator extends BaseApplicationGenerator { get composing() { return this.asComposingTaskGroup({ + async composeBackendType() { + if (!this.jhipsterConfig.backendType || ['spring-boot', 'java'].includes(this.jhipsterConfig.backendType.toLowerCase())) { + await this.composeWithJHipster(GENERATOR_SPRING_BOOT); + } + }, async composing() { const { buildTool, @@ -634,16 +640,9 @@ export default class JHipsterServerGenerator extends BaseApplicationGenerator { get preparingEachEntity() { return this.asPreparingEachEntityTaskGroup({ prepareEntity({ entity }) { - const hasAnyAuthority = authorities => - authorities.length > 0 ? `hasAnyAuthority(${authorities.map(auth => `'${auth}'`).join(',')})` : undefined; mutateData(entity, { entityPersistenceLayer: true, entityRestLayer: true, - entitySpringPreAuthorize: hasAnyAuthority(entity.entityAuthority?.split(',') ?? []), - entitySpringReadPreAuthorize: hasAnyAuthority([ - ...(entity.entityAuthority?.split(',') ?? []), - ...(entity.entityReadAuthority?.split(',') ?? []), - ]), }); }, }); diff --git a/generators/spring-boot/README.md b/generators/spring-boot/README.md new file mode 100644 index 000000000000..0fcf03dc108a --- /dev/null +++ b/generators/spring-boot/README.md @@ -0,0 +1,20 @@ +# spring-boot sub-generador + +Spring Boot generator. + +## Customizing + +### Entities + +#### Notable customizations + +##### Layers + +Customize @PreAuthorize annotations at Rest layer. +Calculated using (@EntityAuthority)[../app/README.md#Authority] by default. + +``` +@EntitySpringPreAuthorize("hasAuthority('ROLE_CUSTOM')") +@EntitySpringReadPreAuthorize("hasAuthority('ROLE_CUSTOM_READ')") +entity CustomPreAuthorize {} +``` diff --git a/generators/spring-boot/__snapshots__/generator.spec.ts.snap b/generators/spring-boot/__snapshots__/generator.spec.ts.snap new file mode 100644 index 000000000000..b036a5de59d5 --- /dev/null +++ b/generators/spring-boot/__snapshots__/generator.spec.ts.snap @@ -0,0 +1,486 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`generator - spring-boot with default config should match files snapshot 1`] = ` +{ + ".devcontainer/Dockerfile": { + "stateCleared": "modified", + }, + ".devcontainer/devcontainer.json": { + "stateCleared": "modified", + }, + ".editorconfig": { + "stateCleared": "modified", + }, + ".gitattributes": { + "stateCleared": "modified", + }, + ".gitignore": { + "stateCleared": "modified", + }, + ".husky/pre-commit": { + "stateCleared": "modified", + }, + ".lintstagedrc.cjs": { + "stateCleared": "modified", + }, + ".mvn/jvm.config": { + "stateCleared": "modified", + }, + ".mvn/wrapper/maven-wrapper.jar": { + "stateCleared": "modified", + }, + ".mvn/wrapper/maven-wrapper.properties": { + "stateCleared": "modified", + }, + ".prettierignore": { + "stateCleared": "modified", + }, + ".prettierrc": { + "stateCleared": "modified", + }, + ".yo-rc.json": { + "stateCleared": "modified", + }, + "README.md": { + "stateCleared": "modified", + }, + "checkstyle.xml": { + "stateCleared": "modified", + }, + "mvnw": { + "stateCleared": "modified", + }, + "mvnw.cmd": { + "stateCleared": "modified", + }, + "package.json": { + "stateCleared": "modified", + }, + "pom.xml": { + "stateCleared": "modified", + }, + "sonar-project.properties": { + "stateCleared": "modified", + }, + "src/main/docker/app.yml": { + "stateCleared": "modified", + }, + "src/main/docker/grafana/provisioning/dashboards/JVM.json": { + "stateCleared": "modified", + }, + "src/main/docker/grafana/provisioning/dashboards/dashboard.yml": { + "stateCleared": "modified", + }, + "src/main/docker/grafana/provisioning/datasources/datasource.yml": { + "stateCleared": "modified", + }, + "src/main/docker/jhipster-control-center.yml": { + "stateCleared": "modified", + }, + "src/main/docker/jib/entrypoint.sh": { + "stateCleared": "modified", + }, + "src/main/docker/monitoring.yml": { + "stateCleared": "modified", + }, + "src/main/docker/postgresql.yml": { + "stateCleared": "modified", + }, + "src/main/docker/prometheus/prometheus.yml": { + "stateCleared": "modified", + }, + "src/main/docker/sonar.yml": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/ApplicationWebXml.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/GeneratedByJHipster.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/JhipsterApp.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/aop/logging/LoggingAspect.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/aop/logging/package-info.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/ApplicationProperties.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/AsyncConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/CRLFLogConverter.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/CacheConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/Constants.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/DatabaseConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/DateTimeFormatConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/JacksonConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/LiquibaseConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/LocaleConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/LoggingAspectConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/LoggingConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/SecurityConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/SecurityJwtConfiguration.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/WebConfigurer.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/config/package-info.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/domain/AbstractAuditingEntity.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/domain/Authority.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/domain/User.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/domain/package-info.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/management/SecurityMetersService.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/management/package-info.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/package-info.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/repository/AuthorityRepository.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/repository/UserRepository.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/repository/package-info.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/security/AuthoritiesConstants.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/security/DomainUserDetailsService.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/security/SecurityUtils.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/security/SpringSecurityAuditorAware.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/security/UserNotActivatedException.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/security/package-info.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/EmailAlreadyUsedException.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/InvalidPasswordException.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/MailService.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/UserService.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/UsernameAlreadyUsedException.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/dto/AdminUserDTO.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/dto/PasswordChangeDTO.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/dto/UserDTO.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/dto/package-info.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/mapper/UserMapper.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/mapper/package-info.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/service/package-info.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/AccountResource.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/AuthenticateController.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/AuthorityResource.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/PublicUserResource.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/UserResource.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/errors/BadRequestAlertException.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/errors/EmailAlreadyUsedException.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/errors/ErrorConstants.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/errors/ExceptionTranslator.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/errors/FieldErrorVM.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/errors/InvalidPasswordException.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/errors/LoginAlreadyUsedException.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/errors/package-info.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/package-info.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/vm/KeyAndPasswordVM.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/vm/LoginVM.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/vm/ManagedUserVM.java": { + "stateCleared": "modified", + }, + "src/main/java/com/mycompany/myapp/web/rest/vm/package-info.java": { + "stateCleared": "modified", + }, + "src/main/resources/banner.txt": { + "stateCleared": "modified", + }, + "src/main/resources/config/application-dev.yml": { + "stateCleared": "modified", + }, + "src/main/resources/config/application-prod.yml": { + "stateCleared": "modified", + }, + "src/main/resources/config/application-tls.yml": { + "stateCleared": "modified", + }, + "src/main/resources/config/application.yml": { + "stateCleared": "modified", + }, + "src/main/resources/config/liquibase/changelog/00000000000000_initial_schema.xml": { + "stateCleared": "modified", + }, + "src/main/resources/config/liquibase/data/authority.csv": { + "stateCleared": "modified", + }, + "src/main/resources/config/liquibase/data/user.csv": { + "stateCleared": "modified", + }, + "src/main/resources/config/liquibase/data/user_authority.csv": { + "stateCleared": "modified", + }, + "src/main/resources/config/liquibase/master.xml": { + "stateCleared": "modified", + }, + "src/main/resources/config/tls/keystore.p12": { + "stateCleared": "modified", + }, + "src/main/resources/i18n/messages.properties": { + "stateCleared": "modified", + }, + "src/main/resources/i18n/messages_en.properties": { + "stateCleared": "modified", + }, + "src/main/resources/logback-spring.xml": { + "stateCleared": "modified", + }, + "src/main/resources/templates/error.html": { + "stateCleared": "modified", + }, + "src/main/resources/templates/mail/activationEmail.html": { + "stateCleared": "modified", + }, + "src/main/resources/templates/mail/creationEmail.html": { + "stateCleared": "modified", + }, + "src/main/resources/templates/mail/passwordResetEmail.html": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/IntegrationTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/TechnicalStructureTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/AsyncSyncConfiguration.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/CRLFLogConverterTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/EmbeddedSQL.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/PostgreSqlTestContainer.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/SpringBootTestClassOrderer.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/SqlTestContainer.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/SqlTestContainersSpringContextCustomizerFactory.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/WebConfigurerTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/WebConfigurerTestController.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/config/timezone/HibernateTimeZoneIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/domain/AuthorityTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/domain/AuthorityTestSamples.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/management/SecurityMetersServiceTests.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/repository/timezone/DateTimeWrapper.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/repository/timezone/DateTimeWrapperRepository.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/security/DomainUserDetailsServiceIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/security/SecurityUtilsUnitTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/security/jwt/AuthenticationIntegrationTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/security/jwt/JwtAuthenticationTestUtils.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/security/jwt/TokenAuthenticationIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/security/jwt/TokenAuthenticationSecurityMetersIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/service/MailServiceIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/service/UserServiceIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/service/mapper/UserMapperTest.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/web/rest/AccountResourceIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/web/rest/AuthenticateControllerIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/web/rest/AuthorityResourceIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/web/rest/PublicUserResourceIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/web/rest/TestUtil.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/web/rest/UserResourceIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/web/rest/WithUnauthenticatedMockUser.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/web/rest/errors/ExceptionTranslatorIT.java": { + "stateCleared": "modified", + }, + "src/test/java/com/mycompany/myapp/web/rest/errors/ExceptionTranslatorTestController.java": { + "stateCleared": "modified", + }, + "src/test/resources/config/application-testdev.yml": { + "stateCleared": "modified", + }, + "src/test/resources/config/application-testprod.yml": { + "stateCleared": "modified", + }, + "src/test/resources/config/application.yml": { + "stateCleared": "modified", + }, + "src/test/resources/i18n/messages_en.properties": { + "stateCleared": "modified", + }, + "src/test/resources/junit-platform.properties": { + "stateCleared": "modified", + }, + "src/test/resources/logback.xml": { + "stateCleared": "modified", + }, + "src/test/resources/templates/mail/activationEmail.html": { + "stateCleared": "modified", + }, + "src/test/resources/templates/mail/creationEmail.html": { + "stateCleared": "modified", + }, + "src/test/resources/templates/mail/passwordResetEmail.html": { + "stateCleared": "modified", + }, + "src/test/resources/templates/mail/testEmail.html": { + "stateCleared": "modified", + }, +} +`; diff --git a/generators/spring-boot/generator.spec.ts b/generators/spring-boot/generator.spec.ts new file mode 100644 index 000000000000..09f699dd808a --- /dev/null +++ b/generators/spring-boot/generator.spec.ts @@ -0,0 +1,33 @@ +import { basename, dirname } from 'path'; +import { fileURLToPath } from 'url'; +import { before, it, describe, expect } from 'esmocha'; +import lodash from 'lodash'; + +import { shouldSupportFeatures, testBlueprintSupport } from '../../test/support/tests.js'; +import Generator from './index.js'; +import { defaultHelpers as helpers, result } from '../../test/support/index.js'; + +const { snakeCase } = lodash; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +const generator = basename(__dirname); + +describe(`generator - ${generator}`, () => { + it('generator-list constant matches folder name', async () => { + await expect((await import('../generator-list.js'))[`GENERATOR_${snakeCase(generator).toUpperCase()}`]).toBe(generator); + }); + shouldSupportFeatures(Generator); + describe('blueprint support', () => testBlueprintSupport(generator)); + + describe('with default config', () => { + before(async () => { + await helpers.runJHipster(generator).withJHipsterConfig({ skipClient: true }).withMockedSource(); + }); + + it('should match files snapshot', () => { + expect(result.getStateSnapshot()).toMatchSnapshot(); + }); + }); +}); diff --git a/generators/spring-boot/generator.ts b/generators/spring-boot/generator.ts new file mode 100644 index 000000000000..39c96c8dcf2a --- /dev/null +++ b/generators/spring-boot/generator.ts @@ -0,0 +1,53 @@ +/** + * Copyright 2013-2024 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import BaseApplicationGenerator from '../base-application/index.js'; +import { mutateData } from '../base/support/index.js'; +import { GENERATOR_SPRING_BOOT, GENERATOR_SERVER } from '../generator-list.js'; + +export default class SpringBootGenerator extends BaseApplicationGenerator { + async beforeQueue() { + if (!this.fromBlueprint) { + await this.composeWithBlueprints(GENERATOR_SPRING_BOOT); + } + + if (!this.delegateToBlueprint) { + await this.dependsOnJHipster(GENERATOR_SERVER); + } + } + + get preparingEachEntity() { + return this.asPreparingEachEntityTaskGroup({ + prepareEntity({ entity }) { + const hasAnyAuthority = authorities => + authorities.length > 0 ? `hasAnyAuthority(${authorities.map(auth => `'${auth}'`).join(',')})` : undefined; + mutateData(entity, { + entitySpringPreAuthorize: hasAnyAuthority(entity.entityAuthority?.split(',') ?? []), + entitySpringReadPreAuthorize: hasAnyAuthority([ + ...(entity.entityAuthority?.split(',') ?? []), + ...(entity.entityReadAuthority?.split(',') ?? []), + ]), + }); + }, + }); + } + + get [BaseApplicationGenerator.PREPARING_EACH_ENTITY]() { + return this.delegateTasksToBlueprint(() => this.preparingEachEntity); + } +} diff --git a/generators/spring-boot/index.ts b/generators/spring-boot/index.ts new file mode 100644 index 000000000000..58ac334eafae --- /dev/null +++ b/generators/spring-boot/index.ts @@ -0,0 +1,19 @@ +/** + * Copyright 2013-2024 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export { default } from './generator.js'; diff --git a/generators/spring-boot/types-export.d.ts b/generators/spring-boot/types-export.d.ts new file mode 100644 index 000000000000..91ec213d25dd --- /dev/null +++ b/generators/spring-boot/types-export.d.ts @@ -0,0 +1 @@ +export type { default } from '../base-application/types-export.js'; diff --git a/test/__snapshots__/api.spec.js.snap b/test/__snapshots__/api.spec.js.snap index 20d2d40ae9ce..b5afc8e6c114 100644 --- a/test/__snapshots__/api.spec.js.snap +++ b/test/__snapshots__/api.spec.js.snap @@ -44,6 +44,7 @@ exports[`public api generator-jhipster/generators should match snapshot 1`] = ` "GENERATOR_PROJECT_NAME": "project-name", "GENERATOR_REACT": "react", "GENERATOR_SERVER": "server", + "GENERATOR_SPRING_BOOT": "spring-boot", "GENERATOR_SPRING_CACHE": "spring-cache", "GENERATOR_SPRING_CLOUD_STREAM": "spring-cloud-stream", "GENERATOR_SPRING_DATA_CASSANDRA": "spring-data-cassandra",