Saltar a contenido

Caso de uso: alta de usuario y certificado

Objetivo: dejar a un usuario listo para firmar documentos, desde cero.

1. Registrar el usuario

curl -X POST http://localhost:8080/api/auth/signup \
  -H "Content-Type: application/json" \
  -d '{
    "username": "jperez",
    "password": "Segura123!",
    "email": "jperez@empresa.com",
    "firstName": "Juan",
    "lastName": "Pérez",
    "dni": "12345678",
    "tuition": "MP12345",
    "authorization": "AUTH123456",
    "role": ["user"]
  }'
{ "message": "User with username jperez and dni 12345678 registered successfully!" }

2. Iniciar sesión

curl -X POST http://localhost:8080/api/auth/signin \
  -H "Content-Type: application/json" \
  -d '{ "username": "jperez", "password": "Segura123!" }'
{
  "token": "Bearer eyJhbGciOiJIUzI1NiJ9...",
  "type": "Bearer ",
  "id": 1,
  "refreshToken": "eyJhbGciOiJIUzI1NiJ9...",
  "roles": ["ROLE_USER"]
}

Guardar token (ya incluye Bearer) para usarlo en los siguientes pasos.

Nota: PUT /api/cert/upload-p12 exige rol ROLE_ADMIN o ROLE_SUPER. Si el usuario recién creado solo tiene ROLE_USER, usa para este paso el token de un administrador (o registra al usuario con "role": ["admin"], ver la nota de seguridad en Autenticación).

3. Cifrar la contraseña del .p12

curl -X POST "http://localhost:8080/api/cert/encrypt?data=MiClaveP12Secreta" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..."
{
  "message": "Data encrypted successfully.",
  "certId": 7,
  "passwordEncrypted": "AbCdEf123==:GhIjKl456==",
  "status": "SUCCESS"
}

Guardar certId y passwordEncrypted.

4. Subir el certificado .p12

curl -X PUT http://localhost:8080/api/cert/upload-p12 \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \
  -F "file=@certificado.p12;type=application/x-pkcs12" \
  -F "password=AbCdEf123==:GhIjKl456==" \
  -F "certId=7" \
  -F "dni=12345678"
{
  "id": 7,
  "name": "3c1e2f1a-....p12",
  "expiresCert": "2027-01-01T00:00:00.000+00:00",
  "registered": "2026-07-14T10:00:00.000+00:00",
  "owner": "JUAN PEREZ",
  "dniUser": "12345678",
  "company": "Empresa SAC",
  "jobTitle": "Gerente",
  "principal": true,
  "isValid": true,
  "isRevoked": false
}

El certificado queda marcado como principal para el dni 12345678. A partir de aquí, ese dni puede firmar documentos (ver Firmar un documento por etiqueta o por coordenadas).

5. (Opcional) Subir imagen de firma

curl -X POST http://localhost:8080/api/auth/1/upload-signature-img \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \
  -F "file=@firma.png"
{ "message": "Signature image uploaded successfully" }

Con esto, al firmar con hasImageSignature=true se usará esta imagen en lugar del logo por defecto.