Search in sources :

Example 1 with PermissionList

use of org.folio.okapi.bean.PermissionList in project okapi by folio-org.

the class TenantManager method tenantPerms.

/**
 * Helper to make the tenantPermissions call for one module. Used from
 * ead3RealoadPerms and ead4Permissions.
 */
private void tenantPerms(Tenant tenant, ModuleDescriptor mdTo, ModuleDescriptor permsModule, ProxyContext pc, Handler<ExtendedAsyncResult<Void>> fut) {
    pc.debug("Loading permissions for " + mdTo.getName() + " (using " + permsModule.getName() + ")");
    String moduleTo = mdTo.getId();
    PermissionList pl = new PermissionList(moduleTo, mdTo.getPermissionSets());
    String pljson = Json.encodePrettily(pl);
    pc.debug("tenantPerms Req: " + pljson);
    InterfaceDescriptor permInt = permsModule.getSystemInterface("_tenantPermissions");
    String permPath = "";
    List<RoutingEntry> routingEntries = permInt.getAllRoutingEntries();
    ModuleInstance permInst = null;
    if (!routingEntries.isEmpty()) {
        for (RoutingEntry re : routingEntries) {
            if (re.match(null, "POST")) {
                permPath = re.getPath();
                if (permPath == null || permPath.isEmpty()) {
                    permPath = re.getPathPattern();
                }
                permInst = new ModuleInstance(permsModule, re, permPath);
            }
        }
    }
    if (permInst == null) {
        fut.handle(new Failure<>(USER, "Bad _tenantPermissions interface in module " + permsModule.getId() + ". No path to POST to"));
        return;
    }
    pc.debug("tenantPerms: " + permsModule.getId() + " and " + permPath);
    proxyService.callSystemInterface(tenant, permInst, pljson, pc, cres -> {
        if (cres.failed()) {
            fut.handle(new Failure<>(cres.getType(), cres.cause()));
        } else {
            pc.debug("tenantPerms request to " + permsModule.getName() + " succeeded for module " + moduleTo + " and tenant " + tenant.getId());
            fut.handle(new Success<>());
        }
    });
}
Also used : RoutingEntry(org.folio.okapi.bean.RoutingEntry) PermissionList(org.folio.okapi.bean.PermissionList) ModuleInstance(org.folio.okapi.bean.ModuleInstance) InterfaceDescriptor(org.folio.okapi.bean.InterfaceDescriptor)

Aggregations

InterfaceDescriptor (org.folio.okapi.bean.InterfaceDescriptor)1 ModuleInstance (org.folio.okapi.bean.ModuleInstance)1 PermissionList (org.folio.okapi.bean.PermissionList)1 RoutingEntry (org.folio.okapi.bean.RoutingEntry)1