Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#176261561] Aggregator types SPID configuration #61

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
volumes:
- "./certs:/usr/src/app/certs:delegated"
- "./dist:/usr/src/app/dist:delegated"
command: ["yarn", "dev"]
command: ["yarn", "hot-reload"]
networks:
- io-spid-commons

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"prebuild": "shx rm -rf dist",
"build": "tsc",
"dev": "nodemon --inspect=0.0.0.0 dist/example.js",
"hot-reload": "nodemon --legacy-watch --watch ./dist --inspect=0.0.0.0 --nolazy dist/example.js",
"postversion": "git push && git push --tags",
"test": "jest -i",
"lint": "tslint --project ."
Expand Down
71 changes: 67 additions & 4 deletions src/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ import {
withSpid
} from ".";
import { logger } from "./utils/logger";
import { IServiceProviderConfig } from "./utils/middleware";
import {
AggregatedType,
AggregatorType,
ContactType,
EntityType,
IServiceProviderConfig
} from "./utils/middleware";

export const SpidUser = t.intersection([
t.interface({
Expand Down Expand Up @@ -72,13 +78,70 @@ const serviceProviderConfig: IServiceProviderConfig = {
],
name: "Required attrs"
},
spidCieUrl: "https://idserver.servizicie.interno.gov.it:8443/idp/shibboleth",
spidCieUrl: "https://idserver.servizicie.interno.gov.it:443/idp/shibboleth",
spidTestEnvUrl: "https://spid-testenv2:8088",
spidValidatorUrl: "http://localhost:8080",
// spidValidatorUrl: "http://localhost:8080",
strictResponseValidation: {
"http://localhost:8080": true,
"https://spid-testenv2:8088": true
}
},

contacts: [
{
company: "Sogetto Aggregatore s.r.l",
contactType: ContactType.OTHER,
email: "email@example.com" as EmailString,
entityType: EntityType.AGGREGATOR,
extensions: {
FiscalCode: "12345678901",
IPACode: "1",
VATNumber: "12345678902",
aggregatorCert: fs.readFileSync("./certs/cert.pem", "utf-8"),
aggregatorType: AggregatorType.PrivateServicesLightAggregator
},
phone: "+393331234567"
},
{
company: "Società Aggregata S.p.a.",
contactType: ContactType.OTHER,
email: "email@example.com" as EmailString,
entityType: EntityType.AGGREGATED,
extensions: {
FiscalCode: "12345678902",
IPACode: "2",
VATNumber: "12345678902",
aggregatedType: AggregatedType.Private
}
},
{
company: "Azienda_Destinataria_Fatturazione",
contactType: ContactType.BILLING,
email: "email@fatturazione.it" as EmailString,
phone: "+391234567",

billing: {
CessionarioCommittente: {
CodiceEORI: "1",
denominazione: "Denominazione",
fiscalCode: "12345678902",
idCodice: "1",
idPaese: "IT",
name: "Nome Billing",
surname: "Cognome Billing",
title: "Titolo billing",

Sede: {
address: "Piazza Colonna",
cap: "00187",
city: "Roma",
country: "IT",
number: "370",
state: "RM"
}
}
}
}
]
};

const redisClient = redis.createClient({
Expand Down
146 changes: 145 additions & 1 deletion src/utils/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import * as express from "express";
import { array } from "fp-ts/lib/Array";
import { Task, task } from "fp-ts/lib/Task";
import { NonEmptyString } from "italia-ts-commons/lib/strings";
import * as t from "io-ts";
import { EmailString, NonEmptyString } from "italia-ts-commons/lib/strings";
import { enumType } from "italia-ts-commons/lib/types";
import { Profile, SamlConfig, VerifiedCallback } from "passport-saml";
import { RedisClient } from "redis";
import { DoneCallbackT } from "..";
Expand All @@ -23,6 +25,147 @@ interface IServiceProviderOrganization {
displayName: string;
name: string;
}

export enum ContactType {
OTHER = "other",
BILLING = "billing"
}

export enum EntityType {
AGGREGATOR = "spid:aggregator",
AGGREGATED = "spid:aggregated"
}

export enum AggregatorType {
PublicServicesFullAggregator = "PublicServicesFullAggregator",
PublicServicesLightAggregator = "PublicServicesLightAggregator",
PrivateServicesFullAggregator = "PrivateServicesFullAggregator",
PrivateServicesLightAggregator = "PrivateServicesLightAggregator",
PublicServicesFullOperator = "PublicServicesFullOperator",
PublicServicesLightOperator = "PublicServicesLightOperator"
}

export enum AggregatedType {
Public = "Public",
PublicOperator = "PublicOperator",
Private = "Private"
}

const CommonExtension = t.partial({
FiscalCode: t.string,
IPACode: t.string,
VATNumber: t.string
});
type CommonExtension = t.TypeOf<typeof CommonExtension>;

export const LightAggregatorExtension = t.intersection([
t.interface({
aggregatorCert: t.string,
aggregatorType: t.union([
t.literal(AggregatorType.PrivateServicesLightAggregator),
t.literal(AggregatorType.PublicServicesLightAggregator),
t.literal(AggregatorType.PublicServicesLightOperator)
])
}),
CommonExtension
]);
export type LightAggregatorExtension = t.TypeOf<
typeof LightAggregatorExtension
>;

const AggregatorExtension = t.intersection([
t.union([
t.interface({
aggregatorType: t.union([
t.literal(AggregatorType.PrivateServicesFullAggregator),
t.literal(AggregatorType.PublicServicesFullAggregator),
t.literal(AggregatorType.PublicServicesFullOperator)
])
}),
LightAggregatorExtension
]),
CommonExtension
]);
type AggregatorExtension = t.TypeOf<typeof AggregatorExtension>;

const AggregatedExtension = t.intersection([
t.interface({
aggregatedType: enumType<AggregatedType>(AggregatedType, "aggregatedType")
}),
CommonExtension
]);
type AggregatedExtension = t.TypeOf<typeof AggregatedExtension>;

const IBillingInfo = t.intersection(
[
t.interface({
Sede: t.interface({
address: t.string,
cap: t.string,
city: t.string,
country: t.string
})
}),
t.partial({
CodiceEORI: t.string,
Sede: t.partial({
number: t.string,
state: t.string
}),
denominazione: t.string,
fiscalCode: t.string,
idCodice: t.string,
idPaese: t.string,
name: t.string,
surname: t.string,
title: t.string
})
],
"BillingInfo"
);
type IBillingInfo = t.TypeOf<typeof IBillingInfo>;

const ContactPerson = t.union([
t.interface({
billing: t.intersection([
t.interface({
CessionarioCommittente: IBillingInfo
}),
t.partial({
TerzoIntermediarioSoggettoEmittente: IBillingInfo
})
]),
company: t.string,
contactType: t.literal(ContactType.BILLING),
email: EmailString,
phone: t.string
}),
t.intersection([
t.interface({
company: t.string,
contactType: t.literal(ContactType.OTHER),
email: EmailString,
entityType: t.literal(EntityType.AGGREGATOR),
extensions: AggregatorExtension
}),
t.partial({
phone: t.string
})
]),
t.intersection([
t.interface({
company: t.string,
contactType: t.literal(ContactType.OTHER),
email: EmailString,
entityType: t.literal(EntityType.AGGREGATED),
extensions: AggregatedExtension
}),
t.partial({
phone: t.string
})
])
]);
type ContactPerson = t.TypeOf<typeof ContactPerson>;
export interface IServiceProviderConfig {
requiredAttributes: {
attributes: ReadonlyArray<SamlAttributeT>;
Expand All @@ -33,6 +176,7 @@ export interface IServiceProviderConfig {
spidValidatorUrl?: string;
IDPMetadataUrl: string;
organization: IServiceProviderOrganization;
contacts?: ReadonlyArray<ContactPerson>;
publicCert: string;
strictResponseValidation?: StrictResponseValidationOptions;
}
Expand Down
Loading