From 2e20bd6a0e98c13cbca32179b14352ee90925c63 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Mon, 19 Feb 2024 00:28:05 -0800 Subject: [PATCH] Add configuration endpoint. --- .../config/rest/RestAppConfig.java | 1 + .../com/wisemapping/rest/AppController.java | 111 ++++++++++++++ .../com/wisemapping/rest/LabelController.java | 1 - .../wisemapping/rest/MindmapController.java | 2 +- .../wisemapping/rest/model/RestAppConfig.java | 145 ++++++++++++++++++ .../wisemapping/service/MailerService.java | 4 +- .../service/NotificationService.java | 4 +- wise-api/src/main/resources/application.yml | 29 ++-- 8 files changed, 281 insertions(+), 16 deletions(-) create mode 100644 wise-api/src/main/java/com/wisemapping/rest/AppController.java create mode 100644 wise-api/src/main/java/com/wisemapping/rest/model/RestAppConfig.java diff --git a/wise-api/src/main/java/com/wisemapping/config/rest/RestAppConfig.java b/wise-api/src/main/java/com/wisemapping/config/rest/RestAppConfig.java index a55e0142..8e7930c9 100644 --- a/wise-api/src/main/java/com/wisemapping/config/rest/RestAppConfig.java +++ b/wise-api/src/main/java/com/wisemapping/config/rest/RestAppConfig.java @@ -44,6 +44,7 @@ public class RestAppConfig { .requestMatchers(mvc.pattern("/error")).permitAll() .requestMatchers(mvc.pattern("/api/restful/authenticate")).permitAll() .requestMatchers(mvc.pattern("/api/restful/users/")).permitAll() + .requestMatchers(mvc.pattern("/api/restful/app/config")).permitAll() .requestMatchers(mvc.pattern("/api/restful/maps/*/document/xml-pub")).permitAll() .requestMatchers(mvc.pattern("/api/restful/users/resetPassword")).permitAll() .requestMatchers(mvc.pattern("/api/oauth2/googlecallback")).permitAll() diff --git a/wise-api/src/main/java/com/wisemapping/rest/AppController.java b/wise-api/src/main/java/com/wisemapping/rest/AppController.java new file mode 100644 index 00000000..c36d4b0f --- /dev/null +++ b/wise-api/src/main/java/com/wisemapping/rest/AppController.java @@ -0,0 +1,111 @@ +/* + * Copyright [2022] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.wisemapping.rest; + +import com.wisemapping.rest.model.RestAppConfig; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + + +// "config": { +// "apiBaseUrl": "http://localhost:3000", +// "analyticsAccount": "G-RSDEJH16YM", +// "clientType": "mock", +// "recaptcha2Enabled": false, +// "recaptcha2SiteKey": "6Lcat08kAAAAAIP-HjhzIa-Yq21PHgGa_ADWc-Ro", +// "googleOauth2Url": "https: //accounts.google.com/o/oauth2/v2/auth?redirect_uri=https://app.wisemapping.com/c/registration-google&prompt=consent&response_type=code&client_id=625682766634-cocbbbbb403iuvps1evecdk6d7phvbkf.apps.googleusercontent.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&access_type=offline&state=wisemapping&include_granted_scopes=true" +// } +@RestController +@RequestMapping("/api/restful/app") +public class AppController extends BaseController { + + @Value("${app.security.oauth2.google.url:}") + private String googleOauth2Url; + + @Value("${app.registration.enabled:true}") + private Boolean isRegistrationEnabled; + + @Value("${app.registration.captcha.enabled:false}") + private Boolean isCaptchaEnabled; + + @Value("${app.registration.captcha.siteKey:}") + private String captchaSiteKey; + + @Value("${app.site.api-base-url:}") + private String apiBaseUrl; + + @Value("${app.analytics.account:}") + private String analyticsAccount; + + @RequestMapping(method = RequestMethod.GET, value = "/config") + @ResponseStatus(value = HttpStatus.OK) + public RestAppConfig appConfig() { + return new RestAppConfig.RestAppConfigBuilder() + .setApiUrl(apiBaseUrl) + .setCaptchaSiteKey(captchaSiteKey) + .setGoogleOauth2Url(googleOauth2Url) + .setAnalyticsAccount(analyticsAccount) + .setRegistrationEnabled(isRegistrationEnabled) + .build(); + } + + public String getGoogleOauth2Url() { + return googleOauth2Url; + } + + public void setGoogleOauth2Url(String googleOauth2Url) { + this.googleOauth2Url = googleOauth2Url; + } + + public Boolean getRegistrationEnabled() { + return isRegistrationEnabled; + } + + public void setRegistrationEnabled(Boolean registrationEnabled) { + isRegistrationEnabled = registrationEnabled; + } + + public Boolean getCaptchaEnabled() { + return isCaptchaEnabled; + } + + public void setCaptchaEnabled(Boolean captchaEnabled) { + isCaptchaEnabled = captchaEnabled; + } + + public String getCaptchaSiteKey() { + return captchaSiteKey; + } + + public void setCaptchaSiteKey(String captchaSiteKey) { + this.captchaSiteKey = captchaSiteKey; + } + + public String getApiBaseUrl() { + return apiBaseUrl; + } + + public void setApiBaseUrl(String apiBaseUrl) { + this.apiBaseUrl = apiBaseUrl; + } +} diff --git a/wise-api/src/main/java/com/wisemapping/rest/LabelController.java b/wise-api/src/main/java/com/wisemapping/rest/LabelController.java index d3bc48e0..a1385a66 100644 --- a/wise-api/src/main/java/com/wisemapping/rest/LabelController.java +++ b/wise-api/src/main/java/com/wisemapping/rest/LabelController.java @@ -48,7 +48,6 @@ public class LabelController extends BaseController { @Autowired private LabelService labelService; - @RequestMapping(method = RequestMethod.POST, value = "", consumes = {"application/json"}) @ResponseStatus(value = HttpStatus.CREATED) public void createLabel(@RequestBody RestLabel restLabel, @NotNull HttpServletResponse response, @RequestParam(required = false) String title) throws WiseMappingException { diff --git a/wise-api/src/main/java/com/wisemapping/rest/MindmapController.java b/wise-api/src/main/java/com/wisemapping/rest/MindmapController.java index 70d65d5c..54ad7995 100644 --- a/wise-api/src/main/java/com/wisemapping/rest/MindmapController.java +++ b/wise-api/src/main/java/com/wisemapping/rest/MindmapController.java @@ -65,7 +65,7 @@ public class MindmapController extends BaseController { @Autowired private UserService userService; - @Value("${accounts.maxInactive:20}") + @Value("${app.accounts.max-inactive:20}") private int maxAccountsInactive; diff --git a/wise-api/src/main/java/com/wisemapping/rest/model/RestAppConfig.java b/wise-api/src/main/java/com/wisemapping/rest/model/RestAppConfig.java new file mode 100644 index 00000000..41dcd5b9 --- /dev/null +++ b/wise-api/src/main/java/com/wisemapping/rest/model/RestAppConfig.java @@ -0,0 +1,145 @@ +/* + * Copyright [2022] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.wisemapping.rest.model; + + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import org.jetbrains.annotations.NotNull; + + +@JsonAutoDetect( + fieldVisibility = JsonAutoDetect.Visibility.NONE, + getterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY, + isGetterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY) +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class RestAppConfig { + private String apiBaseUrl; + private String googleOauth2Url; + private boolean registrationEnabled; + private boolean recaptcha2Enabled; + private String recaptcha2SiteKey; + private String analyticsAccount; + + RestAppConfig() { + + } + + public String getApiBaseUrl() { + return apiBaseUrl; + } + + public void setApiBaseUrl(String apiBaseUrl) { + this.apiBaseUrl = apiBaseUrl; + } + + public String getGoogleOauth2Url() { + return googleOauth2Url; + } + + public void setGoogleOauth2Url(String googleOauth2Url) { + this.googleOauth2Url = googleOauth2Url; + } + + public boolean isRegistrationEnabled() { + return registrationEnabled; + } + + public void setRegistrationEnabled(boolean registrationEnabled) { + this.registrationEnabled = registrationEnabled; + } + + public boolean isRecaptcha2Enabled() { + return recaptcha2Enabled; + } + + public void setRecaptcha2Enabled(boolean recaptcha2Enabled) { + this.recaptcha2Enabled = recaptcha2Enabled; + } + + public String getRecaptcha2SiteKey() { + return recaptcha2SiteKey; + } + + public void setRecaptcha2SiteKey(String recaptcha2SiteKey) { + this.recaptcha2SiteKey = recaptcha2SiteKey; + } + + public String getAnalyticsAccount() { + return analyticsAccount; + } + + public void setAnalyticsAccount(String analyticsAccount) { + this.analyticsAccount = analyticsAccount; + } + + public static class RestAppConfigBuilder { + private String apiBaseUrl; + private String googleOauth2Url; + private boolean registrationEnabled; + private boolean isCatchaEnabled = false; + private String captchaSiteKey; + private String analyticsAccount; + + public RestAppConfigBuilder setCaptchaSiteKey(@NotNull String captchaSiteKey) { + this.captchaSiteKey = captchaSiteKey; + this.isCatchaEnabled = true; + return this; + } + + public RestAppConfigBuilder setApiUrl(@NotNull String apiBaseUrl) { + this.apiBaseUrl = apiBaseUrl; + return this; + } + + public RestAppConfigBuilder setGoogleOauth2Url(@NotNull String googleOauth2Url) { + this.googleOauth2Url = googleOauth2Url; + return this; + } + + private void setGoogleAnalyticsAccount(@NotNull String analyticsAccount) { + this.analyticsAccount = analyticsAccount; + } + + public RestAppConfigBuilder setRegistrationEnabled(@NotNull boolean registrationEnabled) { + this.registrationEnabled = registrationEnabled; + return this; + } + + public RestAppConfigBuilder setAnalyticsAccount(@NotNull String analyticsAccount) { + this.analyticsAccount = analyticsAccount; + return this; + } + + @NotNull + public RestAppConfig build() { + final RestAppConfig result = new RestAppConfig(); + result.googleOauth2Url = googleOauth2Url; + result.recaptcha2SiteKey = captchaSiteKey; + result.recaptcha2Enabled = isCatchaEnabled; + result.apiBaseUrl = apiBaseUrl; + result.registrationEnabled = registrationEnabled; + result.analyticsAccount = analyticsAccount; + return result; + } + } + +} diff --git a/wise-api/src/main/java/com/wisemapping/service/MailerService.java b/wise-api/src/main/java/com/wisemapping/service/MailerService.java index 05a93dfa..d93b3bec 100644 --- a/wise-api/src/main/java/com/wisemapping/service/MailerService.java +++ b/wise-api/src/main/java/com/wisemapping/service/MailerService.java @@ -44,13 +44,13 @@ public final class MailerService { @Autowired private VelocityEngineWrapper velocityEngineWrapper; - @Value("${app.mail.serverSendEmail}") + @Value("${app.mail.sender-email}") private String serverFromEmail; @Value("${app.mail.enabled:true}") private boolean isEnabled; - @Value("${app.mail.supportEmail}") + @Value("${app.mail.support-email}") private String supportEmail; //~ Methods .............................................................................................. diff --git a/wise-api/src/main/java/com/wisemapping/service/NotificationService.java b/wise-api/src/main/java/com/wisemapping/service/NotificationService.java index bbc17817..cd1047b7 100644 --- a/wise-api/src/main/java/com/wisemapping/service/NotificationService.java +++ b/wise-api/src/main/java/com/wisemapping/service/NotificationService.java @@ -44,7 +44,7 @@ final public class NotificationService { @Autowired private MailerService mailerService; - @Value("${app.site.baseurl:http://localhost:8080/}") + @Value("${app.site.ui-base-url:http://localhost:8080/}") private String baseUrl; public void newCollaboration(@NotNull Collaboration collaboration, @NotNull Mindmap mindmap, @NotNull Account user, @Nullable String message) { @@ -121,7 +121,7 @@ final public class NotificationService { model.put("messageTitle", messageTitle); model.put("messageBody", messageBody); model.put("baseUrl", getBaseUrl()); - model.put("supportEmail", mailerService.getSupportEmail()); + model.put("support-email", mailerService.getSupportEmail()); model.put("doNotReplay", messageSource.getMessage("EMAIL.DO_NOT_REPLAY", new Object[]{mailerService.getSupportEmail()}, locale)); // To resolve resources on templates ... diff --git a/wise-api/src/main/resources/application.yml b/wise-api/src/main/resources/application.yml index 7f098633..e00cd35f 100644 --- a/wise-api/src/main/resources/application.yml +++ b/wise-api/src/main/resources/application.yml @@ -18,7 +18,7 @@ spring: writetimeout: 5000 output: ansi: - enabled=always: + enabled: always application: name: wisemapping-api title: wisemapping-api @@ -55,18 +55,23 @@ logging: # Application Configuration. app: site: - baseurl: https://localhost:8080 + ui-base-url: https://localhost:8080 + api-base-url: https://api.wisemapping.com api: http-basic-enabled: false +# analytics: +# account: jwt: secret: dlqxKAg685SaKhsQXIMeM=JWCw3bkl3Ei3Tb7LMlnd19oMd66burPNlJ0Po1qguyjgpakQTk2CN3 expirationMin: 10080 # One week admin: user: admin@wisemapping.org mail: - serverSendEmail: root@localhost - supportEmail: root@localhost + sender-email: root@localhost + support-email: root@localhost enabled: false + accounts: + max-inactive: 20 ####################################################################################### # Google OAuth Authentication ####################################################################################### @@ -74,7 +79,7 @@ app: #security.oauth2.google.clientId= # OAuth Client secret #security.oauth2.google.clientSecret= - # Redirect to this url, this url must be configured in the google app {baseurl}/c/registration-google + # Redirect to this url, this url must be configured in the google app {ui-base-url}/c/registration-google #security.oauth2.google.callbackUrl= security: # corsAllowedOrigins: https://dev.wisemapping.com @@ -82,13 +87,17 @@ app: google: confirmUrl: https://oauth2.googleapis.com/token userinfoUrl: https://www:googleapis.com/oauth2/v3/userinfo + callbackUrl: https://app.wisemapping.com/c/registration-google + clientId: 625682766634-cocbbbbb403iuvps1evecdk6d7phvbkf.apps.googleusercontent.com url: https://accounts.google.com/o/oauth2/v2/auth?redirect_uri=${app.security.oauth2.google.callbackUrl}&prompt=consent&response_type=code&client_id=${app.security.oauth2.google.clientId}&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&access_type=offline&state=wisemapping&include_granted_scopes=true -# accounts: -# exclusion: -# domain: + # accounts: + # exclusion: + # domain: registration: - enabled: false + enabled: true captcha: enabled: false - secretKey: 6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe + siteKey: some-key + secretKey: some-secret +