SecurityUtils { public static String getTokenStoreFilePath(Config config, boolean onDriver) throws IOException { String tokenFilePrefix; if (config.hasPath(TOKENS_FILE)) { tokenFilePrefix = config.getString(TOKENS_FILE); } else { String userName = UserGroupInformation.getCurrentUser().getShortUserName(); String appId; if (onDriver) { appId = Contexts.getSparkSession().sparkContext().applicationId(); } else { appId = SparkEnv.get().conf().getAppId(); } tokenFilePrefix = String.format("/user/%s/.sparkStaging/%s/envelope_tokens", userName, appId); } return tokenFilePrefix; }  static Token createToken(byte[] rawToken); static Token createToken(byte[] rawToken, int generation); static String getTokenStoreFilePath(Config config, boolean onDriver); static List<Path> getExistingTokenStoreFiles(Config config, Configuration hadoopConf, boolean onDriver); static void deleteTokenStoreFiles(List<Path> files, long delay, Configuration hadoopConf); static Validations getValidations(); static Set<InstantiatedComponent> getAllSecureComponents(InstantiatedComponent component); static final String SECURITY_PREFIX; static final String RENEW_INTERVAL; static final String TOKENS_FILE; static final String TOKENS_CHECK_INTERVAL; static final String TOKENS_RENEW_FACTOR; static final String TOKENS_DELETION_DELAY; }
@Test public void testGetCredentialsFilePath() throws IOException { Config config = ConfigUtils.configFromResource("/security/security_manager_nocredsfile.conf"); Contexts.initialize(config, Contexts.ExecutionMode.UNIT_TEST); String path = SecurityUtils.getTokenStoreFilePath(config, true); assertTrue(path.startsWith("/user")); }