KerberosDescriptorUpdateHelper { public static KerberosDescriptor updateUserKerberosDescriptor(KerberosDescriptor beginningStackKerberosDescriptor, KerberosDescriptor endingStackKerberosDescriptor, KerberosDescriptor userKerberosDescriptor) { KerberosDescriptor updated = new KerberosDescriptor(userKerberosDescriptor.toMap()); updated.setProperties(processProperties( beginningStackKerberosDescriptor.getProperties(), endingStackKerberosDescriptor.getProperties(), updated.getProperties())); updated.setConfigurations(processConfigurations( beginningStackKerberosDescriptor.getConfigurations(), endingStackKerberosDescriptor.getConfigurations(), updated.getConfigurations())); updated.setIdentities(processIdentities( beginningStackKerberosDescriptor.getIdentities(), endingStackKerberosDescriptor.getIdentities(), updated.getIdentities())); updated.setAuthToLocalProperties(processAuthToLocalProperties( beginningStackKerberosDescriptor.getAuthToLocalProperties(), endingStackKerberosDescriptor.getAuthToLocalProperties(), updated.getAuthToLocalProperties())); updated.setServices(processServices( beginningStackKerberosDescriptor.getServices(), endingStackKerberosDescriptor.getServices(), updated.getServices())); return updated; }  static KerberosDescriptor updateUserKerberosDescriptor(KerberosDescriptor beginningStackKerberosDescriptor,
                                                                KerberosDescriptor endingStackKerberosDescriptor,
                                                                KerberosDescriptor userKerberosDescriptor);  }
@Test public void testUpdateProperties() throws AmbariException { KerberosDescriptor oldValue = KERBEROS_DESCRIPTOR_FACTORY.createInstance("{" + " \"properties\": {" + " \"realm\": \"${kerberos-env/realm}\"," + " \"keytab_dir\": \"/etc/security/keytabs\"," + " \"additional_realms\": \"\"," + " \"old_property\": \"old_value\"" + " }" + "}"); KerberosDescriptor newValue = KERBEROS_DESCRIPTOR_FACTORY.createInstance("{" + " \"properties\": {" + " \"realm\": \"${kerberos-env/realm}\"," + " \"keytab_dir\": \"/etc/security/keytabs\"," + " \"additional_realms\": \"\"," + " \"new_property\": \"new_value\"" + " }" + "}"); KerberosDescriptor userValue = KERBEROS_DESCRIPTOR_FACTORY.createInstance("{" + " \"properties\": {" + " \"realm\": \"EXAMPLE.COM\"," + " \"keytab_dir\": \"/etc/security/keytabs\"," + " \"additional_realms\": \"\"," + " \"old_property\": \"old_value\"" + " }" + "}"); KerberosDescriptor updatedUserValue = KerberosDescriptorUpdateHelper.updateUserKerberosDescriptor( oldValue, newValue, userValue); Assert.assertEquals( KERBEROS_DESCRIPTOR_FACTORY.createInstance( "{\n" + " \"properties\": {\n" + " \"new_property\": \"new_value\",\n" + " \"realm\": \"EXAMPLE.COM\",\n" + " \"additional_realms\": \"\",\n" + " \"keytab_dir\": \"/etc/security/keytabs\"\n" + " }\n" + "}"), updatedUserValue); }
@Test public void testUpdateAuthToLocalRules() throws AmbariException { KerberosDescriptor oldValue = KERBEROS_DESCRIPTOR_FACTORY.createInstance( "{\n" + " \"auth_to_local_properties\" : [\n" + " \"core-site/hadoop.security.auth_to_local\",\n" + " \"some-site/to.be.removed\"\n" + " ]\n" + "}\n"); KerberosDescriptor newValue = KERBEROS_DESCRIPTOR_FACTORY.createInstance( "{\n" + " \"auth_to_local_properties\" : [\n" + " \"core-site/hadoop.security.auth_to_local\",\n" + " \"some-site/to.be.added\"\n" + " ]\n" + "}\n"); KerberosDescriptor userValue = KERBEROS_DESCRIPTOR_FACTORY.createInstance( "{\n" + " \"auth_to_local_properties\" : [\n" + " \"core-site/hadoop.security.auth_to_local\",\n" + " \"some-site/added.by.user\"\n" + " ]\n" + "}\n"); KerberosDescriptor updatedUserValue = KerberosDescriptorUpdateHelper.updateUserKerberosDescriptor( oldValue, newValue, userValue); Assert.assertEquals( KERBEROS_DESCRIPTOR_FACTORY.createInstance( "{\n" + " \"auth_to_local_properties\" : [\n" + " \"core-site/hadoop.security.auth_to_local\",\n" + " \"some-site/to.be.added\",\n" + " \"some-site/added.by.user\"\n" + " ]\n" + "}\n"), updatedUserValue); }