Commit 3061eeb8 authored by Miguel Mateo Montero's avatar Miguel Mateo Montero
Browse files

TTA first release

parents
#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.
##List of Modules
--
# 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[] args) {
uri_ = BASE_URI;
String uri = Configuration.getProperty("uri");
if (uri != null)
uri_ = uri;
Configuration.name_ = "blogic";
PropertyConfigurator.configure(dir_+"/rest_log4j.properties");
System.out.println("uri: "+ uri_);
final HttpServer server = startServer();
System.out.println(String.format("Jersey app started with WADL available at "
+ "%s"
+ ".", uri_));
try {
while (System.in.read()!=500);
} catch (IOException e) {
logger_.error(e,e);
e.printStackTrace();
}
}
public static HttpServer startServer() {
// create a resource config that scans for JAX-RS resources and providers
// in main.java.com.ari package
final ResourceConfig rc = new ResourceConfig().packages("com.ari.api");
// create and start a new instance of grizzly http server
// exposing the Jersey application at BASE_URI
return GrizzlyHttpServerFactory.createHttpServer(URI.create(uri_), rc);
}
}
# LIGHTest/dao
This module is designed to parse and store, in DB, translation declaration for the Trust Translation Authority. This module is not strictly necessary for the TTA but has been added to provide fail recovery support. Also it can provide Scheme load from sternal repository (requires ETSI).
It provides a REST API to create and delete Translation declarations and to retrieve scheme and scheme/level info DB.
## Requirements
* MongoDB
## Configuration files:
#### rest_log4j.properties
* loggin propoerties.
#### dao.properties
* dao module properties:
* uri: own URL
* mongo-db-name: name of the Dta Base (lightest).
* agreement-collection: name of the collection for agreements. This collection store agreements created for TTaAPI. This is translations declarations received from the Business Logic Module.
* scheme-collection: name of the collection for Trust Schemes. This collection store Schemes loaded from external repository (ETSI).
* db_port: Port of MongoDB (example: 3117)
* db_url: URL of the MongoDB (example: 127.0.0.1)
* mongo-db-pwd: password to access to the data base
* mongo-db-user: user name to access to the data base
## 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/dao/schemeLevelDetails | ```{"scheme-level":"eidas.eseal.advance``` | TBD | this request is used to retrieve the details of a Trust Scheme-Level from TSPA (TBD)
POST | http://127.0.0.7:8097/dao/getSchemeDetails | ```{"scheme":"eidas.eseal``` | TBD | This this request is used to retrieve the details of a Trust Scheme-Level from TSPA (TBD)
POST | http://127.0.0.7:8097/dao/createAgreement | ```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/dao/removeAgreement | ```agreement description in JSON format, see bellow``` | HTTP result code | this request is used to delete a Translation declaration (files and DNS RR)
GET | http://127.0.0.7:8097/dao/getAgreementNames | | List of translation declaration names | this request is used to retrieve a list containing all the names of translation declarations hosted
POST | http://127.0.0.7:8097/dao/agrement | {"name":"agreement-name"} | translation or agreement details in JSON, see bellow | this request is used to retrieve the details of a specific translation or agreement.
##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"
}
]
}
}
```
#configuration file of dao component
uri=http://127.0.0.1:8094/dao
#name of the data base
mongo-db-name=lightest
#
#name of the collection for Agreements, used to store information obtained by TTaApi
agreement-collection=agreements
#
#name of the collection for TSL, used to store information obtained by TestProviderFeedingApi
scheme-collection=schemes
#
#port where mongo db is waiting for connections
db_port=25555
#
#ur or IP address of the mongo db
db_url=172.24.76.37
#
#pwd of the mongo database
mongo-db-pwd=D4r10.6000