use of net.sourceforge.prograde.type.Priority in project ddf by codice.
the class PermissionActivator method start.
@SuppressWarnings("squid:S1149")
@Override
public void start(BundleContext bundleContext) throws Exception {
System.setProperty("/", File.separator);
this.conditionalPermissionAdmin = getConditionalPermissionAdmin(bundleContext);
String policyDir = SecurityActions.getSystemProperty("ddf.home") + File.separator + "security";
if (policyDir.startsWith("=")) {
policyDir = policyDir.substring(1);
}
File policyDirFile = new File(policyDir);
List<ParsedPolicy> parsedPolicies = new ArrayList<>();
for (File file : Objects.requireNonNull(policyDirFile.listFiles())) {
ParsedPolicy parse = null;
try {
parse = new Parser(false).parse(file);
} catch (Exception e) {
systemExit(file);
}
parsedPolicies.add(parse);
}
ConditionalPermissionUpdate conditionalPermissionUpdate = conditionalPermissionAdmin.newConditionalPermissionUpdate();
conditionalPermissionUpdate.getConditionalPermissionInfos().clear();
this.priorityResult = null;
List<ConditionalPermissionInfo> allGrantInfos = new ArrayList<>();
List<ConditionalPermissionInfo> allDenyInfos = new ArrayList<>();
for (ParsedPolicy parsedPolicy : parsedPolicies) {
List<ParsedPolicyEntry> grantEntries = parsedPolicy.getGrantEntries();
List<ParsedPolicyEntry> denyEntries = parsedPolicy.getDenyEntries();
buildConditionalPermissionInfo(grantEntries, allGrantInfos, ConditionalPermissionInfo.ALLOW);
buildConditionalPermissionInfo(denyEntries, allDenyInfos, ConditionalPermissionInfo.DENY);
Priority priority = parsedPolicy.getPriority();
if (priorityResult == null) {
this.priorityResult = priority;
} else if (priority != priorityResult) {
// if they don't match, then we can't make a determination on the priority, so we'll
// default to deny
this.priorityResult = Priority.DENY;
}
}
if (priorityResult == null && !allGrantInfos.isEmpty() && !allDenyInfos.isEmpty()) {
this.priorityResult = Priority.GRANT;
}
if (priorityResult == Priority.GRANT) {
conditionalPermissionUpdate.getConditionalPermissionInfos().addAll(allGrantInfos);
conditionalPermissionUpdate.getConditionalPermissionInfos().addAll(allDenyInfos);
conditionalPermissionUpdate.getConditionalPermissionInfos().add(getAllPermission(ConditionalPermissionInfo.ALLOW));
} else if (priorityResult == Priority.DENY) {
conditionalPermissionUpdate.getConditionalPermissionInfos().addAll(allDenyInfos);
conditionalPermissionUpdate.getConditionalPermissionInfos().addAll(allGrantInfos);
conditionalPermissionUpdate.getConditionalPermissionInfos().add(getAllPermission(ConditionalPermissionInfo.DENY));
}
conditionalPermissionUpdate.commit();
}
Aggregations