/** * Acquire the delegation token for the specified filesytem. * Before requesting a new delegation token, tries to find one already available. * * @param fs the filesystem that requires the delegation token * @throws IOException on fs.getDelegationToken() failure */ public void acquireDelegationToken(final FileSystem fs) throws IOException { if (userProvider.isHadoopSecurityEnabled()) { this.fs = fs; userToken = userProvider.getCurrent().getToken("HDFS_DELEGATION_TOKEN", fs.getCanonicalServiceName()); if (userToken == null) { hasForwardedToken = false; try { userToken = fs.getDelegationToken(renewer); } catch (NullPointerException npe) { // we need to handle NullPointerException in case HADOOP-10009 is missing LOG.error("Failed to get token for " + renewer); } } else { hasForwardedToken = true; LOG.info("Use the existing token: " + userToken); } } }
NetworkInterceptor implements Interceptor { public static final String DEBUG_TAG = NetworkInterceptor.class.getSimpleName(); @Override public Response intercept(Chain chain) throws IOException { Request request=chain.request(); User user=UserHandler.getUser(); if (user!=null&&user.getToken()!=null){ Log.d(DEBUG_TAG,"Authorization: "+user.getToken()); request=request.newBuilder().addHeader("Authorization",user.getToken()) // Only if the response is stored .addHeader("Cache-Control", "only-if-cached") // Return cached responses not older than 2419200 seconds (28 days) //.addHeader("Cache-Control", "max-stale=2419200") .method(request.method(),request.body()) .build(); } Response response = chain.proceed(request); Log.d(DEBUG_TAG, "Cache-Control: " + response.cacheControl()); return response; } }
/** * Acquire the delegation token for the specified filesytem. * Before requesting a new delegation token, tries to find one already available. * * @param fs the filesystem that requires the delegation token * @throws IOException on fs.getDelegationToken() failure */ public void acquireDelegationToken(final FileSystem fs) throws IOException { if (userProvider.isHadoopSecurityEnabled()) { this.fs = fs; userToken = userProvider.getCurrent().getToken("HDFS_DELEGATION_TOKEN", fs.getCanonicalServiceName()); if (userToken == null) { hasForwardedToken = false; try { userToken = fs.getDelegationToken(renewer); } catch (NullPointerException npe) { // we need to handle NullPointerException in case HADOOP-10009 is missing LOG.error("Failed to get token for " + renewer); } } else { hasForwardedToken = true; LOG.info("Use the existing token: " + userToken); } } }