1 package fr.paris.lutece.plugins.identitystore.modules.fccertifier.service.certifier;
2
3 import fr.paris.lutece.plugins.identitystore.service.certifier.IGenerateAutomaticCertifierAttribute;
4 import fr.paris.lutece.plugins.identitystore.v2.web.rs.dto.IdentityDto;
5 import fr.paris.lutece.portal.service.util.AppLogService;
6 import fr.paris.lutece.util.fckey.FCKeyException;
7 import fr.paris.lutece.util.fckey.FCKeyService;
8
9
10
11
12 public class AutomaticFcKeyGenerator implements IGenerateAutomaticCertifierAttribute {
13
14
15 private static final String FIELD_SEPARATOR="|";
16 private static final String CRYPTO_ALGO ="SHA-256";
17
18
19 private String _strGenderAttribute;
20
21
22 private String _strFirstNameAttribute;
23
24
25 private String _strFamilyNameAttribute;
26
27
28 private String _strBirthplaceAttribute;
29
30
31 private String _strBirthdateAttribute;
32
33
34 private String _strBirthcountryAttribute;
35
36
37
38
39
40
41 public String getGenderAttribute() {
42 return _strGenderAttribute;
43 }
44
45
46
47
48
49
50 public void setGenderAttribute(String _strGenderAttribute) {
51 this._strGenderAttribute = _strGenderAttribute;
52 }
53
54
55
56
57
58
59 public void setFirstNameAttribute(String _strFirstNameAttribute) {
60 this._strFirstNameAttribute = _strFirstNameAttribute;
61 }
62
63
64
65
66
67
68 public void setFamilyNameAttribute(String _strFamilyNameAttribute) {
69 this._strFamilyNameAttribute = _strFamilyNameAttribute;
70 }
71
72
73
74
75
76
77 public void setBirthplaceAttribute(String _strBirthplaceAttribute) {
78 this._strBirthplaceAttribute = _strBirthplaceAttribute;
79 }
80
81
82
83
84
85
86 public void setBirthdateAttribute(String _strBirthdateAttribute) {
87 this._strBirthdateAttribute = _strBirthdateAttribute;
88 }
89
90
91
92
93
94
95 public void setBirthcountryAttribute(String _strBirthcountryAttribute) {
96 this._strBirthcountryAttribute = _strBirthcountryAttribute;
97 }
98
99
100
101
102
103
104 @Override
105 public boolean mustBeGenerated(IdentityDto identityDTO, String strCertifierCode) {
106
107 if (containsAttributeCertificated(identityDTO, _strGenderAttribute, strCertifierCode)
108 && containsAttributeCertificated(identityDTO, _strFirstNameAttribute, strCertifierCode)
109 && containsAttributeCertificated(identityDTO, _strFamilyNameAttribute, strCertifierCode)
110 && containsAttributeCertificated(identityDTO, _strBirthplaceAttribute, strCertifierCode)
111 && containsAttributeCertificated(identityDTO, _strBirthcountryAttribute, strCertifierCode)
112 && containsAttributeCertificated(identityDTO, _strBirthdateAttribute, strCertifierCode)) {
113
114 try {
115 FCKeyService.validateKeyInformations(identityDTO.getAttributes().get(_strGenderAttribute).getValue(),
116 identityDTO.getAttributes().get(_strFirstNameAttribute).getValue(),
117 identityDTO.getAttributes().get(_strFamilyNameAttribute).getValue(),
118 identityDTO.getAttributes().get(_strBirthplaceAttribute).getValue(),
119 identityDTO.getAttributes().get(_strBirthcountryAttribute).getValue(),
120 identityDTO.getAttributes().get(_strBirthdateAttribute).getValue());
121 return true;
122 } catch (FCKeyException e) {
123 AppLogService.error("the FC key can not be generated for customer id "+ identityDTO.getCustomerId(), e);
124 }
125
126 }
127 return false;
128
129 }
130
131
132
133
134
135 @Override
136 public String getValue(IdentityDto identityDTO) {
137
138
139 String strFcKey = "";
140 try {
141 strFcKey=FCKeyService.getKey(identityDTO.getAttributes().get(_strGenderAttribute).getValue(),
142 identityDTO.getAttributes().get(_strFirstNameAttribute).getValue(),
143 identityDTO.getAttributes().get(_strFamilyNameAttribute).getValue(),
144 identityDTO.getAttributes().get(_strBirthplaceAttribute).getValue(),
145 identityDTO.getAttributes().get(_strBirthcountryAttribute).getValue(),
146 identityDTO.getAttributes().get(_strBirthdateAttribute).getValue());
147
148 } catch (FCKeyException e) {
149 AppLogService.error("An error appear during FC key generation for customer id "+identityDTO.getCustomerId(),e);
150 }
151
152 return strFcKey;
153
154
155
156
157
158 }
159
160
161
162
163 private boolean containsAttributeCertificated(IdentityDto identityDto, String strAtrributeKey,
164 String strFcCertifierCode) {
165
166 return identityDto.getAttributes().containsKey(strAtrributeKey)
167 && identityDto.getAttributes().get(strAtrributeKey).getCertificate() != null && strFcCertifierCode
168 .equals(identityDto.getAttributes().get(strAtrributeKey).getCertificate().getCertifierCode());
169
170 }
171
172 }