SecurityUtils { public static Set<InstantiatedComponent> getAllSecureComponents(InstantiatedComponent component) throws Exception { Set<InstantiatedComponent> secureComponents = Sets.newHashSet(); Component thisComponent = component.getComponent(); if (thisComponent instanceof UsesDelegationTokens) { secureComponents.add(component); } if (thisComponent instanceof InstantiatesComponents) { Set<InstantiatedComponent> instantiatedComponents = ((InstantiatesComponents)thisComponent).getComponents(component.getConfig(), true); for (InstantiatedComponent instantiatedComponent : instantiatedComponents) { secureComponents.addAll(getAllSecureComponents(instantiatedComponent)); } } return secureComponents; }  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 testGetAllSecureComponents() throws Exception { TopLevelInstantiates topLevel = new TopLevelInstantiates() { @Override public void configure(Config config) {} @Override public Set<InstantiatedComponent> getComponents(Config config, boolean configure) throws Exception { SecureInstantiator secondLevel = new SecureInstantiator() { @Override public void configure(Config config) {} @Override public TokenProvider getTokenProvider() { return new TestTokenProvider(); } @Override public Set<InstantiatedComponent> getComponents(Config config, boolean configure) throws Exception { SecureComponent thirdLevelA = new SecureComponent() { @Override public void configure(Config config) {} @Override public TokenProvider getTokenProvider() { return new TestTokenProvider(); } }; Component thirdLevelB = new Component() { @Override public void configure(Config config) {} }; return Sets.newHashSet(new InstantiatedComponent(thirdLevelA, ConfigFactory.empty(), "tlA"), new InstantiatedComponent(thirdLevelB, ConfigFactory.empty(), "tlB")); } }; return Collections.singleton(new InstantiatedComponent(secondLevel, ConfigFactory.empty(), "second")); } }; Set<InstantiatedComponent> secureComponents = SecurityUtils.getAllSecureComponents(new InstantiatedComponent(topLevel, ConfigFactory.empty(), "top")); assertEquals(2, secureComponents.size()); }