/** * Resolve the context of an entry. This is an effective test of * JAAS setup, because it will relay detected problems up * @param context context name * @return the entry * @throws RuntimeException if there is no context entry found */ public static AppConfigurationEntry[] validateContext(String context) { if (context == null) { throw new RuntimeException("Null context argument"); } if (context.isEmpty()) { throw new RuntimeException("Empty context argument"); } javax.security.auth.login.Configuration configuration = javax.security.auth.login.Configuration.getConfiguration(); AppConfigurationEntry[] entries = configuration.getAppConfigurationEntry(context); if (entries == null) { throw new RuntimeException( String.format("Entry \"%s\" not found; " + "JAAS config = %s", context, describeProperty(Environment.JAAS_CONF_KEY) )); } return entries; }
@Test public void testClientLogin() throws Throwable { LoginContext client = login(ALICE_LOCALHOST, ALICE_CLIENT_CONTEXT, keytab_alice); try { logLoginDetails(ALICE_LOCALHOST, client); String confFilename = System.getProperty(Environment.JAAS_CONF_KEY); assertNotNull("Unset: "+ Environment.JAAS_CONF_KEY, confFilename); String config = FileUtils.readFileToString(new File(confFilename)); LOG.info("{}=\n{}", confFilename, config); RegistrySecurity.setZKSaslClientProperties(ALICE, ALICE_CLIENT_CONTEXT); } finally { client.logout(); } }
@Override public void commandRun() { List<Environment.Entry> env = Environment.list(); pw.println("Environment:"); for(Environment.Entry e : env) { pw.print(e.getKey()); pw.print("="); pw.println(e.getValue()); } }
@Override public CommandResponse run(ZooKeeperServer zkServer, Map<String, String> kwargs) { CommandResponse response = initializeResponse(); for (Entry e : Environment.list()) { response.put(e.getKey(), e.getValue()); } return response; }
@Override public void commandRun() { List<Environment.Entry> env = Environment.list(); pw.println("Environment:"); for (Environment.Entry e : env) { pw.print(e.getKey()); pw.print("="); pw.println(e.getValue()); } }
/** * Bind the JVM JAS setting to the specified JAAS file. * * <b>Important:</b> once a file has been loaded the JVM doesn't pick up * changes * @param jaasFile the JAAS file */ public static void bindJVMtoJAASFile(File jaasFile) { String path = jaasFile.getAbsolutePath(); if (LOG.isDebugEnabled()) { LOG.debug("Binding {} to {}", Environment.JAAS_CONF_KEY, path); } System.setProperty(Environment.JAAS_CONF_KEY, path); }
/** * Build up low-level security diagnostics to aid debugging * @return a string to use in diagnostics */ public String buildSecurityDiagnostics() { StringBuilder builder = new StringBuilder(); builder.append(secureRegistry ? "secure registry; " : "insecure registry; "); builder.append("Curator service access policy: ").append(access); builder.append("; System ACLs: ").append(aclsToString(systemACLs)); builder.append("User: ").append(UgiInfo.fromCurrentUser()); builder.append("; Kerberos Realm: ").append(kerberosRealm); builder.append(describeProperty(Environment.JAAS_CONF_KEY)); String sasl = System.getProperty(PROP_ZK_ENABLE_SASL_CLIENT, DEFAULT_ZK_ENABLE_SASL_CLIENT); boolean saslEnabled = Boolean.valueOf(sasl); builder.append(describeProperty(PROP_ZK_ENABLE_SASL_CLIENT, DEFAULT_ZK_ENABLE_SASL_CLIENT)); if (saslEnabled) { builder.append("; JAAS Client Identity") .append("=") .append(jaasClientIdentity) .append("; "); builder.append(KEY_REGISTRY_CLIENT_JAAS_CONTEXT) .append("=") .append(jaasClientContext) .append("; "); builder.append(describeProperty(PROP_ZK_SASL_CLIENT_USERNAME)); builder.append(describeProperty(PROP_ZK_SASL_CLIENT_CONTEXT)); } builder.append(describeProperty(PROP_ZK_ALLOW_FAILED_SASL_CLIENTS, "(undefined but defaults to true)")); builder.append(describeProperty( PROP_ZK_SERVER_MAINTAIN_CONNECTION_DESPITE_SASL_FAILURE)); return builder.toString(); }
@Test public void testJaasFileSetup() throws Throwable { // the JVM has seemed inconsistent on setting up here assertNotNull("jaasFile", jaasFile); String confFilename = System.getProperty(Environment.JAAS_CONF_KEY); assertEquals(jaasFile.getAbsolutePath(), confFilename); }
@Test public void testJaasFileBinding() throws Throwable { // the JVM has seemed inconsistent on setting up here assertNotNull("jaasFile", jaasFile); RegistrySecurity.bindJVMtoJAASFile(jaasFile); String confFilename = System.getProperty(Environment.JAAS_CONF_KEY); assertEquals(jaasFile.getAbsolutePath(), confFilename); }