21
21
22
22
package app .coronawarn .verification .portal .controller ;
23
23
24
+ import app .coronawarn .verification .portal .SecurityConfig ;
24
25
import app .coronawarn .verification .portal .client .TeleTan ;
25
26
import app .coronawarn .verification .portal .service .TeleTanService ;
26
27
import feign .FeignException ;
38
39
import org .springframework .stereotype .Controller ;
39
40
import org .springframework .ui .Model ;
40
41
import org .springframework .web .bind .annotation .GetMapping ;
42
+ import org .springframework .web .bind .annotation .ModelAttribute ;
41
43
import org .springframework .web .bind .annotation .PostMapping ;
42
44
import org .springframework .web .bind .annotation .RequestMapping ;
43
45
import org .springframework .web .bind .annotation .RequestMethod ;
@@ -92,14 +94,19 @@ public class VerificationPortalController {
92
94
private static final String ATTR_TELETAN = "teleTAN" ;
93
95
private static final String ATTR_USER = "userName" ;
94
96
private static final String ATTR_PW_RESET_URL = "pwResetUrl" ;
97
+ private static final String ATTR_ROLE_TEST = "role_test" ;
98
+ private static final String ATTR_ROLE_EVENT = "role_event" ;
99
+
100
+ private static final String TELETAN_TYPE_TEST = "TEST" ;
101
+ private static final String TELETAN_TYPE_EVENT = "EVENT" ;
95
102
96
103
/**
97
104
* The Keycloak password reset URL.
98
105
*/
99
106
@ Value ("${keycloak-pw.reset-url}" )
100
107
private String pwResetUrl ;
101
108
102
- private static final Map <String , LocalDateTime > rateLimitingUserMap = new ConcurrentHashMap <String , LocalDateTime >();
109
+ private static final Map <String , LocalDateTime > rateLimitingUserMap = new ConcurrentHashMap <>();
103
110
104
111
@ Value ("${rateLimiting.enabled}" )
105
112
private boolean rateLimitingEnabled ;
@@ -142,6 +149,7 @@ public String start(HttpServletRequest request, Model model) {
142
149
if (model != null ) {
143
150
model .addAttribute (ATTR_USER , user .replace ("<" , "" ).replace (">" , "" ));
144
151
model .addAttribute (ATTR_PW_RESET_URL , pwResetUrl );
152
+ setRoleDependentAttributes (model , principal );
145
153
}
146
154
147
155
HttpSession session = request .getSession ();
@@ -161,12 +169,19 @@ public String start(HttpServletRequest request, Model model) {
161
169
* @return the name of the Thymeleaf template to be used for the HTML page
162
170
*/
163
171
@ PostMapping (value = ROUTE_TELETAN )
164
- public String teletan (HttpServletRequest request , Model model ) {
172
+ public String teletan (
173
+ HttpServletRequest request ,
174
+ Model model ,
175
+ @ ModelAttribute ("EVENT" ) String eventButton ,
176
+ @ ModelAttribute ("TEST" ) String testButton ) {
177
+
165
178
TeleTan teleTan = new TeleTan ("123456789" );
166
179
KeycloakAuthenticationToken principal = (KeycloakAuthenticationToken ) request
167
180
.getUserPrincipal ();
168
181
String user = ((KeycloakPrincipal ) principal .getPrincipal ()).getName ();
169
182
183
+ String teleTanType = "" ;
184
+
170
185
// initially the TEMPLATE_INDEX is used (without showing the teleTAN)
171
186
String template = TEMPLATE_START ;
172
187
HttpSession session = request .getSession ();
@@ -180,7 +195,13 @@ public String teletan(HttpServletRequest request, Model model) {
180
195
}
181
196
182
197
try {
183
- teleTan = teleTanService .createTeleTan (token );
198
+ if (!eventButton .isEmpty ()) {
199
+ teleTan = teleTanService .createTeleTan (token , TELETAN_TYPE_EVENT );
200
+ teleTanType = TELETAN_TYPE_EVENT ;
201
+ } else if (!testButton .isEmpty ()) {
202
+ teleTan = teleTanService .createTeleTan (token , TELETAN_TYPE_TEST );
203
+ teleTanType = TELETAN_TYPE_TEST ;
204
+ }
184
205
} catch (FeignException e ) {
185
206
if (e .status () == HttpStatus .TOO_MANY_REQUESTS .value ()) {
186
207
throw new ServerRateLimitationException ("Too many requests. Please wait a moment." );
@@ -189,7 +210,7 @@ public String teletan(HttpServletRequest request, Model model) {
189
210
}
190
211
}
191
212
192
- log .info ("TeleTan successfully retrieved for user: {}" , user );
213
+ log .info ("TeleTan Type {} successfully retrieved for user: {}" , teleTanType , user );
193
214
template = TEMPLATE_TELETAN ;
194
215
}
195
216
session .setAttribute (SESSION_ATTR_TELETAN , "TeleTAN" );
@@ -198,6 +219,7 @@ public String teletan(HttpServletRequest request, Model model) {
198
219
model .addAttribute (ATTR_TELETAN , teleTan .getValue ().replace ("<" , "" ).replace (">" , "" ));
199
220
model .addAttribute (ATTR_USER , user .replace ("<" , "" ).replace (">" , "" ));
200
221
model .addAttribute (ATTR_PW_RESET_URL , pwResetUrl );
222
+ setRoleDependentAttributes (model , principal );
201
223
}
202
224
return template ;
203
225
}
@@ -230,4 +252,13 @@ public String logout(HttpServletRequest request) {
230
252
}
231
253
return "redirect:" + TEMPLATE_START ;
232
254
}
255
+
256
+ private void setRoleDependentAttributes (Model model , KeycloakAuthenticationToken token ) {
257
+ model .addAttribute (ATTR_ROLE_TEST , token .getAuthorities ().stream ()
258
+ .anyMatch (grantedAuthority -> grantedAuthority .getAuthority ().equals ("ROLE_" + SecurityConfig .ROLE_C19HOTLINE )));
259
+
260
+ model .addAttribute (ATTR_ROLE_EVENT , token .getAuthorities ().stream ()
261
+ .anyMatch (grantedAuthority ->
262
+ grantedAuthority .getAuthority ().equals ("ROLE_" + SecurityConfig .ROLE_C19HOTLINE_EVENT )));
263
+ }
233
264
}
0 commit comments