This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Commit cdad7952 authored by Michael Breu's avatar Michael Breu 💬
Browse files

Intermediate commit

parent 05e9a60a
......@@ -10,4 +10,19 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
*/
@ConfigurationProperties(prefix = "application", ignoreUnknownFields = false)
public class ApplicationProperties {
private String pluginToken;
/**
* @return the pluginToken
*/
public String getPluginToken() {
return pluginToken;
}
/**
* @param pluginToken the pluginToken to set
*/
public void setPluginToken(String pluginToken) {
this.pluginToken = pluginToken;
}
}
......@@ -3,6 +3,7 @@ package org.codeability.sharing.demo.service;
import org.codeability.sharing.plugins.api.SharingPluginConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
......@@ -11,12 +12,32 @@ import org.springframework.stereotype.Service;
@Service
public class SharingPluginService {
/**
* the authorization token.
* Should be more sophisticated, than just a simple string.
*/
@Value("${application.pluginToken}")
private String pluginToken;
/**
* the base url for call backs
*/
private String apiBaseUrl = null;
private final Logger log = LoggerFactory.getLogger(SharingPluginService.class);
public SharingPluginService() {
}
public boolean validate(String accessToken, String apiBaseUrl) {
boolean valid = pluginToken.equals(accessToken);
if(valid) {
this.apiBaseUrl = apiBaseUrl;
}
return valid;
}
public SharingPluginConfig getPluginConfig(String baseAPIURI) {
SharingPluginConfig.Action actionCollection = new SharingPluginConfig.Action(
......@@ -33,4 +54,8 @@ public class SharingPluginService {
return pluginConfig;
}
public String getApiBaseUrl() {
return apiBaseUrl;
}
}
......@@ -4,10 +4,12 @@ import org.codeability.sharing.demo.service.SharingPluginService;
import org.codeability.sharing.plugins.api.SharingPluginConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
......@@ -19,10 +21,14 @@ import org.springframework.web.bind.annotation.RestController;
public class SharingSupportResource {
private final Logger log = LoggerFactory.getLogger(SharingSupportResource.class);
@SuppressWarnings("unused")
private final Logger log = LoggerFactory.getLogger(SharingSupportResource.class);
private SharingPluginService sharingPluginService;
@Value("${jhipster.clientApp.name}")
private String applicationName;
public SharingSupportResource(SharingPluginService sharingPluginService) {
this.sharingPluginService = sharingPluginService;
}
......@@ -33,7 +39,12 @@ public class SharingSupportResource {
* @return Sharing Plugin configuration
*/
@GetMapping("/sharingPluginConfig")
public ResponseEntity<SharingPluginConfig> getConfig() {
public ResponseEntity<SharingPluginConfig> getConfig(@RequestParam String accessToken, @RequestParam String apiBaseUrl) {
if(!sharingPluginService.validate(accessToken, apiBaseUrl)) {
return ResponseEntity.badRequest().headers(io.github.jhipster.web.util.HeaderUtil.createFailureAlert(applicationName, true, "PluginConfig", "Token invalid",
"Token not valid. Request ignored.")).build();
}
return ResponseEntity.ok(sharingPluginService.getPluginConfig("/api"));
}
......
......@@ -177,4 +177,5 @@ jhipster:
# https://www.jhipster.tech/common-application-properties/
# ===================================================================
# application:
application:
pluginToken: "2c8845a4-b3df-414b-a682-36e2313dc1c0"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment