public static DelegationToken getDelegationTokenFromJson(JSONObject json) throws JSONException { DelegationToken ret = new DelegationToken(); if (json.has("token")) { ret.setToken(json.getString("token")); } else if (json.has("expiration-time")) { ret.setNextExpirationTime(json.getLong("expiration-time")); } return ret; }
extractToken(tokenData.getToken()); DelegationToken respToken = new DelegationToken(); respToken.setNextExpirationTime(renewTime); return Response.status(Status.OK).entity(respToken).build();
Exception { final String renewer = tokenData.getRenewer(); GetDelegationTokenResponse resp; try { .getRenewDate(identifier); DelegationToken respToken = new DelegationToken(tk.encodeToUrlString(), renewer, identifier .getOwner().toString(), tk.getKind().toString(), currentExpiration, identifier.getMaxDate());
@POST @Path("/delegation-token/expiration") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Response postDelegationTokenExpiration(@Context HttpServletRequest hsr) throws AuthorizationException, IOException, InterruptedException, Exception { init(); UserGroupInformation callerUGI; try { callerUGI = createKerberosUserGroupInformation(hsr); } catch (YarnException ye) { return Response.status(Status.FORBIDDEN).entity(ye.getMessage()).build(); } DelegationToken requestToken = new DelegationToken(); requestToken.setToken(extractToken(hsr).encodeToUrlString()); return renewDelegationToken(requestToken, hsr, callerUGI); }
@Override public Void call() throws Exception { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token") .header(yarnTokenHeader, tmpToken.getToken()) .accept(contentType).delete(ClientResponse.class); assertResponseStatusCode(Status.OK, response.getStatusInfo()); assertTokenCancelled(tmpToken.getToken()); return null; } });
final DelegationToken dtoken = new DelegationToken(); String renewer = "client2"; dtoken.setRenewer(renewer);
@Override public Void call() throws Exception { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token").accept(contentType) .entity(body, mediaType).post(ClientResponse.class); assertResponseStatusCode(Status.OK, response.getStatusInfo()); DelegationToken tok = getDelegationTokenFromResponse(response); assertFalse(tok.getToken().isEmpty()); Token<RMDelegationTokenIdentifier> token = new Token<RMDelegationTokenIdentifier>(); token.decodeFromUrlString(tok.getToken()); assertEquals(renewer, token.decodeIdentifier().getRenewer().toString()); assertValidRMToken(tok.getToken()); DelegationToken dtoken = new DelegationToken(); response = resource().path("ws").path("v1").path("cluster") .path("delegation-token").accept(contentType) .entity(dtoken, mediaType).post(ClientResponse.class); assertResponseStatusCode(Status.OK, response.getStatusInfo()); tok = getDelegationTokenFromResponse(response); assertFalse(tok.getToken().isEmpty()); token = new Token<RMDelegationTokenIdentifier>(); token.decodeFromUrlString(tok.getToken()); assertEquals("", token.decodeIdentifier().getRenewer().toString()); assertValidRMToken(tok.getToken()); return null; } });
assertValidRMToken(responseToken.getToken()); String body = generateRenewTokenBody(mediaType, responseToken.getToken()); ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token").path("expiration") .header(yarnTokenHeader, responseToken.getToken()) .accept(contentType).entity(body, mediaType) .post(ClientResponse.class); String message = "Expiration time not as expected: old = " + oldExpirationTime + "; new = " + tok.getNextExpirationTime(); assertTrue(message, tok.getNextExpirationTime() > oldExpirationTime); oldExpirationTime = tok.getNextExpirationTime(); resource().path("ws").path("v1").path("cluster") .path("delegation-token").path("expiration") .header(yarnTokenHeader, responseToken.getToken()) .accept(contentType).entity(body, mediaType) .post(ClientResponse.class); message = "Expiration time not as expected: old = " + oldExpirationTime + "; new = " + tok.getNextExpirationTime(); assertTrue(message, tok.getNextExpirationTime() > oldExpirationTime); return tok;
@Override public Void call() throws Exception { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token") .header(yarnTokenHeader, tmpToken.getToken()) .accept(contentType).delete(ClientResponse.class); assertEquals(Status.OK, response.getClientResponseStatus()); assertTokenCancelled(tmpToken.getToken()); return null; } });
@POST @Path("/delegation-token/expiration") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Response postDelegationTokenExpiration(@Context HttpServletRequest hsr) throws AuthorizationException, IOException, InterruptedException, Exception { init(); UserGroupInformation callerUGI; try { callerUGI = createKerberosUserGroupInformation(hsr); } catch (YarnException ye) { return Response.status(Status.FORBIDDEN).entity(ye.getMessage()).build(); } DelegationToken requestToken = new DelegationToken(); requestToken.setToken(extractToken(hsr).encodeToUrlString()); return renewDelegationToken(requestToken, hsr, callerUGI); }
final DelegationToken dtoken = new DelegationToken(); String renewer = "client2"; dtoken.setRenewer(renewer);
@Override public Void call() throws Exception { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token").accept(contentType) .entity(body, mediaType).post(ClientResponse.class); assertEquals(Status.OK, response.getClientResponseStatus()); DelegationToken tok = getDelegationTokenFromResponse(response); assertFalse(tok.getToken().isEmpty()); Token<RMDelegationTokenIdentifier> token = new Token<RMDelegationTokenIdentifier>(); token.decodeFromUrlString(tok.getToken()); assertEquals(renewer, token.decodeIdentifier().getRenewer().toString()); assertValidRMToken(tok.getToken()); DelegationToken dtoken = new DelegationToken(); response = resource().path("ws").path("v1").path("cluster") .path("delegation-token").accept(contentType) .entity(dtoken, mediaType).post(ClientResponse.class); assertEquals(Status.OK, response.getClientResponseStatus()); tok = getDelegationTokenFromResponse(response); assertFalse(tok.getToken().isEmpty()); token = new Token<RMDelegationTokenIdentifier>(); token.decodeFromUrlString(tok.getToken()); assertEquals("", token.decodeIdentifier().getRenewer().toString()); assertValidRMToken(tok.getToken()); return null; } });
assertValidRMToken(responseToken.getToken()); String body = generateRenewTokenBody(mediaType, responseToken.getToken()); ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token").path("expiration") .header(yarnTokenHeader, responseToken.getToken()) .accept(contentType).entity(body, mediaType) .post(ClientResponse.class); String message = "Expiration time not as expected: old = " + oldExpirationTime + "; new = " + tok.getNextExpirationTime(); assertTrue(message, tok.getNextExpirationTime() > oldExpirationTime); oldExpirationTime = tok.getNextExpirationTime(); resource().path("ws").path("v1").path("cluster") .path("delegation-token").path("expiration") .header(yarnTokenHeader, responseToken.getToken()) .accept(contentType).entity(body, mediaType) .post(ClientResponse.class); message = "Expiration time not as expected: old = " + oldExpirationTime + "; new = " + tok.getNextExpirationTime(); assertTrue(message, tok.getNextExpirationTime() > oldExpirationTime); return tok;
public static DelegationToken getDelegationTokenFromJson(JSONObject json) throws JSONException { DelegationToken ret = new DelegationToken(); if (json.has("token")) { ret.setToken(json.getString("token")); } else if (json.has("expiration-time")) { ret.setNextExpirationTime(json.getLong("expiration-time")); } return ret; }
extractToken(tokenData.getToken()); DelegationToken respToken = new DelegationToken(); respToken.setNextExpirationTime(renewTime); return Response.status(Status.OK).entity(respToken).build();
@Override public Void call() throws Exception { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token") .header(yarnTokenHeader, tmpToken2.getToken()) .accept(contentType).delete(ClientResponse.class); assertEquals(Status.FORBIDDEN, response.getClientResponseStatus()); assertValidRMToken(tmpToken2.getToken()); return null; } });
@POST @Path(RMWSConsts.DELEGATION_TOKEN_EXPIRATION) @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Override public Response postDelegationTokenExpiration(@Context HttpServletRequest hsr) throws AuthorizationException, IOException, InterruptedException, Exception { UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true); initForWritableEndpoints(callerUGI, false); try { createKerberosUserGroupInformation(hsr, callerUGI); callerUGI.setAuthenticationMethod(AuthenticationMethod.KERBEROS); } catch (YarnException ye) { return Response.status(Status.FORBIDDEN).entity(ye.getMessage()).build(); } DelegationToken requestToken = new DelegationToken(); requestToken.setToken(extractToken(hsr).encodeToUrlString()); return renewDelegationToken(requestToken, hsr, callerUGI); }
final DelegationToken dtoken = new DelegationToken(); String renewer = "client2"; dtoken.setRenewer(renewer); String[] mediaTypes = { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
Exception { final String renewer = tokenData.getRenewer(); GetDelegationTokenResponse resp; try { .getRenewDate(identifier); DelegationToken respToken = new DelegationToken(tk.encodeToUrlString(), renewer, identifier .getOwner().toString(), tk.getKind().toString(), currentExpiration, identifier.getMaxDate());
public static DelegationToken getDelegationTokenFromXML(String tokenXML) throws IOException, ParserConfigurationException, SAXException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(tokenXML)); Document dom = db.parse(is); NodeList nodes = dom.getElementsByTagName("delegation-token"); assertEquals("incorrect number of elements", 1, nodes.getLength()); Element element = (Element) nodes.item(0); DelegationToken ret = new DelegationToken(); String token = WebServicesTestUtils.getXmlString(element, "token"); if (token != null) { ret.setToken(token); } else { long expiration = WebServicesTestUtils.getXmlLong(element, "expiration-time"); ret.setNextExpirationTime(expiration); } return ret; }