This is the codeAbility Sharing Platform! Learn more about the
codeAbility Sharing Platform
.
Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
development
sharing
sharing plugin Demo
Commits
cdad7952
Commit
cdad7952
authored
Apr 27, 2021
by
Michael Breu
💬
Browse files
Intermediate commit
parent
05e9a60a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
3 deletions
+55
-3
src/main/java/org/codeability/sharing/demo/config/ApplicationProperties.java
...odeability/sharing/demo/config/ApplicationProperties.java
+15
-0
src/main/java/org/codeability/sharing/demo/service/SharingPluginService.java
...odeability/sharing/demo/service/SharingPluginService.java
+25
-0
src/main/java/org/codeability/sharing/demo/web/rest/SharingSupportResource.java
...ability/sharing/demo/web/rest/SharingSupportResource.java
+13
-2
src/main/resources/config/application.yml
src/main/resources/config/application.yml
+2
-1
No files found.
src/main/java/org/codeability/sharing/demo/config/ApplicationProperties.java
View file @
cdad7952
...
...
@@ -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
;
}
}
src/main/java/org/codeability/sharing/demo/service/SharingPluginService.java
View file @
cdad7952
...
...
@@ -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
;
}
}
src/main/java/org/codeability/sharing/demo/web/rest/SharingSupportResource.java
View file @
cdad7952
...
...
@@ -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"
));
}
...
...
src/main/resources/config/application.yml
View file @
cdad7952
...
...
@@ -177,4 +177,5 @@ jhipster:
# https://www.jhipster.tech/common-application-properties/
# ===================================================================
# application:
application
:
pluginToken
:
"
2c8845a4-b3df-414b-a682-36e2313dc1c0"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment