Search in sources :

Example 1 with UserData

use of com.tremolosecurity.scalejs.data.UserData in project OpenUnison by TremoloSecurity.

the class ScaleMain method lookupUser.

private void lookupUser(HttpFilterRequest request, HttpFilterResponse response, Gson gson) throws LDAPException, IOException {
    response.setContentType("application/json");
    AuthInfo userData = ((AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL)).getAuthInfo();
    Set<String> allowedAttrs = null;
    if (scaleConfig.getUiDecisions() != null) {
        allowedAttrs = this.scaleConfig.getUiDecisions().availableAttributes(userData, request.getServletRequest());
    }
    UserData userToSend = new UserData();
    userToSend.setDn(userData.getUserDN());
    for (String attrName : this.scaleConfig.getUserAttributeList()) {
        if (allowedAttrs == null || allowedAttrs.contains(attrName)) {
            Attribute attr = new Attribute(attrName);
            Attribute fromUser = userData.getAttribs().get(attrName);
            if (fromUser != null) {
                attr.getValues().addAll(fromUser.getValues());
                if (attrName.equalsIgnoreCase(this.scaleConfig.getUidAttributeName())) {
                    userToSend.setUid(fromUser.getValues().get(0));
                }
            }
            userToSend.getAttributes().add(attr);
        }
    }
    if (this.scaleConfig.getRoleAttribute() != null && !this.scaleConfig.getRoleAttribute().isEmpty()) {
        Attribute fromUser = userData.getAttribs().get(this.scaleConfig.getRoleAttribute());
        Attribute attr = new Attribute(this.scaleConfig.getRoleAttribute());
        if (fromUser != null) {
            attr.getValues().addAll(fromUser.getValues());
        }
        userToSend.getAttributes().add(attr);
    }
    ArrayList<String> attrNames = new ArrayList<String>();
    attrNames.add("cn");
    LDAPSearchResults res = GlobalEntries.getGlobalEntries().getConfigManager().getMyVD().search(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getLdapRoot(), 2, equal(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getGroupMemberAttribute(), userData.getUserDN()).toString(), attrNames);
    while (res.hasMore()) {
        LDAPEntry entry = res.next();
        LDAPAttribute la = entry.getAttribute("cn");
        if (la != null) {
            userToSend.getGroups().add(la.getStringValue());
        }
    }
    ScaleJSUtils.addCacheHeaders(response);
    response.getWriter().println(gson.toJson(userToSend).trim());
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) AuthInfo(com.tremolosecurity.proxy.auth.AuthInfo) LDAPEntry(com.novell.ldap.LDAPEntry) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) UserData(com.tremolosecurity.scalejs.data.UserData) Attribute(com.tremolosecurity.saml.Attribute) LDAPAttribute(com.novell.ldap.LDAPAttribute) ScaleAttribute(com.tremolosecurity.scalejs.cfg.ScaleAttribute) ArrayList(java.util.ArrayList) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) RichTextString(org.apache.poi.ss.usermodel.RichTextString) AuthController(com.tremolosecurity.proxy.auth.AuthController)

Aggregations

LDAPAttribute (com.novell.ldap.LDAPAttribute)1 LDAPEntry (com.novell.ldap.LDAPEntry)1 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)1 AuthController (com.tremolosecurity.proxy.auth.AuthController)1 AuthInfo (com.tremolosecurity.proxy.auth.AuthInfo)1 Attribute (com.tremolosecurity.saml.Attribute)1 ScaleAttribute (com.tremolosecurity.scalejs.cfg.ScaleAttribute)1 UserData (com.tremolosecurity.scalejs.data.UserData)1 ArrayList (java.util.ArrayList)1 RichTextString (org.apache.poi.ss.usermodel.RichTextString)1 XSSFRichTextString (org.apache.poi.xssf.usermodel.XSSFRichTextString)1