20
20
import ru .loolzaaa .authserver .exception .RequestErrorException ;
21
21
import ru .loolzaaa .authserver .model .User ;
22
22
import ru .loolzaaa .authserver .model .UserAttributes ;
23
+ import ru .loolzaaa .authserver .model .UserConfigWrapper ;
23
24
import ru .loolzaaa .authserver .model .UserPrincipal ;
24
25
import ru .loolzaaa .authserver .repositories .UserRepository ;
25
26
@@ -97,11 +98,11 @@ public RequestStatusDTO createUser(String app, CreateUserRequestDTO newUser) {
97
98
User user = userRepository .findByLogin (login ).orElse (null );
98
99
99
100
if (user != null ) {
100
- if (user .getConfig ().has (app )) {
101
+ if (user .getJsonConfig ().has (app )) {
101
102
log .warn ("Try to add [{}] application in user [{}] where it already exist" , app , login );
102
103
throw new RequestErrorException ("App [%s] for user [%s] already exist!" , app , login );
103
104
} else {
104
- ((ObjectNode ) user .getConfig ()).set (app , newUser .getConfig ());
105
+ ((ObjectNode ) user .getJsonConfig ()).set (app , newUser .getConfig ());
105
106
userRepository .updateConfigByLogin (user .getConfig (), login );
106
107
107
108
log .info ("Added [{}] application for user [{}]" , app , login );
@@ -127,7 +128,13 @@ public RequestStatusDTO createUser(String app, CreateUserRequestDTO newUser) {
127
128
.put (UserAttributes .CREDENTIALS_EXP , Instant .now ().plus (Duration .ofDays (365 )).toEpochMilli ());
128
129
if (!config .has (app )) config .set (app , newUser .getConfig ());
129
130
130
- user = User .builder ().login (login ).salt (salt ).config (config ).name (name ).enabled (true ).build ();
131
+ user = User .builder ()
132
+ .login (login )
133
+ .salt (salt )
134
+ .config (new UserConfigWrapper (config ))
135
+ .name (name )
136
+ .enabled (true )
137
+ .build ();
131
138
userRepository .save (user );
132
139
133
140
jdbcTemplate .update ("INSERT INTO hashes VALUES (?)" , hash );
@@ -188,9 +195,9 @@ public RequestStatusDTO changeUserLockStatus(String login, Boolean enabled, Bool
188
195
answer .append (enabled ? "enabled" : "disabled" );
189
196
}
190
197
if (lock != null ) {
191
- JsonNode userConfig = user .getConfig ();
198
+ JsonNode userConfig = user .getJsonConfig ();
192
199
((ObjectNode ) userConfig .get (ssoServerProperties .getApplication ().getName ())).put (UserAttributes .LOCK , lock );
193
- userRepository .updateConfigByLogin (userConfig , login );
200
+ userRepository .updateConfigByLogin (user . getConfig () , login );
194
201
log .info ("User [{}] {}" , login , lock ? "locked" : "unlocked" );
195
202
answer .append (lock ? "locked" : "unlocked" );
196
203
}
@@ -223,11 +230,11 @@ public RequestStatusDTO changeUserPassword(String login, String oldPassword, Str
223
230
224
231
userRepository .updateSaltByLogin (salt , login );
225
232
226
- ((ObjectNode ) user .getConfig ().get (ssoServerProperties .getApplication ().getName ()))
233
+ ((ObjectNode ) user .getJsonConfig ().get (ssoServerProperties .getApplication ().getName ()))
227
234
.put (UserAttributes .CREDENTIALS_EXP , Instant .now ().plus (Duration .ofDays (365 )).toEpochMilli ());
228
235
229
- if (user .getConfig ().has (UserAttributes .TEMPORARY )) {
230
- ((ObjectNode ) user .getConfig ().get (UserAttributes .TEMPORARY )).put ("pass" , newPassword );
236
+ if (user .getJsonConfig ().has (UserAttributes .TEMPORARY )) {
237
+ ((ObjectNode ) user .getJsonConfig ().get (UserAttributes .TEMPORARY )).put ("pass" , newPassword );
231
238
userRepository .updateConfigByLogin (user .getConfig (), login );
232
239
}
233
240
@@ -258,13 +265,13 @@ public RequestStatusDTO changeApplicationConfigForUser(String login, String app,
258
265
throw new RequestErrorException ("There is no user with login [%s]" , login );
259
266
}
260
267
261
- JsonNode userConfig = user .getConfig ();
268
+ JsonNode userConfig = user .getJsonConfig ();
262
269
if (!userConfig .has (app )) {
263
270
log .warn ("Try to change non existing config [{}] for user: {}" , app , login );
264
271
throw new RequestErrorException ("There is no [%s] config for user [%s]" , app , login );
265
272
}
266
273
267
- ((ObjectNode ) user .getConfig ()).set (app , appConfig );
274
+ ((ObjectNode ) user .getJsonConfig ()).set (app , appConfig );
268
275
userRepository .updateConfigByLogin (user .getConfig (), login );
269
276
270
277
log .info ("Application [{}] config was changed for user [{}]" , app , login );
@@ -285,13 +292,13 @@ public RequestStatusDTO deleteApplicationConfigForUser(String login, String app)
285
292
throw new RequestErrorException ("There is no user with login [%s]" , login );
286
293
}
287
294
288
- JsonNode userConfig = user .getConfig ();
295
+ JsonNode userConfig = user .getJsonConfig ();
289
296
if (!userConfig .has (app )) {
290
297
log .warn ("Try to delete non existing config [{}] for user: {}" , app , login );
291
298
throw new RequestErrorException ("There is no [%s] config for user [%s]" , app , login );
292
299
}
293
300
294
- ((ObjectNode ) user .getConfig ()).remove (app );
301
+ ((ObjectNode ) user .getJsonConfig ()).remove (app );
295
302
userRepository .updateConfigByLogin (user .getConfig (), login );
296
303
297
304
log .info ("Application [{}] config was deleted for user [{}]" , app , login );
@@ -310,7 +317,7 @@ public RequestStatusDTO createTemporaryUser(String temporaryLogin, long dateFrom
310
317
log .warn ("Try to create temporary user for non existing user: {}" , temporaryLogin );
311
318
throw new RequestErrorException ("There is no original user [%s]" , temporaryLogin );
312
319
}
313
- if (temporaryUser .getConfig ().has (UserAttributes .TEMPORARY )) {
320
+ if (temporaryUser .getJsonConfig ().has (UserAttributes .TEMPORARY )) {
314
321
log .warn ("Try to create temporary user for ALREADY temporary user: {}" , temporaryLogin );
315
322
throw new RequestErrorException ("Temporary users can't create other temporary users" );
316
323
}
@@ -340,9 +347,9 @@ public RequestStatusDTO createTemporaryUser(String temporaryLogin, long dateFrom
340
347
temporaryNode .put ("dateTo" , dateToLdt .toLocalDate ().toString ());
341
348
temporaryNode .put ("pass" , dTemporaryPassword );
342
349
temporaryNode .put ("originTabNumber" , temporaryLogin );
343
- ((ObjectNode ) temporaryUser .getConfig ()).set (UserAttributes .TEMPORARY , temporaryNode );
350
+ ((ObjectNode ) temporaryUser .getJsonConfig ()).set (UserAttributes .TEMPORARY , temporaryNode );
344
351
345
- ((ObjectNode ) temporaryUser .getConfig ().get (ssoServerProperties .getApplication ().getName ()))
352
+ ((ObjectNode ) temporaryUser .getJsonConfig ().get (ssoServerProperties .getApplication ().getName ()))
346
353
.put (UserAttributes .CREDENTIALS_EXP , Instant .now ().plus (Duration .ofDays (90 )).toEpochMilli ());
347
354
348
355
dTemporaryUser = User .builder ()
@@ -368,7 +375,7 @@ private boolean checkUserAndDeleteHash(User user, String password) {
368
375
try {
369
376
authenticationProvider .authenticate (new UsernamePasswordAuthenticationToken (user .getLogin (), password ));
370
377
} catch (AccountStatusException ex ) {
371
- if (!user .getConfig ().has (UserAttributes .TEMPORARY )) {
378
+ if (!user .getJsonConfig ().has (UserAttributes .TEMPORARY )) {
372
379
throw ex ;
373
380
}
374
381
}
0 commit comments