从线程获取 JAAS 的调用者主体集
调用者主体集(或“已接收的主体集”)包含该请求的调用中使用的用户认证信息。在发出 WSSubject.getCallerSubject 应用程序编程接口 (API) 后返回此主体集,以防止替换现有对象。此主体集被标记为只读。可以使用此 API 来获取对 WSCredential 凭证的访问,以便您可以在凭证内的散列映射中放入或设置数据。
开始之前
您需要以下 Java™ 2 安全许可权来运行此 API:permission javax.security.auth.AuthPermission "wssecurity.getCallerSubject;"。
如果使用 Kerberos 认证机制,那么 KDC 策略会启用 Kerberos 委派,客户机具有可转发的 Kerberos 凭单,主体集具有客户机 Kerberos 凭单和 GSS 委派凭证。可以使用 API 来访问 Kerberos 凭单和 GSS 委派凭证。
关于此任务
主体集中的大多数数据不往下游传播到另一个服务器。只有 WSCredential 凭证中的凭证令牌往下游传播,并且生成新的调用者主体集。
过程
示例
try { javax.security.auth.Subject caller_subject; com.ibm.websphere.security.cred.WSCredential caller_cred;
caller_subject = com.ibm.websphere.security.auth.WSSubject.getCallerSubject(); if (caller_subject != null) { caller_cred = caller_subject.getPublicCredentials
(com.ibm.websphere.security.cred.WSCredential.class).iterator().next();
String CALLERDATA = (String) caller_cred.get ("MYKEY");
System.out.println("My data from the Caller credential is: " + CALLERDATA); } }
catch (WSSecurityException e) { // log error } catch (Exception e) { // log error }