miércoles, 24 de mayo de 2017

The way to implements Unit Tests in Spring Boot

For doing Tests in Spring Boot you have to know the next things:

- You need a java test and resources test directories in your project. In the resources directory you put the files for the src/test/java and the src/test/resources directory the test you want to pass when you do the maven build.
- You need am application-TEST.yml file in your resources directory for configure the test calls.
- When you implements a Test you have to use the next anotations before the class name:

@org.junit.runner.RunWith(SpringJUnit4ClassRunner.class)
@org.springframework.boot.test.SpringApplicationConfiguration(classes = ClassName.class)
@org.springframework.test.context.ActiveProfiles(value = "TEST")

- For test a Service implemented in you src/main/java directory you have to indicate this way:

@org.springframework.beans.factory.annotation.Autowired
MyService service;

- At last, you need to indicate the method that test one call like:

@org.junit.Test
public void test() {
    ... do the test and finally verify the result of the test
    assertThat(result).isEqualTo("OK");
}

Here you have implemented your first test.

For call it, you have to run the maven test option.

For skip one test, you can indicate @org.junit.Ignore and the test don't will be executed.

For skip all test, you can indicate to maven that don't want to execute test this way:

Go to run configuration and check the option skip tests.

Any question of this tip, don't doubt ask me!

Try it and have fun!

miércoles, 10 de mayo de 2017

The Electronic Signatures Types: XAdES, PAdES and CAdES

Hi everyone,

I'm currently working on Pompeu Fabra University in the Electronic Administration Department.

I'm doing a Signature Project that signs, completes and validates in XAdES, PAdES and CAdES signature types.

Now I want to explain what consists my project, the troubles I had to resolve and the conclusions.

First of all, I want to explain the signature types:

XAdES: XML Advanced Electronic Signature

This signature can sign BINARI or XML files and the way for complete and validate is different. The XAdES Signature Type generates a XML Signature file. For a correct validation, the generated signature must have a correctly hash document code. So the libraries used are important, because differents libraries generates differents XML files.

There are three Signature Types: Detached (the signature don't includes the file signed), Atached Enveloped (when the signature comprises a part of the document containing the signed data) and Atached Enveloping (when the signature contains the signed data withing itself).

PAdES: PDF Advanced Electronic Signature

This signature only can sign BINARI files. The PAdES Signature Type generate a PDF Signature file that is the result of sign or complete the PDF file we want to sign. So the PAdES Signature only exists in Atached way.

CAdES: CMS Advanced Electronic Signature

This signature only can sign BINARI files. The CAdES Signature Type generate a p7b Signature file that is a binary file. There are Atached or Detached Signature Types, but don't exists the Enveloped or Enveloping concept.

Now I'm going to explain how to implements a Sign Service:

For implements a WebService I use Spring Boot and Java 8.

First of all, you have to find the Service you want to use, in my case I choose DSS (Digital Signature Service): here is the git repository.

Take a look to the repository and, when you are ready, make the next steps:

- Add the necessaries maven dependencies.
- Find the Cookbook example and try to understand how it goes and reply the example to your code.

Is very easy to integrate the DSS Sign Service.

In a week I've integrated a PAdES Enveloped, XAdES Detached and CAdES Detached Sign Service with an indicated Certificate.

And finally, I'm going to explain how I've done a Complete and Validation Signature Service:

For implements a WebService I use Spring Boot and Java 8.

First of all, you have to find the Service you want to use. In my case, I choose Psis Client from AOC: here you have the explanations in his web.

Here AOC offers some example codes and calls for integrate his Service in your Application.

Now you are in the moment to play and improve your code.

After over 3 months you will have your Complete and Validation Signature Service, but, what it's more important, You are going to learn a lot.

I've done a Complete and Validation PAdES Enveloped, XAdES Detached and CAdES Detached Signature Service three months ago.

If you are interested in more details, contact me and we could collaborate together in your project.