fixing hello world service

This commit is contained in:
Luca Frosini 2024-05-24 18:08:07 +02:00
parent 1635ac0bd9
commit 688700b5ab
6 changed files with 742 additions and 1512 deletions

View File

@ -1,7 +1,25 @@
{
"id": "f1860155-0d84-4c0c-917b-2f8f015b2752",
"name": "/gcube/devsec/devVRE",
"id": "ff7036fd-e12d-4dd7-9d0f-816bb5a0f06a",
"name": "Hello World Env for devVRE",
"values": [
{
"key": "introspect_secret",
"value": "",
"type": "secret",
"enabled": true
},
{
"key": "password",
"value": "",
"type": "secret",
"enabled": true
},
{
"key": "service_client_secret",
"value": "",
"type": "secret",
"enabled": true
},
{
"key": "realm",
"value": "d4science",
@ -10,7 +28,7 @@
},
{
"key": "username",
"value": "alfredo.oliviero",
"value": "luca.frosini",
"type": "default",
"enabled": true
},
@ -21,29 +39,11 @@
"enabled": true
},
{
"key": "service_client_secret",
"value": "09c26f24-3c65-4039-9fa0-e5cc4f4032cd",
"type": "secret",
"enabled": true
},
{
"key": "proxy_disabled",
"value": "false",
"type": "default",
"enabled": true
},
{
"key": "scope_context",
"key": "context",
"value": "/gcube/devsec/devVRE",
"type": "default",
"enabled": true
},
{
"key": "key_password",
"value": "password_alfredo.oliviero",
"type": "default",
"enabled": false
},
{
"key": "keycloak_url",
"value": "https://accounts.dev.d4science.org/auth",
@ -62,44 +62,14 @@
"type": "default",
"enabled": true
},
{
"key": "password",
"value": "",
"type": "secret",
"enabled": true
},
{
"key": "introspect_client",
"value": "token-exchange-dedicated",
"type": "default",
"enabled": true
},
{
"key": "introspect_secret",
"value": "CSFoPr80ua1jv1kMdKRvYT8yU56Hrrdm",
"type": "secret",
"enabled": true
},
{
"key": "user_test",
"value": "andrea.rossi",
"type": "default",
"enabled": true
},
{
"key": "pass_test",
"value": "gcube321",
"type": "secret",
"enabled": true
},
{
"key": "social_access_token",
"value": "",
"type": "default",
"enabled": true
}
],
"_postman_variable_scope": "environment",
"_postman_exported_at": "2024-05-22T13:44:26.620Z",
"_postman_exported_at": "2024-05-24T16:06:23.560Z",
"_postman_exported_using": "Postman/11.1.14"
}

View File

@ -0,0 +1,692 @@
{
"info": {
"_postman_id": "e152bab3-7be5-4fe2-81bd-625fec76373d",
"name": "Hello World Service",
"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": "3092110"
},
"item": [
{
"name": "LOGIN",
"item": [
{
"name": "Clear Env",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"console.log(\"executing clear script\");",
"",
"variables = [",
" 'token',",
" 'access_token',",
" 'refresh_token',",
"",
" 'uma_token',",
" 'uma_refresh',",
"",
" 'profile_token',",
" 'gcube_token',",
" 'oidc_access_token',",
" 'oidc_refresh_token',",
" 'id_token',",
"",
" 'clientId',",
"",
" 'current_username',",
" 'current_password',",
" 'current_context',",
" 'current_url-encoded-context',",
" 'current_iam-url',",
" 'current_client-id',",
" 'current_uma-token',",
" 'current_access-token',",
"",
" 'oidc_token',",
" 'oidc_access_token',",
" 'oidc_refresh_token',",
" 'uma_token',",
" 'exchanged_token'",
"",
"]",
"",
"for (var v of variables) {",
" pm.environment.unset(v);",
" pm.globals.unset(v);",
"}",
"",
" ",
"",
"",
" ",
""
],
"type": "text/javascript",
"packages": {}
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "/",
"path": [
""
]
}
},
"response": []
},
{
"name": "Get User Token For Context",
"event": [
{
"listen": "test",
"script": {
"exec": [
"var jsonData = JSON.parse(responseBody);",
"postman.setEnvironmentVariable(\"oidc_access_token\", jsonData.access_token);",
"postman.setEnvironmentVariable(\"oidc_refresh_token\", jsonData.refresh_token);",
"",
"postman.setEnvironmentVariable(\"uma_token\", jsonData.access_token);",
"",
"postman.setEnvironmentVariable(\"access_token\", jsonData.access_token);",
"postman.setEnvironmentVariable(\"refresh_token\", jsonData.refresh_token);",
""
],
"type": "text/javascript",
"packages": {}
}
},
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript",
"packages": {}
}
}
],
"request": {
"auth": {
"type": "noauth"
},
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/x-www-form-urlencoded"
},
{
"key": "X-D4Science-Context",
"value": "{{encoded_context}}"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "client_id",
"value": "{{service_client_id}}",
"type": "text"
},
{
"key": "username",
"value": "{{username}}",
"type": "text"
},
{
"key": "password",
"value": "{{password}}",
"type": "text"
},
{
"key": "grant_type",
"value": "password",
"type": "text"
},
{
"key": "client_secret",
"value": "{{service_client_secret}}",
"type": "text"
}
]
},
"url": {
"raw": "{{keycloak_url}}/realms/{{realm}}/protocol/openid-connect/token",
"host": [
"{{keycloak_url}}"
],
"path": [
"realms",
"{{realm}}",
"protocol",
"openid-connect",
"token"
]
},
"description": "Obtain UAT = user access token from a user in realm"
},
"response": []
},
{
"name": "Get ClientId Token For Context",
"event": [
{
"listen": "test",
"script": {
"exec": [
"var jsonData = JSON.parse(responseBody);",
"",
"// postman.setEnvironmentVariable(\"refresh_token\", jsonData.refresh_token);",
"// postman.setEnvironmentVariable(\"id_token\", jsonData.id_token);",
"",
"postman.setEnvironmentVariable(\"oidc_access_token\", jsonData.access_token);",
"",
"postman.setEnvironmentVariable(\"access_token\", jsonData.access_token);",
"postman.setEnvironmentVariable(\"token\", jsonData.access_token);",
"",
""
],
"type": "text/javascript",
"packages": {}
}
}
],
"request": {
"auth": {
"type": "noauth"
},
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/x-www-form-urlencoded"
},
{
"key": "X-D4Science-Context",
"value": "{{encoded_context}}"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "client_id",
"value": "{{service_client_id}}",
"type": "text"
},
{
"key": "client_secret",
"value": "{{service_client_secret}}",
"type": "text"
},
{
"key": "grant_type",
"value": "client_credentials",
"type": "text"
}
]
},
"url": {
"raw": "{{keycloak_url}}/realms/{{realm}}/protocol/openid-connect/token",
"host": [
"{{keycloak_url}}"
],
"path": [
"realms",
"{{realm}}",
"protocol",
"openid-connect",
"token"
]
},
"description": "Obtain SAT (service account token)"
},
"response": []
},
{
"name": "Validate Access Token",
"request": {
"auth": {
"type": "noauth"
},
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Basic YWxmcmVkby1pZG0tc2VydmljZS1kZXY6OTc5YmQzYmMtNWNjNC0xMWVjLWJmNjMtMDI0MmFjMTMwMDAy"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "token",
"value": "{{access_token}}",
"type": "text"
},
{
"key": "username\n",
"value": "{{introspect_client}}",
"type": "text",
"disabled": true
},
{
"key": "password",
"value": "{{introspect_secret}}",
"type": "text",
"disabled": true
},
{
"key": "client_id",
"value": "{{introspect_client}}",
"type": "text"
},
{
"key": "client_secret",
"value": "{{introspect_secret}}",
"type": "text"
}
]
},
"url": {
"raw": "{{keycloak_url}}/realms/{{realm}}/protocol/openid-connect/token/introspect",
"host": [
"{{keycloak_url}}"
],
"path": [
"realms",
"{{realm}}",
"protocol",
"openid-connect",
"token",
"introspect"
]
}
},
"response": []
}
]
},
{
"name": "REST",
"item": [
{
"name": "authorized",
"item": [
{
"name": "legacy-token",
"item": [
{
"name": "hello TOKEN PARAM",
"request": {
"auth": {
"type": "noauth"
},
"method": "GET",
"header": [
{
"key": "",
"value": "{{token}}"
}
],
"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": "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": "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 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": []
}
]
},
{
"name": "hello",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{base_url}}/{{application}}/hello",
"host": [
"{{base_url}}"
],
"path": [
"{{application}}",
"hello"
]
}
},
"response": []
},
{
"name": "details",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{base_url}}/{{application}}/details",
"host": [
"{{base_url}}"
],
"path": [
"{{application}}",
"details"
]
}
},
"response": []
},
{
"name": "auth org member",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{uma_token}}",
"type": "string"
}
]
},
"method": "GET",
"header": [],
"url": {
"raw": "{{base_url}}/{{application}}/auth/org_member",
"host": [
"{{base_url}}"
],
"path": [
"{{application}}",
"auth",
"org_member"
]
}
},
"response": []
},
{
"name": "auth member",
"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": "No Auth Required",
"item": [
{
"name": "guest",
"request": {
"auth": {
"type": "noauth"
},
"method": "GET",
"header": [],
"url": {
"raw": "{{base_url}}/{{application}}/guest",
"host": [
"{{base_url}}"
],
"path": [
"{{application}}",
"guest"
]
}
},
"response": []
},
{
"name": "404 Not Found",
"request": {
"auth": {
"type": "noauth"
},
"method": "GET",
"header": [],
"url": {
"raw": "{{base_url}}/{{application}}/guest/not-found",
"host": [
"{{base_url}}"
],
"path": [
"{{application}}",
"guest",
"not-found"
]
}
},
"response": []
},
{
"name": "400 Bad Request",
"request": {
"auth": {
"type": "noauth"
},
"method": "GET",
"header": [],
"url": {
"raw": "{{base_url}}/{{application}}/guest/bad-request",
"host": [
"{{base_url}}"
],
"path": [
"{{application}}",
"guest",
"bad-request"
]
}
},
"response": []
},
{
"name": "PURGE with 204 No Content",
"request": {
"auth": {
"type": "noauth"
},
"method": "PURGE",
"header": [],
"url": {
"raw": "{{base_url}}/{{application}}/guest/test-purge",
"host": [
"{{base_url}}"
],
"path": [
"{{application}}",
"guest",
"test-purge"
]
}
},
"response": []
}
]
}
]
}
],
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{access_token}}",
"type": "string"
}
]
},
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"packages": {},
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"packages": {},
"exec": [
""
]
}
}
],
"variable": [
{
"key": "base_url",
"value": "http://localhost:8080",
"type": "string"
},
{
"key": "role_name",
"value": "Member"
},
{
"key": "application",
"value": "hello-world-service",
"type": "string"
},
{
"key": "base_url_marco",
"value": "http://146.48.85.179:9999",
"type": "string"
},
{
"key": "base_url_local",
"value": "http://localhost:8080",
"type": "string"
}
]
}

View File

@ -47,7 +47,7 @@ The most common error statuses a client can obtain are:
* **409 Conflict** the request could not be completed due to a conflict with the current state of the target resource (e.g. the name of the resource already exists) `<https://tools.ietf.org/html/rfc7231#section-6.5.8>`_;
* **500 Internal Server Error** indicate a server failure `<https://tools.ietf.org/html/rfc7231#section-6.6.1>`_.
You can find a complete list of HTTP Status at `<https://httpstatuses.com/>`_
You can find a complete list of HTTP Status at `<https://httpstatuses.com/>`_ or `<https://httpstatuses.io/>`_
If you get a *500 Internal Server Error*, please report it in the `gCube ticketing system <https://support.d4science.org>`_.

View File

@ -0,0 +1,17 @@
package org.gcube.service.helloworld.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import jakarta.ws.rs.HttpMethod;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@HttpMethod("PURGE")
public @interface PURGE {
}

View File

@ -1,5 +1,6 @@
package org.gcube.service.helloworld.rest;
import org.gcube.service.helloworld.annotation.PURGE;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -8,6 +9,8 @@ import jakarta.ws.rs.GET;
import jakarta.ws.rs.NotFoundException;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
@Path("guest")
public class ExcludeAuthorizationService {
@ -44,4 +47,10 @@ public class ExcludeAuthorizationService {
throw new NotFoundException();
}
@PURGE
@Path("test-purge")
public Response testPurge() throws WebApplicationException {
return Response.status(Status.NO_CONTENT).build();
}
}