0

我目前正在测试部署在 IBM Websphere Application Server 上的 Web 应用程序。我知道我可以通过控制台配置设置 LTPAToken 超时。但是,有什么方法可以检索超时持续时间或 JAVA 中的侦听器以指示 ltpatoken 已过期?

4

2 回答 2

0

您可以像这样在 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>");
        }
    }
}
于 2017-12-08T10:26:57.533 回答
0

SingleSignonToken 的 getExpiration() 方法以毫秒为单位返回过期时间。你可以做这样的事情,

ssoToken.getExpiration() - System.currentTimeMillis();

找出这个令牌还剩多少时间。或者,您可以调用 isValid() 方法来为您执行此操作。

于 2018-01-02T21:22:02.467 回答