Example #1
0
 /**
  * Constructs a new Krb5Config entry with the specified ticket cache and logs in with that entry.
  *
  * <p>If <code>cache</code> is <code>null</code>, then <code>Krb5Config.setTicketCache</code> will
  * be set to <code>true</code> and the default ticket cache will be used.
  *
  * <p>Equivalent to the following calls:
  *
  * <pre>
  * Krb5Config kc = Krb5Config.getInstance();
  * if (cache != null)
  *    kc.setTicketCache(cache);
  * else
  *    kc.setUseTicketCache(true);
  * LoginContext lc = Login.login(kc);
  * </pre>
  */
 public static LoginContext withTicketCache(String cache) throws LoginException {
   Krb5Config kc = Krb5Config.getInstance();
   // kc.setStoreKey(true);
   if (cache != null) {
     kc.setTicketCache(cache);
   } else {
     kc.setUseTicketCache(true);
   }
   Configuration dc = new DynamicConfiguration(S_CONFIG_NAME, new AppConfigurationEntry[] {kc});
   return new LoginContext(S_CONFIG_NAME, null, null, dc);
 }
Example #2
0
 public static LoginContext withPassword(String name, final String password)
     throws LoginException {
   Krb5Config kc = Krb5Config.getInstance();
   kc.setPrincipal(name);
   kc.setUseTicketCache(false);
   kc.setStoreKey(false);
   Configuration dc = new DynamicConfiguration(S_CONFIG_NAME, new AppConfigurationEntry[] {kc});
   CallbackHandler handler =
       new CallbackHandler() {
         public void handle(Callback[] callbacks)
             throws IOException, UnsupportedCallbackException {
           for (Callback callback : callbacks) {
             if (callback instanceof PasswordCallback) {
               PasswordCallback pc = (PasswordCallback) callback;
               pc.setPassword(password.toCharArray());
             }
           }
         }
       };
   return new LoginContext(S_CONFIG_NAME, null, handler, dc);
 }
Example #3
0
 /**
  * Constructs a new Krb5Config entry with the specified principal and keytab, logs in with that
  * entry, and then removes that entry and returns the new LoginContext.
  *
  * <p>Equivalent to the following calls:
  *
  * <pre>
  * Krb5Config kc = Krb5Config.getInstance();
  * kc.setPrincipal(principal);
  * kc.setKeyTab(keytab);
  * kc.setStoreKey(true);
  * LoginContext lc = Login.login(kc);
  * </pre>
  */
 public static LoginContext withKeyTab(String principal, String keytab) throws LoginException {
   /*
    * com.sun.security.auth.module.Krb5LoginModule required
    * useKeyTab=true
    * debug=true
    * keyTab="/apps/workgroup-audit/keytab/keytab.workgroup-audit"
    * doNotPrompt=true
    * storeKey=true
    * principal="service/[email protected]"
    * useTicketCache=true
    */
   Krb5Config kc = Krb5Config.getInstance();
   // kc.setDebug(true);
   kc.setPrincipal(principal);
   kc.setKeyTab(keytab);
   kc.setStoreKey(true);
   kc.setDoNotPrompt(true);
   kc.setUseTicketCache(true);
   Configuration dc = new DynamicConfiguration(S_CONFIG_NAME, new AppConfigurationEntry[] {kc});
   return new LoginContext(S_CONFIG_NAME, null, null, dc);
 }
Example #4
0
 public static Krb5Config getInstance() {
   HashMap<String, String> options = new HashMap<String, String>();
   Krb5Config kc = new Krb5Config(DEFAULT_LOGIN_MODULE_NAME, DEFAULT_CONTROL_FLAG, options);
   kc.mOptions = options;
   return kc;
 }