配置入站标识映射

对于入站标识映射,请编写定制登录模块,并在系统登录配置中将 WebSphere® Application Server 配置成首先运行该登录模块。在编写定制登录模块时,请考虑以下步骤。

过程

  1. 从回调获得入站用户标识,并映射标识(如果需要) 此步骤在登录模块的 login 方法中发生。有效认证带有 NameCallback 和/或 WSCredTokenCallback 回调。以下代码样本说明如何确定用户标识:
    javax.security.auth.callback.Callback callbacks[] = 
       new javax.security.auth.callback.Callback[3];
    	callbacks[0] = new javax.security.auth.callback.NameCallback("");
    	callbacks[1] = new javax.security.auth.callback.PasswordCallback
         ("Password: ", false);
    	callbacks[2] = new com.ibm.websphere.security.auth.callback.
         WSCredTokenCallbackImpl("");
    	callbacks[3] = new com.ibm.wsspi.security.auth.callback.
         WSTokenHolderCallback("");
    
    	try
    	{
    		callbackHandler.handle(callbacks);
    	} 
    	catch (Exception e)
    	{
    		// Handles exceptions
    		throw new WSLoginFailedException (e.getMessage(), e);
    	}
    
    	// Shows which callbacks contain information
    	boolean identitySwitched = false;
    	String uid = ((NameCallback) callbacks[0]).getName();
    	char password[] = ((PasswordCallback) callbacks[1]).getPassword();
    	byte[] credToken = ((WSCredTokenCallbackImpl) callbacks[2]).getCredToken();
    	java.util.List authzTokenList = ((WSTokenHolderCallback) 
         callbacks[3]).getTokenHolderList();
    
    	if (credToken != null)
    	{
    		try
    		{
    			String uniqueID = WSSecurityPropagationHelper.validateLTPAToken(credToken);
    			String realm = WSSecurityPropagationHelper.getRealmFromUniqueID (uniqueID);
           // Now set the string to the UID so that you can use the result for either
           // mapping or logging in.
    			uid = WSSecurityPropagationHelper.getUserFromUniqueID (uniqueID);
    		}
    		catch (Exception e)
    		{
    			// Handles the exception
    		}	
    	}
    	else if (uid == null)
    	{
         // Throws an exception if authentication data is not valid.
         // You must have either UID or CredToken
    		throw new WSLoginFailedException("invalid authentication data.");
    	}
    	else if (uid != null && password != null)
    	{
         // This is a typical authentication. You can choose to map this ID to  
         // another ID or you can skip it and allow WebSphere Application Server 
         // to log in for you. When passwords are presented, be very careful to not 
         // validate the password because this is the initial authentication.
    		
    		return true;
    	}
    
        // If desired, map this uid to something else and set the identitySwitched 
        // boolean. If the identity was changed, clear the propagated attributes 
        // below so they are not used incorrectly.
    	uid = myCustomMappingRoutine (uid);
    	
        // Clear the propagated attributes because they are no longer applicable 
        // to the new identity
    	if (identitySwitched)
    	{
    		((WSTokenHolderCallback) callbacks[3]).setTokenHolderList(null);
    	}
  2. 检查以查看是否发生属性传播,以及在存在相同标识时用户的属性是否已存在。 检查以查看发送服务器是否已存在用户属性,避免对用户注册表查找的重复调用。要检查用户属性,请对分析回调所包含信息的 WSTokenHolderCallback 使用方法,以确定该信息是否足够供 WebSphere Application Server 创建主体集。以下是用户属性的代码样本检查:
    boolean requiresLogin = 
    ((com.ibm.wsspi.security.auth.callback.WSTokenHolderCallback) 
    callbacks[2]).getrequiresLogin();
    如果没有足够的属性来构成执行授权所需的 WSCredential 和 WSPrincipal 对象,那么上一个代码样本将返回 true 结果。当结果为 false 时,可选择停止按存在的必需信息进行处理,以在不执行其他远程用户注册表调用的情况下创建主体集。
  3. 可选: 在用户注册表中查找必需的属性,将属性放入散列表,然后将该散列表添加到共享状态。 如果标识切换到此登录模块中,那么您必须完成以下步骤:
    1. 创建属性的散列表,如以下示例中所示。
    2. 将该散列表添加到共享状态。
    如果标识未切换,但是前面显示的 requiresLogin 代码样本的值为 true,那么可创建属性的散列表。但是,当 WebSphere Application Server 为您处理登录时,您无须创建散列表。但是,您可能考虑在使用自己的特定用户注册表的特殊情况下创建散列表以收集属性。创建 UserRegistry 实现、使用散列表以及允许 WebSphere Application Server 为您收集用户属性,这可能是最简单的解决方案。下表说明如何创建用户属性的散列表
    if (requiresLogin || identitySwitched)
    	{
    		// Retrieves the default InitialContext for this server.
    		javax.naming.InitialContext ctx = new javax.naming.InitialContext();
    
    		// Retrieves the local UserRegistry implementation.
    		com.ibm.websphere.security.UserRegistry reg = (com.ibm.websphere.
            security.UserRegistry) 
    		ctx.lookup("UserRegistry");				
    
         // Retrieves the user registry uniqueID based on the uid specified
         // in the NameCallback.
    		String uniqueid = reg.getUniqueUserId(uid);
    	 	uid = WSSecurityPropagationHelper.getUserFromUniqueID (uniqueid);
    			
         // Retrieves the display name from the user registry based on the uniqueID.
    		String securityName = reg.getUserSecurityName(uid);
    	
         // Retrieves the groups associated with the uniqueID.
    		java.util.List groupList = reg.getUniqueGroupIds(uid);
    			
         // Creates the java.util.Hashtable with the information that you gathered 
         // from the UserRegistry implementation.
    		java.util.Hashtable hashtable = new java.util.Hashtable();
    		hashtable.put(com.ibm.wsspi.security.token.AttributeNameConstants.
           WSCREDENTIAL_UNIQUEID, uniqueid);
         hashtable.put(com.ibm.wsspi.security.token.AttributeNameConstants.
           WSCREDENTIAL_SECURITYNAME, securityName);
    		hashtable.put(com.ibm.wsspi.security.token.AttributeNameConstants.
           WSCREDENTIAL_GROUPS, groupList);
    
         // Adds a cache key that is used as part of the lookup mechanism for 
         // the created Subject. The cache key can be an object, but should have 
         // an implemented toString method. Make sure that the cacheKey contains 
         // enough information to scope it to the user and any additional attributes 
         // that you are using. If you do not specify this property the Subject is 
         // scoped to the returned WSCREDENTIAL_UNIQUEID, by default.
    		hashtable.put(com.ibm.wsspi.security.token.AttributeNameConstants.
            WSCREDENTIAL_CACHE_KEY, "myCustomAttribute" + uniqueid);
    		// Adds the hashtable to the sharedState of the Subject.
    		_sharedState.put(com.ibm.wsspi.security.token.AttributeNameConstants.
            WSCREDENTIAL_PROPERTIES_KEY, hashtable);
    	}
    下列规则更详细地定义如何执行散列表登录。必须在主体集(公用或专用凭证集合)或共享状态散列映射中使用 java.util.Hashtable 对象。com.ibm.wsspi.security.token.AttributeNameConstants 类定义包含用户信息的键。如果使用列在轻量级第三方认证 (LTPA) 登录模块之前的定制登录模块将散列表对象放入登录上下文的共享状态,请使用下列键在共享状态 hashMap 中搜索 java.util.Hashtable 对象的值:
    属性
    com.ibm.wsspi.security.cred.propertiesObject
    对属性的引用
    AttributeNameConstants.WSCREDENTIAL_PROPERTIES_KEY
    说明
    此键搜索在登录上下文的共享状态中包含必需属性的 Hashtable 对象。
    期望的结果
    java.util.Hashtable 对象。

    如果在主体集或共享状态区域中找到 java.util.Hashtable 对象,那么验证散列表中是否存在下列属性:

    属性
    com.ibm.wsspi.security.cred.uniqueId
    对属性的引用
    AttributeNameConstants.WSCREDENTIAL_UNIQUEID
    返回
    java.util.String
    说明
    此属性值必须是用户的唯一表示。对于 WebSphere Application Server 缺省实现,此属性表示应用程序授权表中存储的信息。当信息已部署,并执行用户对角色映射后,此信息位于应用程序部署描述符中。如果使用对 WebSphere Application Server 用户注册表实现的查找来执行用户到角色映射,请参阅需要的格式示例。

    如果第三方权限提供程序重设用户对角色映射,那么第三方权限提供程序定义此格式。要确保与 WebSphere Application Server 缺省实现在唯一标识值方面的兼容性,调用 WebSphere Application Server public String getUniqueUserId(String userSecurityName) UserRegistry 方法。

    需要的格式示例
    表 1. 格式示例.

    此表提供了配置入站标识映射时的某些格式示例。

    领域 格式 (uniqueUserId)
    轻量级目录访问协议 (Lightweight Directory Access Protocol, LDAP) ldaphost.austin.ibm.com:389/cn=user,o=ibm,c=us
    Windows MYWINHOST/S-1-5-21-963918322-163748893-4247568029-500
    UNIX MYUNIXHOST/32

    com.ibm.wsspi.security.cred.uniqueId 属性是必需的。

    属性
    com.ibm.wsspi.security.cred.securityName
    对属性的引用
    AttributeNameConstants. WSCREDENTIAL_ SECURITYNAME
    返回
    java.util.String
    说明
    此属性搜索认证用户的 securityName。此名称通常称为显示名短名称WebSphere Application Server 为 getRemoteUser、getUserPrincipal 和 getCallerPrincipal 应用程序编程接口 (API) 使用 securityName 属性。要确保与 WebSphere Application Server 缺省实现在 securityName 值方面的兼容性,调用 WebSphere Application Server public String getUserSecurityName(String uniqueUserId) UserRegistry 方法。
    需要的格式示例
    表 2. 格式示例. 此表给出期望的格式示例。
    领域 格式 (uniqueUserId)
    LDAP user (LDAP UID)
    Windows user (Windows username)
    UNIX user (UNIX username)

    com.ibm.wsspi.security.cred.securityName 属性是必需的。

    属性
    com.ibm.wsspi.security.cred.groups
    对属性的引用
    AttributeNameConstants. WSCREDENTIAL_GROUPS
    返回
    java.util.ArrayList
    说明
    此键搜索此用户所属的组的数组列表。这些组是以 realm_name/user_name 格式指定的。当 WebSphere Application Server 授权引擎使用这些组在部署描述符中进行组对角色映射时,这些组的格式很重要。提供的格式必须与 WebSphere Application Server 缺省实现需要的格式匹配。在使用第三方权限提供程序时,必须使用第三方提供程序所需的格式。要确保与 WebSphere Application Server 缺省实现在唯一组标识值方面的兼容性,请调用 WebSphere Application Server public List getUniqueGroupIds(String uniqueUserId) UserRegistry 方法。
    数组列表中每个组需要的格式示例
    表 3. 格式示例. 此表给出数组列表中每个组的期望格式示例。
    领域 格式
    LDAP ldap1.austin.ibm.com:389/cn=group1,o=ibm,c=us
    Windows MYWINREALM/S-1-5-32-544
    UNIX MY/S-1-5-32-544

    com.ibm.wsspi.security.cred.groups 属性不是必需的。用户不需要具有关联组。

    属性
    com.ibm.wsspi.security.cred.cacheKey
    对属性的引用
    AttributeNameConstants. WSCREDENTIAL_CACHE_KEY
    返回
    java.lang.Object
    说明
    这个键属性可指定表示登录唯一属性(包括可能影响唯一性的特定于用户的信息以及用户动态属性)的对象。例如,当用户从位置 A 登录时,这可能影响他们的访问控制,那么高速缓存键需要包括位置 A,以便接收到的主体集是当前位置的正确主体集。

    此 com.ibm.wsspi.security.cred.cacheKey 属性不是必需的。未指定此属性时,高速缓存查询是对 WSCREDENTIAL_UNIQUEID 指定的值。在 java.util.Hashtable 对象中找到此信息时,WebSphere Application Server 创建的主体集类似于通过正常登录过程获得的主体集(至少对于 LTPA 来说如此)。新的主体集包含 WSCredential 对象和 WSPrincipal 对象,其使用散列表对象中找到的信息完全填充。

  4. 将您的定制登录模块添加到 RMI_INBOUND、WEB_INBOUND 和缺省 Java™ 认证和授权服务 (JAAS) 系统登录配置中。 配置 RMI_INBOUND 登录配置,以便 WebSphere Application Server 首先装入新的定制登录模块。
    1. 单击安全性 > 全局安全性 > Java 认证和授权服务 > 系统登录 > RMI_INBOUND
    2. 在“其他属性”下,单击 JAAS 登录模块 > 新建,以将您的登录模块添加到 RMI_INBOUND 配置中。
    3. 返回 RMI_INBOUND 的 JAAS 登录模块面板。
    4. 单击设置顺序以更改装入登录模块的顺序,以便 WebSphere Application Server 首先装入定制登录模块。 使用上移下移按钮来排列登录模块的顺序。
    5. 为 WEB_INBOUND 和 DEFAULT 登录配置重复前面的三步。

结果

此过程为入站请求配置标识映射。

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



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