List of usage examples for java.security AccessControlException AccessControlException
public AccessControlException(String s)
From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPropertyUtil.java
public static Node lookupNodeReference(String nodeIdentifier, Session session) { Node n = null;//www . ja v a 2s. com if (session != null) { try { n = session.getNodeByIdentifier(nodeIdentifier); } catch (AccessDeniedException e) { log.debug("Access denied", e); throw new AccessControlException(e.getMessage()); } catch (RepositoryException e) { } } return n; }
From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrUtil.java
public static <T extends Serializable> T getGenericJson(Node parent, String nodeName, boolean allowClassNotFound) { try {//w ww . j a v a2s .com Node jsonNode = parent.getNode(nodeName); return getGenericJson(jsonNode, allowClassNotFound); } catch (AccessDeniedException e) { log.debug("Access denied", e); throw new AccessControlException(e.getMessage()); } catch (RepositoryException e) { throw new MetadataRepositoryException("Failed to deserialize generic JSON node", e); } }
From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPropertyUtil.java
public static void setWeakReferenceProperty(Node node, String name, Node ref) { try {/*from w w w. ja va 2 s. c om*/ //ensure checked out // JcrVersionUtil.ensureCheckoutNode(node); if (node == null) { throw new IllegalArgumentException("Cannot set a property on a null-node!"); } if (name == null) { throw new IllegalArgumentException("Cannot set a property without a provided name"); } Value weakRef = node.getSession().getValueFactory().createValue(ref, true); node.setProperty(name, weakRef); } catch (AccessDeniedException e) { log.debug("Access denied", e); throw new AccessControlException(e.getMessage()); } catch (RepositoryException e) { throw new MetadataRepositoryException("Failed to set weak ref property value: " + name + "=" + ref, e); } }
From source file:servlets.User_servlets.java
private void get_user_list_handler(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/*from w ww.j a v a 2s . c o m*/ DAO dao_instance = null; ArrayList<Object> userList = null; String loggedUser = ""; try { Map<String, Cookie> cookies = this.getCookies(request); 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 * 3b 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 ALL REGISTERED USERS. IF ERROR --> throws * exception if not valid session, GO TO STEP 3b ELSE --> GO TO * STEP 2 * ******************************************************* */ dao_instance = DAOProvider.getDAOByName("User"); userList = dao_instance.findAll(null); } catch (Exception e) { ServerErrorManager.handleException(e, User_servlets.class.getName(), "getUserListPostHandler", e.getMessage()); } finally { /** * ******************************************************* * STEP 3b CATCH ERROR AND WRITE RESPONSE. * ******************************************************* */ if (ServerErrorManager.errorStatus()) { response.setStatus(400); response.getWriter().print(ServerErrorManager.getErrorResponse()); } else { String usersJSON = "["; for (int i = 0; i < userList.size(); i++) { //TODO: USE FUNCTION IS ADMIN if (isValidAdminUser(loggedUser)) { ((User) userList.get(i)).setLoggedIn(UserSessionManager.getUserSessionManager() .isLoggedUser(((User) userList.get(i)).getUserID())); } usersJSON += ((User) userList.get(i)).toJSON() + ((i < userList.size() - 1) ? "," : ""); } usersJSON += "]"; response.getWriter().print(usersJSON); } if (dao_instance != null) { dao_instance.closeConnection(); } } } catch (Exception e) { ServerErrorManager.handleException(e, User_servlets.class.getName(), "getUserListPostHandler", e.getMessage()); response.setStatus(400); response.getWriter().print(ServerErrorManager.getErrorResponse()); } }
From source file:servlets.File_servlets.java
private void get_all_files_handler(HttpServletRequest request, HttpServletResponse response) throws IOException { try {/*from w ww. jav a 2 s . c om*/ DAO dao_instance = null; String directoryContent = ""; try { Map<String, Cookie> cookies = this.getCookies(request); String loggedUser = cookies.get("loggedUser").getValue(); String sessionToken = cookies.get("sessionToken").getValue(); String loggedUserID = cookies.get("loggedUserID").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 Experiment Object from DB. IF ERROR --> throws * MySQL exception, GO TO STEP 3b ELSE --> GO TO STEP 3 * ******************************************************* */ String experiment_id; if (request.getParameter("experiment_id") != null) { experiment_id = request.getParameter("experiment_id"); } else { experiment_id = cookies.get("currentExperimentID").getValue(); } /** * ******************************************************* * STEP 3 Check that the user is a valid owner for the * experiment. * ******************************************************* */ dao_instance = DAOProvider.getDAOByName("Experiment"); Experiment experiment = (Experiment) dao_instance.findByID(experiment_id, null); if (!experiment.isOwner(loggedUserID) && !experiment.isMember(loggedUserID) && !loggedUserID.equals("admin")) { throw new AccessControlException( "Cannot get files for selected Experiment. Current user is not a valid member for this Experiment."); } if (request.getParameter("credentials") != null) { byte[] decoded = Base64.decodeBase64(request.getParameter("credentials")); String[] credentials = new String(decoded).split(":", 2); experiment.setDataDirectoryUser(credentials[0]); experiment.setDataDirectoryPass(credentials[1]); } else if (request.getParameter("apikey") != null) { experiment.setDataDirectoryApiKey(request.getParameter("apikey")); } //If using an external storage and pass or user is not set if (!("local_directory".equals(experiment.getDataDirectoryInformation().get("type")) || "none".equals(experiment.getDataDirectoryInformation().get("type"))) && ("".equals(experiment.getDataDirectoryInformation().get("user")) || "".equals(experiment.getDataDirectoryInformation().get("pass")))) { directoryContent = "{\"success\" : false, \"error_code\" : 201, \"host\" : \"" + experiment.getDataDirectoryInformation().get("host") + "\"}"; } else { directoryContent = FileManager.getFileManager(DATA_LOCATION).getDirectoryContent("", experiment.getDataDirectoryInformation()); } } catch (Exception e) { ServerErrorManager.handleException(e, File_servlets.class.getName(), "get_all_files_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 * ******************************************************* */ response.getWriter().print(directoryContent); } /** * ******************************************************* * 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, File_servlets.class.getName(), "get_all_files_handler", e.getMessage()); response.setStatus(400); response.getWriter().print(ServerErrorManager.getErrorResponse()); } }
From source file:com.spectralogic.ds3client.integration.GetJobManagement_Test.java
@Test public void testReadRetrybugWhenChannelThrowsAccessException() throws IOException, URISyntaxException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { final String tempPathPrefix = null; final Path tempDirectoryPath = Files.createTempDirectory(Paths.get("."), tempPathPrefix); final AtomicBoolean caughtException = new AtomicBoolean(false); try {//from w w w. ja v a2s. c o m final String DIR_NAME = "largeFiles/"; final String FILE_NAME = "lesmis-copies.txt"; final Path objPath = ResourceUtils.loadFileResource(DIR_NAME + FILE_NAME); final long bookSize = Files.size(objPath); final Ds3Object obj = new Ds3Object(FILE_NAME, bookSize); final Ds3ClientShim ds3ClientShim = new Ds3ClientShim((Ds3ClientImpl) client); final int maxNumBlockAllocationRetries = 1; final int maxNumObjectTransferAttempts = 3; final Ds3ClientHelpers ds3ClientHelpers = Ds3ClientHelpers.wrap(ds3ClientShim, maxNumBlockAllocationRetries, maxNumObjectTransferAttempts); final Ds3ClientHelpers.Job readJob = ds3ClientHelpers.startReadJob(BUCKET_NAME, Arrays.asList(obj)); final GetJobSpectraS3Response jobSpectraS3Response = ds3ClientShim .getJobSpectraS3(new GetJobSpectraS3Request(readJob.getJobId())); assertThat(jobSpectraS3Response.getMasterObjectListResult(), is(notNullValue())); readJob.transfer(new Ds3ClientHelpers.ObjectChannelBuilder() { @Override public SeekableByteChannel buildChannel(final String key) throws IOException { throw new AccessControlException(key); } }); } catch (final IOException e) { caughtException.set(true); assertTrue(e.getCause() instanceof AccessControlException); } finally { FileUtils.deleteDirectory(tempDirectoryPath.toFile()); } assertTrue(caughtException.get()); }
From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrUtil.java
/** * Create a new JcrObject (Wrapper Object) that invokes a constructor with at least parameter of type Node *//*from ww w . j a va2s . c o m*/ public static <T extends JcrObject> T addJcrObject(Node parent, String name, String nodeType, Class<T> type, Object... constructorArgs) { try { Node child = parent.addNode(name, nodeType); return createJcrObject(child, type, constructorArgs); } catch (AccessDeniedException e) { log.debug("Access denied", e); throw new AccessControlException(e.getMessage()); } catch (RepositoryException e) { throw new MetadataRepositoryException("Failed to add new createJcrObject child node " + type, e); } }
From source file:com.sshtools.appframework.ui.SshToolsApplication.java
@SuppressWarnings("serial") private void loadMRU() { try {// w w w . j a v a 2 s . co m if (System.getSecurityManager() != null) { AccessController.checkPermission(new FilePermission("<<ALL FILES>>", "write")); } File a = getApplicationPreferencesDirectory(); if (a == null) { throw new AccessControlException("Application preferences directory not specified."); } InputStream in = null; MRUList mru = new MRUList(); try { File f = new File(a, getApplicationName() + ".mru"); if (f.exists()) { in = new FileInputStream(f); mru.reload(in); } } catch (Exception e) { e.printStackTrace(); } finally { IOUtil.closeStream(in); } mruModel = new MRUListModel() { @Override public void add(File f) { super.add(f); saveMRU(SshToolsApplication.this); } @Override public void setMRUList(MRUList mru) { super.setMRUList(mru); } }; mruModel.setMRUList(mru); } catch (AccessControlException ace) { ace.printStackTrace(); } }
From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrUtil.java
public static Map<String, Object> jcrObjectAsMap(JcrObject obj) { String nodeName = obj.getNodeName(); String path = obj.getPath();/*from w ww .j a v a2 s .c o m*/ String identifier = null; try { identifier = obj.getObjectId(); } catch (AccessDeniedException e) { log.debug("Access denied", e); throw new AccessControlException(e.getMessage()); } catch (RepositoryException e) { throw new RuntimeException(e); } String type = obj.getTypeName(); Map<String, Object> props = obj.getProperties(); Map<String, Object> finalProps = new HashMap<>(); if (props != null) { finalProps.putAll(finalProps); } finalProps.put("nodeName", nodeName); if (identifier != null) { finalProps.put("nodeIdentifier", identifier); } finalProps.put("nodePath", path); finalProps.put("nodeType", type); return finalProps; }
From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPropertyUtil.java
public static void setProperty(Node node, String name, Object value) { try {//from w w w. j a v a2s .c o m //ensure checked out // JcrVersionUtil.ensureCheckoutNode(node); if (node == null) { throw new IllegalArgumentException("Cannot set a property on a null-node!"); } if (name == null) { throw new IllegalArgumentException("Cannot set a property without a provided name"); } if (value == null) { node.setProperty(name, (Value) null); } else if (value instanceof Enum) { node.setProperty(name, ((Enum) value).name()); } else if (value instanceof JcrObject) { node.setProperty(name, ((JcrObject) value).getNode()); } else if (value instanceof Value) { node.setProperty(name, (Value) value); } else if (value instanceof Node) { node.setProperty(name, (Node) value); } else if (value instanceof Binary) { node.setProperty(name, (Binary) value); } else if (value instanceof Calendar) { node.setProperty(name, (Calendar) value); } else if (value instanceof DateTime) { Calendar cal = Calendar.getInstance(); cal.setTime(((DateTime) value).toDate()); node.setProperty(name, cal); } else if (value instanceof Date) { Calendar cal = Calendar.getInstance(); cal.setTime((Date) value); node.setProperty(name, cal); } else if (value instanceof BigDecimal) { node.setProperty(name, (BigDecimal) value); } else if (value instanceof Long) { node.setProperty(name, ((Long) value).longValue()); } else if (value instanceof Double) { node.setProperty(name, (Double) value); } else if (value instanceof Boolean) { node.setProperty(name, (Boolean) value); } else if (value instanceof InputStream) { node.setProperty(name, (InputStream) value); } else if (value instanceof Collection) { String[] list = new String[((Collection<Object>) value).size()]; int pos = 0; for (Object cal : (Collection<Object>) value) { list[pos] = cal.toString(); pos += 1; } node.setProperty(name, list); } else { node.setProperty(name, value.toString()); } } catch (AccessDeniedException e) { log.debug("Access denied", e); throw new AccessControlException(e.getMessage()); } catch (RepositoryException e) { throw new MetadataRepositoryException("Failed to set property value: " + name + "=" + value, e); } }