配置不使用注册表交互的 UsernameToken 调用者配置

要在不访问 WebSphere® 注册表的情况下使 UsernameToken 向调用者配置进行认证,您可以替换 UsernameToken 使用者的认证方法,并将调用者配置为使用替代 JAAS 登录配置。

关于此任务

本信息仅适用于 Java API for XML Web Services (JAX-WS)。

缺省情况下,JAX-WS Web Service 安全性 UsernameToken 使用者 UNTConsumeLoginModule 始终根据 WebSphere 注册表来验证令牌中包含的用户名和密码。可以使用 GenericSecurityTokenFactory 提供的 SPI 来用自己的认证方法替代此认证方法。有关更多信息,请参阅“使用堆栈化 JAAS 登录模块来替换 UsernameToken 使用者的认证方法”

将调用者配置添加到服务提供者的 WS-Security 约束时,也会始终根据 WebSphere 注册表来验证 UsernameToken 中包含的用户名和密码。如果提供了用户名和密码,那么将根据 WebSphere 注册表来验证该用户名和密码。如果仅提供了用户名,那么该用户名必须存在于 WebSphere 注册表中。这些验证发生在 com.ibm.ws.security.server.lm.ltpaLoginModule 模块中,该模块是 wss.caller Java™认证和授权服务 (JAAS) 配置堆栈的一部分,如以下示例所示:

com.ibm.ws.wssecurity.impl.auth.module.PreCallerLoginModule
com.ibm.ws.wssecurity.impl.auth.module.UNTCallerLoginModule
...
com.ibm.ws.wssecurity.impl.auth.module.WSWSSLoginModule
com.ibm.ws.security.server.lm.ltpaLoginModule
com.ibm.ws.security.server.lm.wsMapDefaultInboundLoginModule

WebSphere WS-Security 运行时不支持为调用者使用不包括 ltpaLoginModule 和 wsMapDefaultInboundLoginModule 登录模块的 JAAS 配置。

要在不访问 WebSphere 注册表的情况下将 UsernameToken 与调用者配置配合使用,必须阻止 UNTConsumeLoginModule 和 ltpaLoginModule 模块访问注册表并提供替代模块。

过程

  1. 要阻止 UNTConsumeLoginModule 模块访问注册表,请替换 UsernameToken 使用者的认证方法。有关更多信息,请参阅 twbs_replace_authmethod_usernametoken.html
  2. 开发在 com.ibm.ws.wssecurity.impl.auth.module.WSWSSLoginModule 上堆叠的 JAAS 登录模块。 以下示例显示 JAAS 登录模块的样本代码:
    package test.tokens;
    
    import java.util.Map;
    import java.util.Hashtable;
    
    import javax.security.auth.Subject;
    import javax.security.auth.callback.CallbackHandler;
    import javax.security.auth.login.LoginException;
    import javax.security.auth.spi.LoginModule;
    import com.ibm.websphere.wssecurity.wssapi.token.UsernameToken;
    import com.ibm.websphere.wssecurity.wssapi.token.SecurityToken;
    import com.ibm.wsspi.security.token.AttributeNameConstants;
    
    public class MyAuthLoginModule implements LoginModule {
    
      private Map<String, ?> _sharedState;
    
      public void initialize(Subject subject, CallbackHandler callbackHandler,
                             Map<String, ?> sharedState, Map<String, ?> options) {
    
        this._sharedState = sharedState;  
      }
    
      public boolean login() throws LoginException {
        //For the sake of readability, this login module does not
        //protect against all NPE's
    
    	String username = null;
    	  
    	// get the caller token
    	SecurityToken callerIdentityToken = (SecurityToken)this._sharedState.get(
    	    com.ibm.wsspi.wssecurity.core.Constants.WSSECURITY_CALLER_IDENTITY);
    
    	// if its a UsernameToken, get the username
    	if (callerIdentityToken instanceof UsernameToken) {
    	  username = ((UsernameToken)callerIdentityToken).getUsername();
    	}
    	if (username == null) {
    	  throw new LoginException("Unable to obtain username");
    	}
    
    	Hashtable customProperties = (Hashtable)_sharedState.get(AttributeNameConstants.WSCREDENTIAL_PROPERTIES_KEY);
    	if (customProperties == null) {
    	  customProperties = new Hashtable();
    	}
    
    	// setting the UNIQUEID makes ltpaLoginModule skip the registry check	  
    		// Default realm is used here, but any trusted realm can be used
       String uid = "defaultWIMFileBasedRealm/" + username;
       customProperties.put(AttributeNameConstants.WSCREDENTIAL_UNIQUEID, uid)
     //implement the rest of the methods required by the
     //LoginModule interface
    }
  3. 创建新的 JAAS 登录配置。
    1. 在管理控制台中,转至安全性 > 全局安全性
    2. 在“认证”下面,转至 Java 认证和授权服务 > 系统登录
    3. 单击新建,然后在“别名”下输入 test.auth.unt
    4. 添加 JAAS 登录模块。 必须按所示顺序添加以下登录模块:
      • com.ibm.ws.wssecurity.impl.auth.module.PreCallerLoginModule
      • com.ibm.ws.wssecurity.impl.auth.module.UNTCallerLoginModule
      • test.tokens.MyAuthLoginModule
        要点: 此模块的名称必须与您开发的 JAAS 登录模块匹配。
      • com.ibm.ws.wssecurity.impl.auth.module.WSWSSLoginModule
      • com.ibm.ws.security.server.lm.ltpaLoginModule
      • com.ibm.ws.security.server.lm.wsMapDefaultInboundLoginModule
      对于每个登录模块:
      1. 在“JAAS 登录模块”下,单击新建
      2. 在“模块类名”下,输入登录模块的名称。
      3. 仅对于 test.tokens.MyAuthLoginModule,选择使用登录模块代理
      4. 单击确定
    5. 单击确定,然后单击保存
  4. 配置调用者以使用新的 JAAS 配置。
    1. 在管理控制台中,打开要更改的绑定配置。
    2. 选择 WS-Security > 调用者
    3. 选择要更改的调用者配置。
    4. 在“JAAS 登录”下,选择 test.auth.unt
    5. 单击确定,然后单击保存
  5. 重新启动应用程序服务器以应用 JAAS 配置更改。
  6. 测试服务。

指示主题类型的图标 任务主题



时间戳记图标 最近一次更新时间: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twbs_config_wssec_caller_no_reg
文件名:twbs_config_wssec_caller_no_reg.html