-
Notifications
You must be signed in to change notification settings - Fork 4
/
createidps.js
114 lines (93 loc) · 4.5 KB
/
createidps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const {from, of, concat, EMPTY} = require('rxjs')
const {map, mergeMap, isEmpty} = require('rxjs/operators')
const {config, patchTemplate, enrichIdpWithConfigData} = require('./src/common')
const {
httpGrabIdPsMetadata,
httpCallKeycloakImportConfig,
httpCallKeycloakCreateIdP,
httpCallKeycloakDeleteIdP,
httpCallKeycloakCreateAllMappers
} = require('./src/http')
const idPTemplate = JSON.parse(patchTemplate('./template/idpmodel.json'))
var getOfficialSpididPsMetadata$;
if(typeof(config.spidMetadataOfficialURL) !== 'undefined' && config.spidMetadataOfficialURL !== "") {
//recupero url metadati
getOfficialSpididPsMetadata$ = from(httpGrabIdPsMetadata())
.pipe(mergeMap(httpResponse => from(httpResponse.data.data.filter(idp => !config.singleIdp || idp.ipa_entity_code == config.singleIdp).map(idp => enrichIdpWithConfigData(idp)))));
}
else
getOfficialSpididPsMetadata$ = EMPTY;
if (config.createSpidTestIdP === 'true') {
let spidTestIdPOfficialMetadata = {
ipa_entity_code: config.spidTestIdPAlias,
entity_id: config.spidTestIdPAlias,
entity_name: config.spidTestIdPAlias,
metadata_url: config.spidTestIdPMetadataURL,
entity_type: 'IdP'
}
getOfficialSpididPsMetadata$ = concat(getOfficialSpididPsMetadata$, of(enrichIdpWithConfigData(spidTestIdPOfficialMetadata)));
}
if (config.createSpidValidatorIdP === 'true') {
let spidValidatorIdPOfficialMetadata = {
ipa_entity_code: config.spidValidatorIdPAlias,
entity_id: config.spidValidatorIdPAlias,
entity_name: config.spidValidatorIdPAlias,
metadata_url: config.spidValidatorIdPMetadataURL,
displayName: config.spidValidatorIdPDisplayName,
entity_type: 'IdP'
}
getOfficialSpididPsMetadata$ = concat(getOfficialSpididPsMetadata$, of(enrichIdpWithConfigData(spidValidatorIdPOfficialMetadata)))
}
if (config.createSpidDemoIdP === 'true') {
let spidDemoIdPOfficialMetadata = {
ipa_entity_code: config.spidDemoIdPAlias,
entity_id: config.spidDemoIdPAlias,
entity_name: config.spidDemoIdPAlias,
metadata_url: config.spidDemoIdPMetadataURL,
hideOnLoginPage: "false",
entity_type: 'IdP'
}
getOfficialSpididPsMetadata$ = concat(getOfficialSpididPsMetadata$, of(enrichIdpWithConfigData(spidDemoIdPOfficialMetadata)))
}
var noIdpToSetUp;
getOfficialSpididPsMetadata$.pipe(isEmpty()).subscribe(r => {
noIdpToSetUp = r;
});
if(noIdpToSetUp){
console.error("No idp configured to be set up, exiting");
return;
}
//getOfficialSpididPsMetadata$.subscribe(console.log);
//richiesta cancellazione degli idPs da keycloak
var deleteKeycloakSpidIdPs$ = getOfficialSpididPsMetadata$
.pipe(mergeMap(spidIdPOfficialMetadata => from(httpCallKeycloakDeleteIdP(spidIdPOfficialMetadata.alias).then(httpResponse => spidIdPOfficialMetadata))))
//richiesta conversione in import-config model [idP,import-config-response]
var getKeycloakImportConfigModels$ = deleteKeycloakSpidIdPs$
.pipe(mergeMap(spidIdPOfficialMetadata => from(httpCallKeycloakImportConfig(spidIdPOfficialMetadata.metadata_url).
then(httpResponse => {
return [spidIdPOfficialMetadata, httpResponse.data]
}))))
//trasformazione ed arricchimento => modello per creare l'idP su keycloak
var enrichedModels$ = getKeycloakImportConfigModels$
.pipe(map(spidIdPOfficialMetadataWithImportConfigModel => {
let [idPOfficialMetadata, importConfigModel] = spidIdPOfficialMetadataWithImportConfigModel
let configIdp = {...idPTemplate.config, ...importConfigModel, ...idPOfficialMetadata.config}
let firstLevel = {
alias: idPOfficialMetadata.alias,
displayName: idPOfficialMetadata.displayName,
}
let merged = {...idPTemplate, ...firstLevel}
merged.config = configIdp
return merged
}))
//creazione dello spid idP su keycloak
var createSpidIdPsOnKeycloak$ = enrichedModels$
.pipe(mergeMap(idPToCreateModel => from(httpCallKeycloakCreateIdP(idPToCreateModel).then(httpResponse => [idPToCreateModel.alias, httpResponse]))))
//creazione dei mappers per lo spid id
var createKeycloackSpidIdPsMappers$ = createSpidIdPsOnKeycloak$.pipe(mergeMap(idPAliasWithHttpCreateResponse => {
let [alias, createResponse] = idPAliasWithHttpCreateResponse
return from(httpCallKeycloakCreateAllMappers(alias).then(response => {
return {alias, create_response: createResponse, mapper_response: response}
}))
}))
createKeycloackSpidIdPsMappers$.subscribe(console.log)