/** * Realizes the action to pull an artifact * * @return The operation's result */ protected XSPReply doPullArtifact() { Artifact artifact = input.poll(); if (artifact == null) return new XSPReplyApiError(ConnectionService.ERROR_EMPTY_QUEUE); return new XSPReplyResult<>(artifact); }
@Override public XSPReply setPolicy(String actionId, String policyDefinition) { ASTNode definition = JSONLDLoader.parseJSON(Logging.get(), policyDefinition); if (definition == null) return new XSPReplyApiError(HttpApiService.ERROR_CONTENT_PARSING_FAILED); SecuredActionPolicy policy = SecuredActionPolicyBase.load(definition); if (policy == null) return new XSPReplyApiError(HttpApiService.ERROR_CONTENT_PARSING_FAILED, "Invalid policy definition"); return setPolicy(actionId, policy); } }
/** * @param reader The reader to read from * @param resourceIRI The IRI for the resource to load * @param syntax The expected syntax * @return The reply */ public XSPReply load(Reader reader, String resourceIRI, String syntax) { BufferedLogger bufferedLogger = new BufferedLogger(); try { Collection<Quad> quads = load(bufferedLogger, reader, resourceIRI, syntax); if (quads == null || !bufferedLogger.getErrorMessages().isEmpty()) return new XSPReplyApiError(HttpApiService.ERROR_CONTENT_PARSING_FAILED, bufferedLogger.getErrorsAsString()); return new XSPReplyResultCollection<>(quads); } catch (TranslationException exception) { bufferedLogger.error(exception); return new XSPReplyApiError(HttpApiService.ERROR_CONTENT_PARSING_FAILED, bufferedLogger.getErrorsAsString()); } }
@Override public HttpResponse handle(SecurityService securityService, HttpApiRequest request) { if (!HttpConstants.METHOD_POST.equals(request.getMethod())) return new HttpResponse(HttpURLConnection.HTTP_BAD_METHOD, HttpConstants.MIME_TEXT_PLAIN, "Expected POST method"); byte[] content = request.getContent(); if (content == null || content.length == 0) return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_FAILED_TO_READ_CONTENT), null); BufferedLogger logger = new BufferedLogger(); ASTNode root = JSONLDLoader.parseJSON(logger, new String(content, IOUtils.CHARSET)); if (root == null) return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_CONTENT_PARSING_FAILED, logger.getErrorsAsString()), null); return XSPReplyUtils.toHttpResponse(perform(new XOWLImpactAnalysisSetup(root)), null); }
for (Addon addon : addons) { if (Objects.equals(addon.getIdentifier(), identifier)) return new XSPReplyApiError(ERROR_ADDON_ALREADY_INSTALLED); if (!directory.mkdirs()) { Logging.get().error("Failed to create directory " + directory.getAbsolutePath()); return new XSPReplyApiError(ERROR_INVALID_ADDON_PACKAGE, "Failed to unpack the addon."); } catch (IOException exception) { Logging.get().error(exception); return new XSPReplyApiError(ERROR_INVALID_ADDON_PACKAGE, "Failed to unpack the addon."); return new XSPReplyApiError(ERROR_INVALID_ADDON_PACKAGE, "No descriptor found."); if (definition == null) { IOUtils.deleteFolder(directory); return new XSPReplyApiError(ERROR_INVALID_ADDON_PACKAGE, "Failed to read the descriptor."); Logging.get().error(exception); IOUtils.deleteFolder(directory); return new XSPReplyApiError(ERROR_INVALID_ADDON_PACKAGE, "Failed to read the descriptor."); return new XSPReplyApiError(ERROR_INVALID_ADDON_PACKAGE, "Descriptor does not match the provided identifier."); if (!fileBundle.exists()) { IOUtils.deleteFolder(directory); return new XSPReplyApiError(ERROR_INVALID_ADDON_PACKAGE, "Addon package does not contain bundle " + fileBundle.getName());
@Override public XSPReply unassignRoleToGroup(String group, String role) { // check input data PlatformGroup groupObj = getGroup(group); if (groupObj == null) return new XSPReplyApiError(ERROR_INVALID_GROUP, group); PlatformRole roleObj = getRole(role); if (roleObj == null) return new XSPReplyApiError(ERROR_INVALID_ROLE, role); // check for current user with admin role SecurityService securityService = Register.getComponent(SecurityService.class); if (securityService == null) return XSPReplyServiceUnavailable.instance(); XSPReply reply = securityService.getPolicy().checkAction(securityService, SecurityService.ACTION_UNASSIGN_ROLE_TO_GROUP); if (!reply.isSuccess()) return reply; // execute Map<String, Node> parameters = new HashMap<>(); parameters.put("entity", nodes.getIRINode(GROUPS + group)); parameters.put("role", nodes.getIRINode(ROLES + role)); reply = database.executeStoredProcedure(procedures.get("procedure-unassign-role"), new BaseStoredProcedureContext(Collections.<String>emptyList(), Collections.<String>emptyList(), parameters)); if (!reply.isSuccess()) return reply; return XSPReplySuccess.instance(); }
String contentType = request.getContentType(); if (name == null) return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_QUERY_PARAMETERS, "'name'"), null); if (base == null) return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_QUERY_PARAMETERS, "'base'"), null); if (version == null) return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_QUERY_PARAMETERS, "'version'"), null); if (archetype == null) return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_QUERY_PARAMETERS, "'archetype'"), null); if (contentType == null || contentType.isEmpty()) return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_HEADER_CONTENT_TYPE), null); int index = contentType.indexOf(";"); if (index != -1)
@Override public XSPReply addAdminToGroup(String user, String group) { // check input data PlatformGroup groupObject = getGroup(group); if (groupObject == null) return new XSPReplyApiError(ERROR_INVALID_GROUP, group); PlatformUser newUser = getUser(user); if (newUser == null) return new XSPReplyApiError(ERROR_INVALID_USER, user); // check the current user is either the platform admin or the group admin SecurityService securityService = Register.getComponent(SecurityService.class); if (securityService == null) return XSPReplyServiceUnavailable.instance(); XSPReply reply = securityService.getPolicy().checkAction(securityService, SecurityService.ACTION_ADD_ADMIN_TO_GROUP, groupObject); if (!reply.isSuccess()) return reply; // execute Map<String, Node> parameters = new HashMap<>(); parameters.put("group", nodes.getIRINode(GROUPS + group)); parameters.put("admin", nodes.getIRINode(USERS + user)); reply = database.executeStoredProcedure(procedures.get("procedure-add-admin"), new BaseStoredProcedureContext(Collections.<String>emptyList(), Collections.<String>emptyList(), parameters)); if (!reply.isSuccess()) return reply; return XSPReplySuccess.instance(); }
@Override public XSPReply assignRoleToUser(String user, String role) { // check input data PlatformUser userObj = getUser(user); if (userObj == null) return new XSPReplyApiError(ERROR_INVALID_USER, user); PlatformRole roleObj = getRole(role); if (roleObj == null) return new XSPReplyApiError(ERROR_INVALID_ROLE, role); // check for current user with admin role SecurityService securityService = Register.getComponent(SecurityService.class); if (securityService == null) return XSPReplyServiceUnavailable.instance(); XSPReply reply = securityService.getPolicy().checkAction(securityService, SecurityService.ACTION_ASSIGN_ROLE_TO_USER); if (!reply.isSuccess()) return reply; // execute Map<String, Node> parameters = new HashMap<>(); parameters.put("entity", nodes.getIRINode(USERS + user)); parameters.put("role", nodes.getIRINode(ROLES + role)); reply = database.executeStoredProcedure(procedures.get("procedure-assign-role"), new BaseStoredProcedureContext(Collections.<String>emptyList(), Collections.<String>emptyList(), parameters)); if (!reply.isSuccess()) return reply; return XSPReplySuccess.instance(); }
@Override public XSPReply removeAdminFromGroup(String user, String group) { // check input data PlatformGroup groupObject = getGroup(group); if (groupObject == null) return new XSPReplyApiError(ERROR_INVALID_GROUP, group); PlatformUser newUser = getUser(user); if (newUser == null) return new XSPReplyApiError(ERROR_INVALID_USER, user); // check the current user is either the platform admin or the group admin SecurityService securityService = Register.getComponent(SecurityService.class); if (securityService == null) return XSPReplyServiceUnavailable.instance(); XSPReply reply = securityService.getPolicy().checkAction(securityService, SecurityService.ACTION_REMOVE_ADMIN_FROM_GROUP, groupObject); if (!reply.isSuccess()) return reply; // execute Map<String, Node> parameters = new HashMap<>(); parameters.put("group", nodes.getIRINode(GROUPS + group)); parameters.put("admin", nodes.getIRINode(USERS + user)); reply = database.executeStoredProcedure(procedures.get("procedure-remove-admin"), new BaseStoredProcedureContext(Collections.<String>emptyList(), Collections.<String>emptyList(), parameters)); if (!reply.isSuccess()) return reply; return XSPReplySuccess.instance(); }
@Override public XSPReply unassignRoleToUser(String user, String role) { // check input data PlatformUser userObj = getUser(user); if (userObj == null) return new XSPReplyApiError(ERROR_INVALID_USER, user); PlatformRole roleObj = getRole(role); if (roleObj == null) return new XSPReplyApiError(ERROR_INVALID_ROLE, role); // check for current user with admin role SecurityService securityService = Register.getComponent(SecurityService.class); if (securityService == null) return XSPReplyServiceUnavailable.instance(); XSPReply reply = securityService.getPolicy().checkAction(securityService, SecurityService.ACTION_UNASSIGN_ROLE_TO_USER); if (!reply.isSuccess()) return reply; // execute Map<String, Node> parameters = new HashMap<>(); parameters.put("entity", nodes.getIRINode(USERS + user)); parameters.put("role", nodes.getIRINode(ROLES + role)); reply = database.executeStoredProcedure(procedures.get("procedure-unassign-role"), new BaseStoredProcedureContext(Collections.<String>emptyList(), Collections.<String>emptyList(), parameters)); if (!reply.isSuccess()) return reply; return XSPReplySuccess.instance(); }
@Override public XSPReply addUserToGroup(String user, String group) { // check input data PlatformGroup groupObject = getGroup(group); if (groupObject == null) return new XSPReplyApiError(ERROR_INVALID_GROUP, group); PlatformUser newUser = getUser(user); if (newUser == null) return new XSPReplyApiError(ERROR_INVALID_USER, user); // check the current user is either the platform admin or the group admin SecurityService securityService = Register.getComponent(SecurityService.class); if (securityService == null) return XSPReplyServiceUnavailable.instance(); XSPReply reply = securityService.getPolicy().checkAction(securityService, SecurityService.ACTION_ADD_USER_TO_GROUP, groupObject); if (!reply.isSuccess()) return reply; // execute Map<String, Node> parameters = new HashMap<>(); parameters.put("group", nodes.getIRINode(GROUPS + group)); parameters.put("user", nodes.getIRINode(USERS + user)); reply = database.executeStoredProcedure(procedures.get("procedure-add-member"), new BaseStoredProcedureContext(Collections.<String>emptyList(), Collections.<String>emptyList(), parameters)); if (!reply.isSuccess()) return reply; return XSPReplySuccess.instance(); }
@Override public XSPReply removeUserFromGroup(String user, String group) { // check input data PlatformGroup groupObject = getGroup(group); if (groupObject == null) return new XSPReplyApiError(ERROR_INVALID_GROUP, group); PlatformUser newUser = getUser(user); if (newUser == null) return new XSPReplyApiError(ERROR_INVALID_USER, user); // check the current user is either the platform admin or the group admin SecurityService securityService = Register.getComponent(SecurityService.class); if (securityService == null) return XSPReplyServiceUnavailable.instance(); XSPReply reply = securityService.getPolicy().checkAction(securityService, SecurityService.ACTION_REMOVE_USER_FROM_GROUP, groupObject); if (!reply.isSuccess()) return reply; // execute Map<String, Node> parameters = new HashMap<>(); parameters.put("group", nodes.getIRINode(GROUPS + group)); parameters.put("user", nodes.getIRINode(USERS + user)); reply = database.executeStoredProcedure(procedures.get("procedure-remove-member"), new BaseStoredProcedureContext(Collections.<String>emptyList(), Collections.<String>emptyList(), parameters)); if (!reply.isSuccess()) return reply; return XSPReplySuccess.instance(); }
@Override public XSPReply assignRoleToGroup(String group, String role) { // check input data PlatformGroup groupObj = getGroup(group); if (groupObj == null) return new XSPReplyApiError(ERROR_INVALID_GROUP, group); PlatformRole roleObj = getRole(role); if (roleObj == null) return new XSPReplyApiError(ERROR_INVALID_ROLE, role); // check for current user with admin role SecurityService securityService = Register.getComponent(SecurityService.class); if (securityService == null) return XSPReplyServiceUnavailable.instance(); XSPReply reply = securityService.getPolicy().checkAction(securityService, SecurityService.ACTION_ASSIGN_ROLE_TO_GROUP); if (!reply.isSuccess()) return reply; // execute Map<String, Node> parameters = new HashMap<>(); parameters.put("entity", nodes.getIRINode(GROUPS + group)); parameters.put("role", nodes.getIRINode(ROLES + role)); reply = database.executeStoredProcedure(procedures.get("procedure-assign-role"), new BaseStoredProcedureContext(Collections.<String>emptyList(), Collections.<String>emptyList(), parameters)); if (!reply.isSuccess()) return reply; return XSPReplySuccess.instance(); }
if (service != null) return new XSPReplyApiError(ERROR_CONNECTOR_SAME_ID); return new XSPReplyApiError(ERROR_NO_FACTORY);
@Override public XSPReply renameUser(String identifier, String name) { // check authorization SecurityService securityService = Register.getComponent(SecurityService.class); if (securityService == null) return XSPReplyServiceUnavailable.instance(); PlatformUser userObject = getUser(identifier); if (userObject == null) return new XSPReplyApiError(ERROR_INVALID_USER, identifier); XSPReply reply = securityService.getPolicy().checkAction(securityService, SecurityService.ACTION_RENAME_USER, userObject); if (!reply.isSuccess()) return reply; synchronized (cacheUsers) { Map<String, Node> parameters = new HashMap<>(); parameters.put("entity", nodes.getIRINode(USERS + identifier)); parameters.put("newName", nodes.getLiteralNode(name, Vocabulary.xsdString, null)); reply = database.executeStoredProcedure(procedures.get("procedure-rename-entity"), new BaseStoredProcedureContext(Collections.<String>emptyList(), Collections.<String>emptyList(), parameters)); if (!reply.isSuccess()) return reply; cacheUsers.remove(identifier); return XSPReplySuccess.instance(); } }
@Override public XSPReply renameGroup(String identifier, String name) { // check authorization SecurityService securityService = Register.getComponent(SecurityService.class); if (securityService == null) return XSPReplyServiceUnavailable.instance(); PlatformGroup groupObject = getGroup(identifier); if (groupObject == null) return new XSPReplyApiError(ERROR_INVALID_GROUP, identifier); XSPReply reply = securityService.getPolicy().checkAction(securityService, SecurityService.ACTION_RENAME_GROUP, groupObject); if (!reply.isSuccess()) return reply; synchronized (cacheGroups) { // rename the entity Map<String, Node> parameters = new HashMap<>(); parameters.put("entity", nodes.getIRINode(GROUPS + identifier)); parameters.put("newName", nodes.getLiteralNode(name, Vocabulary.xsdString, null)); reply = database.executeStoredProcedure(procedures.get("procedure-rename-entity"), new BaseStoredProcedureContext(Collections.<String>emptyList(), Collections.<String>emptyList(), parameters)); if (!reply.isSuccess()) return reply; cacheGroups.remove(identifier); return XSPReplySuccess.instance(); } }
@Override public XSPReply renameRole(String identifier, String name) { // check authorization SecurityService securityService = Register.getComponent(SecurityService.class); if (securityService == null) return XSPReplyServiceUnavailable.instance(); PlatformRole roleObject = getRole(identifier); if (roleObject == null) return new XSPReplyApiError(ERROR_INVALID_ROLE, identifier); XSPReply reply = securityService.getPolicy().checkAction(securityService, SecurityService.ACTION_RENAME_ROLE, roleObject); if (!reply.isSuccess()) return reply; synchronized (cacheRoles) { // rename the entity Map<String, Node> parameters = new HashMap<>(); parameters.put("entity", nodes.getIRINode(ROLES + identifier)); parameters.put("newName", nodes.getLiteralNode(name, Vocabulary.xsdString, null)); reply = database.executeStoredProcedure(procedures.get("procedure-rename-entity"), new BaseStoredProcedureContext(Collections.<String>emptyList(), Collections.<String>emptyList(), parameters)); if (!reply.isSuccess()) return reply; cacheRoles.remove(identifier); return XSPReplySuccess.instance(); } }
return new XSPReplyApiError(ERROR_ADDON_NOT_INSTALLED);
String descriptorId = request.getParameter("descriptor"); if (descriptorId == null) return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_EXPECTED_QUERY_PARAMETERS, "'descriptor'"), null); String content = new String(request.getContent(), IOUtils.CHARSET); if (content.isEmpty()) return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_FAILED_TO_READ_CONTENT), null); return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_CONTENT_PARSING_FAILED, logger.getErrorsAsString()), null); return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_PARAMETER_RANGE, "'descriptor' is not the identifier of a recognized connector descriptor"), null); ConnectorServiceData specification = new ConnectorServiceData(descriptor, root); if (!specification.getIdentifier().equals(connectorId)) return XSPReplyUtils.toHttpResponse(new XSPReplyApiError(ERROR_PARAMETER_RANGE, "'identifier' is not the same as URI parameter"), null); XSPReply reply = spawn(descriptor, specification); if (!reply.isSuccess())