Skip to content

Commit

Permalink
Merge pull request #20298 from mshima/skip_ci-user_management
Browse files Browse the repository at this point in the history
Rework user management.
  • Loading branch information
DanielFran committed Nov 13, 2022
2 parents c7bbff3 + 8d326e0 commit e95e5fd
Show file tree
Hide file tree
Showing 141 changed files with 412 additions and 1,733 deletions.
15 changes: 9 additions & 6 deletions generators/app/__snapshots__/generator.spec.mts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ Object {
"buildToolGradle": false,
"buildToolMaven": true,
"buildToolUnknown": false,
"builtInAuthority": true,
"builtInUser": true,
"cacheManagerIsAvailable": true,
"cacheProvider": "ehcache",
"cacheProviderCaffeine": false,
Expand Down Expand Up @@ -240,6 +238,9 @@ Object {
"frontendAppName": "jhipsterApp",
"gatewayServerPort": undefined,
"gatlingTests": false,
"generateBuiltInAuthorityEntity": true,
"generateBuiltInUserEntity": true,
"generateUserManagement": true,
"gradleEnterpriseHost": "",
"hipster": "jhipster_family_member_3",
"humanizedBaseName": "JHipster",
Expand Down Expand Up @@ -393,8 +394,6 @@ Object {
"buildToolGradle": false,
"buildToolMaven": true,
"buildToolUnknown": false,
"builtInAuthority": true,
"builtInUser": true,
"cacheManagerIsAvailable": false,
"cacheProvider": "no",
"cacheProviderCaffeine": false,
Expand Down Expand Up @@ -587,6 +586,9 @@ Object {
"frontendAppName": "jhipsterApp",
"gatewayServerPort": undefined,
"gatlingTests": false,
"generateBuiltInAuthorityEntity": true,
"generateBuiltInUserEntity": true,
"generateUserManagement": true,
"gradleEnterpriseHost": undefined,
"hipster": "jhipster_family_member_3",
"humanizedBaseName": "JHipster",
Expand Down Expand Up @@ -741,8 +743,6 @@ Object {
"buildToolGradle": false,
"buildToolMaven": true,
"buildToolUnknown": false,
"builtInAuthority": false,
"builtInUser": false,
"cacheManagerIsAvailable": true,
"cacheProvider": "hazelcast",
"cacheProviderCaffeine": false,
Expand Down Expand Up @@ -935,6 +935,9 @@ Object {
"frontendAppName": "jhipsterApp",
"gatewayServerPort": 8080,
"gatlingTests": false,
"generateBuiltInAuthorityEntity": false,
"generateBuiltInUserEntity": false,
"generateUserManagement": false,
"gradleEnterpriseHost": undefined,
"hipster": "jhipster_family_member_3",
"humanizedBaseName": "JHipster",
Expand Down
4 changes: 3 additions & 1 deletion generators/azure-app-service/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,9 @@ which is free for the first 30 days`);
_computeDerivedConfig(config = _.defaults({}, this.jhipsterConfig, defaultConfig), dest = this) {
this.loadAppConfig(config, dest);
this.loadServerConfig(config, dest);
super.loadDerivedAppConfig(dest);

this.loadDerivedAppConfig(dest);
this.loadDerivedServerConfig(dest, dest);
dest.azureAppInsightsInstrumentationKeyEmpty = config.azureAppInsightsInstrumentationKey === '';
}

Expand Down
4 changes: 4 additions & 0 deletions generators/azure-spring-cloud/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export default class AzureSpringCloudGenerator extends BaseGenerator {
this.loadAppConfig();
this.loadServerConfig();
this.loadPlatformConfig();

this.loadDerivedAppConfig();
this.loadDerivedServerConfig();
this.loadDerivedPlatformConfig();
},
getConfig() {
this.env.options.appPath = this.config.get('appPath') || constants.CLIENT_MAIN_SRC_DIR;
Expand Down
4 changes: 4 additions & 0 deletions generators/base-application/types.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ export type CommonClientServerApplication = BaseApplication &

dockerServicesDir?: string;
prettierExtensions?: string;

generateUserManagement?: boolean;
generateBuiltInUserEntity?: boolean;
generateBuiltInAuthorityEntity?: boolean;
};

type ServiceDiscoveryType = 'no' | 'eureka' | 'consul';
Expand Down
4 changes: 3 additions & 1 deletion generators/base-docker/docker-base.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ export function loadConfigs() {
_.defaults(config, this.getDefaultConfigForApplicationType(config.applicationType));
this.loadAppConfig(config, config);
this.loadServerConfig(config, config);
this.loadDerivedPlatformConfig(config);
this.loadPlatformConfig(config, config);

this.loadDerivedAppConfig(config);
this.loadDerivedPlatformConfig(config);
this.loadDerivedServerConfig(config);

if (config.applicationType === MONOLITH) {
Expand Down
2 changes: 1 addition & 1 deletion generators/base/generator-base-private.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ export default class PrivateBase extends Generator {
const otherEntityAngularName = relationship.otherEntityAngularName;
const importType = `I${otherEntityAngularName}`;
let importPath;
if (this.isBuiltInUser(otherEntityAngularName)) {
if (relationship.otherEntity?.builtInUser) {
importPath = clientFramework === ANGULAR ? 'app/entities/user/user.model' : 'app/shared/model/user.model';
} else {
importPath =
Expand Down
96 changes: 16 additions & 80 deletions generators/base/generator-base.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -223,82 +223,6 @@ export default class JHipsterBaseGenerator extends PrivateBase {
return [];
}

/**
* @private
* Verify if the entity is a built-in Entity.
* @param {String} entityName - Entity name to verify.
* @return {boolean} true if the entity is built-in.
*/
isBuiltInEntity(entityName) {
return this.isBuiltInUser(entityName) || this.isBuiltInAuthority(entityName);
}

/**
* @private
* Verify if the application is using built-in User.
* @return {boolean} true if the User is built-in.
*/
isUsingBuiltInUser() {
return (
!this.jhipsterConfig ||
(!this.jhipsterConfig.skipUserManagement && this.jhipsterConfig.databaseType !== NO_DATABASE) ||
(this.jhipsterConfig.authenticationType === OAUTH2 && this.jhipsterConfig.databaseType !== NO_DATABASE)
);
}

/**
* @private
* Verify if the entity is a User entity.
* @param {String} entityName - Entity name to verify.
* @return {boolean} true if the entity is User.
*/
isUserEntity(entityName) {
return _.upperFirst(entityName) === 'User';
}

/**
* @private
* Verify if the entity is a built-in User.
* @param {String} entityName - Entity name to verify.
* @return {boolean} true if the entity is User and is built-in.
*/
isBuiltInUser(entityName) {
return this.isUsingBuiltInUser() && this.isUserEntity(entityName);
}

/**
* @private
* Verify if the application is using built-in Authority.
* @return {boolean} true if the Authority is built-in.
*/
isUsingBuiltInAuthority() {
return (
!this.jhipsterConfig ||
(!this.jhipsterConfig.skipUserManagement && [SQL, MONGODB, COUCHBASE, NEO4J].includes(this.jhipsterConfig.databaseType)) ||
(this.jhipsterConfig.authenticationType === OAUTH2 && this.jhipsterConfig.databaseType !== NO_DATABASE)
);
}

/**
* @private
* Verify if the entity is a Authority entity.
* @param {String} entityName - Entity name to verify.
* @return {boolean} true if the entity is Authority.
*/
isAuthorityEntity(entityName) {
return _.upperFirst(entityName) === 'Authority';
}

/**
* @private
* Verify if the entity is a built-in Authority.
* @param {String} entityName - Entity name to verify.
* @return {boolean} true if the entity is Authority and is built-in.
*/
isBuiltInAuthority(entityName) {
return this.isUsingBuiltInAuthority() && this.isAuthorityEntity(entityName);
}

/**
* @private
* Replace placeholders with versions from packageJsonSourceFile.
Expand Down Expand Up @@ -1410,7 +1334,7 @@ export default class JHipsterBaseGenerator extends PrivateBase {

const entities = [...new Set((this.jhipsterConfig.entities || []).concat(entityNames))]
.map(entityName => ({ name: entityName, definition: this.readEntityJson(entityName) }))
.filter(entity => entity && !this.isBuiltInUser(entity.name) && !this.isBuiltInAuthority(entity.name) && entity.definition)
.filter(entity => entity && !entity.builtInUser && entity.definition)
.sort(isBefore);
this.jhipsterConfig.entities = entities.map(({ name }) => name);
return entities;
Expand Down Expand Up @@ -2407,7 +2331,6 @@ templates: ${JSON.stringify(existingTemplates, null, 2)}`;
dest.skipFakeData = config.skipFakeData;
dest.entitySuffix = config.entitySuffix;
dest.dtoSuffix = config.dtoSuffix;
dest.skipUserManagement = config.skipUserManagement;
dest.skipCheckLengthOfIdentifier = config.skipCheckLengthOfIdentifier;
dest.microfrontend = config.microfrontend;
dest.microfrontends = config.microfrontends;
Expand Down Expand Up @@ -2439,6 +2362,7 @@ templates: ${JSON.stringify(existingTemplates, null, 2)}`;
dest.rememberMeKey = config.rememberMeKey;
dest.jwtSecretKey = config.jwtSecretKey;
dest.fakerSeed = config.fakerSeed;
dest.skipUserManagement = config.skipUserManagement;
}

/**
Expand Down Expand Up @@ -2495,6 +2419,9 @@ templates: ${JSON.stringify(existingTemplates, null, 2)}`;
dest.authenticationTypeSession = dest.authenticationType === SESSION;
dest.authenticationTypeJwt = dest.authenticationType === JWT;
dest.authenticationTypeOauth2 = dest.authenticationType === OAUTH2;

dest.generateUserManagement = !dest.skipUserManagement && dest.authenticationType !== OAUTH2 && dest.applicationType !== MICROSERVICE;
dest.generateBuiltInUserEntity = dest.generateUserManagement;
}

/**
Expand Down Expand Up @@ -2598,8 +2525,6 @@ templates: ${JSON.stringify(existingTemplates, null, 2)}`;
} else {
dest.gradleEnterpriseHost = config.gradleEnterpriseHost;
}

this.loadDerivedServerConfig(dest);
}

/**
Expand Down Expand Up @@ -2684,6 +2609,17 @@ templates: ${JSON.stringify(existingTemplates, null, 2)}`;
dest.serviceDiscoveryConsul = dest.serviceDiscoveryType === CONSUL;
dest.serviceDiscoveryEureka = dest.serviceDiscoveryType === EUREKA;
dest.serviceDiscoveryAny = ![undefined, false, 'no'].includes(dest.serviceDiscoveryType);

if (dest.databaseType === NO_DATABASE) {
// User management requires a database.
dest.generateUserManagement = false;
}
// TODO make UserEntity optional on relationships for microservices and oauth2
// Used for relationships and syncWithIdp
dest.generateBuiltInUserEntity =
dest.generateUserManagement ||
dest.authenticationType === OAUTH2 ||
(dest.applicationType === MICROSERVICE && !dest.skipUserManagement);
}

/**
Expand Down
17 changes: 8 additions & 9 deletions generators/bootstrap-application-base/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,15 @@ export default class BootStrapApplicationBase extends BaseApplicationGenerator<C
get loadingEntities() {
return this.asLoadingEntitiesTaskGroup({
loadUser({ application }) {
if (application.skipUserManagement && !application.authenticationTypeOauth2) {
return;
}
if (this.sharedData.hasEntity('User')) {
throw new Error("Fail to bootstrap 'User', already exists.");
}
if (application.generateBuiltInUserEntity) {
if (this.sharedData.hasEntity('User')) {
throw new Error("Fail to bootstrap 'User', already exists.");
}

const user = createUserEntity.call(this, {}, application);
this.sharedData.setEntity('User', user);
application.user = user;
const user = createUserEntity.call(this, {}, application);
this.sharedData.setEntity('User', user);
application.user = user;
}
},
loadingEntities({ entitiesToLoad }) {
for (const { entityName, entityStorage } of entitiesToLoad) {
Expand Down
1 change: 1 addition & 0 deletions generators/bootstrap-application-base/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function createUserEntity(customUserData = {}, application) {
fields: userEntityDefinition ? userEntityDefinition.fields || [] : [],
dto: true,
adminUserDto: `AdminUser${application.dtoSuffix ?? ''}`,
builtInUser: true,
...customUserData,
};

Expand Down
2 changes: 0 additions & 2 deletions generators/bootstrap-application/generator.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,6 @@ Object {
"authenticationType": "jwt",
"baseName": "jhipster",
"blobFields": Any<Array>,
"builtInUser": false,
"changelogDate": "20220129025419",
"changelogDateForRecent": 2022-01-29T02:54:19.000Z,
"clientFramework": "angular",
Expand Down Expand Up @@ -976,7 +975,6 @@ Object {
"authenticationType": "jwt",
"baseName": "jhipster",
"blobFields": Any<Array>,
"builtInUser": false,
"changelogDate": "20220129025419",
"changelogDateForRecent": 2022-01-29T02:54:19.000Z,
"clientFramework": "angular",
Expand Down
12 changes: 3 additions & 9 deletions generators/ci-cd/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ export default class CiCdGenerator extends BaseApplicationGenerator {

getSharedConfig() {
this.loadAppConfig();
this.loadClientConfig();
this.loadServerConfig();
this.loadPlatformConfig();

this.loadDerivedAppConfig();
this.loadDerivedServerConfig();
},

getConfig() {
Expand Down Expand Up @@ -191,14 +192,7 @@ export default class CiCdGenerator extends BaseApplicationGenerator {
get loading() {
return {
loadSharedConfig() {
this.loadAppConfig();
this.loadDerivedAppConfig();
this.loadClientConfig();
this.loadDerivedClientConfig();
this.loadServerConfig();
this.loadTranslationConfig();
this._loadCiCdConfig();
this.loadPlatformConfig();
},
};
}
Expand Down
Loading

0 comments on commit e95e5fd

Please sign in to comment.