java获取kdc的tgt,Java Kerberos票证续订TGT

I am using Krb5LoginModule in one of the POC. I have provided useDefaultCache=true and renewTGT=true.

The code throws an exception when the ticket is expired although I have mentioned renewTGT=true. I have set up allowtgtsessionkey value to 1 in windows registry (I am running XP SP2). The KDC (ActiveDirectory) settings are default. Ticket lifetime = 10 hours and renewal request threshold = 7 days.

Source Code

import java.util.HashMap;

import java.util.Map;

import javax.security.auth.Subject;

import com.sun.security.auth.module.Krb5LoginModule;

public class Temp3 {

public static void main(String[] args) throws Exception {

System.setProperty("sun.security.krb5.debug", "true");

Subject subject = new Subject();

Krb5LoginModule krb5 = new Krb5LoginModule();

Map map = new HashMap ();

map.put("useTicketCache", "true");

map.put("doNotPrompt", "true");

map.put("renewTGT", "true");

map.put("debug", "true");

krb5.initialize(subject, null, null, map);

krb5.login();

krb5.commit();

System.out.println(subject);

}

}

The code works fine when the ticket is not expired i.e the time I ran kinit within 10 hours of running the code above.

I wrote this POC because I have to run JDBC based applications using SQL Server driver (version 4.0). I don't want long running services to fail during the database reconnect attempts which might occur due to factors such as network glitch resulting in broken pipe.

解决方案

You are going the wrong way. Fist of all you should use LoginContext to obtain credentials and not interact with Kerberos 5 directly. Second, non-human access needs a keytab. This is equivalent to a TGT. Export a Keytab for your server and modify the Krb5LoginModule configration. This tutorial will help you.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值