/
pii.go
29 lines (25 loc) · 886 Bytes
/
pii.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
package keycloakb
import (
"github.com/cloudtrust/keycloak-bridge/internal/constants"
kc "github.com/cloudtrust/keycloak-client"
)
var (
// These attributes should not be used anymore
attrbBirthDateLegacy = kc.AttributeKey("birthDate")
attrbGenderLegacy = kc.AttributeKey("gender")
piiAttributes = map[kc.AttributeKey]kc.AttributeKey{
constants.AttrbBirthDate: attrbBirthDateLegacy,
constants.AttrbGender: attrbGenderLegacy,
}
)
// ConvertLegacyAttribute ensure that PII are located in the well named attributes
func ConvertLegacyAttribute(user *kc.UserRepresentation) {
for attrbSecure, attrbLegacy := range piiAttributes {
if value := user.GetAttributeString(attrbSecure); value == nil {
if value = user.GetAttributeString(attrbLegacy); value != nil {
user.SetAttributeString(attrbSecure, *value)
delete(*user.Attributes, attrbLegacy)
}
}
}
}