static void withPermsForRead(RestdModel model, RouteBuilder route, String type) { MetaEntity entity = (MetaEntity)model.getAttribute(MetaEntity.class.getName()); if(null != entity) { route.setExtension(entity); route.setAllowAnonymous(entity.getAnonymous()); List<SimpleSecurity> secs = new ArrayList<>(); List<MApiSecurityReq> seqs = new ArrayList<>(); if(null != entity.getUserPerms()) { SimpleSecurity.Builder sec = new SimpleSecurity.Builder(); sec.setUserRequired(true); sec.setPermissions(getReadScope(entity.getUserPerms(), type)); secs.add(sec.build()); seqs.add(new MApiSecurityReq(SecurityConsts.USER, sec.getPermissions())); } if(null != entity.getClientPerms()) { SimpleSecurity.Builder sec = new SimpleSecurity.Builder(); sec.setClientRequired(true); sec.setPermissions(getReadScope(entity.getClientPerms(), type)); secs.add(sec.build()); seqs.add(new MApiSecurityReq(SecurityConsts.CLIENT, sec.getPermissions())); } if(!secs.isEmpty()) { route.setSecurities(secs.toArray(new SimpleSecurity[0])); } if(!seqs.isEmpty()) { route.setExtension(MApiSecurityReq[].class, seqs.toArray(new MApiSecurityReq[0])); } } }
SimpleSecurity.Builder sec = new SimpleSecurity.Builder(); sec.setUserRequired(true); op.setSecurities(new SimpleSecurity[]{sec.build()}); SimpleSecurity.Builder sec = new SimpleSecurity.Builder(); sec.setUserRequired(true); sec.setPermissions(user.getPermissions()); secs.add(sec.build()); SimpleSecurity.Builder sec = new SimpleSecurity.Builder(); sec.setClientRequired(true); sec.setPermissions(client.getPermissions()); secs.add(sec.build());
static void withPermsForWrite(RestdModel model, RouteBuilder route, String type) { MetaEntity entity = (MetaEntity)model.getAttribute(MetaEntity.class.getName()); if(null != entity) { route.setExtension(entity); route.setAllowAnonymous(entity.getAnonymous()); List<SimpleSecurity> secs = new ArrayList<>(); List<MApiSecurityReq> seqs = new ArrayList<>(); if(null != entity.getUserPerms()) { SimpleSecurity.Builder sec = new SimpleSecurity.Builder(); sec.setUserRequired(true); sec.setPermissions(getWriteScope(entity.getUserPerms(), type)); secs.add(sec.build()); seqs.add(new MApiSecurityReq(SecurityConsts.USER, sec.getPermissions())); } if(null != entity.getClientPerms()) { SimpleSecurity.Builder sec = new SimpleSecurity.Builder(); sec.setClientRequired(true); sec.setPermissions(getWriteScope(entity.getClientPerms(), type)); secs.add(sec.build()); seqs.add(new MApiSecurityReq(SecurityConsts.CLIENT, sec.getPermissions())); } if(!secs.isEmpty()) { route.setSecurities(secs.toArray(new SimpleSecurity[0])); } if(!seqs.isEmpty()) { route.setExtension(MApiSecurityReq[].class, seqs.toArray(new MApiSecurityReq[0])); } } }