List of usage examples for java.security AccessControlException getMessage
public String getMessage()
From source file:org.infoscoop.admin.web.AuthenticationServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //Authenticator a = AuthenticatorManager.getInstance().getAuthenticator(); String action = ((HttpServletRequest) request).getPathInfo(); String uid = request.getParameter("uid"); String password = request.getParameter("password"); if (password != null) { password = password.trim();/* w w w.ja v a2s.c o m*/ } String new_password = request.getParameter("new_password"); if (new_password != null) { new_password = new_password.trim(); } if (logger.isDebugEnabled()) { logger.debug("uid=" + uid + ",password=" + password); } String errorPath = "/admin/login.jsp"; try { // if("/changePassword".equals(action)){ // errorPath = "/changePassword.jsp"; // changePassword(uid, password, new_password); // }else{ login(request, uid, password); // } String redirectPath = "/admin/index.jsp"; Cookie[] cookies = request.getCookies(); for (int i = 0; i < cookies.length; i++) { if ("redirect_path".equals(cookies[i].getName())) { redirectPath = cookies[i].getValue(); break; } } ((HttpServletResponse) response).sendRedirect(request.getContextPath() + redirectPath); } catch (AccessControlException e) { logger.error(e); HttpSession session = request.getSession(); session.setAttribute("errorMsg", e.getMessage()); //getServletContext().getRequestDispatcher(errorPath).forward(request, response); ((HttpServletResponse) response).sendRedirect(request.getContextPath() + errorPath); } catch (Exception e) { String logMsg = "Unexpected error occurred. "; logger.error(logMsg, e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, logMsg); } }
From source file:org.opencron.agent.Bootstrap.java
private void await() throws Exception { // Negative values - don't wait on port - opencron is embedded or we just don't like ports if (port == -2) { return;/*from w ww . ja va2 s . c o m*/ } if (port == -1) { try { awaitThread = Thread.currentThread(); while (!stopAwait) { try { Thread.sleep(10000); } catch (InterruptedException ex) { // continue and check the flag } } } finally { awaitThread = null; } return; } // Set up a server socket to wait on try { awaitSocket = new ServerSocket(AgentProperties.getInt("opencron.shutdown")); } catch (IOException e) { logger.error("[opencron] agent .await: create[{}] ", AgentProperties.getInt("opencron.shutdown"), e); return; } try { awaitThread = Thread.currentThread(); // Loop waiting for a connection and a valid command while (!stopAwait) { ServerSocket serverSocket = awaitSocket; if (serverSocket == null) { break; } // Wait for the next connection Socket socket = null; StringBuilder command = new StringBuilder(); try { InputStream stream; long acceptStartTime = System.currentTimeMillis(); try { socket = serverSocket.accept(); socket.setSoTimeout(10 * 1000); // Ten seconds stream = socket.getInputStream(); } catch (SocketTimeoutException ste) { // This should never happen but bug 56684 suggests that // it does. logger.warn("[opencron] agentServer accept.timeout", Long.valueOf(System.currentTimeMillis() - acceptStartTime), ste); continue; } catch (AccessControlException ace) { logger.warn("[opencron] agentServer .accept security exception: {}", ace.getMessage(), ace); continue; } catch (IOException e) { if (stopAwait) { break; } logger.error("[opencron] agent .await: accept: ", e); break; } // Read a set of characters from the socket int expected = 1024; // Cut off to avoid DoS attack while (expected < shutdown.length()) { if (random == null) { random = new Random(); } expected += (random.nextInt() % 1024); } while (expected > 0) { int ch = -1; try { ch = stream.read(); } catch (IOException e) { logger.warn("[opencron] agent .await: read: ", e); ch = -1; } if (ch < 32) // Control character or EOF terminates loop break; command.append((char) ch); expected--; } } finally { try { if (socket != null) { socket.close(); } } catch (IOException e) { } } boolean match = command.toString().equals(shutdown); if (match) { break; } else { logger.warn("[opencron] agent .await: Invalid command '" + command.toString() + "' received"); } } } finally { ServerSocket serverSocket = awaitSocket; awaitThread = null; awaitSocket = null; // Close the server socket and return if (serverSocket != null) { try { serverSocket.close(); } catch (IOException e) { // Ignore } } } }
From source file:org.springframework.core.env.AbstractEnvironment.java
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public Map<String, Object> getSystemEnvironment() { if (suppressGetenvAccess()) { return Collections.emptyMap(); }//from w ww. ja v a 2 s . c om try { return (Map) System.getenv(); } catch (AccessControlException ex) { return (Map) new ReadOnlySystemAttributesMap() { @Override @Nullable protected String getSystemAttribute(String attributeName) { try { return System.getenv(attributeName); } catch (AccessControlException ex) { if (logger.isInfoEnabled()) { logger.info("Caught AccessControlException when accessing system environment variable '" + attributeName + "'; its value will be returned [null]. Reason: " + ex.getMessage()); } return null; } } }; } }
From source file:org.springframework.core.env.AbstractEnvironment.java
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public Map<String, Object> getSystemProperties() { try {/*from w ww . j a v a 2 s .com*/ return (Map) System.getProperties(); } catch (AccessControlException ex) { return (Map) new ReadOnlySystemAttributesMap() { @Override @Nullable protected String getSystemAttribute(String attributeName) { try { return System.getProperty(attributeName); } catch (AccessControlException ex) { if (logger.isInfoEnabled()) { logger.info( "Caught AccessControlException when accessing system property '" + attributeName + "'; its value will be returned [null]. Reason: " + ex.getMessage()); } return null; } } }; } }
From source file:servlets.User_servlets.java
private void user_sign_up_handler(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/*from www. ja va 2 s . c om*/ DAO dao_instance = null; User user = null; boolean ROLLBACK_NEEDED = false; String error = ""; try { /** * ******************************************************* * STEP 1 Check if the user exists in the DB. IF ERROR --> * throws MySQL exception, GO TO STEP 2b throws * NoSuchAlgorithmException, GO TO STEP 2b ELSE --> GO TO STEP 2 * ******************************************************* */ JsonParser parser = new JsonParser(); JsonObject requestData = (JsonObject) parser.parse(request.getReader()); String email = requestData.get("email").getAsString(); String user_id = requestData.get("user_id").getAsString(); String password = requestData.get("password").getAsString(); password = SHA1.getHash(password); dao_instance = DAOProvider.getDAOByName("User"); Object[] params = { null, false, true }; user = (User) ((User_JDBCDAO) dao_instance).findByID(email, params); if (user != null) { throw new AccessControlException("Email already registered."); } user = (User) ((User_JDBCDAO) dao_instance).findByID(user_id, null); if (user != null) { throw new AccessControlException( "There is another user with that name. Try with another name."); } /** * ******************************************************* * STEP 2 Create the new user instance. * ******************************************************* */ user = new User(user_id, email); user.setPassword(password); user.setRandomAPICode(); /** * ******************************************************* * STEP 3 INSERT IN DATABASE. IF ERROR --> throws exception if * not valid session, GO TO STEP 4b ELSE --> GO TO STEP 4 * ******************************************************* */ dao_instance = DAOProvider.getDAOByName("User"); dao_instance.disableAutocommit(); ROLLBACK_NEEDED = true; dao_instance.insert(user); /** * ******************************************************* * STEP 4 COMMIT CHANGES IN DB. IF ERROR --> throws exception if * not valid session, GO TO STEP 4b ELSE --> GO TO STEP 5 * ******************************************************* */ dao_instance.doCommit(); } catch (AccessControlException e) { error = e.getMessage(); } catch (Exception e) { ServerErrorManager.handleException(e, User_servlets.class.getName(), "userLoginPostHandler", e.getMessage()); } finally { /** * ******************************************************* * STEP 3b CATCH ERROR. GO TO STEP 4 * ******************************************************* */ if (ServerErrorManager.errorStatus()) { response.setStatus(400); response.getWriter().print(ServerErrorManager.getErrorResponse()); if (ROLLBACK_NEEDED) { dao_instance.doRollback(); } } else { /** * ******************************************************* * STEP 3A WRITE RESPONSE ERROR. GO TO STEP 4 * ******************************************************* */ if (error.length() > 0) { JsonObject obj = new JsonObject(); obj.add("success", new JsonPrimitive(false)); obj.add("reason", new JsonPrimitive(error)); response.getWriter().print(obj.toString()); } else { JsonObject obj = new JsonObject(); obj.add("success", new JsonPrimitive(true)); response.getWriter().print(obj.toString()); } } /** * ******************************************************* * 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, User_servlets.class.getName(), "userSignUpPostHandler", e.getMessage()); response.setStatus(400); response.getWriter().print(ServerErrorManager.getErrorResponse()); } }