Java Security kinit(String username, char[] password)

Here you can find the source of kinit(String username, char[] password)

Description

kinit via code

License

Apache License

Declaration

public static LoginContext kinit(String username, char[] password) throws LoginException 

Method Source Code

    //package com.java2s;
    //License from project: Apache License 

    import javax.security.auth.callback.Callback;
    import javax.security.auth.callback.CallbackHandler;
    import javax.security.auth.callback.NameCallback;
    import javax.security.auth.callback.PasswordCallback;

    import javax.security.auth.login.LoginContext;
    import javax.security.auth.login.LoginException;

    public class Main {
        private static final String LOGIN_MODULE = "KerberosUtil";
//  ww w  . j av a  2  s . c o m
        /**
         * kinit via code
         */
        public static LoginContext kinit(String username, char[] password) throws LoginException {
   CallbackHandler handler = (callbacks) -> {
      for (Callback c : callbacks) {
         if (c instanceof NameCallback) {
            ((NameCallback) c).setName(username);
         }
         if (c instanceof PasswordCallback) {
            ((PasswordCallback) c).setPassword(password);
         }
      }
   };

   LoginContext lc = new LoginContext(LOGIN_MODULE, handler);
   lc.login();
   return lc;
}
    }

Related

  1. getTicketGrantingTicket(Subject subject)
  2. isDN(String user)
  3. isOriginalTicketGrantingTicket(KerberosTicket ticket)
  4. jaasConfig(String loginContextName, String key)
  5. jaasConfigOption(Configuration jaasConfig, String loginContextName, String key, String loginModuleName)
  6. logout()
  7. parseDirectives(byte[] buf)
  8. secretKey(final String key)
  9. serializeKerberosTicket(KerberosTicket tgt)