List of usage examples for java.lang SecurityException getMessage
public String getMessage()
From source file:eu.asterics.mw.services.AstericsErrorHandling.java
/** * This method creates the logger. Actually there are 4 types of loggers: * "severe": logs fatal errors i.e. errors that prevent the ARE from functioning * "warning": logs errors other than fatal e.g. component errors * "info": logs informative messages//from w w w . j a v a 2s . c o m * "fine": logs debugging messages * * Each logger by default also logs all messages with severity level higher than its own. * E.g. the warning logger logs warning and severe messages, the info logger logs info, * warning and severe messages etc. The same applies to the consoleHandler, i.e. by * setting its level to info, the console will also print severe and warning messages * along with info messages */ public Logger getLogger() { if (logger == null) { logger = Logger.getLogger("AstericsLogger"); FileHandler warningFileHandler, severeFileHandler, infoFileHandler, fineFileHandler; ConsoleHandler consoleHandler; try { //cleanup before starting: logger.setUseParentHandlers(false); // remove and handlers that will be replaced Handler[] handlers = logger.getHandlers(); for (Handler handler : handlers) { if (handler.getClass() == ConsoleHandler.class) logger.removeHandler(handler); } File logFolder = new File(System.getProperty(LOG_PATH_PROPERTY, ResourceRegistry.TMP_FOLDER)); if (!logFolder.exists()) { FileUtils.forceMkdir(logFolder); } //Create handlers severeFileHandler = new FileHandler(new File(logFolder, "asterics_logger_severe.log").getPath(), true); warningFileHandler = new FileHandler(new File(logFolder, "asterics_logger_warning.log").getPath(), true); infoFileHandler = new FileHandler(new File(logFolder, "asterics_logger.log").getPath(), true); fineFileHandler = new FileHandler(new File(logFolder, "asterics_logger_fine.log").getPath(), true); consoleHandler = new ConsoleHandler(); //Set report level of handlers severeFileHandler.setLevel(Level.SEVERE); warningFileHandler.setLevel(Level.WARNING); infoFileHandler.setLevel(Level.INFO); fineFileHandler.setLevel(Level.FINE); //The consoleHandler prints log messaged to the console. Its //severety level can be adjusted accordingly. String level = getLoggerLevel(); switch (level) { case "INFO": consoleHandler.setLevel(Level.INFO); break; case "WARNING": consoleHandler.setLevel(Level.WARNING); break; case "FINE": consoleHandler.setLevel(Level.FINE); break; case "SEVERE": consoleHandler.setLevel(Level.SEVERE); break; default: consoleHandler.setLevel(Level.INFO); break; } //Add handlers to the logger logger.addHandler(warningFileHandler); logger.addHandler(severeFileHandler); logger.addHandler(infoFileHandler); logger.addHandler(fineFileHandler); logger.addHandler(consoleHandler); //Create formatters for the handlers (optional) severeFileHandler.setFormatter(new SimpleFormatter()); warningFileHandler.setFormatter(new SimpleFormatter()); infoFileHandler.setFormatter(new SimpleFormatter()); fineFileHandler.setFormatter(new SimpleFormatter()); consoleHandler.setFormatter(new SimpleFormatter()); logger.setLevel(Level.ALL); logger.setUseParentHandlers(false); } catch (SecurityException e) { System.out.println(AstericsErrorHandling.class.getName() + ": Error creating AstericsLogger: " + e.getMessage()); } catch (IOException e) { //logger.warning(this.getClass().getName()+ // ": Error creating AstericsLogger: "+e.getMessage()); System.out.println(AstericsErrorHandling.class.getName() + ": Error creating AstericsLogger: " + e.getMessage()); } } return logger; }
From source file:org.sakaiproject.kernel.rest.RestMySitesProvider.java
/** * {@inheritDoc}//w w w . j a v a 2 s . c o m * * @see org.sakaiproject.kernel.api.rest.RestProvider#dispatch(java.lang.String[], * javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse) */ public void dispatch(String[] elements, HttpServletRequest request, HttpServletResponse response) { try { if (elements.length == 1 && SITES_ELEMENT.equals(elements[0])) { KernelManager kernelManager = new KernelManager(); Kernel kernel = kernelManager.getKernel(); if (null == sessionManagerService) { sessionManagerService = kernel.getService(SessionManagerService.class); } Session session = sessionManagerService.getCurrentSession(); User user = session.getUser(); String uuid = null; if (user == null || user.getUuid() == null) { uuid = "anon"; } else { uuid = user.getUuid(); } UserEnvironment env = simpleJcrUserEnvironmentResolverService.resolve(user); LOG.info("getting subjects...."); String[] subjects = env.getSubjects(); LOG.info("list of subjects for user (" + uuid + ", " + subjects.length + " total):"); for (int i = 0; i < subjects.length; ++i) { LOG.info("--> " + subjects[i]); } LOG.info("Parsing for startindex param from request ....." + request); /* * parse and handle the paging This is coded according to OpenSocial API * v.8.1 * http://www.opensocial.org/Technical-Resources/opensocial-spec-v081 * /restful -protocol#TOC-2.1-Responses */ Map<String, Object> pagingEnvelope = new HashMap<String, Object>(); // check for startIndex param try { String param = request.getParameter(INPUT_PARAM_NAME_STARTINDEX); int startIndex = Integer.parseInt(param); pagingEnvelope.put(OUTPUT_PARAM_NAME_STARTINDEX, startIndex); } catch (NumberFormatException e) {// just skip it } catch (Exception e) { LOG.error("General Exception thrown parsing request for startIndex"); } // / check for 'count' param try { // /set to 'count' until we know how many values we have left to // display int itemsPerPage = Integer.parseInt(request.getParameter(INPUT_PARAM_NAME_COUNT)); pagingEnvelope.put(OUTPUT_PARAM_NAME_ITEMSPERPAGE, itemsPerPage); } catch (NumberFormatException e) { // just skip it } catch (Exception e) { LOG.error("General Exception thrown parsing request for itemsPerPage"); } if (debug) { LOG.debug("getting subjects as sites...."); } SiteBean memSite = null; Set<SiteBean> sites = new HashSet<SiteBean>(); for (String s : subjects) { if (s != null) { String[] parts = s.split(":"); if (parts.length == 2) { memSite = siteService.getSiteById(parts[0]); if (null == memSite) { LOG.warn("group id not found as a site id... subject token: " + s); } else { if (debug) { LOG.debug("Site found: " + memSite.getName()); } if (!sites.contains(memSite)) { sites.add(memSite); } } } else { LOG.error("malformed subject in userenvronment (user: " + uuid + ")"); } } else { LOG.error("null subject found in userenvironment (user: " + uuid + ")"); } } pagingEnvelope.put(OUTPUT_PARAM_NAME_TOTALRESULTS, sites.size()); pagingEnvelope.put(OUTPUT_SITES_KEY, sites.toArray()); sendOutput(response, pagingEnvelope); } } catch (SecurityException ex) { throw ex; } catch (RestServiceFaultException ex) { throw ex; } catch (Exception ex) { throw new RestServiceFaultException(ex.getMessage(), ex); } }
From source file:com.sun.socialsite.web.rest.servlets.GadgetizerDataServlet.java
private boolean isExecutionAlloweded(SocialSiteToken token, App app) throws SocialSiteException { try {/*w ww . ja va 2 s . c o m*/ PermissionManager permissionManager = Factory.getSocialSite().getPermissionManager(); Permission p = new AppPermission(app.getURL().toString(), "execute"); permissionManager.checkPermission(p, token); return true; } catch (SecurityException se) { // Only log the exception if debug logging is enabled if (log.isDebugEnabled()) { log.debug(se.getMessage(), se); } if (log.isWarnEnabled()) { String msg = String.format("token[%s] does not have acess to execute app[%s]", token.toSerialForm(), app.getURL()); log.warn(msg); } return false; } }
From source file:test.unit.be.fedict.eid.applet.shared.UnmarshallerTest.java
@Test public void unsecureHttpReceiver() throws Exception { // setup/*from w ww. ja v a2s . com*/ ProtocolMessageCatalog catalog = new AppletProtocolMessageCatalog(); Unmarshaller unmarshaller = new Unmarshaller(catalog); HttpReceiver mockHttpReceiver = EasyMock.createMock(HttpReceiver.class); // stubs EasyMock.expect(mockHttpReceiver.isSecure()).andStubReturn(false); // prepare EasyMock.replay(mockHttpReceiver); // operate try { unmarshaller.receive(mockHttpReceiver); fail(); } catch (SecurityException e) { // expected // verify LOG.debug("expected error: " + e.getMessage()); EasyMock.verify(mockHttpReceiver); } }
From source file:fr.jayasoft.ivy.url.HttpClientHandler.java
private HttpClientHelper getHttpClientHelper() { if (_httpClientHelper == null) { // use commons httpclient 3.0 if available try {/*from ww w . j a v a 2s .com*/ HttpMethodBase.class.getMethod("getResponseContentLength", new Class[0]); _httpClientHelper = new HttpClientHelper3x(); Message.verbose("using commons httpclient 3.x helper"); } catch (SecurityException e) { Message.verbose( "unable to get access to getResponseContentLength of commons-httpclient HeadMethod. Please use commons-httpclient 3.0 or use ivy with sufficient security permissions."); Message.verbose("exception: " + e.getMessage()); _httpClientHelper = new HttpClientHelper2x(); Message.verbose("using commons httpclient 2.x helper"); } catch (NoSuchMethodException e) { _httpClientHelper = new HttpClientHelper2x(); Message.verbose("using commons httpclient 2.x helper"); } } return _httpClientHelper; }
From source file:com.springsource.hq.plugin.tcserver.plugin.serverconfig.FileSettingsRepository.java
private boolean checkAndCreateParentDirectories(String installPath, String filePath) throws PluginException { boolean canWrite = new File(installPath).canWrite(); boolean exists = false; if (canWrite) { String absoluteDirectory = filePath.substring(0, filePath.lastIndexOf('/')); File directory = new File(absoluteDirectory); exists = directory.exists();//from w w w .j a v a 2 s . c o m if (!exists) { try { exists = directory.mkdirs(); } catch (SecurityException e) { throw new PluginException( "Unable to create directory structure '" + absoluteDirectory + "': " + e.getMessage()); } } else if (!directory.canWrite()) { throw new PluginException("Unable to write to directory: " + absoluteDirectory); } } else { throw new PluginException("Unable to write to directory:" + installPath); } return exists; }
From source file:de.jwi.jfm.servlets.Controller.java
private String handleQuery(HttpServletRequest request, HttpServletResponse response, Folder folder) throws OutOfSyncException, IOException { String rc = ""; HttpSession session = request.getSession(); String target = null;/*from www .j a va2s. c om*/ int action = NOP_ACTION; String[] selectedfiles = request.getParameterValues("index"); String logout = request.getParameter("logout"); if ("t".equals(logout)) { request.getSession().invalidate(); return ""; } String sum = request.getParameter("sum"); if ("t".equals(sum)) { folder.sum(); return ""; } String sort = request.getParameter("sort"); if ("nd".equals(sort)) { folder.sort(Folder.SORT_NAME_DOWN); return ""; } else if ("nu".equals(sort)) { folder.sort(Folder.SORT_NAME_UP); return ""; } else if ("su".equals(sort)) { folder.sort(Folder.SORT_SIZE_UP); return ""; } else if ("sd".equals(sort)) { folder.sort(Folder.SORT_SIZE_DOWN); return ""; } else if ("du".equals(sort)) { folder.sort(Folder.SORT_DATE_UP); return ""; } else if ("dd".equals(sort)) { folder.sort(Folder.SORT_DATE_DOWN); return ""; } OutputStream out = null; String command = request.getParameter("command"); if ("Mkdir".equals(command)) { target = request.getParameter("newdir"); action = MKDIR_ACTION; } if ("GetURL".equals(command)) { target = request.getParameter("url"); action = GETURL_ACTION; } else if ("Delete".equals(command)) { action = DELETE_ACTION; } else if ("Rename to".equals(command)) { target = request.getParameter("renameto"); action = RENAME_ACTION; } else if ("Unzip".equals(command)) { action = UNZIP_ACTION; } else if ("ZipDownload".equals(command)) { action = ZIP_ACTION; response.setContentType("application/zip"); response.setHeader("Content-Disposition", "inline; filename=\"jFMdownload.zip\""); out = response.getOutputStream(); } else if ("Copy to".equals(command)) { target = request.getParameter("copyto"); action = COPY_ACTION; } else if ("Move to".equals(command)) { target = request.getParameter("moveto"); action = MOVE_ACTION; } else if ("Chmod to".equals(command)) { target = request.getParameter("chmodto"); action = CHMOD_ACTION; } else if ("DeleteRecursively".equals(command)) { target = request.getParameter("confirm"); action = DELETE_RECURSIVE_ACTION; } else if ("FtpUpload to".equals(command)) { target = request.getParameter("ftpto"); action = FTPUP_ACTION; } else if ("Join".equals(command)) { action = JOIN_ACTION; } else if ("cut".equals(command)) { action = CLIPBOARD_CUT_ACTION; } else if ("copy".equals(command)) { action = CLIPBOARD_COPY_ACTION; } else if ("paste".equals(command)) { action = CLIPBOARD_PASTE_ACTION; } else if ("clear".equals(command)) { action = CLIPBOARD_CLEAR_ACTION; } if (NOP_ACTION == action) { return ""; } try { rc = folder.action(action, out, selectedfiles, target, session); } catch (SecurityException e) { rc = "SecurityException: " + e.getMessage(); return rc; } folder.load(); return rc; }
From source file:org.jvnet.hudson.plugins.mavendepsupdate.MavenDependencyUpdateTrigger.java
private boolean usePrivateRepo() { boolean usePrivate = false; Project<?, ?> fp = (Project<?, ?>) this.job; for (Builder b : fp.getBuilders()) { if (b instanceof Maven) { if (((Maven) b).usePrivateRepository) { usePrivate = true;//from w w w. j a v a 2 s . co m } } } // check if there is a method called usesPrivateRepository if (!usePrivate) { try { Method method = this.job.getClass().getMethod("usesPrivateRepository", (Class<?>) null); Boolean bool = (Boolean) method.invoke(this.job, (Object[]) null); return bool.booleanValue(); } catch (SecurityException e) { LOGGER.warning("ignore " + e.getMessage()); } catch (NoSuchMethodException e) { LOGGER.warning("ignore " + e.getMessage()); } catch (IllegalArgumentException e) { LOGGER.warning("ignore " + e.getMessage()); } catch (IllegalAccessException e) { LOGGER.warning("ignore " + e.getMessage()); } catch (InvocationTargetException e) { LOGGER.warning("ignore " + e.getMessage()); } } return usePrivate; }
From source file:org.sakaiproject.kernel.rest.RestUserProvider.java
/** * {@inheritDoc}// w w w . jav a 2 s . c o m * * @see org.sakaiproject.kernel.api.rest.RestProvider#dispatch(java.lang.String[], * javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ public void dispatch(String[] elements, HttpServletRequest request, HttpServletResponse response) { try { if ("POST".equals(request.getMethod())) { // Security is managed by the JCR Map<String, Object> map = null; if ("new".equals(elements[1])) { map = createUser(request, response); } else if ("changepassword".equals(elements[1])) { map = changePassword(request, response, elements.length > 2 ? elements[2] : null); } if (map != null) { String responseBody = beanConverter.convertToString(map); response.setContentType(RestProvider.CONTENT_TYPE); response.getOutputStream().print(responseBody); } } else { if ("GET".equals(request.getMethod()) && elements.length == 3 && getKey().equals(elements[0]) && EXISTS.equals(elements[2]) && elements[1].trim().length() > 0) { handleUserExists(elements[1].trim(), response); } else { throw new RestServiceFaultException(HttpServletResponse.SC_METHOD_NOT_ALLOWED); } } } catch (SecurityException ex) { throw ex; } catch (RestServiceFaultException ex) { throw ex; } catch (Exception ex) { throw new RestServiceFaultException(ex.getMessage(), ex); } }
From source file:org.jvnet.hudson.plugins.mavendepsupdate.MavenDependencyUpdateTrigger.java
private FilePath getAlternateSettings(VirtualChannel virtualChannel) { FilePath altSettings = null;//w ww .ja v a2s . co m //-s,--settings or from configuration for maven native project Project<?, ?> fp = (Project<?, ?>) this.job; for (Builder b : fp.getBuilders()) { if (b instanceof Maven) { String targets = ((Maven) b).getTargets(); String[] args = Util.tokenize(targets); if (args == null) { altSettings = null; } CommandLine cli = getCommandLine(args); if (cli != null && cli.hasOption(CLIManager.ALTERNATE_USER_SETTINGS)) { altSettings = new FilePath(virtualChannel, cli.getOptionValue(CLIManager.ALTERNATE_POM_FILE)); } } } // check if there is a method called getAlternateSettings if (altSettings == null) { try { Method method = this.job.getClass().getMethod("getAlternateSettings", (Class<?>) null); String alternateSettings = (String) method.invoke(this.job, (Object[]) null); altSettings = alternateSettings != null ? new FilePath(virtualChannel, alternateSettings) : null; } catch (SecurityException e) { LOGGER.warning("ignore " + e.getMessage()); } catch (NoSuchMethodException e) { LOGGER.warning("ignore " + e.getMessage()); } catch (IllegalArgumentException e) { LOGGER.warning("ignore " + e.getMessage()); } catch (IllegalAccessException e) { LOGGER.warning("ignore " + e.getMessage()); } catch (InvocationTargetException e) { LOGGER.warning("ignore " + e.getMessage()); } } return altSettings; }