我目前正在测试部署在IBM Websphere Application Server上的Web应用程序。我知道我可以通过控制台配置设置LTPAToken超时。但是,有什么方法可以检索JAVA中的超时持续时间或监听器以指示ltpatoken已过期?
您可以像这样在Java代码中获取令牌到期时间(这将为您提供凭证到期时间)
Subject callerSubject = WSSubject.getCallerSubject();
Set<WSCredential> credentials = callerSubject.getPublicCredentials(WSCredential.class);
// should contain only one credential
int credSize = credentials.size();
if( credSize != 1)
throw new RuntimeException("Invalid credential number: "+credSize);
WSCredential cred = credentials.iterator().next();
System.out.println("getExpiration: " + cred.getExpiration()+" date: " + new Date(cred.getExpiration()) + "<BR>");
如果你对ltpatoken特别感兴趣,你需要扩展一下(但可能凭证对你来说已经足够了):
Set tokens = callerSubject.getPrivateCredentials();
for (Object o : tokens) {
if(o instanceof SingleSignonToken) {
SingleSignonToken ssoToken = (SingleSignonToken)o;
System.out.println("getName: " + ssoToken.getName()+"<BR>");
if("LtpaToken".equals(ssoToken.getName())){
System.out.println("getExpiration: " + ssoToken.getExpiration()+"<BR>");
}
}
}
SingleSignonToken的getExpiration()方法以毫秒为单位返回到期时间。你可以这样做,
ssoToken.getExpiration() - System.currentTimeMillis();
找出这个令牌剩下多少时间。或者,您可以调用isValid()方法来为您执行此操作。