Skip to content

Commit

Permalink
Merge branch 'main' into fix-safari
Browse files Browse the repository at this point in the history
  • Loading branch information
sinedied authored Sep 20, 2023
2 parents e96f21c + 3cbcdf4 commit 231505a
Show file tree
Hide file tree
Showing 29 changed files with 104 additions and 94 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM jhipster/jhipster:v8.0.0-beta.2
FROM jhipster/jhipster:v8.0.0-beta.3
USER jhipster
COPY --chown=jhipster:jhipster . /home/jhipster/jhipster-online/
RUN \
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jhonline",
"version": "2.23.5",
"version": "2.24.0",
"description": "JHipster Online is the best place to generate JHipster applications, with no installation required!",
"license": "Apache-2.0",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>io.github.jhipster.online</groupId>
<artifactId>jhonline</artifactId>
<version>2.23.5</version>
<version>2.24.0</version>
<packaging>war</packaging>
<name>Jhonline</name>

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/github/jhipster/online/JhonlineApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ private static void logApplicationStartup(Environment env) {
protocol = "https";
}
String serverPort = env.getProperty("server.port");
String applicationName = env.getProperty("spring.application.name");
String contextPath = env.getProperty("server.servlet.context-path");
if (StringUtils.isBlank(contextPath)) {
contextPath = "/";
Expand All @@ -109,7 +110,7 @@ private static void logApplicationStartup(Environment env) {
"Local: \t\t{}://localhost:{}{}\n\t" +
"External: \t{}://{}:{}{}\n\t" +
"Profile(s): \t{}\n----------------------------------------------------------",
env.getProperty("spring.application.name"),
applicationName,
protocol,
serverPort,
contextPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class TokenProvider {
public TokenProvider(JHipsterProperties jHipsterProperties) {
byte[] keyBytes;
String secret = jHipsterProperties.getSecurity().getAuthentication().getJwt().getSecret();
if (!StringUtils.isEmpty(secret)) {
if (StringUtils.hasLength(secret)) {
log.warn(
"Warning: the JWT key used is not Base64-encoded. " +
"We recommend using the `jhipster.security.authentication.jwt.base64-secret` key for optimum security."
Expand Down
50 changes: 32 additions & 18 deletions src/main/java/io/github/jhipster/online/web/rest/GitResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -114,45 +116,44 @@ public RedirectView callback(@PathVariable String gitProvider, String code) {
try {
String url;
GitProvider gitProviderEnum;
GitAccessTokenRequest request = new GitAccessTokenRequest();
Map<String, String> params = new HashMap<>();
switch (gitProvider.toLowerCase()) {
case GITHUB:
url = applicationProperties.getGithub().getHost() + "/login/oauth/access_token";
gitProviderEnum = GitProvider.GITHUB;
request.setClientId(applicationProperties.getGithub().getClientId());
request.setClientSecret(applicationProperties.getGithub().getClientSecret());
request.setCode(code);
params.put("client_id", applicationProperties.getGithub().getClientId());
params.put("client_secret", applicationProperties.getGithub().getClientSecret());
params.put("code", code);
break;
case GITLAB:
url = applicationProperties.getGitlab().getHost() + "/oauth/token";
gitProviderEnum = GitProvider.GITLAB;
request.setClientId(applicationProperties.getGitlab().getClientId());
request.setClientSecret(applicationProperties.getGitlab().getClientSecret());
request.setGrantType("authorization_code");
request.setRedirectUri(applicationProperties.getGitlab().getRedirectUri());
request.setCode(code);
params.put("client_id", applicationProperties.getGitlab().getClientId());
params.put("client_secret", applicationProperties.getGitlab().getClientSecret());
params.put("code", code);
params.put("grant_type", "authorization_code");
params.put("redirect_uri", applicationProperties.getGitlab().getRedirectUri());
break;
default:
return new ResponseEntity<>(UNKNOWN_GIT_PROVIDER + gitProvider, HttpStatus.INTERNAL_SERVER_ERROR);
}

ObjectMapper objectMapper = new ObjectMapper();
String requestBody = objectMapper.writeValueAsString(request);
HttpClient client = HttpClient.newHttpClient();
HttpRequest httpRequest = HttpRequest
.newBuilder()
.uri(URI.create(url))
.header("Content-Type", MediaType.APPLICATION_JSON_VALUE)
.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE)
.header("Accept", MediaType.APPLICATION_JSON_VALUE)
.header("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0")
.POST(HttpRequest.BodyPublishers.ofString(requestBody))
.POST(HttpRequest.BodyPublishers.ofString(buildQueryString(params)))
.build();

CompletableFuture<HttpResponse<String>> response = client.sendAsync(httpRequest, HttpResponse.BodyHandlers.ofString());

String jsonResponse = response.thenApply(HttpResponse::body).get(5, TimeUnit.SECONDS);
GitAccessTokenResponse accessTokenResponse = objectMapper.readValue(jsonResponse, GitAccessTokenResponse.class);
this.userService.saveToken(accessTokenResponse.getAccessToken(), gitProviderEnum);
this.userService.saveToken(accessTokenResponse.getAccess_token(), gitProviderEnum);
} catch (InterruptedException e) {
log.warn("Interrupted!", e);
// Restore interrupted state...
Expand All @@ -164,6 +165,19 @@ public RedirectView callback(@PathVariable String gitProvider, String code) {
return new ResponseEntity<>(HttpStatus.CREATED);
}

private static String buildQueryString(Map<String, String> params) {
StringBuilder queryString = new StringBuilder();
for (Map.Entry<String, String> entry : params.entrySet()) {
if (queryString.length() > 0) {
queryString.append("&");
}
queryString.append(entry.getKey());
queryString.append("=");
queryString.append(entry.getValue());
}
return queryString.toString();
}

public static class GitAccessTokenRequest {

private String clientId;
Expand Down Expand Up @@ -243,14 +257,14 @@ public String toString() {
@JsonIgnoreProperties(ignoreUnknown = true)
public static class GitAccessTokenResponse {

private String accessToken;
private String access_token;

public String getAccessToken() {
return accessToken;
public String getAccess_token() {
return access_token;
}

public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
public void setAccess_token(String access_token) {
this.access_token = access_token;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class PasswordStrengthBarComponent {
}

getColor(s: number): { idx: number; color: string } {
let idx = 0;
let idx = 4;
if (s <= 10) {
idx = 0;
} else if (s <= 20) {
Expand All @@ -76,8 +76,6 @@ export class PasswordStrengthBarComponent {
idx = 2;
} else if (s <= 40) {
idx = 3;
} else {
idx = 4;
}
return { idx: idx + 1, color: this.colors[idx] };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ export class ConfigurationComponent implements OnInit {
}

filterAndSortBeans(): void {
const beansAscendingSort = this.beansAscending ? -1 : 1;
this.beans = this.allBeans
.filter(bean => !this.beansFilter || bean.prefix.toLowerCase().includes(this.beansFilter.toLowerCase()))
.sort((a, b) => (a.prefix < b.prefix ? (this.beansAscending ? -1 : 1) : this.beansAscending ? 1 : -1));
.sort((a, b) => (a.prefix < b.prefix ? beansAscendingSort : beansAscendingSort * -1));
}
}
2 changes: 1 addition & 1 deletion src/main/webapp/app/blocks/interceptor/auth.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class AuthInterceptor implements HttpInterceptor {
constructor(private localStorage: LocalStorageService, private sessionStorage: SessionStorageService) {}

intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (!request || !request.url || (request.url.startsWith('http') && !(SERVER_API_URL && request.url.startsWith(SERVER_API_URL)))) {
if (!request?.url || (request.url.startsWith('http') && !(SERVER_API_URL && request.url.startsWith(SERVER_API_URL)))) {
return next.handle(request);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class ErrorHandlerInterceptor implements HttpInterceptor {
return next.handle(request).pipe(
tap({
error: (err: HttpErrorResponse) => {
if (!(err.status === 401 && (err.message === '' || (err.url && err.url.includes('api/account'))))) {
if (!(err.status === 401 && (err.message === '' || err.url?.includes('api/account')))) {
this.eventManager.broadcast(new JhiEventWithContent('jhonlineApp.httpError', err));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/app/core/auth/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class AccountService {
}

hasAnyAuthority(authorities: string[] | string): boolean {
if (!this.userIdentity || !this.userIdentity.authorities) {
if (!this.userIdentity?.authorities) {
return false;
}
if (!Array.isArray(authorities)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="col-md-12">
<div class="alert alert-info" role="alert">
<p>Generated applications can be deployed on <a href="https://azure.microsoft.com/products/spring-apps/" target="_blank">Azure Spring Apps</a> in a few easy steps, please refer to the readme file in the generated project for the deployment guide.</p>
<p>Detailed documentation is also available <a href="https://learn.microsoft.com/azure/spring-apps/quickstart-deploy-web-app?pivots=sc-standard" target="_blank">here</a>.</p>
<p>Detailed documentation is also available <a href="https://learn.microsoft.com/azure/spring-apps/quickstart-deploy-web-app?pivots=sc-consumption-plan&tabs=Azure-Developer-CLI" target="_blank">here</a>.</p>
</div>
</div>
<div class="col-md-12">
Expand Down
8 changes: 4 additions & 4 deletions src/main/webapp/app/home/ci-cd/ci-cd.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ export class CiCdComponent implements OnInit {
ngOnInit(): void {
this.gitConfig = this.gitConfigurationService.gitConfig;
if (this.gitConfig) {
this.gitlabConfigured = this.gitConfig.gitlabConfigured || false;
this.githubConfigured = this.gitConfig.githubConfigured || false;
this.gitlabConfigured = this.gitConfig.gitlabConfigured ?? false;
this.githubConfigured = this.gitConfig.githubConfigured ?? false;
}

this.gitConfigurationService.sharedData.subscribe((gitConfig: GitConfigurationModel) => {
this.gitConfig = gitConfig;
this.gitlabConfigured = gitConfig.gitlabConfigured || false;
this.githubConfigured = gitConfig.githubConfigured || false;
this.gitlabConfigured = gitConfig.gitlabConfigured ?? false;
this.githubConfigured = gitConfig.githubConfigured ?? false;
});
}

Expand Down
6 changes: 2 additions & 4 deletions src/main/webapp/app/home/ci-cd/ci-cd.output.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ export class CiCdOutputDialogComponent implements OnInit {
setTimeout(() => {
this.updateLogsData();
}, 2000);
} else {
if (data.endsWith('Generation finished\n')) {
this.displayApplicationUrl = true;
}
} else if (data.endsWith('Generation finished\n')) {
this.displayApplicationUrl = true;
}
},
() => {
Expand Down
14 changes: 7 additions & 7 deletions src/main/webapp/app/home/generator/generator.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ export class GeneratorComponent implements OnInit {
this.languageOptions = GeneratorComponent.getAllSupportedLanguageOptions();
this.gitConfig = this.gitConfigurationService.gitConfig;
if (this.gitConfig) {
this.gitlabConfigured = this.gitConfig.gitlabConfigured || false;
this.githubConfigured = this.gitConfig.githubConfigured || false;
this.gitlabConfigured = this.gitConfig.gitlabConfigured ?? false;
this.githubConfigured = this.gitConfig.githubConfigured ?? false;
}
this.gitConfigurationService.sharedData.subscribe((gitConfig: GitConfigurationModel) => {
if (gitConfig) {
this.gitlabConfigured = gitConfig.gitlabConfigured || false;
this.githubConfigured = gitConfig.githubConfigured || false;
this.gitlabConfigured = gitConfig.gitlabConfigured ?? false;
this.githubConfigured = gitConfig.githubConfigured ?? false;
}
});
}
Expand Down Expand Up @@ -273,8 +273,8 @@ export class GeneratorComponent implements OnInit {

changeDatabaseType(): void {
if (this.model.databaseType === 'sql') {
this.model.prodDatabaseType = AllProdDatabaseTypes.find(type => !this.isProdDatabaseOptionHidden('sql', type)) || 'mysql';
this.model.devDatabaseType = AllDevDatabaseTypes.find(type => !this.isDevDatabaseOptionHidden('sql', type)) || 'h2Disk';
this.model.prodDatabaseType = AllProdDatabaseTypes.find(type => !this.isProdDatabaseOptionHidden('sql', type)) ?? 'mysql';
this.model.devDatabaseType = AllDevDatabaseTypes.find(type => !this.isDevDatabaseOptionHidden('sql', type)) ?? 'h2Disk';
this.model.cacheProvider = 'ehcache';
this.model.enableHibernateCache = true;
} else if (this.model.databaseType === 'mongodb') {
Expand Down Expand Up @@ -310,7 +310,7 @@ export class GeneratorComponent implements OnInit {

if (this.model.databaseType === 'sql') {
// Find first allowed dev database type
this.model.devDatabaseType = AllDevDatabaseTypes.find(type => !this.isDevDatabaseOptionHidden('sql', type)) || 'h2Disk';
this.model.devDatabaseType = AllDevDatabaseTypes.find(type => !this.isDevDatabaseOptionHidden('sql', type)) ?? 'h2Disk';
} else if (this.model.prodDatabaseType === 'mongodb') {
this.model.devDatabaseType = 'mongodb';
this.model.cacheProvider = 'no';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ export class GeneratorOutputDialogComponent implements OnInit {
setTimeout(() => {
this.updateLogsData();
}, 500);
} else {
if (data.endsWith('Generation finished\n')) {
this.displayApplicationUrl = true;
}
} else if (data.endsWith('Generation finished\n')) {
this.displayApplicationUrl = true;
}
},
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export class JHipsterConfigurationModel {
constructor(data?: Partial<JHipsterConfigurationModel>) {
if (data) {
const dataCopy = { ...data };
dataCopy.testFrameworks = [...(data.testFrameworks || [])];
dataCopy.languages = [...(data.languages || [])];
dataCopy.testFrameworks = [...(data.testFrameworks ?? [])];
dataCopy.languages = [...(data.languages ?? [])];
Object.assign(this, data);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/webapp/app/home/git/git.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export class GitComponent implements OnInit {
}

ngOnInit(): void {
this.gitlabConfigured = this.gitConfig.gitlabConfigured || false;
this.githubConfigured = this.gitConfig.githubConfigured || false;
this.gitlabConfigured = this.gitConfig.gitlabConfigured ?? false;
this.githubConfigured = this.gitConfig.githubConfigured ?? false;
this.gitConfigurationService.sharedData.subscribe((gitConfig: GitConfigurationModel) => {
this.gitConfig = gitConfig;
this.gitlabConfigured = gitConfig.gitlabConfigured || false;
this.githubConfigured = gitConfig.githubConfigured || false;
this.gitlabConfigured = gitConfig.gitlabConfigured ?? false;
this.githubConfigured = gitConfig.githubConfigured ?? false;
});

this.gitConfig.availableGitProviders.forEach((provider: any) => {
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/app/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<span class="align-middle h5">Create Application</span>
</a>
</li>
<li class="nav-item" routerLinkActive="active" [routerLinkActiveOptions]="{exact: true}" [hidden]="!enableAzure">
<li class="nav-item" routerLinkActive="active" [routerLinkActiveOptions]="{exact: true}">
<a class="nav-link text-primary mt-3" routerLink="/generate-azure-application">
<span class="btn-rounded align-middle">
<img src="content/images/azure-logo.svg" alt="Microsoft Azure logo" width="32" height="32">
Expand Down
9 changes: 1 addition & 8 deletions src/main/webapp/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,8 @@ export class HomeComponent implements OnInit, OnDestroy {
account: Account | null = null;
authSubscription?: Subscription;
gitConfig: GitConfigurationModel;
enableAzure = false;

constructor(
private accountService: AccountService,
private gitConfigurationService: GitConfigurationService,
public route: ActivatedRoute
) {
constructor(private accountService: AccountService, private gitConfigurationService: GitConfigurationService) {
this.gitConfig = this.gitConfigurationService.gitConfig;
}

Expand All @@ -50,8 +45,6 @@ export class HomeComponent implements OnInit, OnDestroy {
this.account = account;
this.gitConfigurationService.setupGitConfiguration();
});
// TODO: remove this feature flag once the Azure generator is ready
this.enableAzure = Boolean(this.route.snapshot.queryParams['enableAzure']);
}

isAuthenticated(): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ export class JdlMetadataService {
}

private convert(jdlMetadata: JdlMetadata): JdlMetadata {
return Object.assign({}, jdlMetadata);
return { ...jdlMetadata };
}
}
8 changes: 4 additions & 4 deletions src/main/webapp/app/home/jdl-metadata/jdl-studio.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ export class ApplyJdlStudioComponent implements OnInit, OnDestroy {
private jdlService: JdlService
) {
this.gitConfig = this.gitConfigurationService.gitConfig;
this.gitlabConfigured = this.gitConfig.gitlabConfigured || false;
this.githubConfigured = this.gitConfig.githubConfigured || false;
this.gitlabConfigured = this.gitConfig.gitlabConfigured ?? false;
this.githubConfigured = this.gitConfig.githubConfigured ?? false;
}

ngOnInit(): void {
this.gitConfigurationService.sharedData.subscribe((gitConfig: GitConfigurationModel) => {
this.gitConfig = gitConfig;
this.gitlabConfigured = gitConfig.gitlabConfigured || false;
this.githubConfigured = gitConfig.githubConfigured || false;
this.gitlabConfigured = gitConfig.gitlabConfigured ?? false;
this.githubConfigured = gitConfig.githubConfigured ?? false;
});

this.subscription = this.route.params.subscribe(params => {
Expand Down
Loading

0 comments on commit 231505a

Please sign in to comment.