-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_federated_connection_ext.go
360 lines (306 loc) · 13.7 KB
/
model_federated_connection_ext.go
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
package jossoappi
// Transforms the federated connection's channelA (FederatedChannelDTO) into a IdentityProviderChannelDTO
func (f *FederatedConnectionDTO) GetIDPChannel() (*IdentityProviderChannelDTO, error) {
c := f.GetChannelB()
var idpc IdentityProviderChannelDTO
idpc.SetActiveBindings(c.GetActiveBindings())
idpc.SetActiveProfiles(c.GetActiveProfiles())
idpc.SetDescription(c.GetDescription())
idpc.SetDisplayName(c.GetDisplayName())
idpc.SetElementId(c.GetElementId())
idpc.SetId(c.GetId())
idpc.SetLocation(c.GetLocation())
idpc.SetName(c.GetName())
idpc.SetOverrideProviderSetup(c.GetOverrideProviderSetup())
prefered := false
if c.AdditionalProperties["preferred"] != nil {
prefered = (c.AdditionalProperties["preferred"].(bool))
}
idpc.SetPreferred(prefered)
if idpc.GetOverrideProviderSetup() {
idpc.SetSignatureHash(AsString(c.AdditionalProperties["signatureHash"], ""))
idpc.SetMessageTtl(AsInt32(c.AdditionalProperties["messageTtl"], 0))
idpc.SetMessageTtlTolerance(AsInt32(c.AdditionalProperties["messageTtlTolerance"], 0))
accountLinkage := toAccountLinkagePolicyDTO(c.AdditionalProperties["accountLinkagePolicy"].(map[string]interface{}))
idpc.SetAccountLinkagePolicy(accountLinkage)
idpc.SetEnableProxyExtension(AsBool(c.AdditionalProperties["enableProxyExtension"], false))
idMapping := toIdentityMappingPolicyDTO(c.AdditionalProperties["identityMappingPolicy"].(map[string]interface{}))
idpc.SetIdentityMappingPolicy(idMapping)
idpc.SetSignAuthenticationRequests(AsBool(c.AdditionalProperties["signAuthenticationRequests"], false))
idpc.SetWantAssertionSigned(AsBool(c.AdditionalProperties["wantAssertionSigned"], false))
}
idpc.AdditionalProperties = map[string]interface{}{
"@c": ".IdentityProviderChannelDTO",
}
return &idpc, nil
}
// Transforms the IdentityProviderChannelDTO into a FederatedChannel and sets it into channelA
func (f *FederatedConnectionDTO) SetIDPChannel(idpc *IdentityProviderChannelDTO) error {
var c FederatedChannelDTO
c.SetActiveBindings(idpc.GetActiveBindings())
c.SetActiveProfiles(idpc.GetActiveProfiles())
c.SetDescription(idpc.GetDescription())
c.SetDisplayName(idpc.GetDisplayName())
c.SetElementId(idpc.GetElementId())
c.SetId(idpc.GetId())
c.SetLocation(idpc.GetLocation())
c.SetName(idpc.GetName())
c.SetOverrideProviderSetup(idpc.GetOverrideProviderSetup())
c.AdditionalProperties = make(map[string]interface{})
c.AdditionalProperties["preferred"] = idpc.GetPreferred()
c.AdditionalProperties["@c"] = ".IdentityProviderChannelDTO"
if idpc.GetOverrideProviderSetup() {
c.AdditionalProperties["signatureHash"] = idpc.GetSignatureHash()
c.AdditionalProperties["messageTtl"] = idpc.GetMessageTtl()
c.AdditionalProperties["messageTtlTolerance"] = idpc.GetMessageTtlTolerance()
c.AdditionalProperties["accountLinkagePolicy"] = toAccountLinkagePolicyMap(idpc.GetAccountLinkagePolicy())
c.AdditionalProperties["enableProxyExtension"] = idpc.GetEnableProxyExtension()
c.AdditionalProperties["identityMappingPolicy"] = toIdentityMappingPolicyMap(idpc.GetIdentityMappingPolicy())
c.AdditionalProperties["signAuthenticationRequests"] = idpc.GetSignAuthenticationRequests()
c.AdditionalProperties["wantAssertionSigned"] = idpc.GetWantAssertionSigned()
}
f.SetChannelB(c)
return nil
}
// Transforms IdentityMappingPolicyDTO a map
func toIdentityMappingPolicyMap(dto IdentityMappingPolicyDTO) map[string]interface{} {
props := make(map[string]interface{})
props["customMapper"] = dto.GetCustomMapper()
props["elementId"] = dto.GetElementId()
props["id"] = dto.GetId()
props["mappingType"] = dto.GetMappingType()
props["name"] = dto.GetName()
props["useLocalId"] = dto.GetUseLocalId()
props["@c"] = ".IdentityMappingPolicyDTO"
return props
}
// Transforms a map into an IdentityMappingPolicyDTO
func toIdentityMappingPolicyDTO(props map[string]interface{}) IdentityMappingPolicyDTO {
dto := NewIdentityMappingPolicyDTO()
dto.SetCustomMapper(AsString(props["customMapper"], ""))
dto.SetElementId(AsString(props["elementId"], ""))
dto.SetId(AsInt64(props["id"], 0))
dto.SetMappingType(AsString(props["mappingType"], ""))
dto.SetName(AsString(props["name"], ""))
dto.SetUseLocalId(AsBool(props["useLocalId"], false))
dto.AdditionalProperties = map[string]interface{}{
"@c": ".IdentityMappingPolicyDTO",
}
return *dto
}
// Transforms AccountLinkagePolicy a map
func toAccountLinkagePolicyMap(dto AccountLinkagePolicyDTO) map[string]interface{} {
props := make(map[string]interface{})
props["customLinkEmitter"] = dto.GetCustomLinkEmitter()
props["elementId"] = dto.GetElementId()
props["id"] = dto.GetId()
props["linkEmitterType"] = dto.GetLinkEmitterType()
props["name"] = dto.GetName()
props["@c"] = ".AccountLinkagePolicyDTO"
return props
}
// Transforms a map into an AccountLinkagePolicyDTO
func toAccountLinkagePolicyDTO(props map[string]interface{}) AccountLinkagePolicyDTO {
dto := NewAccountLinkagePolicyDTO()
dto.SetCustomLinkEmitter(AsString(props["customLinkEmitter"], ""))
dto.SetElementId(AsString(props["elementId"], ""))
dto.SetId(AsInt64(props["id"], 0))
dto.SetLinkEmitterType(AsString(props["linkEmitterType"], ""))
dto.SetName(AsString(props["name"], ""))
dto.AdditionalProperties = map[string]interface{}{
"@c": ".AccountLinkagePolicyDTO",
}
return *dto
}
// Transforms a map into an EmissionPolicyDTO
func toEmissionPolicyDTO(props map[string]interface{}) AuthenticationAssertionEmissionPolicyDTO {
dto := NewAuthenticationAssertionEmissionPolicyDTO()
dto.SetElementId(AsString(props["elementId"], ""))
dto.SetId(AsInt64(props["id"], 0))
dto.SetName(AsString(props["name"], ""))
dto.AdditionalProperties = map[string]interface{}{
"@c": ".AuthenticationAssertionEmissionPolicyDTO",
}
return *dto
}
// Transforms a map into an AuthenticationContractDTO
func toAuthenticationContractDTO(props map[string]interface{}) AuthenticationContractDTO {
dto := NewAuthenticationContractDTO()
dto.SetElementId(AsString(props["elementId"], ""))
dto.SetId(AsInt64(props["id"], 0))
dto.SetName(AsString(props["name"], ""))
dto.AdditionalProperties = map[string]interface{}{
"@c": ".AuthenticationContractDTO",
}
return *dto
}
// Transforms a map into an AttributeProfileDTO
func toAttributeProfileDTO(props map[string]interface{}) AttributeProfileDTO {
dto := NewAttributeProfileDTO()
dto.SetElementId(AsString(props["elementId"], ""))
dto.SetId(AsInt64(props["id"], 0))
dto.SetName(AsString(props["name"], ""))
dto.SetProfileType(AsString(props["profileType"], ""))
// TODO : Support custom attribute profile
dto.AdditionalProperties = map[string]interface{}{
"@c": ".BuiltInAttributeProfileDTO",
}
return *dto
}
// Transforms a map into an SubjectNameIDPolicyDTO
func toSubjectNameIDPolicyDTO(props map[string]interface{}) SubjectNameIdentifierPolicyDTO {
dto := NewSubjectNameIdentifierPolicyDTO()
dto.SetDescriptionKey(AsString(props["descriptionKey"], ""))
dto.SetId(AsString(props["id"], ""))
dto.SetName(AsString(props["name"], ""))
dto.SetSubjectAttribute(AsString(props["subjectAttribute"], ""))
dto.SetType(AsString(props["type"], ""))
dto.AdditionalProperties = map[string]interface{}{
"@c": ".SubjectNameIdentifierPolicyDTO",
}
return *dto
}
// Transforms the InternalSaml2ServiceProviderChannelDTO into a FederatedChannel and sets it into channelA
func (f *FederatedConnectionDTO) SetSPChannel(spc *InternalSaml2ServiceProviderChannelDTO) error {
var c FederatedChannelDTO
c.SetId(spc.GetId())
c.SetActiveBindings(spc.GetActiveBindings())
c.SetActiveProfiles(spc.GetActiveProfiles())
c.SetDescription(spc.GetDescription())
c.SetDisplayName(spc.GetDisplayName())
c.SetElementId(spc.GetElementId())
c.SetLocation(spc.GetLocation())
c.SetName(spc.GetName())
c.SetOverrideProviderSetup(spc.GetOverrideProviderSetup())
c.AdditionalProperties = make(map[string]interface{})
c.AdditionalProperties["@c"] = ".InternalSaml2ServiceProviderChannelDTO"
if spc.GetOverrideProviderSetup() {
c.AdditionalProperties["emissionPolicy"] = toEmissionPolicyMap(spc.GetEmissionPolicy())
c.AdditionalProperties["restrictedRoles"] = spc.GetRestrictedRoles()
c.AdditionalProperties["requiredRoles"] = spc.GetRequiredRoles()
c.AdditionalProperties["messageTtl"] = spc.GetMessageTtl()
c.AdditionalProperties["requiredRolesMatchMode"] = spc.GetRequiredRolesMatchMode()
c.AdditionalProperties["restrictedRolesMatchMode"] = spc.GetRestrictedRolesMatchMode()
c.AdditionalProperties["encryptAssertionAlgorithm"] = spc.GetEncryptAssertionAlgorithm()
c.AdditionalProperties["ignoreRequestedNameIDPolicy"] = spc.GetIgnoreRequestedNameIDPolicy()
if p, ok := spc.GetSubjectNameIDPolicyOk(); ok {
c.AdditionalProperties["subjectNameIDPolicy"] = toSubjectNameIDPolicyMap(p)
}
c.AdditionalProperties["encryptAssertion"] = spc.GetEncryptAssertion()
c.AdditionalProperties["signatureHash"] = spc.GetSignatureHash()
c.AdditionalProperties["attributeProfile"] = toAttributeProfilemap(spc.GetAttributeProfile())
c.AdditionalProperties["authenticationContract"] = toAuthenticationContractmap(spc.GetAuthenticationContract())
c.AdditionalProperties["wantAuthnRequestsSigned"] = spc.GetWantAuthnRequestsSigned()
}
f.SetChannelA(c)
return nil
}
// IDP Side, has an SP channel
func (f *FederatedConnectionDTO) GetSPChannel() (*InternalSaml2ServiceProviderChannelDTO, error) {
c := f.GetChannelA()
var spc InternalSaml2ServiceProviderChannelDTO
spc.SetId(c.GetId())
spc.SetActiveBindings(c.GetActiveBindings())
spc.SetActiveProfiles(c.GetActiveProfiles())
spc.SetDescription(c.GetDescription())
spc.SetDisplayName(c.GetDisplayName())
spc.SetElementId(c.GetElementId())
spc.SetLocation(c.GetLocation())
spc.SetName(c.GetName())
spc.SetOverrideProviderSetup(c.GetOverrideProviderSetup())
if c.GetOverrideProviderSetup() {
if c.AdditionalProperties["emissionPolicy"] != nil {
emissionPolicy := toEmissionPolicyDTO(c.AdditionalProperties["emissionPolicy"].(map[string]interface{}))
spc.SetEmissionPolicy(emissionPolicy)
}
spc.SetRestrictedRoles(AsStringArr(c.AdditionalProperties["restrictedRoles"]))
spc.SetRequiredRoles(AsStringArr(c.AdditionalProperties["requiredRoles"]))
spc.SetMessageTtl(AsInt32(c.AdditionalProperties["messageTtl"], 0))
spc.SetRequiredRolesMatchMode(AsInt32(c.AdditionalProperties["requiredRolesMatchMode"], 0))
spc.SetRestrictedRolesMatchMode(AsInt32(c.AdditionalProperties["restrictedRolesMatchMode"], 0))
spc.SetEncryptAssertionAlgorithm(AsString(c.AdditionalProperties["encryptAssertionAlgorithm"], ""))
spc.SetIgnoreRequestedNameIDPolicy(AsBool(c.AdditionalProperties["ignoreRequestedNameIDPolicy"], false))
if c.AdditionalProperties["subjectNameIDPolicy"] != nil {
subjectNameId := toSubjectNameIDPolicyDTO(c.AdditionalProperties["subjectNameIDPolicy"].(map[string]interface{}))
spc.SetSubjectNameIDPolicy(subjectNameId)
}
spc.SetEncryptAssertion(AsBool(c.AdditionalProperties["encryptAssertion"], false))
spc.SetSignatureHash(AsString(c.AdditionalProperties["signatureHash"], ""))
if c.AdditionalProperties["attributeProfile"] != nil {
attrProfile := toAttributeProfileDTO(c.AdditionalProperties["attributeProfile"].(map[string]interface{}))
spc.SetAttributeProfile(attrProfile)
}
if c.AdditionalProperties["authenticationContract"] != nil {
authnContract := toAuthenticationContractDTO(c.AdditionalProperties["authenticationContract"].(map[string]interface{}))
spc.SetAuthenticationContract(authnContract)
}
spc.SetWantAuthnRequestsSigned(AsBool(c.AdditionalProperties["wantAuthnRequestsSigned"], false))
}
spc.AdditionalProperties = map[string]interface{}{
"@c": ".InternalSaml2ServiceProviderChannelDTO",
}
return &spc, nil
}
// Transforms AuthenticationContract a map
func toAuthenticationContractmap(dto AuthenticationContractDTO) *map[string]interface{} {
props := make(map[string]interface{})
props["elementId"] = dto.GetElementId()
props["id"] = dto.GetId()
props["name"] = dto.GetName()
props["@c"] = ".AuthenticationContractDTO"
return &props
}
// Transforms AttributeProfile a map
func toAttributeProfilemap(dto AttributeProfileDTO) *map[string]interface{} {
props := make(map[string]interface{})
props["elementId"] = dto.GetElementId()
props["id"] = dto.GetId()
props["name"] = dto.GetName()
props["profileType"] = dto.GetProfileType()
props["@c"] = ".BuiltInAttributeProfileDTO"
return &props
}
// Transforms EmissionPolicy a map
func toEmissionPolicyMap(dto AuthenticationAssertionEmissionPolicyDTO) *map[string]interface{} {
props := make(map[string]interface{})
props["elementId"] = dto.GetElementId()
props["id"] = dto.GetId()
props["name"] = dto.GetName()
props["@c"] = ".AuthenticationAssertionEmissionPolicyDTO"
return &props
}
// Transforms SubjectNameIDPolicy a map
func toSubjectNameIDPolicyMap(dto *SubjectNameIdentifierPolicyDTO) *map[string]interface{} {
props := make(map[string]interface{})
props["descriptionKey"] = dto.GetDescriptionKey()
props["id"] = dto.GetId()
props["name"] = dto.GetName()
props["subjectAttribute"] = dto.GetSubjectAttribute()
props["type"] = dto.GetType()
props["@c"] = ".SubjectNameIdentifierPolicyDTO"
return &props
}
func addFederatedConnection(fcs []FederatedConnectionDTO,
target string,
spChannel *InternalSaml2ServiceProviderChannelDTO,
idpChannel *IdentityProviderChannelDTO) ([]FederatedConnectionDTO, error) {
// Create new Federated Connection
var fc FederatedConnectionDTO
fc.AdditionalProperties = map[string]interface{}{
"@c": ".FederatedConnectionDTO",
}
fc.SetName(target)
fc.SetIDPChannel(idpChannel)
fc.SetSPChannel(spChannel)
fcs = append(fcs, fc)
return fcs, nil
}
func removeFederatedConnection(fcs []FederatedConnectionDTO, target string) ([]FederatedConnectionDTO, error) {
var newFcs []FederatedConnectionDTO
for _, fc := range fcs {
if fc.GetName() != target {
newFcs = append(newFcs, fc)
}
}
return newFcs, nil
}