52
52
import io .hops .hopsworks .common .user .AuthController ;
53
53
import io .hops .hopsworks .common .user .QrCode ;
54
54
import io .hops .hopsworks .common .user .UsersController ;
55
- import io .hops .hopsworks .common .util .DateUtils ;
56
55
import io .hops .hopsworks .common .util .Settings ;
57
56
import io .hops .hopsworks .exceptions .HopsSecurityException ;
58
57
import io .hops .hopsworks .exceptions .UserException ;
59
58
import io .hops .hopsworks .jwt .Constants ;
60
59
import io .hops .hopsworks .jwt .JWTController ;
61
- import io .hops .hopsworks .jwt .JsonWebToken ;
62
60
import io .hops .hopsworks .jwt .annotation .JWTRequired ;
63
61
import io .hops .hopsworks .jwt .exception .DuplicateSigningKeyException ;
64
62
import io .hops .hopsworks .jwt .exception .InvalidationException ;
93
91
import javax .ws .rs .core .SecurityContext ;
94
92
import java .security .GeneralSecurityException ;
95
93
import java .security .NoSuchAlgorithmException ;
96
- import java .time .LocalDateTime ;
97
- import java .time .temporal .ChronoUnit ;
98
- import java .util .Collection ;
99
- import java .util .HashMap ;
100
- import java .util .List ;
101
- import java .util .Map ;
102
94
import java .util .logging .Level ;
103
95
import java .util .logging .Logger ;
104
96
@@ -230,18 +222,14 @@ public Response serviceLogin(@FormParam("email") String email, @FormParam("passw
230
222
if (!needLogin (request , null , user )) {
231
223
return Response .ok ().build ();
232
224
}
225
+
233
226
if (!userController .isUserInRole (user , "AGENT" )) {
234
227
throw new HopsSecurityException (RESTCodes .SecurityErrorCode .REST_ACCESS_CONTROL , Level .FINE ,
235
228
"Users are not allowed to access this endpoint, use auth/login instead" ,
236
229
"User " + user .getUsername () + " tried to login but they don't have AGENT role" );
237
230
}
238
231
request .getSession ();
239
232
240
- Collection roles = user .getBbcGroupCollection ();
241
- if (roles == null || roles .isEmpty ()) {
242
- throw new UserException (RESTCodes .UserErrorCode .NO_ROLE_FOUND , Level .FINE );
243
- }
244
-
245
233
statusValidator .checkStatus (user .getStatus ());
246
234
String saltedPassword = authController .preLoginCheck (user , password , null );
247
235
@@ -251,47 +239,9 @@ public Response serviceLogin(@FormParam("email") String email, @FormParam("passw
251
239
authController .registerAuthenticationFailure (user );
252
240
throw new UserException (RESTCodes .UserErrorCode .AUTHENTICATION_FAILURE , Level .FINE , null , ex .getMessage (), ex );
253
241
}
254
-
255
- // First generate the one-time tokens for renewal of master token
256
- String renewalKeyName = jwtController .getServiceOneTimeJWTSigningKeyname (user .getUsername (),
257
- request .getRemoteHost ());
258
- LocalDateTime masterExpiration = DateUtils .getNow ().plus (settings .getServiceJWTLifetimeMS (), ChronoUnit .MILLIS );
259
- LocalDateTime notBefore = jwtController .computeNotBefore4ServiceRenewalTokens (masterExpiration );
260
- LocalDateTime expiresAt = notBefore .plus (settings .getServiceJWTLifetimeMS (), ChronoUnit .MILLIS );
261
- List <String > userRoles = userUtilities .getUserRoles (user );
262
-
263
- JsonWebToken renewalJWTSpec = new JsonWebToken ();
264
- renewalJWTSpec .setSubject (user .getUsername ());
265
- renewalJWTSpec .setIssuer (settings .getJWTIssuer ());
266
- renewalJWTSpec .setAudience (JWTHelper .SERVICE_RENEW_JWT_AUDIENCE );
267
- renewalJWTSpec .setKeyId (renewalKeyName );
268
- renewalJWTSpec .setNotBefore (DateUtils .localDateTime2Date (notBefore ));
269
- renewalJWTSpec .setExpiresAt (DateUtils .localDateTime2Date (expiresAt ));
270
-
271
- Map <String , Object > claims = new HashMap <>(4 );
272
- claims .put (Constants .RENEWABLE , false );
273
- claims .put (Constants .EXPIRY_LEEWAY , 3600 );
274
- claims .put (Constants .ROLES , userRoles .toArray (new String [1 ]));
275
-
276
- String [] oneTimeRenewalTokens = jwtController .generateOneTimeTokens4ServiceJWTRenewal (renewalJWTSpec , claims ,
277
- settings .getJWTSigningKeyName ());
278
-
279
- // Then generate the master service token
280
- try {
281
- String signingKeyID = jwtController .getSignKeyID (oneTimeRenewalTokens [0 ]);
282
- claims .clear ();
283
- // The rest of JWT claims will be added by JWTHelper
284
- claims .put (Constants .RENEWABLE , false );
285
- claims .put (Constants .SERVICE_JWT_RENEWAL_KEY_ID , signingKeyID );
286
- String token = jWTHelper .createToken (user , settings .getJWTIssuer (), claims );
287
-
288
- ServiceJWTDTO renewTokensResponse = new ServiceJWTDTO ();
289
- renewTokensResponse .setRenewTokens (oneTimeRenewalTokens );
290
- return Response .ok ().header (AUTHORIZATION , Constants .BEARER + token ).entity (renewTokensResponse ).build ();
291
- } catch (Exception ex ) {
292
- jwtController .deleteSigningKey (renewalKeyName );
293
- throw ex ;
294
- }
242
+
243
+ String token = jWTHelper .createToken (user , settings .getJWTIssuer (), null );
244
+ return Response .ok ().header (AUTHORIZATION , Constants .BEARER + token ).build ();
295
245
}
296
246
297
247
@ GET
0 commit comments