Simple Kerberos client in Java?

后端 未结 9 604
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 06:47

Applications such a Google\'s Chrome and IE can transparently handle Kerberos authentication; however I can not find a \"simple\" Java solution to match this transparency. A

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 07:13

    Ok if you want to avoid using a login.conf file you need to code differently:-

    //define your own configuration
    import javax.security.auth.login.Configuration;
    public class CustomLoginConfiguration extends Configuration
    
    //pass certain parameters to its constructor
    //define an config entry
    import javax.security.auth.login.AppConfigurationEntry;
    private AppConfigurationEntry configEntry;
    
    //define a map of params you wish to pass and fill them up
    //the map contains entries similar to one you have in login.conf
    Map params = new HashMap();
    
    //define the configuration
    configEntry = new AppConfigurationEntry(
                "com.sun.security.auth.module.Krb5LoginModule",
                AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, params);
    
    //implement getappconfig method
    public AppConfigurationEntry[] getAppConfigurationEntry() {
        return new AppConfigurationEntry[] { configEntry };
    }
    

    Now once you are done with this definition you can use this in you use this to fetch tickets from kdc

    //get ticket in login context
    LoginContext lc = null;
        lc = new LoginContext("lc", null, callback, new CustomLoginConfiguration(argumentlist));
        lc.login();
    

    Now from here on you can fetch jaas subject and can basically do a ton of authentication stuff.

    In case you need further pointers just leave a comment.

提交回复
热议问题