DefinitionAccess access = def.getAccess();
if (access.isGlobal() || !access.requiresAuthentication()) {
return null;
}
ConfigAdapter configAdapter = Aura.getConfigAdapter();
String referencingNamespace = null;
if (referencingDescriptor != null) {
String prefix = referencingDescriptor.getPrefix();
if (configAdapter.isUnsecuredPrefix(prefix)) {
return null;
}
referencingNamespace = referencingDescriptor.getNamespace();
// The caller is in a system namespace let them through
if (configAdapter.isPrivilegedNamespace(referencingNamespace)) {
return null;
}
}
DefDescriptor<?> desc = def.getDescriptor();
String namespace;
String target;
if (def instanceof AttributeDef) {
AttributeDef attributeDef = (AttributeDef) def;
DefDescriptor<? extends RootDefinition> parentDescriptor = attributeDef.getParentDescriptor();
namespace = parentDescriptor.getNamespace();
target = String.format("%s:%s.%s", namespace, parentDescriptor.getName(), desc.getName());
} else {
namespace = desc.getNamespace();
target = String.format("%s:%s", namespace, desc.getName());
}
// Cache key is of the form "referencingNamespace>defNamespace:defName[.subDefName].defTypeOrdinal"
DefType defType = desc.getDefType();
String key = String.format("%s>%s.%d", referencingNamespace == null ? "" : referencingNamespace, target,
defType.ordinal());
String status = accessCheckCache.getIfPresent(key);
if (status == null) {
status = "";
// Protect against re-entry
accessCheckCache.put(key, status);
// System.out.printf("** MDR.miss.assertAccess() cache miss for: %s\n", key);
DefDescriptor<? extends Definition> descriptor = def.getDescriptor();
if (!configAdapter.isUnsecuredNamespace(namespace)
&& !configAdapter.isUnsecuredPrefix(descriptor.getPrefix())) {
if (referencingNamespace == null || referencingNamespace.isEmpty()) {
status = String
.format("Access to %s '%s' disallowed by MasterDefRegistry.assertAccess(): referencing namespace was empty or null",
defType, target);
} else if (!referencingNamespace.equals(namespace)) {