在WebSphere 8.5上使用JASPIC auth模块

时间:2014-12-29 09:53:59

标签: java websphere websphere-8 jaspic

我有一个JASPIC auth模块,可以在GlassFish,WildFly和WebLogic上运行良好。

现在我们有一个使用WebSphere 8.5的新客户,我无法让auth模块在那里正常运行。

问题是WebSphere不接受auth模块放入CallerPrincipalCallback的用户名。我们其他受支持的服务器只接受这个,但出于某种原因,WebSphere认为它需要执行一些额外的检查。

在调查这个问题之后,我偶然发现了这个问题:https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014937852

这完全描述了我的问题,但那里没有给出解决方案。

我如何让WebSphere在处理CallerPrincipalHandler并接受像所有其他服务器一样的用户名?

2 个答案:

答案 0 :(得分:5)

归因于WebSphere 8.5,WRT的行为JASPIC CallerPrincipalCallback的处理与JASPIC规范不兼容。

CallerPrincipalCallback必须能够支持用户注册表所在的情况 集成在SAM中,包括用于提供用户组成员资格。

对于基于密码的验证的特殊情况,SAM可以调用提供CallbackHandler的容器来处理PasswordValidationCallback;在这种情况下,如果在与容器的CallbackHandler集成的用户注册表中不存在用户名和/或密码组合,则CallbackHandler将返回失败结果。在这种情况下,SAM将返回失败的(或继续)身份验证结果,并且不会调用CallbackHandler来处理CallerPrincipalCallback。

HTH,

Ron Monzillo

答案 1 :(得分:1)

一般情况下,我通常建议尽可能使用容器身份验证/授权,因为服务器基础结构已经提供了容器身份验证/授权,并且大多数情况下都足够了。

但是,如果你需要它,这里有一些提示。

如果您想避免额外检查,并允许对不在WebSphere用户注册表中的用户进行身份验证,则必须创建这样的完整主题(这是固定用户简化),而不是使用回调:

public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject,
        Subject serviceSubject) throws AuthException {

   String uniqueid = "test";
   String username = "test";
   String password = "test";

   Hashtable hashtable = new Hashtable();
   hashtable.put(AttributeNameConstants.WSCREDENTIAL_UNIQUEID, uniqueid);
   hashtable.put(AttributeNameConstants.WSCREDENTIAL_SECURITYNAME, username);
   hashtable.put(AttributeNameConstants.WSCREDENTIAL_PASSWORD, password);
   List groups = new ArrayList();

   // if you want to use existing group uncomment this
   // com.ibm.websphere.security.UserRegistry reg = 
   //  (com.ibm.websphere.security.UserRegistry) ctx.lookup("UserRegistry");    
   // String groupID reg.getUniqueGroupId("testers");
   // groups.add(groupID); // for federated registry it returns cn=testers,o=defaultWIMFileBasedRealm


   // if you want to use fake groups just add them here, and provide correct binding file - see below. If you don't want to use groups just omit WSCREDENTIAL_GROUPS  
   groups.add("testers");

   hashtable.put(AttributeNameConstants.WSCREDENTIAL_GROUPS, groups); //optional 
   hashtable.put(AttributeNameConstants.WSCREDENTIAL_CACHE_KEY, "myCustomAttribute" + uniqueid);
   clientSubject.getPrivateCredentials().add(hashtable);

   return AuthStatus.SUCCESS;

}

我假设您要将这些用户映射到应用程序中的某些安全角色。您可以使用用户,组或特殊主题对其进行映射。您需要在application.xml中定义角色,如下所示:

<security-role>
    <role-name>user</role-name>
</security-role>

并且您将需要绑定文件,因为无法通过控制台为不存在的用户/组进行绑定。创建ibm-application-bnd.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<application-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-application-bnd_1_2.xsd"
version="1.2">

  <security-role name="user">
    <user name="test" access-id="user:defaultWIMFileBasedRealm/test"/>
    <group name="testers" access-id="group:defaultWIMFileBasedRealm/testers"/>
    <special-subject type="ALL_AUTHENTICATED_USERS" />
  </security-role>
</application-bnd>

我提供了各种映射的示例,使用适合您需求的映射:

  • user - 用于将指定用户映射到角色
  • group - 用于将组映射到角色
  • special-subject - 如果您希望任何成功通过身份验证的用户具有该角色。

重要如果您想使用虚假用户/群组,则必须提供access-id属性,如果他们在注册表中,则只需提供name

另见: