List of usage examples for java.security AccessControlException AccessControlException
public AccessControlException(String s)
From source file:servlets.Analysis_servlets.java
private void lock_analysis_handler(HttpServletRequest request, HttpServletResponse response) throws IOException { boolean alreadyLocked = false; String locker_id = ""; ArrayList<String> notLockedSteps = new ArrayList<String>(); try {/*w w w. ja va2s . co m*/ JsonParser parser = new JsonParser(); JsonObject requestData = (JsonObject) parser.parse(request.getReader()); String loggedUser = requestData.get("loggedUser").getAsString(); String sessionToken = requestData.get("sessionToken").getAsString(); /** * ******************************************************* * STEP 1 CHECK IF THE USER IS LOGGED CORRECTLY IN THE APP. IF ERROR * --> throws exception if not valid session, GO TO STEP ELSE --> GO * TO STEP 2 ******************************************************* */ if (!checkAccessPermissions(loggedUser, sessionToken)) { throw new AccessControlException("Your session is invalid. User or session token not allowed."); } /** * ******************************************************* * STEP 2 GET THE OBJECT ID AND TRY TO LOCK IT. IF ERROR --> throws * exception, GO TO STEP ELSE --> GO TO STEP 3 * ******************************************************* */ String analysis_id = requestData.get("analysis_id").getAsString(); alreadyLocked = !BlockedElementsManager.getBlockedElementsManager().lockObject(analysis_id, loggedUser); /** * ******************************************************* * STEP 3 TRY TO LOCK THE STEPS. exception, GO TO STEP ELSE --> GO * TO STEP 3 ******************************************************* */ if (!alreadyLocked) { DAO dao_instance = DAOProvider.getDAOByName("Analysis"); boolean loadRecursive = true; Object[] params = { loadRecursive }; Analysis analysis = (Analysis) dao_instance.findByID(analysis_id, params); dao_instance.closeConnection(); String step_id; for (Step step : analysis.getNonProcessedData()) { step_id = step.getStepID(); if (!BlockedElementsManager.getBlockedElementsManager().lockObject(step_id, loggedUser)) { notLockedSteps.add(step_id); } } for (Step step : analysis.getProcessedData()) { step_id = step.getStepID(); if (!BlockedElementsManager.getBlockedElementsManager().lockObject(step_id, loggedUser)) { notLockedSteps.add(step_id); } } //UNLOCK STEPS AND ANALYSIS if (notLockedSteps.size() > 0) { BlockedElementsManager.getBlockedElementsManager().unlockObject(analysis_id, loggedUser); for (Step step : analysis.getNonProcessedData()) { BlockedElementsManager.getBlockedElementsManager().unlockObject(step.getStepID(), loggedUser); } for (Step step : analysis.getProcessedData()) { BlockedElementsManager.getBlockedElementsManager().unlockObject(step.getStepID(), loggedUser); } } } else { locker_id = BlockedElementsManager.getBlockedElementsManager().getLockerID(analysis_id); } } catch (Exception e) { ServerErrorManager.handleException(e, Analysis_servlets.class.getName(), "lock_analysis_handler", e.getMessage()); } finally { /** * ******************************************************* * STEP 4b CATCH ERROR. GO TO STEP 5 * ******************************************************* */ if (ServerErrorManager.errorStatus()) { response.setStatus(400); response.getWriter().print(ServerErrorManager.getErrorResponse()); } else { /** * ******************************************************* * STEP 3A WRITE RESPONSE . * ******************************************************* */ JsonObject obj = new JsonObject(); if (alreadyLocked) { obj.add("success", new JsonPrimitive(false)); obj.add("reason", new JsonPrimitive(BlockedElementsManager.getErrorMessage())); obj.add("user_id", new JsonPrimitive(locker_id)); } else if (notLockedSteps.size() > 0) { JsonArray _notLockedSteps = new JsonArray(); obj.add("success", new JsonPrimitive(false)); obj.add("reason", new JsonPrimitive("Some of the steps are locked by other users")); for (String step_id : notLockedSteps) { _notLockedSteps.add(new JsonPrimitive(step_id)); } obj.add("notLockedSteps", _notLockedSteps); } else { obj.add("success", new JsonPrimitive(true)); } response.getWriter().print(obj.toString()); } } }
From source file:servlets.Samples_servlets.java
private void remove_biocondition_handler(HttpServletRequest request, HttpServletResponse response) throws IOException { try {//from w ww .j a va 2 s.com String biocondition_id = ""; String loggedUser = ""; boolean ROLLBACK_NEEDED = false; DAO dao_instance = null; try { JsonParser parser = new JsonParser(); JsonObject requestData = (JsonObject) parser.parse(request.getReader()); loggedUser = requestData.get("loggedUser").getAsString(); String loggedUserID = requestData.get("loggedUserID").getAsString(); String sessionToken = requestData.get("sessionToken").getAsString(); /** * ******************************************************* * STEP 1 CHECK IF THE USER IS LOGGED CORRECTLY IN THE APP. IF * ERROR --> throws exception if not valid session, GO TO STEP * 4b ELSE --> GO TO STEP 2 * ******************************************************* */ if (!checkAccessPermissions(loggedUser, sessionToken)) { throw new AccessControlException("Your session is invalid. User or session token not allowed."); } /** * ******************************************************* * STEP 2 Try to lock the Object . IF FAILED --> throws * exception, GO TO STEP 3b ELSE --> GO TO STEP 3 * ******************************************************* */ biocondition_id = requestData.get("biocondition_id").getAsString(); boolean alreadyLocked = !BlockedElementsManager.getBlockedElementsManager() .lockObject(biocondition_id, loggedUserID); if (alreadyLocked) { String locker_id = BlockedElementsManager.getBlockedElementsManager() .getLockerID(biocondition_id); if (!locker_id.equals(loggedUser)) { throw new Exception( "Sorry but this biological condition is being edited by other user. Please try later."); } } dao_instance = DAOProvider.getDAOByName("Biocondition"); dao_instance.disableAutocommit(); ROLLBACK_NEEDED = true; boolean loadRecursive = true; Object[] params = { loadRecursive }; BioCondition bioCondition = (BioCondition) dao_instance.findByID(biocondition_id, params); //Check if user is member or owner if (bioCondition.isOwner(loggedUserID) || "admin".equals(loggedUserID)) { if (bioCondition.getOwners().length == 1 || "admin".equals(loggedUserID)) { //If is the last owner or the admin, remove the entire experiment dao_instance.remove(biocondition_id); } else { //else just remove the entry in the table of ownerships ((BioCondition_JDBCDAO) dao_instance).removeOwnership(loggedUserID, biocondition_id); } } /** * ******************************************************* * STEP 9 COMMIT CHANGES TO DATABASE. throws SQLException IF * ERROR --> throws SQL Exception, GO TO STEP ? ELSE --> GO TO * STEP 10 * ******************************************************* */ dao_instance.doCommit(); } catch (Exception e) { if (e.getClass().getSimpleName().equals("MySQLIntegrityConstraintViolationException")) { ServerErrorManager.handleException(null, null, null, "Unable to remove the selected Biocondition.</br>This Biocondition contains one or more Analytical samples that are being used by some Raw data.</br>Remove first those Raw data and try again later."); } else if (e.getClass().getSimpleName().equals("AccessControlException")) { ServerErrorManager.handleException(null, null, null, e.getMessage()); } else { ServerErrorManager.handleException(e, Samples_servlets.class.getName(), "remove_biocondition_handler", e.getMessage()); } } finally { /** * ******************************************************* * STEP 4b CATCH ERROR. GO TO STEP 5 * ******************************************************* */ if (ServerErrorManager.errorStatus()) { response.setStatus(400); response.getWriter().print(ServerErrorManager.getErrorResponse()); if (ROLLBACK_NEEDED) { dao_instance.doRollback(); } } else { JsonObject obj = new JsonObject(); obj.add("success", new JsonPrimitive(true)); response.getWriter().print(obj.toString()); } BlockedElementsManager.getBlockedElementsManager().unlockObject(biocondition_id, loggedUser); /** * ******************************************************* * STEP 11 Close connection. * ******************************************************** */ if (dao_instance != null) { dao_instance.closeConnection(); } } //CATCH IF THE ERROR OCCURRED IN ROLL BACK OR CONNECTION CLOSE } catch (Exception e) { ServerErrorManager.handleException(e, Samples_servlets.class.getName(), "remove_biocondition_handler", e.getMessage()); response.setStatus(400); response.getWriter().print(ServerErrorManager.getErrorResponse()); } }
From source file:xtremweb.dispatcher.HTTPHandler.java
/** * @param login is the new user login/*ww w . j av a 2s .c o m*/ * @param emailaddr is the new user email address * @return a new user * @throws IOException * @throws AccessControlException * @throws InvalidKeyException * @throws NoSuchAlgorithmException * @since 11.0.0 */ private UserInterface newUser(String login, final String emailaddr) throws IOException, InvalidKeyException, AccessControlException, NoSuchAlgorithmException { if (!Dispatcher.getConfig().getBoolean(XWPropertyDefs.DELEGATEDREGISTRATION)) { throw new AccessControlException("DELEGATEDREGISTRATION is not allowed"); } final UserInterface admin = Dispatcher.getConfig().getProperty(XWPropertyDefs.ADMINLOGIN) == null ? null : DBInterface.getInstance() .user(SQLRequest.MAINTABLEALIAS + "." + UserInterface.Columns.LOGIN.toString() + "='" + Dispatcher.getConfig().getProperty(XWPropertyDefs.ADMINLOGIN) + "'"); if (admin == null) { throw new AccessControlException("can't insert new OAuth user"); } final String random = emailaddr + System.currentTimeMillis() + Math.random(); final String shastr = XWTools.sha256(random); final UserInterface client = new UserInterface(); client.setUID(new UID()); client.setOwner(Dispatcher.getConfig().getAdminUid()); client.setLogin(login); client.setPassword(shastr); client.setRights(UserRightEnum.STANDARD_USER); client.setEMail(emailaddr); DBInterface.getInstance().addUser(admin, client); return client; }
From source file:servlets.Analysis_servlets.java
private void unlock_analysis_handler(HttpServletRequest request, HttpServletResponse response) throws IOException { boolean alreadyUnlocked = false; ArrayList<String> notUnlockedSteps = new ArrayList<String>(); try {/*from ww w. j a v a2s . c om*/ JsonParser parser = new JsonParser(); JsonObject requestData = (JsonObject) parser.parse(request.getReader()); String loggedUser = requestData.get("loggedUser").getAsString(); String sessionToken = requestData.get("sessionToken").getAsString(); /** * ******************************************************* * STEP 1 CHECK IF THE USER IS LOGGED CORRECTLY IN THE APP. IF ERROR * --> throws exception if not valid session, GO TO STEP ELSE --> GO * TO STEP 2 ******************************************************* */ if (!checkAccessPermissions(loggedUser, sessionToken)) { throw new AccessControlException("Your session is invalid. User or session token not allowed."); } /** * ******************************************************* * STEP 2 GET THE OBJECT ID AND TRY TO UNLOCK IT. IF ERROR --> * throws exception, GO TO STEP ELSE --> GO TO STEP 3 * ******************************************************* */ String analysis_id = requestData.get("analysis_id").getAsString(); alreadyUnlocked = !BlockedElementsManager.getBlockedElementsManager().unlockObject(analysis_id, loggedUser); /** * ******************************************************* * STEP 3 TRY TO UNLOCK THE STEPS. exception, GO TO STEP ELSE --> GO * TO STEP 3 ******************************************************* */ DAO dao_instance = DAOProvider.getDAOByName("Analysis"); boolean loadRecursive = true; Object[] params = { loadRecursive }; Analysis analysis = (Analysis) dao_instance.findByID(analysis_id, params); dao_instance.closeConnection(); if (analysis != null) { String step_id; for (Step step : analysis.getNonProcessedData()) { step_id = step.getStepID(); if (!BlockedElementsManager.getBlockedElementsManager().unlockObject(step_id, loggedUser)) { notUnlockedSteps.add(step_id); } } for (Step step : analysis.getProcessedData()) { step_id = step.getStepID(); if (!BlockedElementsManager.getBlockedElementsManager().unlockObject(step_id, loggedUser)) { notUnlockedSteps.add(step_id); } } } } catch (Exception e) { ServerErrorManager.handleException(e, Analysis_servlets.class.getName(), "unlock_analysis_handler", e.getMessage()); } finally { /** * ******************************************************* * STEP 3b CATCH ERROR. * ******************************************************* */ if (ServerErrorManager.errorStatus()) { response.setStatus(400); response.getWriter().print(ServerErrorManager.getErrorResponse()); } else { /** * ******************************************************* * STEP 3A WRITE RESPONSE . * ******************************************************* */ JsonObject obj = new JsonObject(); if (alreadyUnlocked) { obj.add("success", new JsonPrimitive(false)); obj.add("reason", new JsonPrimitive(BlockedElementsManager.getErrorMessage())); } else { obj.add("success", new JsonPrimitive(true)); if (notUnlockedSteps.size() > 0) { JsonArray _notUnlockedSteps = new JsonArray(); for (String step_id : notUnlockedSteps) { _notUnlockedSteps.add(new JsonPrimitive(step_id)); } obj.add("notUnlockedSteps", _notUnlockedSteps); } } response.getWriter().print(obj.toString()); } } }
From source file:servlets.Samples_servlets.java
/** * This function returns all the bioreplicates stored in the DB for a given * BioReplicateID/* w w w .j a va2 s . co m*/ * * * @param request * @param response * @throws ServletException * @throws IOException */ private void get_all_bioreplicates_handler(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { DAO dao_instance = null; ArrayList<Object> bioreplicatesList = null; try { /** * ******************************************************* * STEP 1 CHECK IF THE USER IS LOGGED CORRECTLY IN THE APP. IF * ERROR --> throws exception if not valid session, GO TO STEP * 5b ELSE --> GO TO STEP 2 * ******************************************************* */ if (!checkAccessPermissions(request.getParameter("loggedUser"), request.getParameter("sessionToken"))) { throw new AccessControlException("Your session is invalid. User or session token not allowed."); } /** * ******************************************************* * STEP 2 Get ALL THE Object from DB. IF ERROR --> throws MySQL * exception, GO TO STEP 3b ELSE --> GO TO STEP 3 * ******************************************************* */ dao_instance = DAOProvider.getDAOByName("Bioreplicate"); String biocondition_id = request.getParameter("biocondition_id"); boolean loadRecursive = false; Object[] params = { biocondition_id, loadRecursive }; bioreplicatesList = dao_instance.findAll(params); } catch (Exception e) { ServerErrorManager.handleException(e, Samples_servlets.class.getName(), "get_all_bioreplicates_handler", e.getMessage()); } finally { /** * ******************************************************* * STEP 3b CATCH ERROR. GO TO STEP 4 * ******************************************************* */ if (ServerErrorManager.errorStatus()) { response.setStatus(400); response.getWriter().print(ServerErrorManager.getErrorResponse()); } else { /** * ******************************************************* * STEP 3A WRITE RESPONSE ERROR. GO TO STEP 4 * ******************************************************* */ String bioreplicatesJSON = "bioreplicatesList : ["; for (Object bioreplicate : bioreplicatesList) { bioreplicatesJSON += ((Bioreplicate) bioreplicate).toJSON() + ", "; } bioreplicatesJSON += "]"; response.getWriter().print("{success: " + true + ", " + bioreplicatesJSON + " }"); } /** * ******************************************************* * STEP 4 Close connection. * ******************************************************** */ if (dao_instance != null) { dao_instance.closeConnection(); } } //CATCH IF THE ERROR OCCURRED IN ROLL BACK OR CONNECTION CLOSE } catch (Exception e) { ServerErrorManager.handleException(e, Samples_servlets.class.getName(), "get_all_bioreplicates_handler", e.getMessage()); response.setStatus(400); response.getWriter().print(ServerErrorManager.getErrorResponse()); } }
From source file:org.apache.hadoop.yarn.server.resourcemanager.ClientRMService.java
private void handleNoAccess(String name, String queue, String auditConstant, String acl, String op) throws YarnException { RMAuditLogger.logFailure(name, auditConstant, "User doesn't have permissions to " + acl, "ClientRMService", auditConstant);//from w w w . j av a 2s . co m throw RPCUtil.getRemoteException(new AccessControlException( "User " + name + " cannot perform operation " + op + " on queue " + queue)); }
From source file:org.apache.hadoop.yarn.server.resourcemanager.ClientRMService.java
@Override public UpdateApplicationPriorityResponse updateApplicationPriority(UpdateApplicationPriorityRequest request) throws YarnException, IOException { ApplicationId applicationId = request.getApplicationId(); Priority newAppPriority = request.getApplicationPriority(); UserGroupInformation callerUGI;// w ww.ja v a 2s.co m try { callerUGI = UserGroupInformation.getCurrentUser(); } catch (IOException ie) { LOG.info("Error getting UGI ", ie); RMAuditLogger.logFailure("UNKNOWN", AuditConstants.UPDATE_APP_PRIORITY, "UNKNOWN", "ClientRMService", "Error getting UGI", applicationId); throw RPCUtil.getRemoteException(ie); } RMApp application = this.rmContext.getRMApps().get(applicationId); if (application == null) { RMAuditLogger.logFailure(callerUGI.getUserName(), AuditConstants.UPDATE_APP_PRIORITY, "UNKNOWN", "ClientRMService", "Trying to update priority of an absent application", applicationId); throw new ApplicationNotFoundException( "Trying to update priority of an absent application " + applicationId); } if (!checkAccess(callerUGI, application.getUser(), ApplicationAccessType.MODIFY_APP, application)) { RMAuditLogger.logFailure(callerUGI.getShortUserName(), AuditConstants.UPDATE_APP_PRIORITY, "User doesn't have permissions to " + ApplicationAccessType.MODIFY_APP.toString(), "ClientRMService", AuditConstants.UNAUTHORIZED_USER, applicationId); throw RPCUtil.getRemoteException( new AccessControlException("User " + callerUGI.getShortUserName() + " cannot perform operation " + ApplicationAccessType.MODIFY_APP.name() + " on " + applicationId)); } UpdateApplicationPriorityResponse response = recordFactory .newRecordInstance(UpdateApplicationPriorityResponse.class); // Update priority only when app is tracked by the scheduler if (!ACTIVE_APP_STATES.contains(application.getState())) { if (COMPLETED_APP_STATES.contains(application.getState())) { // If Application is in any of the final states, change priority // can be skipped rather throwing exception. RMAuditLogger.logSuccess(callerUGI.getShortUserName(), AuditConstants.UPDATE_APP_PRIORITY, "ClientRMService", applicationId); response.setApplicationPriority(application.getApplicationSubmissionContext().getPriority()); return response; } String msg = "Application in " + application.getState() + " state cannot update priority."; RMAuditLogger.logFailure(callerUGI.getShortUserName(), AuditConstants.UPDATE_APP_PRIORITY, "UNKNOWN", "ClientRMService", msg); throw new YarnException(msg); } try { rmContext.getScheduler().updateApplicationPriority(newAppPriority, applicationId); } catch (YarnException ex) { RMAuditLogger.logFailure(callerUGI.getShortUserName(), AuditConstants.UPDATE_APP_PRIORITY, "UNKNOWN", "ClientRMService", ex.getMessage()); throw ex; } RMAuditLogger.logSuccess(callerUGI.getShortUserName(), AuditConstants.UPDATE_APP_PRIORITY, "ClientRMService", applicationId); response.setApplicationPriority(application.getApplicationSubmissionContext().getPriority()); return response; }
From source file:servlets.Samples_servlets.java
/** * */*from ww w . j a v a2 s . c o m*/ * * @param request * @param response * @throws IOException */ private void export_samples_handler(HttpServletRequest request, HttpServletResponse response) throws IOException { try { DAO dao_instance = null; BioCondition biocondition = null; String tmpFile = ""; Path tmpDir = null; try { String format = request.getParameter("format"); if (format == null) { format = "json"; } Map<String, Cookie> cookies = this.getCookies(request); String loggedUser, sessionToken; loggedUser = cookies.get("loggedUser").getValue(); sessionToken = cookies.get("sessionToken").getValue(); /** * ******************************************************* * STEP 1 CHECK IF THE USER IS LOGGED CORRECTLY IN THE APP. IF * ERROR --> throws exception if not valid session, GO TO STEP * 5b ELSE --> GO TO STEP 2 * ******************************************************* */ if (!checkAccessPermissions(loggedUser, sessionToken)) { throw new AccessControlException("Your session is invalid. User or session token not allowed."); } /** * ******************************************************* * STEP 2 Get THE ANALYSIS Object from DB. IF ERROR --> throws * MySQL exception, GO TO STEP 3b ELSE --> GO TO STEP 3 * ******************************************************* */ dao_instance = DAOProvider.getDAOByName("Biocondition"); boolean loadRecursive = true; Object[] params = { loadRecursive }; String biocondition_id = request.getParameter("biocondition_id"); biocondition = (BioCondition) dao_instance.findByID(biocondition_id, params); tmpDir = Files.createTempDirectory(null); tmpFile = biocondition.export(tmpDir.toString(), format, this.getServletContext().getRealPath("/data/templates")); } catch (Exception e) { ServerErrorManager.handleException(e, Analysis_servlets.class.getName(), "export_samples_handler", e.getMessage()); } finally { /** * ******************************************************* * STEP 3b CATCH ERROR. GO TO STEP 4 * ******************************************************* */ if (ServerErrorManager.errorStatus()) { response.setStatus(400); response.getWriter().print(ServerErrorManager.getErrorResponse()); } else { /** * ******************************************************* * STEP 3A WRITE RESPONSE ERROR. GO TO STEP 4 * ******************************************************* */ // reads input file from an absolute path File downloadFile = new File(tmpFile); try { FileInputStream inStream = new FileInputStream(downloadFile); // gets MIME type of the file String mimeType = getServletContext().getMimeType(tmpFile); if (mimeType == null) { // set to binary type if MIME mapping not found mimeType = "application/octet-stream"; } response.setContentType(mimeType); response.setHeader("Content-Disposition", "filename=\"" + downloadFile.getName() + "\""); // obtains response's output stream OutputStream outStream = response.getOutputStream(); byte[] buffer = new byte[4096]; int bytesRead = -1; while ((bytesRead = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, bytesRead); } inStream.close(); outStream.close(); } catch (Exception ex) { } finally { if (downloadFile.exists()) { downloadFile.delete(); } if (tmpDir != null) { Files.delete(tmpDir); } } } /** * ******************************************************* * STEP 4 Close connection. * ******************************************************** */ if (dao_instance != null) { dao_instance.closeConnection(); } } //CATCH IF THE ERROR OCCURRED IN ROLL BACK OR CONNECTION CLOSE } catch (Exception e) { ServerErrorManager.handleException(e, Analysis_servlets.class.getName(), "export_samples_handler", e.getMessage()); response.setStatus(400); response.getWriter().print(ServerErrorManager.getErrorResponse()); } }
From source file:org.apache.hadoop.yarn.server.resourcemanager.ClientRMService.java
/** * Signal a container.// w ww . ja v a 2 s . c o m * After the request passes some sanity check, it will be delivered * to RMNodeImpl so that the next NM heartbeat will pick up the signal request */ @SuppressWarnings("unchecked") @Override public SignalContainerResponse signalToContainer(SignalContainerRequest request) throws YarnException, IOException { ContainerId containerId = request.getContainerId(); UserGroupInformation callerUGI; try { callerUGI = UserGroupInformation.getCurrentUser(); } catch (IOException ie) { LOG.info("Error getting UGI ", ie); throw RPCUtil.getRemoteException(ie); } ApplicationId applicationId = containerId.getApplicationAttemptId().getApplicationId(); RMApp application = this.rmContext.getRMApps().get(applicationId); if (application == null) { RMAuditLogger.logFailure(callerUGI.getUserName(), AuditConstants.SIGNAL_CONTAINER, "UNKNOWN", "ClientRMService", "Trying to signal an absent container", applicationId, containerId); throw RPCUtil.getRemoteException("Trying to signal an absent container " + containerId); } if (!checkAccess(callerUGI, application.getUser(), ApplicationAccessType.MODIFY_APP, application)) { RMAuditLogger.logFailure(callerUGI.getShortUserName(), AuditConstants.SIGNAL_CONTAINER, "User doesn't have permissions to " + ApplicationAccessType.MODIFY_APP.toString(), "ClientRMService", AuditConstants.UNAUTHORIZED_USER, applicationId); throw RPCUtil.getRemoteException( new AccessControlException("User " + callerUGI.getShortUserName() + " cannot perform operation " + ApplicationAccessType.MODIFY_APP.name() + " on " + applicationId)); } RMContainer container = scheduler.getRMContainer(containerId); if (container != null) { this.rmContext.getDispatcher().getEventHandler() .handle(new RMNodeSignalContainerEvent(container.getContainer().getNodeId(), request)); RMAuditLogger.logSuccess(callerUGI.getShortUserName(), AuditConstants.SIGNAL_CONTAINER, "ClientRMService", applicationId, containerId); } else { RMAuditLogger.logFailure(callerUGI.getUserName(), AuditConstants.SIGNAL_CONTAINER, "UNKNOWN", "ClientRMService", "Trying to signal an absent container", applicationId, containerId); throw RPCUtil.getRemoteException("Trying to signal an absent container " + containerId); } return recordFactory.newRecordInstance(SignalContainerResponse.class); }
From source file:servlets.Samples_servlets.java
/** * *//from www . jav a2 s. c om * This function reads the configuration files that set the supported LIMS * systems for registering external samples. * * @param request * @param response * @throws IOException */ private void get_external_sources(HttpServletRequest request, HttpServletResponse response) throws IOException { ArrayList<JsonObject> response_content = new ArrayList<JsonObject>(); try { Map<String, Cookie> cookies = this.getCookies(request); JsonParser parser = new JsonParser(); String loggedUser = cookies.get("loggedUser").getValue(); String sessionToken = cookies.get("sessionToken").getValue(); /** * ******************************************************* * STEP 1 CHECK IF THE USER IS LOGGED CORRECTLY IN THE APP. IF ERROR * --> throws exception if not valid session, GO TO STEP 5b ELSE --> * GO TO STEP 2 * ******************************************************* */ if (!checkAccessPermissions(loggedUser, sessionToken)) { throw new AccessControlException("Your session is invalid. Please sign in again."); } //For each JSON file in the directory File folder = new File( DATA_LOCATION + File.separator + "extensions" + File.separator + "external_sources"); //Check if exist, create otherwise if (!folder.exists()) { String path = Samples_servlets.class.getResource("/sql_scripts/extensions/external_sources/") .getPath(); FileUtils.copyDirectory(new File(path), folder); } File[] listOfFiles = folder.listFiles(); BufferedReader br; for (File file : listOfFiles) { if (file.isFile()) { //Read the JS0N file br = new BufferedReader(new FileReader(file)); parser = new JsonParser(); JsonObject data = parser.parse(br).getAsJsonObject(); //Check if type == LIMS if ("lims".equalsIgnoreCase(data.get("type").getAsString())) { //If so, add the source to response data.add("file_name", new JsonPrimitive(file.getName())); response_content.add(data); } } } } catch (Exception e) { ServerErrorManager.handleException(e, Samples_servlets.class.getName(), "get_external_sources", e.getMessage()); } finally { /** * ******************************************************* * STEP 3b CATCH ERROR. GO TO STEP 4 * ******************************************************* */ if (ServerErrorManager.errorStatus()) { response.setStatus(400); response.getWriter().print(ServerErrorManager.getErrorResponse()); } else { /** * ******************************************************* * STEP 3A WRITE SUCCESS RESPONSE. GO TO STEP 4 * ******************************************************* */ JsonObject obj = new JsonObject(); JsonArray _response = new JsonArray(); for (JsonObject element : response_content) { _response.add(element); } obj.add("external_sources", _response); response.getWriter().print(obj.toString()); } } }