@Test public void testValidatePrincipalAndKeytab() { final ComponentLog log = Mockito.mock(ComponentLog.class); final Configuration config = new Configuration(); List<ValidationResult> results = KerberosProperties.validatePrincipalAndKeytab( "test", config, null, null, log); Assert.assertEquals(0, results.size()); results = KerberosProperties.validatePrincipalAndKeytab( "test", config, "principal", null, log); Assert.assertEquals(0, results.size()); results = KerberosProperties.validatePrincipalAndKeytab( "test", config, "principal", "keytab", log); Assert.assertEquals(0, results.size()); config.set("hadoop.security.authentication", "kerberos"); config.set("hadoop.security.authorization", "true"); results = KerberosProperties.validatePrincipalAndKeytab( "test", config, null, null, log); Assert.assertEquals(2, results.size()); }
public static List<ValidationResult> validatePrincipalAndKeytab(final String subject, final Configuration config, final String principal, final String keytab, final ComponentLog logger) { final List<ValidationResult> results = new ArrayList<>(); final boolean isSecurityEnabled = SecurityUtil.isSecurityEnabled(config); final boolean blankPrincipal = (principal == null || principal.isEmpty()); if (isSecurityEnabled && blankPrincipal) { results.add(new ValidationResult.Builder() .valid(false) .subject(subject) .explanation("Kerberos Principal must be provided when using a secure configuration") .build()); } final boolean blankKeytab = (keytab == null || keytab.isEmpty()); if (isSecurityEnabled && blankKeytab) { results.add(new ValidationResult.Builder() .valid(false) .subject(subject) .explanation("Kerberos Keytab must be provided when using a secure configuration") .build()); } if (!isSecurityEnabled && (!blankPrincipal || !blankKeytab)) { logger.warn("Configuration does not have security enabled, Keytab and Principal will be ignored"); } return results; }
KerberosProperties { public static List<ValidationResult> validatePrincipalAndKeytab(final String subject, final Configuration config, final String principal, final String keytab, final ComponentLog logger) { final List<ValidationResult> results = new ArrayList<>(); final boolean isSecurityEnabled = SecurityUtil.isSecurityEnabled(config); final boolean blankPrincipal = (principal == null || principal.isEmpty()); if (isSecurityEnabled && blankPrincipal) { results.add(new ValidationResult.Builder() .valid(false) .subject(subject) .explanation("Kerberos Principal must be provided when using a secure configuration") .build()); } final boolean blankKeytab = (keytab == null || keytab.isEmpty()); if (isSecurityEnabled && blankKeytab) { results.add(new ValidationResult.Builder() .valid(false) .subject(subject) .explanation("Kerberos Keytab must be provided when using a secure configuration") .build()); } if (!isSecurityEnabled && (!blankPrincipal || !blankKeytab)) { logger.warn("Configuration does not have security enabled, Keytab and Principal will be ignored"); } return results; } }
KerberosProperties { public static List<ValidationResult> validatePrincipalAndKeytab(final String subject, final Configuration config, final String principal, final String keytab, final ComponentLog logger) { final List<ValidationResult> results = new ArrayList<>(); final boolean isSecurityEnabled = SecurityUtil.isSecurityEnabled(config); final boolean blankPrincipal = (principal == null || principal.isEmpty()); if (isSecurityEnabled && blankPrincipal) { results.add(new ValidationResult.Builder() .valid(false) .subject(subject) .explanation("Kerberos Principal must be provided when using a secure configuration") .build()); } final boolean blankKeytab = (keytab == null || keytab.isEmpty()); if (isSecurityEnabled && blankKeytab) { results.add(new ValidationResult.Builder() .valid(false) .subject(subject) .explanation("Kerberos Keytab must be provided when using a secure configuration") .build()); } if (!isSecurityEnabled && (!blankPrincipal || !blankKeytab)) { logger.warn("Configuration does not have security enabled, Keytab and Principal will be ignored"); } return results; } KerberosProperties(final File kerberosConfigFile); }
KerberosProperties { public static List<ValidationResult> validatePrincipalAndKeytab(final String subject, final Configuration config, final String principal, final String keytab, final ComponentLog logger) { final List<ValidationResult> results = new ArrayList<>(); final boolean isSecurityEnabled = SecurityUtil.isSecurityEnabled(config); final boolean blankPrincipal = (principal == null || principal.isEmpty()); if (isSecurityEnabled && blankPrincipal) { results.add(new ValidationResult.Builder() .valid(false) .subject(subject) .explanation("Kerberos Principal must be provided when using a secure configuration") .build()); } final boolean blankKeytab = (keytab == null || keytab.isEmpty()); if (isSecurityEnabled && blankKeytab) { results.add(new ValidationResult.Builder() .valid(false) .subject(subject) .explanation("Kerberos Keytab must be provided when using a secure configuration") .build()); } if (!isSecurityEnabled && (!blankPrincipal || !blankKeytab)) { logger.warn("Configuration does not have security enabled, Keytab and Principal will be ignored"); } return results; } KerberosProperties(final File kerberosConfigFile); File getKerberosConfigFile(); Validator getKerberosConfigValidator(); PropertyDescriptor getKerberosPrincipal(); PropertyDescriptor getKerberosKeytab(); static List<ValidationResult> validatePrincipalAndKeytab(final String subject, final Configuration config, final String principal, final String keytab, final ComponentLog logger); }
KerberosProperties { public static List<ValidationResult> validatePrincipalAndKeytab(final String subject, final Configuration config, final String principal, final String keytab, final ComponentLog logger) { final List<ValidationResult> results = new ArrayList<>(); final boolean isSecurityEnabled = SecurityUtil.isSecurityEnabled(config); final boolean blankPrincipal = (principal == null || principal.isEmpty()); if (isSecurityEnabled && blankPrincipal) { results.add(new ValidationResult.Builder() .valid(false) .subject(subject) .explanation("Kerberos Principal must be provided when using a secure configuration") .build()); } final boolean blankKeytab = (keytab == null || keytab.isEmpty()); if (isSecurityEnabled && blankKeytab) { results.add(new ValidationResult.Builder() .valid(false) .subject(subject) .explanation("Kerberos Keytab must be provided when using a secure configuration") .build()); } if (!isSecurityEnabled && (!blankPrincipal || !blankKeytab)) { logger.warn("Configuration does not have security enabled, Keytab and Principal will be ignored"); } return results; } KerberosProperties(final File kerberosConfigFile); File getKerberosConfigFile(); Validator getKerberosConfigValidator(); PropertyDescriptor getKerberosPrincipal(); PropertyDescriptor getKerberosKeytab(); static List<ValidationResult> validatePrincipalAndKeytab(final String subject, final Configuration config, final String principal, final String keytab, final ComponentLog logger);  }