Example usage for org.apache.zookeeper.server ZooKeeperSaslServer DEFAULT_LOGIN_CONTEXT_NAME

List of usage examples for org.apache.zookeeper.server ZooKeeperSaslServer DEFAULT_LOGIN_CONTEXT_NAME

Introduction

In this page you can find the example usage for org.apache.zookeeper.server ZooKeeperSaslServer DEFAULT_LOGIN_CONTEXT_NAME.

Prototype

String DEFAULT_LOGIN_CONTEXT_NAME

To view the source code for org.apache.zookeeper.server ZooKeeperSaslServer DEFAULT_LOGIN_CONTEXT_NAME.

Click Source Link

Usage

From source file:com.lami.tuomatuo.mq.zookeeper.server.auth.SaslServerCallbackHandler.java

License:Apache License

public SaslServerCallbackHandler(Configuration configuration) throws IOException {
    String serverSection = System.getProperty(ZooKeeperSaslServer.LOGIN_CONTEXT_NAME_KEY,
            ZooKeeperSaslServer.DEFAULT_LOGIN_CONTEXT_NAME);
    AppConfigurationEntry configurationEntries[] = configuration.getAppConfigurationEntry(serverSection);

    if (configurationEntries == null) {
        String errorMessage = "Could not find a 'Server' entry in this configuration: Server cannot start.";
        LOG.error(errorMessage);/*from  ww w . j  a v  a 2s  .c om*/
        throw new IOException(errorMessage);
    }
    credentials.clear();
    for (AppConfigurationEntry entry : configurationEntries) {
        Map<String, ?> options = entry.getOptions();
        // Populate DIGEST-MD5 user -> password map with JAAS configuration entries from the "Server" section.
        // Usernames are distinguished from other options by prefixing the username with a "user_" prefix.
        for (Map.Entry<String, ?> pair : options.entrySet()) {
            String key = pair.getKey();
            if (key.startsWith(USER_PREFIX)) {
                String userName = key.substring(USER_PREFIX.length());
                credentials.put(userName, (String) pair.getValue());
            }
        }
    }
}

From source file:org.apache.hadoop.registry.secure.TestSecureRegistry.java

License:Apache License

/**
* this is a cut and paste of some of the ZK internal code that was
 * failing on windows and swallowing its exceptions
 *///ww  w .  j  a va 2 s  .  c o m
@Test
public void testLowlevelZKSaslLogin() throws Throwable {
    RegistrySecurity.bindZKToServerJAASContext(ZOOKEEPER_SERVER_CONTEXT);
    String serverSection = System.getProperty(ZooKeeperSaslServer.LOGIN_CONTEXT_NAME_KEY,
            ZooKeeperSaslServer.DEFAULT_LOGIN_CONTEXT_NAME);
    assertEquals(ZOOKEEPER_SERVER_CONTEXT, serverSection);

    AppConfigurationEntry entries[];
    entries = javax.security.auth.login.Configuration.getConfiguration()
            .getAppConfigurationEntry(serverSection);

    assertNotNull("null entries", entries);

    SaslServerCallbackHandler saslServerCallbackHandler = new SaslServerCallbackHandler(
            javax.security.auth.login.Configuration.getConfiguration());
    Login login = new Login(serverSection, saslServerCallbackHandler);
    try {
        login.startThreadIfNeeded();
    } finally {
        login.shutdown();
    }
}