use of javax.security.auth.Subject in project hbase by apache.
the class HttpDoAsClient method getSubject.
static Subject getSubject() throws Exception {
if (!secure)
return new Subject();
/*
* To authenticate the DemoClient, kinit should be invoked ahead.
* Here we try to get the Kerberos credential from the ticket cache.
*/
LoginContext context = new LoginContext("", new Subject(), null, new Configuration() {
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
Map<String, String> options = new HashMap<>();
options.put("useKeyTab", "false");
options.put("storeKey", "false");
options.put("doNotPrompt", "true");
options.put("useTicketCache", "true");
options.put("renewTGT", "true");
options.put("refreshKrb5Config", "true");
options.put("isInitiator", "true");
String ticketCache = System.getenv("KRB5CCNAME");
if (ticketCache != null) {
options.put("ticketCache", ticketCache);
}
options.put("debug", "true");
return new AppConfigurationEntry[] { new AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule", AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, options) };
}
});
context.login();
return context.getSubject();
}
use of javax.security.auth.Subject in project hive by apache.
the class HttpAuthUtils method getKerberosServiceTicket.
/**
* @return Stringified Base64 encoded kerberosAuthHeader on success
* @throws Exception
*/
public static String getKerberosServiceTicket(String principal, String host, String serverHttpUrl, boolean assumeSubject) throws Exception {
String serverPrincipal = ShimLoader.getHadoopThriftAuthBridge().getServerPrincipal(principal, host);
if (assumeSubject) {
// With this option, we're assuming that the external application,
// using the JDBC driver has done a JAAS kerberos login already
AccessControlContext context = AccessController.getContext();
Subject subject = Subject.getSubject(context);
if (subject == null) {
throw new Exception("The Subject is not set");
}
return Subject.doAs(subject, new HttpKerberosClientAction(serverPrincipal, serverHttpUrl));
} else {
// JAAS login from ticket cache to setup the client UserGroupInformation
UserGroupInformation clientUGI = ShimLoader.getHadoopThriftAuthBridge().getCurrentUGIWithConf("kerberos");
return clientUGI.doAs(new HttpKerberosClientAction(serverPrincipal, serverHttpUrl));
}
}
use of javax.security.auth.Subject in project storm by apache.
the class AutoHBase method main.
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
Map conf = new HashMap();
//with realm e.g. storm@WITZEND.COM
conf.put(Config.TOPOLOGY_SUBMITTER_PRINCIPAL, args[0]);
// hbase principal storm-hbase@WITZEN.COM
conf.put(HBASE_PRINCIPAL_KEY, args[1]);
// storm hbase keytab /etc/security/keytabs/storm-hbase.keytab
conf.put(HBASE_KEYTAB_FILE_KEY, args[2]);
AutoHBase autoHBase = new AutoHBase();
autoHBase.prepare(conf);
Map<String, String> creds = new HashMap<String, String>();
autoHBase.populateCredentials(creds, conf);
LOG.info("Got HBase credentials" + autoHBase.getCredentials(creds));
Subject s = new Subject();
autoHBase.populateSubject(s, creds);
LOG.info("Got a Subject " + s);
autoHBase.renew(creds, conf);
LOG.info("renewed credentials" + autoHBase.getCredentials(creds));
}
use of javax.security.auth.Subject in project storm by apache.
the class AutoHDFS method main.
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
Map conf = new HashMap();
//with realm e.g. storm@WITZEND.COM
conf.put(Config.TOPOLOGY_SUBMITTER_PRINCIPAL, args[0]);
//with realm e.g. hdfs@WITZEND.COM
conf.put(STORM_USER_NAME_KEY, args[1]);
// /etc/security/keytabs/storm.keytab
conf.put(STORM_KEYTAB_FILE_KEY, args[2]);
Configuration configuration = new Configuration();
AutoHDFS autoHDFS = new AutoHDFS();
autoHDFS.prepare(conf);
Map<String, String> creds = new HashMap<String, String>();
autoHDFS.populateCredentials(creds, conf);
LOG.info("Got HDFS credentials", autoHDFS.getCredentials(creds));
Subject s = new Subject();
autoHDFS.populateSubject(s, creds);
LOG.info("Got a Subject " + s);
autoHDFS.renew(creds, conf);
LOG.info("renewed credentials", autoHDFS.getCredentials(creds));
}
use of javax.security.auth.Subject in project storm by apache.
the class BlobStoreTest method getNimbusSubject.
//Gets Nimbus Subject with NimbusPrincipal set on it
public static Subject getNimbusSubject() {
Subject nimbus = new Subject();
nimbus.getPrincipals().add(new NimbusPrincipal());
return nimbus;
}
Aggregations