Java Code Examples for org.apache.hadoop.security.UserGroupInformation.loginUserFromSubject()

The following are Jave code examples for showing how to use loginUserFromSubject() of the org.apache.hadoop.security.UserGroupInformation class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Hydrograph   File: KerberosUtilities.java   Source Code and License Vote up 11 votes
/**
 *
 * @param user
 * @param password
 * @param configuration
 * @throws LoginException
 * @throws IOException
 */
private void getKerberosToken(String user, char[] password, Configuration configuration)
        throws LoginException, IOException {
    LOG.trace("Entering method getKerberosToken() for user: " + user);
    URL url = HydrographService.class.getClassLoader().getResource("jaas.conf");
    System.setProperty("java.security.auth.login.config", url.toExternalForm());

    LOG.info("Generating Kerberos ticket for user: " + user);
    UserGroupInformation.setConfiguration(configuration);

    lc = new LoginContext("EntryName", new UserPassCallbackHandler(user, password));
    lc.login();

    Subject subject = lc.getSubject();
    UserGroupInformation.loginUserFromSubject(subject);
    Subject.doAs(subject, this);
    LOG.info("Kerberos ticket successfully generated for user: " + user);
}