@Override protected Object authorize(Object object) { return ApiUtils.authorize(object); }
@Override protected Resource constructResource(final IdFormatter idFormatter, SchemaFactory schemaFactory, final Schema schema, Object obj, ApiRequest apiRequest) { return ApiUtils.createResourceWithAttachments(this, apiRequest, idFormatter, schemaFactory, schema, obj, new HashMap<String, Object>()); }
@Override protected String getUser(ApiRequest request, Object response) { return ApiUtils.getPolicy().getUserName(); }
protected ResourceDefinition newResource(String name, Include include) { ResourceDefinition def = new ResourceDefinition(name); if (include != null) { for (String link : include.getLinks()) { for (Object obj : getLinkInternal(def, link, null)) { ApiUtils.addAttachement(def, link, obj); } } } return def; }
public static String getAttachementKey(Object obj) { return getAttachementKey(obj, ObjectUtils.getId(obj)); }
public static Object getFirstFromList(Object obj) { if (obj instanceof Collection) { return getFirstFromList(((Collection) obj).getData()); } if (obj instanceof List) { List<?> list = (List<?>) obj; return list.size() > 0 ? list.get(0) : null; } return null; }
@Bean ConfigBasedHtmlTemplate ConfigBasedHtmlTemplate() { io.cattle.platform.api.html.ConfigBasedHtmlTemplate template = new ConfigBasedHtmlTemplate(); template.setSettings(new ApiSettings()); return template; }
@Override protected Schema getSchemaForDisplay(SchemaFactory schemaFactory, Object obj) { String schemaId = ApiUtils.getSchemaIdForDisplay(schemaFactory, obj); Schema schema = schemaFactory.getSchema(schemaId); if (schema == null) { /* Check core schema because the parent might not be authorized */ schemaId = ApiUtils.getSchemaIdForDisplay(getObjectManager().getSchemaFactory(), obj); /* Still get schema from request's schemaFactory */ schema = schemaFactory.getSchema(schemaId); } return schema; }
public static <T> List<T> authorize(List<T> list) { return getPolicy().authorizeList(list); }
@Override protected Resource constructResource(IdFormatter idFormatter, SchemaFactory schemaFactory, Schema schema, Object obj, ApiRequest apiRequest) { Map<String, Object> transitioningFields = metaDataManager.getTransitionFields(schema, obj); return ApiUtils.createResourceWithAttachments(this, apiRequest, idFormatter, schemaFactory, schema, obj, transitioningFields); }
@Override public Object transform(Object input) { input = ApiUtils.authorize(input); if (input == null) return null; return resourceManager.convertResponse(input, request); } });
private void validateInfraAccess(String type) { if (REG_TOKEN.equalsIgnoreCase(type) && !infraAccess.canModifyInfrastructure(ApiUtils.getPolicy())) { throw new ClientVisibleException(ResponseCodes.FORBIDDEN, "Forbidden", "Cannot access registrationToken", null); } } }
private void validateInfraAccess(ApiRequest request, String action) { if (!infraAccess.canModifyInfrastructure(ApiUtils.getPolicy())) { String message = String.format("Cannot %s machine", action); throw new ClientVisibleException(ResponseCodes.FORBIDDEN, "Forbidden", message, null); } } }
private void validateInfraAccess(ApiRequest request, String action) { if (!infraAccess.canModifyInfrastructure(ApiUtils.getPolicy())) { String message = String.format("Cannot %s host", action); throw new ClientVisibleException(ResponseCodes.FORBIDDEN, "Forbidden", message, null); } } }
private Stack validateInfraAccess(ApiRequest request, String action, Stack stack, Service service) { if (ObjectUtils.isSystem(stack) && !infraAccess.canModifyInfrastructure(ApiUtils.getPolicy())) { String message = String.format("Cannot %s system service", action); throw new ClientVisibleException(ResponseCodes.FORBIDDEN, "Forbidden", message, null); } return stack; } }
private void validateInfraAccess(ApiRequest request, Stack stack, String action) { if (stack.getSystem() && !infraAccess.canModifyInfrastructure(ApiUtils.getPolicy())) { String message = String.format("Cannot %s system stack", action); throw new ClientVisibleException(ResponseCodes.FORBIDDEN, "Forbidden", message, null); } }
private void validateInfraAccess(Object instance, String action) { if (ObjectUtils.isSystem(instance) && !infraAccess.canModifyInfrastructure(ApiUtils.getPolicy())) { String message = String.format("Cannot %s system container", action); throw new ClientVisibleException(ResponseCodes.FORBIDDEN, "Forbidden", message, null); } }
@Override public Object create(String type, ApiRequest request, ResourceManager next) { Policy policy = ApiUtils.getPolicy(); Agent agent = objectManager.loadResource(Agent.class, policy.getOption(Policy.AGENT_ID)); if (agent == null) { throw new ClientVisibleException(ResponseCodes.FORBIDDEN, VERIFY_AGENT); } return super.create(type, request, next); } }
protected Agent getAgent() { Agent agent = objectManager.loadResource(Agent.class, ApiUtils.getPolicy().getOption(Policy.AGENT_ID)); if (agent == null) { throw new ClientVisibleException(ResponseCodes.FORBIDDEN, VERIFY_AGENT); } return agentDao.getHostAgentForDelegate(agent.getId()); }