HopsworksRMAppSecurityActions extends AbstractSecurityActions implements RMAppSecurityActions { @Override public String renewJWT(JWTSecurityHandler.JWTMaterialParameter jwtParameter) throws IOException, GeneralSecurityException { if (!jwtConfigured) { jwtNotConfigured("renewJWT"); } CloseableHttpResponse response = null; try { ServiceJWTManager.JWTDTO payload = new ServiceJWTManager.JWTDTO(); payload.setToken(jwtParameter.getToken()); payload.setExpiresAt(DateUtils.localDateTime2Date(jwtParameter.getExpirationDate())); payload.setNbf(DateUtils.localDateTime2Date(jwtParameter.getValidNotBefore())); HttpPut request = new HttpPut(jwtRenewPath); request.setEntity(new StringEntity(parser.toJson(payload))); response = doJSONCall(request, "Could not renew JWT for " + jwtParameter.getAppUser() + "/" + jwtParameter.getApplicationId()); ServiceJWTManager.JWTDTO jwtResponse = parser.fromJson(EntityUtils.toString(response.getEntity()), ServiceJWTManager.JWTDTO.class); return jwtResponse.getToken(); } finally { if (response != null) { response.close(); } } } HopsworksRMAppSecurityActions(); @Override X509SecurityHandler.CertificateBundle sign(PKCS10CertificationRequest csr); @Override int revoke(String certificateIdentifier); @Override String generateJWT(JWTSecurityHandler.JWTMaterialParameter jwtParameter); @Override String renewJWT(JWTSecurityHandler.JWTMaterialParameter jwtParameter); @Override void invalidateJWT(String signingKeyName); static final String REVOKE_CERT_ID_PARAM; }
@Test(timeout = 15000) public void testRenewJWT() throws Exception { ApplicationId appId = ApplicationId.newInstance(System.currentTimeMillis(), 1); JWTSecurityHandler.JWTMaterialParameter jwtParam0 = createJWTParameter(appId, 2, ChronoUnit.SECONDS); RMAppSecurityActions actor = (RMAppSecurityActions) HopsSecurityActionsFactory.getInstance().getActor(conf, conf.get(YarnConfiguration.HOPS_RM_SECURITY_ACTOR_KEY, YarnConfiguration.HOPS_RM_SECURITY_ACTOR_DEFAULT)); String jwt0 = actor.generateJWT(jwtParam0); TimeUnit.SECONDS.sleep(10); JWTSecurityHandler.JWTMaterialParameter jwtParam1 = createJWTParameter(appId); jwtParam1.setToken(jwt0); String jwt1 = actor.renewJWT(jwtParam1); Assert.assertNotNull(jwt1); Assert.assertNotEquals(jwt0, jwt1); }