Commit 2e92108c authored by Miguel Mateo Montero's avatar Miguel Mateo Montero
Browse files

tta release v1.0, without tspa nor dns integration

parent 474238bf
This diff is collapsed.
#LIGHTest Project
Lightweight Infrastructure for Global Heterogeneous Trust management in support of an
open Ecosystem of Stakeholders and Trust schemes.
##GIT for all developments of Atos in the project.
This branch provides a deployment for Tomcat application server.
All projects has been joined in order to provide one only deployable app.
##List of Modules
--
{
"info": {
"_postman_id": "e2105ef7-36e9-4f4b-984b-8a8d04c9ec18",
"name": "TTA",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "create_scheme",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n\t\"agreement\": {\r\n\t\t\"name\": \"agreement-name\",\r\n\t\t\"status\": \"active\",\r\n\t\t\"creation-date\": \"2018-08-10\",\r\n\t\t\"leaving-date\": \"2019-08-10\",\r\n\t\t\"activation-date\": \"2018-08-10\",\r\n\t\t\"source\": {\r\n\t\t\t\"level\": \"source-scheme-level\",\r\n\t\t\t\"name\": \"source-scheme-name\",\r\n\t\t\t\"provider\": \"scheme-owner\",\r\n\t\t\t\"params\": [{\r\n\t\t\t\t\t\"name\": \"param1-name\",\r\n\t\t\t\t\t\"value\": \"param1-value\"\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\t\"name\": \"param2-name\",\r\n\t\t\t\t\t\"value\": \"param2-value\"\r\n\t\t\t\t}\r\n\t\t\t]\r\n\t\t},\r\n\t\t\"target\": {\r\n\t\t\t\"level\": \"target-scheme-level\",\r\n\t\t\t\"name\": \"target-scheme-name\",\r\n\t\t\t\"provider\": \"scheme-owner\",\r\n\t\t\t\"params\": [{\r\n\t\t\t\t\t\"name\": \"param3-name\",\r\n\t\t\t\t\t\"value\": \"param3-value\"\r\n\t\t\t\t},\r\n\t\t\t\t{\r\n\t\t\t\t\t\"name\": \"param4-name\",\r\n\t\t\t\t\t\"value\": \"param5-value\"\r\n\t\t\t\t}\r\n\t\t\t]\r\n\t\t}\r\n\t}\r\n}"
},
"url": {
"raw": "http://tta-lightest.eu:8080/ttaFM/mng/rsc/createTranslation",
"protocol": "http",
"host": [
"tta-lightest",
"eu"
],
"port": "8080",
"path": [
"ttaFM",
"mng",
"rsc",
"createTranslation"
]
},
"description": "to create translation"
},
"response": []
},
{
"name": "getTranslations",
"request": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://tta-lightest.eu:8080/ttaFM/mng/rsc/getTranslations",
"protocol": "http",
"host": [
"tta-lightest",
"eu"
],
"port": "8080",
"path": [
"ttaFM",
"mng",
"rsc",
"getTranslations"
]
}
},
"response": []
},
{
"name": "getTranslation",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\"name\":\"agreement-name\"}"
},
"url": {
"raw": "http://tta-lightest.eu:8080/ttaFM/mng/rsc/getTranslation",
"protocol": "http",
"host": [
"tta-lightest",
"eu"
],
"port": "8080",
"path": [
"ttaFM",
"mng",
"rsc",
"getTranslation"
]
}
},
"response": []
},
{
"name": "deleteTranslation",
"request": {
"method": "DELETE",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\"name\":\"agreement-name\"}"
},
"url": {
"raw": "http://tta-lightest.eu:8080/ttaFM/mng/rsc/deleteTranslation",
"protocol": "http",
"host": [
"tta-lightest",
"eu"
],
"port": "8080",
"path": [
"ttaFM",
"mng",
"rsc",
"deleteTranslation"
]
}
},
"response": []
}
]
}
\ No newline at end of file
# LIGHTest/blogic
This module is designed as entry point to the management interface of the Trust Translation Authority.
It provides a REST API to create and delete Translation declarations and to retrieve scheme and scheme/level info from TSPA.
## Requirements
## Configuration files:
#### rest_log4j.properties
* loggin propoerties.
#### blogic.properties
* blogic module properties:
* uri: own URL (example: http://127.0.0.1:8097/tta).
* daoURL: URL of dao module (example: http://127.0.0.1/8091/dao ) it is the value of URI property in dao configuration file.
* filemanagerUri: url of file manager module (example: http://127.0.0.1.8095/filemng) it is the value of URI property in fileManger configuration file.
* fileServerURL: url of the file server (example: http://127.0.0.1:8096/translationdeclarations) it is the value of URI property in fileServer configuration file.
* dnsURL: url of the DNS management API (example: http://lightest.nlnetlabs.nl).
* dns-user: user name for authentication on DNS API.
* dns-pwd: user password for authentication on DNS API.
## API
All API access is over HTTP. Data is sent and received as JSON.
Request method | Request URI | Request data | Response data | Description
-------------------|---------------------|----------------------|-----------------------|-----------------------
POST | http://127.0.0.7:8097/tta/getSchemeLevelDetails | ```{"scheme-level":"eidas.eseal.advance``` | TBD | this request is used to retrieve the details of a Trust Scheme-Level
POST | http://127.0.0.7:8097/tta/getSchemeDetails | ```{"scheme":"eidas.eseal``` | TBD | This this request is used to retrieve the details of a Trust Scheme-Level
POST | http://127.0.0.7:8097/tta/createTranslation | ```agreement description in JSON format, see bellow``` | HTTP result code | this request is used to create a Translation declaration (files and DNS RR)
POST | http://127.0.0.7:8097/tta/deleteTranslation | ```agreement description in JSON format, see bellow``` | HTTP result code | this request is used to delete a Translation declaration (files and DNS RR)
##Agreement Description (JSON format)
```
"agreement":"{
"name":"agreement-name",
"status":"current-status",
"creation-date":"2018-08-10",
"leaving-date":"2019-08-10",
"activation-date":"2018-08-10",
"source":{
"level":"scheme-level",
"name":"scheme-name",
"provider":"scheme-owner",
"params":[
{
"name":"param1-name",
"value":"param1-value"
},
{
"name":"param2-name",
"value":"param2-value"
}
]
},
"target":{
"level":"scheme-level",
"name":"scheme-name",
"provider":"scheme-owner",
"params":[
{
"name":"param1-name",
"value":"param1-value"
},
{
"name":"param2-name",
"value":"param2-value"
}
]
}
}
```
#12-07-2018
uri=http://127.0.0.1:8092/blogic
daoURL=http:/127.0.0.1/8091/dao
filemanagerUri=http://127.0.0.1.8095/file/mng
fileServerURL=http://127.0.0.1/translationdeclarations
dnsURL=http://lightest.nlnetlabs.nl
dns-user=xxx
dns-pwd=yyy
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ari.lightest</groupId>
<packaging>jar</packaging>
<artifactId>blogic</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>lightest_blogic</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20151123</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.w3c</groupId>
<artifactId>dom</artifactId>
<version>2.3.0-jaxb-1.0.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.ari.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<jersey.version>2.26-b06</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
\ No newline at end of file
log4j.rootLogger=DEBUG, file
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=./blogic.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
package com.ari.api;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.json.JSONObject;
import com.ari.conf.Configuration;
/**
* Copyright © 2018 Atos Spain SA. All rights reserved.
* This file is part of Lightest Trust Translation functionality
* It is free software: you can redistribute it and/or modify it under the terms of Apache 2.0.
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT ANY WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT, IN NO EVENT SHALL THE AUTHORS
* OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* See README file for the full disclaimer information and LICENSE file for full license information in the project root.
*/
/**
* REST API manage data of TTA
*/
@Path("tta")
public class BLogicApi {
public BLogicApi(){
}
/**
* instruct dao component to retrieve detail about a scheme/level from TSPA
* @param agreementDetails description of the translation in JSON format
* @return data retrieved from tspa
*/
@POST
@Path("getSchemeLevelDetails")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public Response getChemeLevelDetails(String commandDetails){
Client client = ClientBuilder.newClient();
WebTarget target = client.target(Configuration.getProperty("daoURL") + "/schemeLevelDetails");
Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON);
Response response = invocationBuilder.post(Entity.entity(commandDetails, MediaType.APPLICATION_JSON));
return Response.fromResponse(response).build();
}
/**
* instruct dao component to retrieve detail about a scheme/level from TSPA
* @param agreementDetails description of the translation in JSON format
* @return data retrieved from tspa
*/
@POST
@Path("getSchemeDetails")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public Response getChemeDetails(String commandDetails){
Client client = ClientBuilder.newClient();
WebTarget target = client.target(Configuration.getProperty("daoURL") + "/schemeDetails");
Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON);
Response response = invocationBuilder.post(Entity.entity(commandDetails, MediaType.APPLICATION_JSON));
return Response.fromResponse(response).build();
}
/**
* create translation declarations files, upload to the file server and set RR in DNS
* @param agreementDetails description of the translation in JSON format
* @return http result code
*/
@POST
@Path("createTranslation")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public Response createTranslation(String commandDetails){
Client daoClient = ClientBuilder.newClient();
String token = null;
//TODO: get token
// two possibilities
// if the operation in dns has to be associated to the client of TTA, it is responsible to get the token and pass it
//as param into the creation resquest
// if the operation is associated to the TTA, we have to retrieve the token here
String user = Configuration.getProperty("dns-user");
String pwd = Configuration.getProperty("dns-pwd");
WebTarget daoTarget = daoClient.target(Configuration.getProperty("daoURL") + "/createAgreement");
Invocation.Builder daoInvocationBuilder = daoTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token);
Response response = daoInvocationBuilder.post(Entity.entity(commandDetails, MediaType.APPLICATION_JSON));
if (response.getStatus() == Response.Status.OK.getStatusCode()){
String daoRes = response.readEntity(String.class);
Client fileMClient = ClientBuilder.newClient();
WebTarget fileMTarget = fileMClient.target(Configuration.getProperty("fileMURL") + "/createFileFromDesc");
Invocation.Builder fileMInvBuild = fileMTarget.request(MediaType.APPLICATION_JSON);
Response fmResponse = fileMInvBuild.post(Entity.entity(daoRes, MediaType.APPLICATION_JSON));
if (fmResponse.getStatus() == Response.Status.OK.getStatusCode()){
String fmRes = response.readEntity(String.class);
JSONObject jo = new JSONObject (fmRes);
String agremane = jo.getString("agreename");
String filename = jo.getString("filename");
Client dnsClient = ClientBuilder.newClient();
WebTarget dnsTarget = dnsClient.target(Configuration.getProperty("dnsURL") + "/"+agremane+"/translation");
Invocation.Builder dnsIB = dnsTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token);
Response dnsR = dnsIB.put(Entity.entity("\"url\":\""+Configuration.getProperty("fileServerURL")+"/"+filename+".tpl\"", MediaType.APPLICATION_JSON));
if (dnsR.getStatus() == Response.Status.OK.getStatusCode()){
dnsR = dnsIB.put(Entity.entity("\"url\":\""+Configuration.getProperty("fileServerURL")+"/"+filename+".xml\"", MediaType.APPLICATION_JSON));
if (dnsR.getStatus() == Response.Status.OK.getStatusCode()){
return Response.status(Response.Status.OK).build();
}else{
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Error while creattin DNS stuff 1").build();
}
}else{
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Error while creattin DNS stuff 1").build();
}
}else{
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Error while creating declarations").build();
}
}else{
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Error while parsing JSON").build();
}
}
@DELETE
@Path("deleteTranslation")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public Response deleteTranslation(String commandDetails){
Client daoClient = ClientBuilder.newClient();
String token = null;
//TODO: get token
// two possibilities
// if the operation in dns has to be associated to the client of TTA, it is responsible to get the token and pass it
//as param into the creation resquest
// if the operation is associated to the TTA, we have to retrieve the token here
String user = Configuration.getProperty("dns-user");
String pwd = Configuration.getProperty("dns-pwd");
WebTarget daoTarget = daoClient.target(Configuration.getProperty("daoURL") + "/deleteAgreement");
Invocation.Builder daoInvocationBuilder = daoTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token);
Response response = daoInvocationBuilder.post(Entity.entity(commandDetails, MediaType.APPLICATION_JSON));
if (response.getStatus() == Response.Status.OK.getStatusCode()){
String daoRes = response.readEntity(String.class);
Client fileMClient = ClientBuilder.newClient();
WebTarget fileMTarget = fileMClient.target(Configuration.getProperty("filemanagerUri") + "/deleteFile");
Invocation.Builder fileMInvBuild = fileMTarget.request(MediaType.APPLICATION_JSON);
Response fmResponse = fileMInvBuild.post(Entity.entity(daoRes, MediaType.APPLICATION_JSON));
if (fmResponse.getStatus() == Response.Status.OK.getStatusCode()){
String fmRes = response.readEntity(String.class);
JSONObject jo = new JSONObject (fmRes);
String agremane = jo.getString("agrname");
Client dnsClient = ClientBuilder.newClient();
WebTarget dnsTarget = dnsClient.target(Configuration.getProperty("dnsURL") + "/"+agremane+"/translation");
Invocation.Builder dnsIB = dnsTarget.request(MediaType.APPLICATION_JSON).header(HttpHeaders.AUTHORIZATION, "Bearer " + token);
Response dnsR = dnsIB.delete();
if (dnsR.getStatus() == Response.Status.OK.getStatusCode()){
return Response.status(Response.Status.OK).build();
}else{
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Error while deleting DNS stuff 1").build();
}
}else{
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Error while deleting declarations").build();
}
}else{
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Error while deleting parsed JSON").build();
}
}
}
package com.ari.api;
import java.io.IOException;
import java.net.URI;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;
import com.ari.conf.Configuration;
/**
* Copyright � 2018 Atos Spain SA. All rights reserved.
* This file is part of Lightest Trust Translation functionality
* It is free software: you can redistribute it and/or modify it under the terms of Apache 2.0.
* THE SOFTWARE IS PROVIDED �AS IS�, WITHOUT ANY WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT, IN NO EVENT SHALL THE AUTHORS
* OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* See README file for the full disclaimer information and LICENSE file for full license information in the project root.
*/
/**
*
* Class Properties:
* BASE_URI_: default base URI for the server.
* uri_: base uri of the server.
* logger_:
* dir_: path of the base directory of the application.
*
*/
public class Main {
public static final String BASE_URI = "http://127.0.0.1:8092/blogic";
static String uri_;
public static Logger logger_ = null;
public static String dir_ = ".";
public static void main(String[]