-
-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10928 from renanfranca/1133-vue-oauth2-keycloak-m…
…odule add vue oauth2 keycloak module
- Loading branch information
Showing
23 changed files
with
1,341 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
.../client/vue/security/oauth2_keycloak/application/VueOAuth2KeycloakApplicationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...generator/client/vue/security/oauth2_keycloak/domain/VueOAuth2KeycloakModulesFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...security/oauth2_keycloak/infrastructure/primary/VueOAuth2KeycloakModuleConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...n/java/tech/jhipster/lite/generator/client/vue/security/oauth2_keycloak/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.