代码之家  ›  专栏  ›  技术社区  ›  dikkini

在TAI中编程验证用户

  •  0
  • dikkini  · 技术社区  · 9 年前

    我在发展 TAI 它们必须在WebSpherePortal中授权用户。

    我的 使用 OpenID Connect获取有关用户的所有信息,我想构建一些上下文,将其提供给WAS,并告诉WAS,他必须在没有本地帐户的情况下信任该上下文。

    如何验证用户 在本地存储库中没有用户帐户?

    更新:

    代码:

    String userid = "bob";
    String uniqueid = "bob";
    
    Hashtable hashtable = new Hashtable();
    hashtable.put(AttributeNameConstants.WSCREDENTIAL_UNIQUEID, uniqueid);
    hashtable.put(AttributeNameConstants.WSCREDENTIAL_SECURITYNAME, userid);
    hashtable.put(AttributeNameConstants.WSCREDENTIAL_CACHE_KEY, uniqueid+"MyCustom");
    
    Subject subject = new Subject();
    subject.getPublicCredentials().add(hashtable);
    return TAIResult.create(HttpServletResponse.SC_OK, "ignored", subject);
    

    日志:

    [25.03.15 20:16:33:521 AMT] 00000043 ServiceLogger I com.ibm.ws.ffdc.IncidentStreamImpl initialize FFDC0009I: FFDC opened incident stream file  WebSphere_Portal_00000043_15.03.25_20.16.33_0.txt
    [25.03.15 20:16:33:537 AMT] 00000043 ServiceLogger I com.ibm.ws.ffdc.IncidentStreamImpl resetIncidentStream FFDC0010I: FFDC closed incident stream file WebSphere_Portal_00000043_15.03.25_20.16.33_0.txt
    [25.03.15 20:16:33:677 AMT] 00000043 StorageApi    E com.ibm.wps.policy.commands.StorageApi StorageApi EJQAB0064E: A Null argument was passed to the StorageApi constructor.
    [25.03.15 20:16:33:724 AMT] 00000043 PolicyService E com.ibm.wps.policy.services.PolicyService Error Occured while creating storageAPI EJQAB0064E: A Null argument was passed to the StorageApi constructor.
    

    FFDC:

    ------Start of DE processing------ = [3/25/15 20:16:33:474 AMT] , key = com.ibm.websphere.wim.exception.PropertyNotDefinedException com.ibm.ws.security.auth.ContextManagerImpl.runAs 4153
    Exception = com.ibm.websphere.wim.exception.PropertyNotDefinedException
    Source = com.ibm.ws.security.auth.ContextManagerImpl.runAs
    probeid = 4153
    Stack Dump = com.ibm.websphere.wim.exception.PropertyNotDefinedException: CWWIM0514W The 'dn' property is not defined.
    

    对于此错误,我发现 this information .

    但我不明白他们想让我。。。

    说明:

    我有FederatedRepository,其中只有一个LDAP存储库。

    更新#2:

    我在WAS 8.5.5.2上做了这样的TAI,没有错误,只有白色屏幕。我尝试使用组“wpsadmins”验证用户“bob”。有些FederatedRepository具有一个基于文件的内置存储库。

    更新#3:

    我为WAS编写了自定义应用程序,其中我有一个按钮,它向Servlet发出POST请求。

    部分代码:

    if (req.getRemoteUser() == null) {
        req
                .setAttribute("errorMessage",
                        "<b>Error: Please log in before accessing PrintUserInfo.<b>");
        RequestDispatcher disp = getServletContext().getRequestDispatcher(
                "/login.jsp");
        disp.forward(req, resp);
        return;
    }
    resp.setContentType("text/html");
    PrintWriter out = new PrintWriter(resp.getOutputStream());
    
    String id = WSSubject.getCallerPrincipal();
    out.println("The WAS Subject layer thinks you are " + id);
        Context ic = new InitialContext();
        Object objRef = ic.lookup("UserRegistry");
        UserRegistry userReg = (UserRegistry) PortableRemoteObject.narrow(
                objRef, UserRegistry.class);
        out.println("<BR><BR>The user registry says your display name is: "
                + userReg.getUserDisplayName(req.getUserPrincipal()
                        .getName()));
    
        Subject subject = WSSubject.getCallerSubject();
        Set credSet = subject.getPublicCredentials(WSCredential.class);
        //should be impossible.
        if (credSet.size() > 1) {
            System.out
                    .println("Expected only one WSCredential in Subject set");
            throw new Exception("Expected one WSCredential, found "
                    + credSet.size());
        }
    if (credSet.isEmpty()) {
        System.out.println("Credential set is empty");
        throw new Exception("Found no credentials");
    }
    //get one and only one element of Set
    Iterator iter = credSet.iterator();
    WSCredential creds = (WSCredential) iter.next();
    out.println("<BR><BR>Looking into your Subject your userid is "
            + creds.getSecurityName());
    out.println("<BR><BR>Looking into your Subject your uniqueid is "
            + creds.getUniqueSecurityName());
    out
            .println("<BR><BR>Looking into your Subject I see these groups: ");
    //List groups = helper.getGroups();
    List groups = creds.getGroupIds();
    iter = groups.iterator();
    while (iter.hasNext()) {
        String gid = (String) iter.next();
        out.println("<BR>Group ID: " + gid);
    }
    

    TAI的新版本:

    String userid = "alisa";
    String uniqueid = "bob";
    
    // add admin group 
    
    // stash in hashtable
    Hashtable hashtable = new Hashtable();
    
    
    try {
        InitialContext ctx = new InitialContext();
        UserRegistry reg  =(UserRegistry)ctx.lookup("UserRegistry");
        String wpsadminsGroupUniqueId = reg.getUniqueGroupId("wpsadmins");
        List<String> groups = new ArrayList<String>();
        groups.add(wpsadminsGroupUniqueId);
        hashtable.put(AttributeNameConstants.WSCREDENTIAL_GROUPS, groups);
    } catch (Exception  e) {
        System.out.println("EXCEPTION IN TAI");
        e.printStackTrace();
    }
    
    hashtable.put(AttributeNameConstants.WSCREDENTIAL_UNIQUEID,uniqueid);
    hashtable.put(AttributeNameConstants.WSCREDENTIAL_SECURITYNAME,userid);
    hashtable.put(AttributeNameConstants.WSCREDENTIAL_CACHE_KEY,uniqueid+"MyCustom");
    
    Subject subject = new Subject();
    subject.getPublicCredentials().add(hashtable);
    return TAIResult.create(HttpServletResponse.SC_OK, "ignored", subject);
    

    所以我从Subject获得了我的凭据,包括userId、uniqueId和来自LDAP的组。

    结果:

    The WAS Subject layer thinks you are alisa 
    
    The user registry says your display name is: 
    
    Looking into your Subject your userid is alisa 
    
    Looking into your Subject your uniqueid is bob 
    
    Looking into your Subject I see these groups: 
    Group ID: group:domain:port/cn=wpsadmins,cn=CN,ou=OU,o=O,o=O,c=ru 
    

    更新#4

    我在TAI中添加了几个组,并在Portal中进行了授权(我认为),但我只看到白色屏幕,没有任何内容。发生了什么?

    更新#5

    WPS给了我一个例外:

    [26.03.15 18:47:41:006 AMT] 0000004e DefaultLoginF E com.ibm.wps.auth.impl.DefaultLoginFilter doLoginWithExceptions WpsException occured: com.ibm.wps.services.authentication.exceptions.UserRetrieveException: EJPSD0008E: Exception occurred while retrieving the user [null] from the user registry.
    
    2 回复  |  直到 9 年前
        1
  •  2
  •   Gas    9 年前

    您需要创建完整主题,以查看更多详细信息 Advanced authentication in WebSphere Application Server .

    简而言之,您需要使用类似的代码:

    String userid = "bob";//get from request
    String uniqueid = "bob";
    
    // stash in hashtable
    Hashtable hashtable = new Hashtable();
    hashtable.put(AttributeNameConstants.WSCREDENTIAL_UNIQUEID,uniqueid);
    hashtable.put(AttributeNameConstants.WSCREDENTIAL_SECURITYNAME,userid);
    // hashtable.put(AttributeNameConstants.WSCREDENTIAL_GROUPS,groups);
    hashtable.put(AttributeNameConstants.WSCREDENTIAL_CACHE_KEY,uniqueid+"MyCustom");
    
    Subject subject = new Subject();
    subject.getPublicCredentials().add(hashtable);
    return TAIResult.create(HttpServletResponse.SC_OK, "ignored", subject); 
    
        2
  •  0
  •   Stefan Schmitt    9 年前

    更新#5中添加的WPS异常 WebSpherePortal要求uniqueid是完全限定的DN。在你的情况下,你只有一个简称。门户使用DN在VMM中查找用户,并期望WSCredential.getUniqueSecurityName()返回DN。