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()));
}
}
}
}
// Now check the apiContext on the auth which is in the list of API
if (api != null) {
for (ApiIds ctx : api.getContextIds()) {
if (ctx.getApiContextName().equals(auth.getApiContext())) {
if (result == null)
result = new ArrayList<CallDescriptor>();
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()));
}
}
}
}
}