public MApiSecurityReq(String name, String[] scopes) { super(name); this.addScopes(scopes); }
public MApiOperationBuilder(Route route) { this.route = route; MApiSecurityReq[] securities = route.getExtension(MApiSecurityReq[].class); if(null != securities) { for(MApiSecurityReq security : securities) { this.security.put(security.getName(), security); } }else { if(!security.containsKey(SwaggerConstants.OAUTH2)){ MApiSecurityReq sec = new MApiSecurityReq(SwaggerConstants.OAUTH2); security.put(sec.getName(), sec); } if(route.getPermissions() != null){ security.get(SwaggerConstants.OAUTH2).addScopes(route.getPermissions()); } } if(null != route.getAllowAnonymous()) { this.allowAnonymous = route.getAllowAnonymous(); } if(null != route.getAllowClientOnly()){ this.allowClientOnly = route.getAllowClientOnly(); } this.extension = route.getExtension(MApiExtension.class); }
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])); } } }
public void addSecurityRequirement(MApiSecurityReq req) { this.security.put(req.getName(), req); }
security.forEach(sc->{ for(Map.Entry<String, Object> entry:sc.entrySet()){ MApiSecurityReq sec = new MApiSecurityReq(entry.getKey()); sec.addScopes(Collections2.toStringArray((Collection<String>)entry.getValue())); mo.getSecurity().put(sec.getName(),sec); break;
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])); } } }
op.setSecurities(new SimpleSecurity[]{sec.build()}); op.addSecurityRequirement(new MApiSecurityReq(SecurityConsts.USER)); }else { List<SimpleSecurity> secs = new ArrayList<>(); secs.add(sec.build()); op.addSecurityRequirement(new MApiSecurityReq(SecurityConsts.USER, user.getPermissions())); secs.add(sec.build()); op.addSecurityRequirement(new MApiSecurityReq(SecurityConsts.CLIENT, client.getPermissions()));