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();
}
}
Aggregations