SignerManager implements Closeable { public void initCustomSigners() { String[] customSigners = ownerConf.getTrimmedStrings(CUSTOM_SIGNERS); if (customSigners == null || customSigners.length == 0) { LOG.debug("No custom signers specified"); return; } for (String customSigner : customSigners) { String[] parts = customSigner.split(":"); if (!(parts.length == 1 || parts.length == 2 || parts.length == 3)) { String message = "Invalid format (Expected name, name:SignerClass," + " name:SignerClass:SignerInitializerClass)" + " for CustomSigner: [" + customSigner + "]"; LOG.error(message); throw new IllegalArgumentException(message); } if (parts.length == 1) { } else { maybeRegisterSigner(parts[0], parts[1], ownerConf); if (parts.length == 3) { Class<? extends AwsSignerInitializer> clazz = null; try { clazz = (Class<? extends AwsSignerInitializer>) ownerConf .getClassByName(parts[2]); } catch (ClassNotFoundException e) { throw new RuntimeException(String.format( "SignerInitializer class" + " [%s] not found for signer [%s]", parts[2], parts[0]), e); } LOG.debug("Creating signer initializer: [{}] for signer: [{}]", parts[2], parts[0]); AwsSignerInitializer signerInitializer = ReflectionUtils .newInstance(clazz, null); initializers.add(signerInitializer); signerInitializer .registerStore(bucketName, ownerConf, delegationTokenProvider, ownerUgi); } } } } SignerManager(String bucketName,
      DelegationTokenProvider delegationTokenProvider, Configuration ownerConf,
      UserGroupInformation ownerUgi); void initCustomSigners(); @Override void close();  }
@Test public void testPredefinedSignerInitialization() throws IOException { Configuration config = new Configuration(); config.set(CUSTOM_SIGNERS, "AWS4SignerType"); SignerManager signerManager = new SignerManager("dontcare", null, config, UserGroupInformation.getCurrentUser()); signerManager.initCustomSigners(); }
@Test public void testCustomSignerFailureIfNotRegistered() throws Exception { Configuration config = new Configuration(); config.set(CUSTOM_SIGNERS, "testsignerUnregistered"); SignerManager signerManager = new SignerManager("dontcare", null, config, UserGroupInformation.getCurrentUser()); signerManager.initCustomSigners(); LambdaTestUtils.intercept(Exception.class, () -> SignerFactory.createSigner("testsignerUnregistered", null)); }
@Test public void testCustomSignerInitialization() throws IOException { Configuration config = new Configuration(); config.set(CUSTOM_SIGNERS, "testsigner1:" + SignerForTest1.class.getName()); SignerManager signerManager = new SignerManager("dontcare", null, config, UserGroupInformation.getCurrentUser()); signerManager.initCustomSigners(); Signer s1 = SignerFactory.createSigner("testsigner1", null); s1.sign(null, null); Assertions.assertThat(SignerForTest1.initialized) .as(SignerForTest1.class.getName() + " not initialized") .isEqualTo(true); }
@Test public void testMultipleCustomSignerInitialization() throws IOException { Configuration config = new Configuration(); config.set(CUSTOM_SIGNERS, "testsigner1:" + SignerForTest1.class.getName() + "," + "testsigner2:" + SignerForTest2.class.getName()); SignerManager signerManager = new SignerManager("dontcare", null, config, UserGroupInformation.getCurrentUser()); signerManager.initCustomSigners(); Signer s1 = SignerFactory.createSigner("testsigner1", null); s1.sign(null, null); Assertions.assertThat(SignerForTest1.initialized) .as(SignerForTest1.class.getName() + " not initialized") .isEqualTo(true); Signer s2 = SignerFactory.createSigner("testsigner2", null); s2.sign(null, null); Assertions.assertThat(SignerForTest2.initialized) .as(SignerForTest2.class.getName() + " not initialized") .isEqualTo(true); }