Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add vue jwt module #11047

Merged
merged 20 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
dc79ea4
test: add tests for the VueJwtModulesFactory
renanfranca Oct 4, 2024
6a693e1
feat: add VueJwtModulesFactory
renanfranca Oct 4, 2024
004b4ff
docs: add vue-jwt-auth-components.md
renanfranca Oct 4, 2024
7c98cad
tests: check for the documentation file at VueJwtModulesFactoryTest
renanfranca Oct 4, 2024
ca82d75
feat: add documentation file at VueJwtModulesFactory
renanfranca Oct 4, 2024
44ad178
refactor: rename documentation name
renanfranca Oct 4, 2024
6c018c1
feat: add template files to be used by vue-jwt module
renanfranca Oct 4, 2024
1adec92
feat: add package-info.java for jwt security
renanfranca Oct 4, 2024
af8f65c
test: add cucumber tests to vue-jwt module
renanfranca Oct 4, 2024
bacc0b0
feat: add vue-jwt module configuration and group vue-oauth2-keycloak …
renanfranca Oct 4, 2024
a450e9a
docs: add JHLite Backend section and update the code blocks content i…
renanfranca Oct 4, 2024
83aff8f
docs: ensure that the reference to the spring-boot-jwt-basic-auth mod…
renanfranca Oct 4, 2024
5eb8c41
ci: rename vueapp to vueoauth2app in generate.sh
renanfranca Oct 4, 2024
44a9844
ci: add vuejwtapp with the new vue-jwt module and cucumber_with_jwt i…
renanfranca Oct 4, 2024
e363184
ci: add vuejwtapp and vueoauth2app to the list of matrix apps in gith…
renanfranca Oct 5, 2024
1069fbe
Revert "ci: add vuejwtapp and vueoauth2app to the list of matrix apps…
renanfranca Oct 7, 2024
859ed86
ci: add vueapp in generate.sh again
renanfranca Oct 7, 2024
9abc82c
docs: add router.ts and main.ts instructions in vue-jwt-authenticatio…
renanfranca Oct 7, 2024
d16d63f
docs: rename vue-authentication-components.md to vue-oauth2-keycloak-…
renanfranca Oct 7, 2024
d7cac9c
refactor: change the folder structure of the vue-oauth2-keycloak modu…
renanfranca Oct 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tech.jhipster.lite.generator.client.vue.security.jwt.application;

import org.springframework.stereotype.Service;
import tech.jhipster.lite.generator.client.vue.security.jwt.domain.VueJwtModulesFactory;
import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;

@Service
public class VueJwtApplicationService {

private final VueJwtModulesFactory factory;

public VueJwtApplicationService() {
factory = new VueJwtModulesFactory();
}

public JHipsterModule buildModule(JHipsterModuleProperties properties) {
return factory.buildModule(properties);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package tech.jhipster.lite.generator.client.vue.security.jwt.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.*;

import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.file.JHipsterDestination;
import tech.jhipster.lite.module.domain.file.JHipsterSource;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
import tech.jhipster.lite.shared.error.domain.Assert;
import tech.jhipster.lite.shared.slug.domain.JHLiteModuleSlug;

public class VueJwtModulesFactory {

private static final JHipsterSource SOURCE = from("client/vue");
private static final JHipsterSource APP_SOURCE = from("client/vue/security/jwt/webapp/app");
private static final JHipsterSource DOCUMENTATION_SOURCE = SOURCE.append("documentation");

private static final JHipsterDestination MAIN_DESTINATION = to("src/main/webapp/app");
private static final JHipsterDestination TEST_DESTINATION = to("src/test/webapp");

private static final String MAIN_TS_IMPORT_NEEDLE = "// jhipster-needle-main-ts-import";
private static final String MAIN_TS_PROVIDER_NEEDLE = "// jhipster-needle-main-ts-provider";

private static final String JWT_IMPORT =
"""
import { provideForAuth } from '@/auth/application/AuthProvider';
import { AxiosHttp } from '@/shared/http/infrastructure/secondary/AxiosHttp';
import axios from 'axios';
""";

private static final String JWT_SETUP =
"""
const axiosInstance = axios.create({ baseURL: 'http://localhost:8080/' });
const axiosHttp = new AxiosHttp(axiosInstance);
provideForAuth(axiosHttp);
""";

public JHipsterModule buildModule(JHipsterModuleProperties properties) {
Assert.notNull("properties", properties);

//@formatter:off
return moduleBuilder(properties)
.context()
.put("springBootJwtBasicAuthModule", JHLiteModuleSlug.SPRING_BOOT_JWT_BASIC_AUTH.get())
.and()
.documentation(documentationTitle("Vue JWT Authentication Components"),
DOCUMENTATION_SOURCE.template("vue-jwt-authentication-components.md"))
.files()
.batch(APP_SOURCE.append("auth"), MAIN_DESTINATION.append("auth"))
.addTemplate("application/AuthProvider.ts")
.addTemplate("domain/AuthRepository.ts")
.addTemplate("domain/AuthenticatedUser.ts")
.addTemplate("domain/Authentication.ts")
.addTemplate("domain/LoginCredentials.ts")
.addTemplate("infrastructure/secondary/JwtAuthRepository.ts")
.addTemplate("infrastructure/secondary/RestAuthentication.ts")
.addTemplate("infrastructure/secondary/RestLoginCredentials.ts")
.and()
.add(APP_SOURCE.template("test/webapp/unit/auth/application/AuthProvider.spec.ts"), TEST_DESTINATION.append("unit/auth/application/AuthProvider.spec.ts"))
.add(APP_SOURCE.template("test/webapp/unit/auth/infrastructure/secondary/JwtAuthRepository.spec.ts"), TEST_DESTINATION.append("unit/auth/infrastructure/secondary/JwtAuthRepository.spec.ts"))
.add(APP_SOURCE.template("test/webapp/unit/shared/http/infrastructure/secondary/AxiosHttpStub.ts"), TEST_DESTINATION.append("unit/shared/http/infrastructure/secondary/AxiosHttpStub.ts"))
.and()
.mandatoryReplacements()
.in(path("src/main/webapp/app/main.ts"))
.add(lineBeforeText(MAIN_TS_IMPORT_NEEDLE), JWT_IMPORT)
.add(lineBeforeText(MAIN_TS_PROVIDER_NEEDLE), JWT_SETUP)
.and()
.and()
.build();
//@formatter:on
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package tech.jhipster.lite.generator.client.vue.security.jwt.infrastructure.primary;

import static tech.jhipster.lite.shared.slug.domain.JHLiteFeatureSlug.*;
import static tech.jhipster.lite.shared.slug.domain.JHLiteModuleSlug.*;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tech.jhipster.lite.generator.client.vue.security.jwt.application.VueJwtApplicationService;
import tech.jhipster.lite.module.domain.resource.JHipsterModuleOrganization;
import tech.jhipster.lite.module.domain.resource.JHipsterModulePropertiesDefinition;
import tech.jhipster.lite.module.domain.resource.JHipsterModuleResource;

@Configuration
class VueJwtModuleConfiguration {

@Bean
JHipsterModuleResource vueJwtModule(VueJwtApplicationService jwt) {
return JHipsterModuleResource.builder()
.slug(VUE_JWT)
.propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addIndentation().build())
.apiDoc("Vue", "Add JWT authentication to Vue")
.organization(JHipsterModuleOrganization.builder().feature(VUE_AUTHENTICATION).addDependency(VUE_CORE).build())
.tags("client", "vue", "auth", "jwt")
.factory(jwt::buildModule);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@tech.jhipster.lite.BusinessContext
package tech.jhipster.lite.generator.client.vue.security.jwt;
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
package tech.jhipster.lite.generator.client.vue.security.oauth2_keycloak.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.documentationTitle;
import static tech.jhipster.lite.module.domain.JHipsterModule.from;
import static tech.jhipster.lite.module.domain.JHipsterModule.lineBeforeText;
import static tech.jhipster.lite.module.domain.JHipsterModule.moduleBuilder;
import static tech.jhipster.lite.module.domain.JHipsterModule.packageName;
import static tech.jhipster.lite.module.domain.JHipsterModule.path;
import static tech.jhipster.lite.module.domain.JHipsterModule.to;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.COMMON;
import static tech.jhipster.lite.module.domain.JHipsterModule.*;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.*;

import tech.jhipster.lite.module.domain.Indentation;
import tech.jhipster.lite.module.domain.JHipsterModule;
Expand All @@ -19,7 +13,7 @@
public class VueOAuth2KeycloakModulesFactory {

private static final JHipsterSource SOURCE = from("client/vue");
private static final JHipsterSource APP_SOURCE = from("client/vue/webapp/app");
private static final JHipsterSource APP_SOURCE = from("client/vue/security/oauth2_keycloak/webapp/app");
private static final JHipsterSource DOCUMENTATION_SOURCE = SOURCE.append("documentation");

private static final JHipsterDestination MAIN_DESTINATION = to("src/main/webapp/app");
Expand Down Expand Up @@ -54,8 +48,8 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {

//@formatter:off
return moduleBuilder(properties)
.documentation(documentationTitle("Vue Authentication Components"),
DOCUMENTATION_SOURCE.file("vue-authentication-components.md"))
.documentation(documentationTitle("Vue OAuth2 Keycloak Authentication Components"),
DOCUMENTATION_SOURCE.file("vue-oauth2-keycloak-authentication-components.md"))
.packageJson()
.addDependency(packageName("keycloak-js"), COMMON)
.and()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tech.jhipster.lite.generator.client.vue.security.oauth2_keycloak.infrastructure.primary;

import static tech.jhipster.lite.shared.slug.domain.JHLiteModuleSlug.VUE_CORE;
import static tech.jhipster.lite.shared.slug.domain.JHLiteModuleSlug.VUE_OAUTH2_KEYCLOAK;
import static tech.jhipster.lite.shared.slug.domain.JHLiteFeatureSlug.*;
import static tech.jhipster.lite.shared.slug.domain.JHLiteModuleSlug.*;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -19,7 +19,7 @@ JHipsterModuleResource vueOAuth2KeycloakModule(VueOAuth2KeycloakApplicationServi
.slug(VUE_OAUTH2_KEYCLOAK)
.propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addIndentation().build())
.apiDoc("Vue", "Add OAuth2 Keycloak authentication to Vue")
.organization(JHipsterModuleOrganization.builder().addDependency(VUE_CORE).build())
.organization(JHipsterModuleOrganization.builder().feature(VUE_AUTHENTICATION).addDependency(VUE_CORE).build())
.tags("client", "vue", "auth", "oauth2", "keycloak")
.factory(oauth2Keycloak::buildModule);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public enum JHLiteFeatureSlug implements JHipsterFeatureSlugFactory {
SPRING_BOOT_CUCUMBER("spring-boot-cucumber"),
SPRING_SERVER("spring-server"),
SPRING_MVC_SERVER("spring-mvc-server"),
SPRINGDOC("springdoc");
SPRINGDOC("springdoc"),
VUE_AUTHENTICATION("vue-authentication");

private final String slug;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public enum JHLiteModuleSlug implements JHipsterModuleSlugFactory {
TYPESCRIPT("typescript"),
VUE_CORE("vue-core"),
VUE_I18N("vue-i18next"),
VUE_JWT("vue-jwt"),
VUE_OAUTH2_KEYCLOAK("vue-oauth2-keycloak"),
VUE_PINIA("vue-pinia"),
TS_PAGINATION_DOMAIN("ts-pagination-domain"),
Expand Down
Loading
Loading