Search in sources :

Example 1 with ApprovalDetails

use of com.tremolosecurity.provisioning.service.util.ApprovalDetails in project OpenUnison by TremoloSecurity.

the class ScaleMain method loadApproval.

private void loadApproval(HttpFilterRequest request, HttpFilterResponse response, Gson gson) throws ProvisioningException, IOException, LDAPException {
    int approvalID = Integer.parseInt(request.getRequestURI().substring(request.getRequestURI().lastIndexOf('/') + 1));
    AuthInfo userData = ((AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL)).getAuthInfo();
    String uid = userData.getAttribs().get(this.scaleConfig.getUidAttributeName()).getValues().get(0);
    boolean ok = false;
    ApprovalSummaries summaries = ServiceActions.listOpenApprovals(uid, this.scaleConfig.getDisplayNameAttribute(), GlobalEntries.getGlobalEntries().getConfigManager());
    for (ApprovalSummary as : summaries.getApprovals()) {
        if (as.getApproval() == approvalID) {
            ok = true;
        }
    }
    if (!ok) {
        response.setStatus(401);
        response.setContentType("application/json");
        ScaleError error = new ScaleError();
        error.getErrors().add("Unauthorized");
        ScaleJSUtils.addCacheHeaders(response);
        response.getWriter().print(gson.toJson(error).trim());
        response.getWriter().flush();
    } else {
        response.setContentType("application/json");
        ApprovalDetails details = ServiceActions.loadApprovalDetails(uid, approvalID);
        String filter = equal(this.scaleConfig.getUidAttributeName(), details.getUserObj().getUserID()).toString();
        ArrayList<String> attrs = new ArrayList<String>();
        /*for (String attrName : this.scaleConfig.getApprovalAttributes().keySet()) {
				attrs.add(attrName);
			}
			
			if (this.scaleConfig.getRoleAttribute() != null && ! this.scaleConfig.getRoleAttribute().isEmpty()) {
				attrs.add(this.scaleConfig.getRoleAttribute());
			}*/
        LDAPSearchResults res = GlobalEntries.getGlobalEntries().getConfigManager().getMyVD().search(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getLdapRoot(), 2, filter, attrs);
        if (res.hasMore()) {
            LDAPEntry entry = res.next();
            details.getUserObj().getAttribs().clear();
            for (String attrName : this.scaleConfig.getApprovalAttributes().keySet()) {
                LDAPAttribute attr = entry.getAttribute(attrName);
                if (attr != null) {
                    details.getUserObj().getAttribs().put(scaleConfig.getApprovalAttributes().get(attrName).getDisplayName(), new Attribute(scaleConfig.getApprovalAttributes().get(attrName).getDisplayName(), attr.getStringValue()));
                }
            }
            if (this.scaleConfig.getRoleAttribute() != null && !this.scaleConfig.getRoleAttribute().isEmpty()) {
                LDAPAttribute attr = entry.getAttribute(this.scaleConfig.getRoleAttribute());
                if (attr != null) {
                    details.getUserObj().getGroups().clear();
                    for (String val : attr.getStringValueArray()) {
                        details.getUserObj().getGroups().add(val);
                    }
                }
            } else {
                details.getUserObj().getGroups().clear();
                ArrayList<String> attrNames = new ArrayList<String>();
                attrNames.add("cn");
                LDAPSearchResults res2 = GlobalEntries.getGlobalEntries().getConfigManager().getMyVD().search(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getLdapRoot(), 2, equal(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getGroupMemberAttribute(), entry.getDN()).toString(), attrNames);
                while (res2.hasMore()) {
                    LDAPEntry entry2 = res2.next();
                    LDAPAttribute la = entry2.getAttribute("cn");
                    if (la != null) {
                        details.getUserObj().getGroups().add(la.getStringValue());
                    }
                }
            }
        }
        while (res.hasMore()) res.next();
        ScaleJSUtils.addCacheHeaders(response);
        response.getWriter().println(gson.toJson(details).trim());
        response.getWriter().flush();
    }
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) AuthInfo(com.tremolosecurity.proxy.auth.AuthInfo) Attribute(com.tremolosecurity.saml.Attribute) LDAPAttribute(com.novell.ldap.LDAPAttribute) ScaleAttribute(com.tremolosecurity.scalejs.cfg.ScaleAttribute) ArrayList(java.util.ArrayList) ScaleError(com.tremolosecurity.scalejs.data.ScaleError) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) RichTextString(org.apache.poi.ss.usermodel.RichTextString) AuthController(com.tremolosecurity.proxy.auth.AuthController) ApprovalDetails(com.tremolosecurity.provisioning.service.util.ApprovalDetails) LDAPEntry(com.novell.ldap.LDAPEntry) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) ApprovalSummaries(com.tremolosecurity.provisioning.service.util.ApprovalSummaries) ApprovalSummary(com.tremolosecurity.provisioning.service.util.ApprovalSummary)

Aggregations

LDAPAttribute (com.novell.ldap.LDAPAttribute)1 LDAPEntry (com.novell.ldap.LDAPEntry)1 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)1 ApprovalDetails (com.tremolosecurity.provisioning.service.util.ApprovalDetails)1 ApprovalSummaries (com.tremolosecurity.provisioning.service.util.ApprovalSummaries)1 ApprovalSummary (com.tremolosecurity.provisioning.service.util.ApprovalSummary)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 ScaleError (com.tremolosecurity.scalejs.data.ScaleError)1 ArrayList (java.util.ArrayList)1 RichTextString (org.apache.poi.ss.usermodel.RichTextString)1 XSSFRichTextString (org.apache.poi.xssf.usermodel.XSSFRichTextString)1