bug 4964: made listDomainChildren work with "isRecursive" flag

status 4964: resolved fixed
This commit is contained in:
alena 2010-11-11 14:27:25 -08:00
parent 05bbd35860
commit 6e0b500a83
2 changed files with 45 additions and 9 deletions

View File

@ -101,7 +101,9 @@ public class ApiServlet extends HttpServlet {
if (userId != null) {
_apiServer.logoutUser(userId);
}
session.invalidate();
try {
session.invalidate();
}catch (IllegalStateException ise) {}
}
auditTrailSb.append("command=logout");
auditTrailSb.append(" " +HttpServletResponse.SC_OK);
@ -110,7 +112,11 @@ public class ApiServlet extends HttpServlet {
} else if ("login".equalsIgnoreCase(command)) {
auditTrailSb.append("command=login");
// if this is a login, authenticate the user and return
if (session != null) session.invalidate();
if (session != null) {
try {
session.invalidate();
}catch (IllegalStateException ise) {}
}
session = req.getSession(true);
String[] username = (String[])params.get("username");
String[] password = (String[])params.get("password");
@ -160,7 +166,9 @@ public class ApiServlet extends HttpServlet {
return;
} catch (CloudAuthenticationException ex) {
// TODO: fall through to API key, or just fail here w/ auth error? (HTTP 401)
session.invalidate();
try {
session.invalidate();
}catch (IllegalStateException ise) {}
auditTrailSb.append(" " + HttpServletResponse.SC_UNAUTHORIZED + " " + "failed to authenticated user, check username/password are correct");
resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "failed to authenticated user, check username/password are correct");
return;
@ -185,7 +193,9 @@ public class ApiServlet extends HttpServlet {
String sessionKey = (String)session.getAttribute("sessionkey");
String[] sessionKeyParam = (String[])params.get("sessionkey");
if ((sessionKeyParam == null) || (sessionKey == null) || !sessionKey.equals(sessionKeyParam[0])) {
session.invalidate();
try {
session.invalidate();
}catch (IllegalStateException ise) {}
auditTrailSb.append(" " + HttpServletResponse.SC_UNAUTHORIZED + " " + "unable to verify user credentials");
resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "unable to verify user credentials");
return;
@ -204,7 +214,9 @@ public class ApiServlet extends HttpServlet {
} else {
// Invalidate the session to ensure we won't allow a request across management server restarts if the userId was serialized to the
// stored session
session.invalidate();
try {
session.invalidate();
}catch (IllegalStateException ise) {}
auditTrailSb.append(" " + HttpServletResponse.SC_UNAUTHORIZED + " " + "unable to verify user credentials");
resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "unable to verify user credentials");
return;
@ -242,7 +254,9 @@ public class ApiServlet extends HttpServlet {
}
} else {
if (session != null) {
session.invalidate();
try {
session.invalidate();
}catch (IllegalStateException ise) {}
}
auditTrailSb.append(" " + HttpServletResponse.SC_UNAUTHORIZED + " " + "unable to verify user credentials and/or request signature");
resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "unable to verify user credentials and/or request signature");

View File

@ -3464,7 +3464,13 @@ public class ManagementServerImpl implements ManagementServer {
Filter searchFilter = new Filter(DomainVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
Long domainId = cmd.getId();
String domainName = cmd.getDomainName();
Boolean isRecursive = cmd.isRecursive();
Object keyword = cmd.getKeyword();
List <DomainVO> domainList = null;
if (isRecursive == null) {
isRecursive = false;
}
Account account = UserContext.current().getAccount();
if (account != null) {
@ -3477,12 +3483,24 @@ public class ManagementServerImpl implements ManagementServer {
}
}
return searchForDomainChildren(searchFilter, domainId, domainName,
keyword);
domainList = searchForDomainChildren(searchFilter, domainId, domainName,
keyword, null);
if (isRecursive) {
List<DomainVO> childDomains = new ArrayList<DomainVO>();
for (DomainVO domain : domainList) {
String path = domain.getPath();
childDomains.addAll(searchForDomainChildren(searchFilter, null, null,
null, path));
}
return childDomains;
} else {
return domainList;
}
}
private List<DomainVO> searchForDomainChildren(Filter searchFilter,
Long domainId, String domainName, Object keyword) {
Long domainId, String domainName, Object keyword, String path) {
SearchCriteria<DomainVO> sc = _domainDao.createSearchCriteria();
if (keyword != null) {
@ -3499,6 +3517,10 @@ public class ManagementServerImpl implements ManagementServer {
if (domainName != null) {
sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + domainName + "%");
}
if (path != null) {
sc.addAnd("path", SearchCriteria.Op.LIKE, path + "%");
}
return _domainDao.search(sc, searchFilter);
}