// No Auth, but an API: return all Policies with no Auth associated
// => API doesn't have any authentification method
for (String policyIdInApi : api.getPolicyIds()) {
Policy policy = getPolicyById(policyIdInApi);
// Add only if no auth in policy's buckets
boolean add = true;
for(QuotaRLBucket authIds : policy.getAuthIds()) {
if (!authIds.getAuthIds().isEmpty()) {
add = false;
}
}
if(add) {
if (logger.isDebugEnabled()) {
logger.debug("Adding policy {} as it does not have any auth in it's contexts", policy.getId());
}
if (result == null)
result = new ArrayList<CallDescriptor>();
int policyIdx = -1;
if (policy != null && policy.getContextIds().size() > 0) {
policyIdx = policy.getContextIds().get(0);
}
result.add(new CallDescriptor(policy, policyIdx , -1));
}
}
// Now, add the CallDescriptor of the "default" context
if (api.getContextIds().isEmpty() == false) {
if (result == null)
result = new ArrayList<CallDescriptor>();
// Looking for default context, placed at index 0 by addApi
ApiIds ctx = api.getContextIds().get(0);
if (ctx.isStatusActive()) {
if (logger.isDebugEnabled()) {
logger.debug("Adding CallDescriptor({}, {}, {})", new String[] {
null,
""+ctx.getApiContextId(),
""+ctx.getApiBucketId()
});
}
result.add(new CallDescriptor(null, ctx.getApiContextId(), ctx.getApiBucketId()));
}
}
}
} else {
// We have an Auth and an API, check matching policies
for (AuthIds authCtx : auth.getPolicyContexts()) {
String policyIdInAuth = authCtx.getPolicyId();
boolean policyAdded = false;
// API may be null if Auth is for "Company"
if (api != null) {
for (String policyIdInApi : api.getPolicyIds()) {
// Matching means that the policy is in Auth and API
if (policyIdInApi.equals(policyIdInAuth)) {
Policy policy = getPolicyById(policyIdInAuth);
if (result == null)
result = new ArrayList<CallDescriptor>();
if (authCtx.isStatusActive()) {
if (logger.isDebugEnabled()) {
logger.debug("Adding CallDescriptor({}, {}, {})", new String[] {
policy.getId(),
""+authCtx.getPolicyContextId(),
""+authCtx.getPolicyBucketId()
});
}
result.add(new CallDescriptor(policy, authCtx.getPolicyContextId(), authCtx.getPolicyBucketId()));
}
policyAdded = true;
}
}
}
// If the policy wasn't added...
if (!policyAdded) {
// Slow, but need to check if that policy has some API attached
Policy policy = getPolicyById(policyIdInAuth, false);
if ((policy.getApiIds() == null) || policy.getApiIds().isEmpty()) {
if (result == null)
result = new ArrayList<CallDescriptor>();
if (authCtx.isStatusActive()) {
result.add(new CallDescriptor(policy, authCtx.getPolicyContextId(), authCtx.getPolicyBucketId()));
}