Compare commits
9 Commits
c59fa0b7a8
...
c9d0281691
Author | SHA1 | Date |
---|---|---|
Alfredo Oliviero | c9d0281691 | |
Alfredo Oliviero | b2b5367aa5 | |
Alfredo Oliviero | 6ab3c110a2 | |
Alfredo Oliviero | cc2d0b74cd | |
Alfredo Oliviero | bacba3984c | |
Alfredo Oliviero | 12d5b2a1ad | |
Alfredo Oliviero | ccda3995e0 | |
Alfredo Oliviero | 535df5b3a9 | |
Alfredo Oliviero | 1cef40fbbd |
39
.classpath
39
.classpath
|
@ -1,39 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
|
@ -1,2 +1,321 @@
|
|||
/target/
|
||||
/target/
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/java,eclipse,visualstudiocode,intellij,macos,linux,windows,maven
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=java,eclipse,visualstudiocode,intellij,macos,linux,windows,maven
|
||||
|
||||
### Eclipse ###
|
||||
.metadata
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
.recommenders
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
# PyDev specific (Python IDE for Eclipse)
|
||||
*.pydevproject
|
||||
|
||||
# CDT-specific (C/C++ Development Tooling)
|
||||
.cproject
|
||||
|
||||
# CDT- autotools
|
||||
.autotools
|
||||
|
||||
# Java annotation processor (APT)
|
||||
.factorypath
|
||||
|
||||
# PDT-specific (PHP Development Tools)
|
||||
.buildpath
|
||||
|
||||
# sbteclipse plugin
|
||||
.target
|
||||
|
||||
# Tern plugin
|
||||
.tern-project
|
||||
|
||||
# TeXlipse plugin
|
||||
.texlipse
|
||||
|
||||
# STS (Spring Tool Suite)
|
||||
.springBeans
|
||||
|
||||
# Code Recommenders
|
||||
.recommenders/
|
||||
|
||||
# Annotation Processing
|
||||
.apt_generated/
|
||||
.apt_generated_test/
|
||||
|
||||
# Scala IDE specific (Scala & Java development for Eclipse)
|
||||
.cache-main
|
||||
.scala_dependencies
|
||||
.worksheet
|
||||
|
||||
# Uncomment this line if you wish to ignore the project description file.
|
||||
# Typically, this file would be tracked if it contains build/dependency configurations:
|
||||
#.project
|
||||
|
||||
### Eclipse Patch ###
|
||||
# Spring Boot Tooling
|
||||
.sts4-cache/
|
||||
|
||||
### Intellij ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# AWS User-specific
|
||||
.idea/**/aws.xml
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# SonarLint plugin
|
||||
.idea/sonarlint/
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
### Intellij Patch ###
|
||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||
|
||||
# *.iml
|
||||
# modules.xml
|
||||
# .idea/misc.xml
|
||||
# *.ipr
|
||||
|
||||
# Sonarlint plugin
|
||||
# https://plugins.jetbrains.com/plugin/7973-sonarlint
|
||||
.idea/**/sonarlint/
|
||||
|
||||
# SonarQube Plugin
|
||||
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
|
||||
.idea/**/sonarIssues.xml
|
||||
|
||||
# Markdown Navigator plugin
|
||||
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
|
||||
.idea/**/markdown-navigator.xml
|
||||
.idea/**/markdown-navigator-enh.xml
|
||||
.idea/**/markdown-navigator/
|
||||
|
||||
# Cache file creation bug
|
||||
# See https://youtrack.jetbrains.com/issue/JBR-2257
|
||||
.idea/$CACHE_FILE$
|
||||
|
||||
# CodeStream plugin
|
||||
# https://plugins.jetbrains.com/plugin/12206-codestream
|
||||
.idea/codestream.xml
|
||||
|
||||
# Azure Toolkit for IntelliJ plugin
|
||||
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
|
||||
.idea/**/azureSettings.xml
|
||||
|
||||
### Java ###
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
### Linux ###
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
### macOS ###
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
### macOS Patch ###
|
||||
# iCloud generated files
|
||||
*.icloud
|
||||
|
||||
### Maven ###
|
||||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
# Eclipse m2e generated files
|
||||
# Eclipse Core
|
||||
.project
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
.classpath
|
||||
|
||||
### VisualStudioCode ###
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
!.vscode/*.code-snippets
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
# Built Visual Studio Code Extensions
|
||||
*.vsix
|
||||
|
||||
### VisualStudioCode Patch ###
|
||||
# Ignore all local history of files
|
||||
.history
|
||||
.ionide
|
||||
|
||||
### Windows ###
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
Thumbs.db:encryptable
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/java,eclipse,visualstudiocode,intellij,macos,linux,windows,maven
|
||||
|
|
37
.project
37
.project
|
@ -1,37 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>HelloWorld</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -1,6 +0,0 @@
|
|||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/main/resources=UTF-8
|
||||
encoding//src/test/java=UTF-8
|
||||
encoding//src/test/resources=UTF-8
|
||||
encoding/<project>=UTF-8
|
|
@ -1,11 +0,0 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||
org.eclipse.jdt.core.compiler.compliance=11
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=11
|
|
@ -1,4 +0,0 @@
|
|||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
// Usare IntelliSense per informazioni sui possibili attributi.
|
||||
// Al passaggio del mouse vengono visualizzate le descrizioni degli attributi esistenti.
|
||||
// Per altre informazioni, visitare: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "java",
|
||||
"name": "Debug (Attach)",
|
||||
"projectName": "identity-manager",
|
||||
"request": "attach",
|
||||
"hostName": "localhost",
|
||||
"port": 5005
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"java.configuration.updateBuildConfiguration": "automatic"
|
||||
}
|
35
README.md
35
README.md
|
@ -13,6 +13,41 @@ HelloWorld service for smartgears4
|
|||
|
||||
## Documentation
|
||||
|
||||
|
||||
|
||||
start the docker container
|
||||
```./buildImageAndStart.sh```
|
||||
|
||||
test urls (replace {{TOKEN}} with your token):
|
||||
|
||||
|
||||
http://localhost:8080/helloworld/guest
|
||||
|
||||
http://localhost:8080/helloworld/details?gcube-token={{TOKEN}}
|
||||
http://localhost:8080/helloworld/hello/details?gcube-token={{TOKEN}}
|
||||
|
||||
http://localhost:8080/helloworld/auth?gcube-token={{TOKEN}} (checks for myRole role)
|
||||
http://localhost:8080/helloworld/auth/orm_member?gcube-token={{TOKEN}} (checks for OrganizationMember role)
|
||||
|
||||
|
||||
### Authentication:
|
||||
|
||||
#### GCUBE-TOKEN param
|
||||
|
||||
obtain personal token at https://next.dev.d4science.org/group/gcube/home
|
||||
|
||||
add
|
||||
|
||||
|
||||
### DEBUG
|
||||
|
||||
start the docker container in debug Mode
|
||||
```./buildImageAndStartWithDebug.sh```
|
||||
|
||||
connect the JAVA debugger to port 5005
|
||||
|
||||
* VSCODE: press the green play button and start "Debug (Attach)
|
||||
|
||||
## Change log
|
||||
|
||||
See [Releases](https://code-repo.d4science.org/gCubeSystem/helloworld/releases).
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
mvn clean package
|
||||
docker build -t smartgears-helloworld .
|
||||
docker run -p 8080:8080 smartgears-helloworld
|
||||
docker build -t smartgears-helloworld .
|
||||
docker run -p 8080:8080 smartgears-helloworld
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
mvn package
|
||||
docker build -t smartgears-helloworld .
|
||||
docker run -p 8080:8080 -p 5005:5005 -e JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,address=*:5005,server=y,suspend=y" smartgears-helloworld
|
||||
docker build -t smartgears-helloworld .
|
||||
docker run -p 8080:8080 -p 5005:5005 -e JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,address=*:5005,server=y,suspend=y" smartgears-helloworld
|
||||
|
|
|
@ -0,0 +1,333 @@
|
|||
{
|
||||
"info": {
|
||||
"_postman_id": "57ac2a18-0102-4843-afaf-72c05aa24207",
|
||||
"name": "Smartgears4 helloword",
|
||||
"description": "An example collection that can be used for communicating with gcube services\n\nget TOKEN and at UMA_TOKEN from url: [https://next.dev.d4science.org/group/gcube/home](https://next.dev.d4science.org/group/gcube/home)\n\nupdate the collection's variables gcube_token and uma_token",
|
||||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
|
||||
"_exporter_id": "32856827"
|
||||
},
|
||||
"item": [
|
||||
{
|
||||
"name": "hello TOKEN PARAM",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "noauth"
|
||||
},
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "{{base_url}}/{{application}}/hello?gcube-token={{gcube_token}}",
|
||||
"host": [
|
||||
"{{base_url}}"
|
||||
],
|
||||
"path": [
|
||||
"{{application}}",
|
||||
"hello"
|
||||
],
|
||||
"query": [
|
||||
{
|
||||
"key": "gcube-token",
|
||||
"value": "{{gcube_token}}"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "hello BEARER",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "{{uma_token}}",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "{{base_url}}/{{application}}/hello",
|
||||
"host": [
|
||||
"{{base_url}}"
|
||||
],
|
||||
"path": [
|
||||
"{{application}}",
|
||||
"hello"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "details TOKEN PARAM",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "noauth"
|
||||
},
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "{{base_url}}/{{application}}/details?gcube-token={{gcube_token}}",
|
||||
"host": [
|
||||
"{{base_url}}"
|
||||
],
|
||||
"path": [
|
||||
"{{application}}",
|
||||
"details"
|
||||
],
|
||||
"query": [
|
||||
{
|
||||
"key": "gcube-token",
|
||||
"value": "{{gcube_token}}"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "details BEARER",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "{{uma_token}}",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "{{base_url}}/{{application}}/details",
|
||||
"host": [
|
||||
"{{base_url}}"
|
||||
],
|
||||
"path": [
|
||||
"{{application}}",
|
||||
"details"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "guest",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "noauth"
|
||||
},
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "{{base_url}}/{{application}}/guest",
|
||||
"host": [
|
||||
"{{base_url}}"
|
||||
],
|
||||
"path": [
|
||||
"{{application}}",
|
||||
"guest"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "auth TOKEN PARAM",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "{{uma_token}}",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "{{base_url}}/{{application}}/auth/?gcube-token={{gcube_token}}",
|
||||
"host": [
|
||||
"{{base_url}}"
|
||||
],
|
||||
"path": [
|
||||
"{{application}}",
|
||||
"auth",
|
||||
""
|
||||
],
|
||||
"query": [
|
||||
{
|
||||
"key": "gcube-token",
|
||||
"value": "{{gcube_token}}"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "auth org member BEARER",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "{{uma_token}}",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "Z{{base_url}}/{{application}}/auth/org_member",
|
||||
"host": [
|
||||
"Z{{base_url}}"
|
||||
],
|
||||
"path": [
|
||||
"{{application}}",
|
||||
"auth",
|
||||
"org_member"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "auth org member TOKEN PARAM",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "noauth"
|
||||
},
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "{{base_url}}/{{application}}/auth/org_member?gcube-token={{gcube_token}}",
|
||||
"host": [
|
||||
"{{base_url}}"
|
||||
],
|
||||
"path": [
|
||||
"{{application}}",
|
||||
"auth",
|
||||
"org_member"
|
||||
],
|
||||
"query": [
|
||||
{
|
||||
"key": "gcube-token",
|
||||
"value": "{{gcube_token}}"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "auth member BEARER",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "{{uma_token}}",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "{{base_url}}/{{application}}/auth/member",
|
||||
"host": [
|
||||
"{{base_url}}"
|
||||
],
|
||||
"path": [
|
||||
"{{application}}",
|
||||
"auth",
|
||||
"member"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "auth member TOKEN PARAM",
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "noauth"
|
||||
},
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"url": {
|
||||
"raw": "{{base_url}}/{{application}}/auth/member?gcube-token={{gcube_token}}",
|
||||
"host": [
|
||||
"{{base_url}}"
|
||||
],
|
||||
"path": [
|
||||
"{{application}}",
|
||||
"auth",
|
||||
"member"
|
||||
],
|
||||
"query": [
|
||||
{
|
||||
"key": "gcube-token",
|
||||
"value": "{{gcube_token}}"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
}
|
||||
],
|
||||
"event": [
|
||||
{
|
||||
"listen": "prerequest",
|
||||
"script": {
|
||||
"type": "text/javascript",
|
||||
"exec": [
|
||||
""
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"type": "text/javascript",
|
||||
"exec": [
|
||||
""
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"variable": [
|
||||
{
|
||||
"key": "base_url",
|
||||
"value": "http://localhost:8080",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"key": "application",
|
||||
"value": "helloworld",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"key": "gcube_token",
|
||||
"value": "",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"key": "uma_token",
|
||||
"value": "",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -4,4 +4,5 @@ version: 1.0.0
|
|||
description: HelloWorld Service
|
||||
excludes:
|
||||
- path: /excluded
|
||||
- path: /guest
|
||||
- path: /api-docs/*
|
40
pom.xml
40
pom.xml
|
@ -1,4 +1,6 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
|
@ -90,24 +92,24 @@
|
|||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>aspectj-maven-plugin</artifactId>
|
||||
<version>${aspectj-plugin.version}</version>
|
||||
<configuration>
|
||||
<complianceLevel>11</complianceLevel>
|
||||
<source>11</source>
|
||||
<target>11</target>
|
||||
<aspectLibraries>
|
||||
<aspectLibrary>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-control-library</artifactId>
|
||||
</aspectLibrary>
|
||||
</aspectLibraries>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<complianceLevel>11</complianceLevel>
|
||||
<source>11</source>
|
||||
<target>11</target>
|
||||
<aspectLibraries>
|
||||
<aspectLibrary>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-control-library</artifactId>
|
||||
</aspectLibrary>
|
||||
</aspectLibraries>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
|
|
@ -6,10 +6,14 @@ import java.util.Set;
|
|||
import javax.ws.rs.ApplicationPath;
|
||||
import javax.ws.rs.core.Application;
|
||||
|
||||
import org.gcube.service.helloworld.services.AuthorizedMethods;
|
||||
import org.gcube.service.helloworld.services.ExcludeAuthorization;
|
||||
import org.gcube.service.helloworld.services.AuthenticatedService;
|
||||
import org.gcube.service.helloworld.services.ExcludeAuthorizationService;
|
||||
import org.gcube.service.helloworld.services.HelloService;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lucio Lelii (ISTI-CNR)
|
||||
*/
|
||||
|
||||
@ApplicationPath("")
|
||||
public class HelloWorld extends Application {
|
||||
|
@ -18,8 +22,8 @@ public class HelloWorld extends Application {
|
|||
final Set<Class<?>> classes = new HashSet<Class<?>>();
|
||||
// register resources classes implementing Servlets
|
||||
classes.add(HelloService.class);
|
||||
classes.add(AuthorizedMethods.class);
|
||||
classes.add(ExcludeAuthorization.class);
|
||||
classes.add(ExcludeAuthorizationService.class);
|
||||
classes.add(AuthenticatedService.class);
|
||||
return classes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,23 +16,25 @@ import org.slf4j.LoggerFactory;
|
|||
* to the app declaring it via the @ManagedBy annotation. (@see HelloWorld
|
||||
* class)
|
||||
*
|
||||
*
|
||||
* @author lucio
|
||||
*
|
||||
* @author Lucio Lelii (ISTI-CNR)
|
||||
*/
|
||||
|
||||
public class HelloWorldManager implements ApplicationManager {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(HelloWorldManager.class);
|
||||
|
||||
@Override
|
||||
public void onInit() {
|
||||
public void onInit() {
|
||||
if (ContextProvider.get().container().configuration().mode() == Mode.offline) {
|
||||
logger.debug("init called in offline mode");
|
||||
} else {
|
||||
Secret secret = SecretManagerProvider.get();
|
||||
logger.debug("init called in context {}", secret.getContext());
|
||||
if (secret != null) {
|
||||
logger.debug("init called in context {}", secret.getContext());
|
||||
} else {
|
||||
logger.debug("init called in null context");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,8 +43,11 @@ public class HelloWorldManager implements ApplicationManager {
|
|||
logger.debug("shutDown called in offline mode");
|
||||
} else {
|
||||
Secret secret = SecretManagerProvider.get();
|
||||
logger.debug("shutDown called in context {}", secret.getContext());
|
||||
if (secret != null) {
|
||||
logger.debug("shutDown called in context {}", secret.getContext());
|
||||
} else {
|
||||
logger.debug("shutDown called in null context");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package org.gcube.service.helloworld.serializers;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
|
||||
/**
|
||||
* Jackson serializer for ContainerConfiguration
|
||||
*
|
||||
* @author Alfredo Oliviero (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
|
||||
public class ContainerConfigurationSerializer extends StdSerializer<ContainerConfiguration> {
|
||||
protected ContainerConfigurationSerializer(Class<ContainerConfiguration> t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
public ContainerConfigurationSerializer() {
|
||||
super(ContainerConfiguration.class, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ContainerConfiguration configuration, JsonGenerator jgen, SerializerProvider provider)
|
||||
throws IOException {
|
||||
jgen.writeStartObject();
|
||||
jgen.writeObjectField("mode", configuration.mode());
|
||||
jgen.writeObjectField("app", configuration.apps());
|
||||
jgen.writeObjectField("site", configuration.site());
|
||||
jgen.writeObjectField("infrastructure", configuration.infrastructure());
|
||||
jgen.writeObjectField("hostname", configuration.hostname());
|
||||
jgen.writeObjectField("port", configuration.port());
|
||||
jgen.writeObjectField("protocol", configuration.protocol());
|
||||
jgen.writeObjectField("authorizeChildrenContext", configuration.authorizeChildrenContext());
|
||||
jgen.writeObjectField("proxy", configuration.proxy());
|
||||
|
||||
jgen.writeObjectField("desc", configuration.toString());
|
||||
|
||||
jgen.writeEndObject();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package org.gcube.service.helloworld.serializers;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.gcube.smartgears.context.container.ContainerContext;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
|
||||
/**
|
||||
* Jackson serializer for ContainerContext
|
||||
*
|
||||
* @author Alfredo Oliviero (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
|
||||
public class ContainerContextSerializer extends StdSerializer<ContainerContext> {
|
||||
protected ContainerContextSerializer(Class<ContainerContext> t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
public ContainerContextSerializer() {
|
||||
super(ContainerContext.class, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ContainerContext ccontext, JsonGenerator jgen, SerializerProvider provider)
|
||||
throws IOException {
|
||||
jgen.writeStartObject();
|
||||
jgen.writeStringField("id", ccontext.id());
|
||||
// jgen.writeObjectField("configuration.site", ccontext.configuration().site());
|
||||
// jgen.writeObjectField("configuration", ccontext.configuration());
|
||||
jgen.writeObjectField("properties", ccontext.properties());
|
||||
jgen.writeObjectField("authorizationProvider", ccontext.authorizationProvider());
|
||||
|
||||
jgen.writeObjectField("configuration", ccontext.configuration());
|
||||
jgen.writeObjectField("desc", ccontext.toString());
|
||||
|
||||
jgen.writeEndObject();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package org.gcube.service.helloworld.serializers;
|
||||
|
||||
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
|
||||
import org.gcube.smartgears.context.container.ContainerContext;
|
||||
import org.gcube.smartgears.security.SimpleCredentials;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
|
||||
/**
|
||||
* Jackson Serialization utils for Smartgear Context classes
|
||||
*
|
||||
* @author Alfredo Oliviero (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
|
||||
public class ContextSerializator {
|
||||
private static ObjectMapper serializer = null;
|
||||
|
||||
public static ObjectMapper getSerializer() {
|
||||
if (serializer == null) {
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
SimpleModule module = new SimpleModule();
|
||||
// module.addSerializer(Owner.class, new OwnerSerializer());
|
||||
|
||||
module.addSerializer(ContainerConfiguration.class, new ContainerConfigurationSerializer());
|
||||
module.addSerializer(ContainerContext.class, new ContainerContextSerializer());
|
||||
module.addSerializer(SimpleCredentials.class, new SimpleCredentialsSerializer());
|
||||
|
||||
om.registerModule(module);
|
||||
serializer = om;
|
||||
}
|
||||
return serializer;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package org.gcube.service.helloworld.serializers;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.gcube.common.security.Owner;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
|
||||
/**
|
||||
* Jackson serializer for Owner
|
||||
*
|
||||
* @author Alfredo Oliviero (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
|
||||
public class OwnerSerializer extends StdSerializer<Owner> {
|
||||
|
||||
protected OwnerSerializer(Class<Owner> t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
public OwnerSerializer() {
|
||||
super(Owner.class, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(Owner owner, JsonGenerator jgen, SerializerProvider provider) throws IOException {
|
||||
jgen.writeStartObject();
|
||||
jgen.writeStringField("ownerId", owner.getId());
|
||||
jgen.writeStringField("clientName", owner.getClientName());
|
||||
jgen.writeArrayFieldStart("roles");
|
||||
for (String role : owner.getRoles()) {
|
||||
jgen.writeString(role);
|
||||
}
|
||||
jgen.writeEndArray();
|
||||
jgen.writeStringField("email", owner.getEmail());
|
||||
jgen.writeStringField("firstName", owner.getFirstName());
|
||||
jgen.writeStringField("lastName", owner.getLastName());
|
||||
jgen.writeBooleanField("externalClient", owner.isExternalClient());
|
||||
jgen.writeStringField("contactPerson", owner.getClientName());
|
||||
jgen.writeStringField("contactOrganisation", owner.getContactOrganisation());
|
||||
|
||||
jgen.writeEndObject();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package org.gcube.service.helloworld.serializers;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.gcube.smartgears.security.SimpleCredentials;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
|
||||
/**
|
||||
* Jackson serializer for SimpleCredentials
|
||||
*
|
||||
* @author Alfredo Oliviero (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
|
||||
public class SimpleCredentialsSerializer extends StdSerializer<SimpleCredentials> {
|
||||
|
||||
protected SimpleCredentialsSerializer(Class<SimpleCredentials> t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
public SimpleCredentialsSerializer() {
|
||||
super(SimpleCredentials.class, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(SimpleCredentials credentials, JsonGenerator jgen, SerializerProvider provider)
|
||||
throws IOException {
|
||||
jgen.writeStartObject();
|
||||
jgen.writeStringField("clientId", credentials.getClientID());
|
||||
jgen.writeStringField("secret", "[*****]");
|
||||
jgen.writeEndObject();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package org.gcube.service.helloworld.services;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.gcube.common.authorization.control.annotations.AuthorizationControl;
|
||||
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||
import org.gcube.common.security.secrets.Secret;
|
||||
import org.gcube.smartgears.utils.InnerMethodName;
|
||||
|
||||
/**
|
||||
* @author Lucio Le (ISTI - CNR)
|
||||
* @author Alfredo Oliviero (ISTI - CNR)
|
||||
*/
|
||||
|
||||
@Path("auth")
|
||||
public class AuthenticatedService {
|
||||
|
||||
private static final String ALLOWED_ROLE = "myRole";
|
||||
private static final String ALLOWED_ROLE_ORG = "OrganizationMember";
|
||||
private static final String ALLOWED_ROLE_MEMBER = "Member";
|
||||
|
||||
@AuthorizationControl(allowedRoles = { ALLOWED_ROLE_ORG })
|
||||
@GET
|
||||
@Path("org_member")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public String authorizedOrg() {
|
||||
InnerMethodName.set("auth");
|
||||
Secret secret = SecretManagerProvider.get();
|
||||
String userId = secret.getOwner().getId();
|
||||
String context = secret.getContext();
|
||||
return String.format(
|
||||
"User %s in context %s is authorized to execute this method because he has the role %s", userId, context, ALLOWED_ROLE_ORG);
|
||||
}
|
||||
|
||||
@AuthorizationControl(allowedRoles = { ALLOWED_ROLE_MEMBER })
|
||||
@GET
|
||||
@Path("member")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public String authorizedMember() {
|
||||
InnerMethodName.set("auth");
|
||||
Secret secret = SecretManagerProvider.get();
|
||||
String userId = secret.getOwner().getId();
|
||||
String context = secret.getContext();
|
||||
return String.format(
|
||||
"User %s in context %s is authorized to execute this method because he has the role %s", userId, context, ALLOWED_ROLE_MEMBER);
|
||||
}
|
||||
|
||||
|
||||
@AuthorizationControl(allowedRoles = { ALLOWED_ROLE })
|
||||
@GET
|
||||
@Path("")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public String authorized() {
|
||||
InnerMethodName.set("auth");
|
||||
Secret secret = SecretManagerProvider.get();
|
||||
String userId = secret.getOwner().getId();
|
||||
String context = secret.getContext();
|
||||
return String.format(
|
||||
"User %s in context %s is authorized to execute this method because he has the role %s", userId, context, ALLOWED_ROLE);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package org.gcube.service.helloworld.services;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
import org.gcube.common.authorization.control.annotations.AuthorizationControl;
|
||||
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||
import org.gcube.common.security.secrets.Secret;
|
||||
import org.gcube.smartgears.utils.InnerMethodName;
|
||||
|
||||
@Path("auth")
|
||||
public class AuthorizedMethods {
|
||||
|
||||
private static final String ALLOWED_ROLE = "myRole";
|
||||
|
||||
@AuthorizationControl(allowedRoles={ALLOWED_ROLE})
|
||||
@GET
|
||||
public String authorized() {
|
||||
InnerMethodName.set("auth");
|
||||
Secret secret = SecretManagerProvider.get();
|
||||
String userId = secret.getOwner().getId();
|
||||
String context = secret.getContext();
|
||||
return String.format("User %s in context %s is authorized to execute this method because he has the correct role", userId,context);
|
||||
}
|
||||
|
||||
}
|
|
@ -6,10 +6,10 @@ import javax.ws.rs.Path;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Path("excluded")
|
||||
public class ExcludeAuthorization {
|
||||
@Path("guest")
|
||||
public class ExcludeAuthorizationService {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ExcludeAuthorization.class);
|
||||
private final Logger logger = LoggerFactory.getLogger(ExcludeAuthorizationService.class);
|
||||
|
||||
|
||||
/**
|
|
@ -1,36 +1,85 @@
|
|||
package org.gcube.service.helloworld.services;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.gcube.common.security.Owner;
|
||||
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||
import org.gcube.common.security.secrets.Secret;
|
||||
import org.gcube.service.helloworld.manager.HelloWorldManager;
|
||||
import org.gcube.service.helloworld.serializers.ContextSerializator;
|
||||
import org.gcube.smartgears.ContextProvider;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
import org.gcube.smartgears.context.container.ContainerContext;
|
||||
import org.gcube.smartgears.utils.InnerMethodName;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lucio Lelii (ISTI-CNR)
|
||||
* @author Alfredo Oliviero (ISTI-CNR)
|
||||
*/
|
||||
|
||||
@ManagedBy(HelloWorldManager.class)
|
||||
@Path("hello")
|
||||
@Path("")
|
||||
public class HelloService {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(HelloService.class);
|
||||
|
||||
|
||||
@GET
|
||||
@Path("hello")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public String hello() {
|
||||
InnerMethodName.set("hello");
|
||||
Secret secret = SecretManagerProvider.get();
|
||||
String userId = secret.getOwner().getId();
|
||||
String context = secret.getContext();
|
||||
|
||||
|
||||
String infrastructureName = ContextProvider.get().container().configuration().infrastructure();
|
||||
logger.info("caller id is {}",userId);
|
||||
return String.format("Hello %s in context %s in infastructure {}", userId,context, infrastructureName);
|
||||
logger.info("caller id is {}", userId);
|
||||
return String.format("Hello %s in context %s in infastructure %s -roles %s", userId, context,
|
||||
infrastructureName, secret.getOwner().getRoles());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("details")
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public Response details() {
|
||||
InnerMethodName.set("details");
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
|
||||
Secret secret = SecretManagerProvider.get();
|
||||
|
||||
String context = secret.getContext();
|
||||
data.put("context", context);
|
||||
|
||||
Owner owner = secret.getOwner();
|
||||
data.put("owner", owner);
|
||||
|
||||
ContainerContext container = ContextProvider.get().container();
|
||||
data.put("container", container);
|
||||
|
||||
ObjectMapper objectMapper = ContextSerializator.getSerializer();
|
||||
|
||||
try {
|
||||
String jsonData = objectMapper.writeValueAsString(data);
|
||||
return Response.ok(jsonData).build();
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
return Response.serverError().build();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package org.gcube.service.helloworld.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.security.Owner;
|
||||
import org.gcube.smartgears.context.container.ContainerContext;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lucio Lelii (ISTI-CNR)
|
||||
*/
|
||||
|
||||
public class RestUtils {
|
||||
|
||||
public static Map<String, Object> getUserDict(Owner owner) {
|
||||
String userId = owner.getId();
|
||||
String clientName = owner.getClientName();
|
||||
|
||||
String clientId = owner.getId();
|
||||
List<String> roles = owner.getRoles();
|
||||
String email = owner.getEmail();
|
||||
String firstName = owner.getFirstName();
|
||||
String lastName = owner.getLastName();
|
||||
boolean externalClient = owner.isExternalClient();
|
||||
|
||||
String contactPerson = owner.getContactPerson();
|
||||
String contactOrganisation = owner.getContactOrganisation();
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("userid", userId);
|
||||
data.put("clientName", clientName);
|
||||
data.put("clientId", clientId);
|
||||
data.put("roles", roles);
|
||||
data.put("email", email);
|
||||
data.put("firstName", firstName);
|
||||
data.put("lastName", lastName);
|
||||
data.put("externalClient", externalClient);
|
||||
data.put("contactPerson", contactPerson);
|
||||
data.put("contactOrganisation", contactOrganisation);
|
||||
return data;
|
||||
}
|
||||
|
||||
public static Map<String, Object> getContainerDict(ContainerContext container) {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("id", container.id());
|
||||
data.put("configuration", container.configuration());
|
||||
// data.put("lifecycle", container.lifecycle());
|
||||
data.put("properties", container.properties());
|
||||
data.put("authorizationProvider", container.authorizationProvider());
|
||||
return data;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue