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 oauth2 keycloak module #10928

Merged
merged 28 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c28ca94
test: add tests for the VueOAuth2KeycloakModulesFactory
renanfranca Sep 19, 2024
0d9879c
feat: add keycloak-js dependency to common package.json
renanfranca Sep 19, 2024
5206565
feat: add template files to be used by voue-oauth2-keycloak module
renanfranca Sep 19, 2024
afb1725
test: fix block indentation
renanfranca Sep 19, 2024
6e63bd0
test: update vue main.ts.template file and add it to the VueOAuth2Key…
renanfranca Sep 19, 2024
e7c8e8b
feat: add VueOAuth2KeycloakModulesFactory
renanfranca Sep 19, 2024
ff4f9af
fix: sonar issues at KeycloakHttp.ts.mustache
renanfranca Sep 19, 2024
bfff100
feat: add vue-authentication-components.md documentation to vue-oauth…
renanfranca Sep 19, 2024
9a98860
fix: remove unused import added to main.ts
renanfranca Sep 19, 2024
d0a2710
feat: add package-info.java
renanfranca Sep 20, 2024
feee6bd
test: add cucumber test to vue-oauth2-keycloak module configuration
renanfranca Sep 20, 2024
a82ece1
feat: add vue-oauth2-keycloak module configuration
renanfranca Sep 20, 2024
b7cdfc2
fix: cucumber test
renanfranca Sep 20, 2024
84b7ac2
refactor: improve VueOAuth2KeycloakModulesFactory code by using const…
renanfranca Sep 20, 2024
72a9c6e
feat: use keycloak-js dependency from COMMON package instead of the A…
renanfranca Sep 20, 2024
76e78c6
fix: update constructor parameter to readonly
renanfranca Sep 20, 2024
42fa491
docs: improve vue authentication components documentation
renanfranca Sep 20, 2024
0de2fbb
feat: add type alias for AuthenticatedUser
renanfranca Sep 20, 2024
1c1d37b
fix: code formatting at AuthRepository.ts
renanfranca Sep 20, 2024
c2407cd
refactor: remove unnecessary else statement
renanfranca Sep 20, 2024
ee0689c
refactor: use promises for error handler and remove console.log
renanfranca Sep 20, 2024
f81efe9
docs: update the AuthVue.component.ts code in vue-authentication-comp…
renanfranca Sep 23, 2024
0fdb2bc
feat: add unit tests to the module to be able to add vue-oauth2-keycl…
renanfranca Sep 23, 2024
c5d397c
feat: add vue-oauth2-keycloak module to the vueapp application at the…
renanfranca Sep 23, 2024
d5c26e9
fix: format import statement in AuthProvider.ts.mustache
renanfranca Sep 23, 2024
c85306a
feat: add unit tests to AuthProvider.ts.mustache to reach 100% code c…
renanfranca Sep 23, 2024
b666ca8
refactor: change template to add order
renanfranca Sep 23, 2024
b1aeaa9
fix: remove unused beforeEach hook in AuthProvider.spec.ts.mustache
renanfranca Sep 23, 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
@@ -1,7 +1,7 @@
package tech.jhipster.lite.generator.client.angular.security.oauth2.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.*;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.ANGULAR;
import static tech.jhipster.lite.module.domain.npm.JHLiteNpmVersionSource.*;
import static tech.jhipster.lite.module.domain.replacement.ReplacementCondition.notMatchingRegex;

import java.util.regex.Pattern;
Expand Down Expand Up @@ -114,7 +114,7 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {
//@formatter:off
return moduleBuilder(properties)
.packageJson()
.addDependency(packageName("keycloak-js"), ANGULAR)
.addDependency(packageName("keycloak-js"), COMMON)
.and()
.files()
.batch(SOURCE.append("auth"), APP_DESTINATION.append("auth"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tech.jhipster.lite.generator.client.vue.security.oauth2_keycloak.application;

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

@Service
public class VueOAuth2KeycloakApplicationService {

private final VueOAuth2KeycloakModulesFactory factory;

public VueOAuth2KeycloakApplicationService() {
factory = new VueOAuth2KeycloakModulesFactory();
}

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

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;
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;

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 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 KEYCLOAK_IMPORT =
"""
import { provideForAuth } from '@/auth/application/AuthProvider';
import { KeycloakHttp } from '@/auth/infrastructure/secondary/KeycloakHttp';
import Keycloak from 'keycloak-js';\
""";
private static final String KEYCLOAK_SETUP =
"""
const keycloakHttp = new KeycloakHttp(
%snew Keycloak({
%surl: 'http://localhost:9080',
%srealm: 'jhipster',
%sclientId: 'web_app',
%s}),
);

provideForAuth(keycloakHttp);\
""";

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

Indentation indentation = properties.indentation();

//@formatter:off
return moduleBuilder(properties)
.documentation(documentationTitle("Vue Authentication Components"),
DOCUMENTATION_SOURCE.file("vue-authentication-components.md"))
.packageJson()
.addDependency(packageName("keycloak-js"), COMMON)
.and()
.files()
.batch(APP_SOURCE.append("auth"), MAIN_DESTINATION.append("auth"))
.addTemplate("application/AuthProvider.ts")
.addTemplate("domain/AuthRepository.ts")
.addTemplate("domain/AuthenticatedUser.ts")
.addTemplate("infrastructure/secondary/KeycloakAuthRepository.ts")
.addTemplate("infrastructure/secondary/KeycloakHttp.ts")
.and()
.add(APP_SOURCE.template("test/webapp/unit/auth/application/AuthProvider.spec.ts"), TEST_DESTINATION.append("unit/auth/application/AuthProvider.spec.ts"))
.batch(APP_SOURCE.append("test/webapp/unit/auth/infrastructure/secondary"), TEST_DESTINATION.append("unit/auth/infrastructure/secondary"))
.addTemplate("KeycloakAuthRepository.spec.ts")
.addTemplate("KeycloakHttp.spec.ts")
.addTemplate("KeycloakHttpStub.ts")
.addTemplate("KeycloakStub.ts")
.and()
.and()
.mandatoryReplacements()
.in(path("src/main/webapp/app/main.ts"))
.add(lineBeforeText(MAIN_TS_IMPORT_NEEDLE),
KEYCLOAK_IMPORT
)
.add(lineBeforeText(MAIN_TS_PROVIDER_NEEDLE),
KEYCLOAK_SETUP.formatted(indentation.spaces(),
indentation.times(2),
indentation.times(2),
indentation.times(2),
indentation.spaces())
)
.and()
.and()
.build();
//@formatter:on
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package tech.jhipster.lite.generator.client.vue.security.oauth2_keycloak.infrastructure.primary;

import static tech.jhipster.lite.generator.slug.domain.JHLiteModuleSlug.*;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tech.jhipster.lite.generator.client.vue.security.oauth2_keycloak.application.VueOAuth2KeycloakApplicationService;
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 VueOAuth2KeycloakModuleConfiguration {

@Bean
JHipsterModuleResource vueOAuth2KeycloakModule(VueOAuth2KeycloakApplicationService oauth2Keycloak) {
return JHipsterModuleResource.builder()
.slug(VUE_OAUTH2_KEYCLOAK)
.propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addIndentation().build())
.apiDoc("Vue", "Add OAuth2 Keycloak authentication to Vue")
.organization(JHipsterModuleOrganization.builder().addDependency(VUE_CORE).build())
.tags("client", "vue", "auth", "oauth2", "keycloak")
.factory(oauth2Keycloak::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.oauth2_keycloak;
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public enum JHLiteModuleSlug implements JHipsterModuleSlugFactory {
SVELTE_CORE("svelte-core"),
TYPESCRIPT("typescript"),
VUE_CORE("vue-core"),
VUE_OAUTH2_KEYCLOAK("vue-oauth2-keycloak"),
VUE_PINIA("vue-pinia"),
TS_PAGINATION_DOMAIN("ts-pagination-domain"),
TS_REST_PAGINATION("ts-rest-pagination");
Expand Down
Loading