List of usage examples for java.lang SecurityException getMessage
public String getMessage()
From source file:org.sakaiproject.kernel.webapp.RestServlet.java
/** * {@inheritDoc}/*from www.ja v a 2 s. co m*/ * * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse) */ @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String requestPath = request.getPathInfo(); if (requestPath == null) { requestPath = ""; } String[] elements = StringUtils.split(requestPath, '/'); String locator = "default"; if (elements != null && elements.length > 0) { locator = elements[0]; } Map<String, RestProvider> restProviders = registry.getMap(); if (locator == null) { locator = "default"; } if ("__describe__".equals(locator)) { locator = "default"; } RestProvider restProvider = restProviders.get(locator); if (restProvider == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND); } else { try { if (requestPath.endsWith("__describe__")) { RestDescription description = restProvider.getDescription(); String format = request.getParameter("fmt"); if ("xml".equals(format)) { response.setContentType("text/xml"); response.getWriter().print(description.toXml()); } else if ("json".equals(format)) { response.setContentType(RestProvider.CONTENT_TYPE); response.getWriter().print(description.toJson()); } else { response.setContentType("text/html"); response.getWriter().print(description.toHtml()); } } else { restProvider.dispatch(elements, request, response); } } catch (SecurityException ex) { response.reset(); response.sendError(HttpServletResponse.SC_FORBIDDEN, ex.getMessage()); } catch (RestServiceFaultException ex) { ex.printStackTrace(); response.reset(); response.sendError(ex.getStatusCode(), ex.getMessage()); } } }
From source file:com.technophobia.webdriver.substeps.runner.DefaultWebDriverFactory.java
/** * By default the HtmlUnit driver is set to en-us. This can cause problems * with formatters.//from w w w . j a v a2 s .c om */ private void setDriverLocale(final WebDriver driver) { try { final Field field = driver.getClass().getDeclaredField("webClient"); if (field != null) { final boolean original = field.isAccessible(); field.setAccessible(true); final WebClient webClient = (WebClient) field.get(driver); if (webClient != null) { webClient.addRequestHeader("Accept-Language", "en-gb"); } field.setAccessible(original); } else { Assert.fail("Failed to get webclient field to set accept language"); } } catch (final IllegalAccessException ex) { LOG.warn(ex.getMessage()); } catch (final SecurityException e) { LOG.warn(e.getMessage()); } catch (final NoSuchFieldException e) { LOG.warn(e.getMessage()); } }
From source file:iddb.core.model.dao.DAOFactory.java
/** * @param key//from w w w. j a va2s.com * @param value * @return * @throws Exception * @throws ClassNotFoundException * @throws IllegalAccessException * @throws InstantiationException */ @SuppressWarnings({ "rawtypes", "unchecked" }) private Object createCachedInstance(String iface, Object impl) throws Exception { String[] ifacePart = StringUtils.split(iface, "."); String ifaceName = ifacePart[ifacePart.length - 1]; log.debug("Getting cached instance for {} - {}", iface, ifaceName); ClassLoader loader = this.getClass().getClassLoader(); try { Class clz = loader.loadClass("iddb.core.model.dao.cached." + ifaceName + "Cached"); Constructor cons = clz.getConstructor(new Class[] { Class.forName(iface) }); return cons.newInstance(impl); } catch (SecurityException e) { log.warn("No cached implementation found for {} - {}", ifaceName, e.getMessage()); throw new Exception(e); } catch (IllegalArgumentException e) { log.warn("No cached implementation found for {} - {}", ifaceName, e.getMessage()); throw new Exception(e); } catch (ClassNotFoundException e) { log.warn("No cached implementation found for {} - {}", ifaceName, e.getMessage()); throw new Exception(e); } catch (NoSuchMethodException e) { log.warn("No cached implementation found for {} - {}", ifaceName, e.getMessage()); throw new Exception(e); } catch (InstantiationException e) { log.warn("No cached implementation found for {} - {}", ifaceName, e.getMessage()); throw new Exception(e); } catch (IllegalAccessException e) { log.warn("No cached implementation found for {} - {}", ifaceName, e.getMessage()); throw new Exception(e); } catch (InvocationTargetException e) { e.printStackTrace(); log.warn("No cached implementation found for {} - {}", ifaceName, e.getMessage()); throw new Exception(e); } }
From source file:org.jadira.scanner.classpath.types.JField.java
public Field getActualField() { try {//from ww w . j a v a 2s . c o m return getEnclosingType().getActualClass().getDeclaredField(getName()); } catch (SecurityException e) { throw new ClasspathAccessException("Problem obtaining field: " + e.getMessage(), e); } catch (NoSuchFieldException e) { throw new ClasspathAccessException("Problem finding field: " + this.toString(), e); } }
From source file:org.phenotips.panels.rest.internal.DefaultGenePanelsPatientResourceImpl.java
@Override public Response getPatientGeneCounts(final String patientId) { // Check if patient ID is provided. if (StringUtils.isBlank(patientId)) { this.logger.error("No patient ID was provided."); return Response.status(Response.Status.BAD_REQUEST).build(); }/*from ww w. j a va 2s. co m*/ // Patient ID is provided, get the gene panel for the patient if user has access and if the patient exists. try { // Try to get the patient object. final Patient patient = this.repository.get(patientId); // Check if the patient exists. if (patient == null) { this.logger.error("Could not find patient with ID {}", patientId); return Response.status(Response.Status.NOT_FOUND).build(); } final JSONObject genePanel = this.genePanelFactory.build(patient).toJSON(); return Response.ok(genePanel, MediaType.APPLICATION_JSON_TYPE).build(); } catch (final SecurityException ex) { // The user has no access rights for the requested patient. this.logger.error("View access denied on patient record [{}]: {}", patientId, ex.getMessage()); return Response.status(Response.Status.UNAUTHORIZED).build(); } }
From source file:com.paladin.mvc.URLMappingFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { // ? ?/*from w ww. j a v a 2 s . com*/ HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; RequestContext rc = RequestContext.begin(this.context, request, response); String req_uri = rc.uri(); try { // URL ? for (String ignoreURI : ignoreURIs) { if (req_uri.startsWith(ignoreURI)) { chain.doFilter(rc.request(), rc.response()); return; } } // URL ? for (String ignoreExt : ignoreExts) { if (req_uri.endsWith(ignoreExt)) { chain.doFilter(rc.request(), rc.response()); return; } } rc.request().setAttribute(REQUEST_URI, req_uri); String[] paths = StringUtils.split(req_uri, '/'); String vm = _GetTemplate(rc.request(), paths, paths.length); rc.forward(vm); } catch (SecurityException e) { String login_page = e.getMessage() + "?goto_page=" + URLEncoder.encode(req_uri, "utf-8"); rc.redirect(login_page); } finally { if (rc != null) rc.end(); } }
From source file:cz.incad.Kramerius.views.inc.details.tabs.LoadCustomViewObject.java
public String getContent() throws IOException, ParserConfigurationException, SAXException { StringBuilder stringBuilder = new StringBuilder(); String tab = this.requestProvider.get().getParameter("tab"); String ds = tab;// ww w. j a va2 s . co m String xsl = tab; if (tab.indexOf('.') >= 0) { ds = tab.split("\\.")[0]; xsl = tab.split("\\.")[1] + ".xsl"; } String pid_path = this.requestProvider.get().getParameter("pid_path"); List<String> pids = Arrays.asList(pid_path.split("/")); if (ds.startsWith("-")) { Collections.reverse(pids); ds = ds.substring(1); } for (String pid : pids) { if (fedoraAccess.isStreamAvailable(pid, ds)) { String mime = fedoraAccess.getMimeTypeForStream(pid, ds); if (mime.equals("text/plain")) { try { InputStream is = fedoraAccess.getDataStream(pid, ds); byte[] bytes = org.apache.commons.io.IOUtils.toByteArray(is); String enc = UnicodeUtil.getEncoding(bytes); ByteArrayInputStream is2 = new ByteArrayInputStream(bytes); stringBuilder.append("<textarea style=\"width:98%; height:98%; border:0; \">" + IOUtils.readAsString(is2, Charset.forName(enc), true) + "</textarea>"); } catch (cz.incad.kramerius.security.SecurityException e) { LOGGER.log(Level.INFO, e.getMessage()); } } else if (mime.equals("text/xml") || mime.equals("application/rdf+xml")) { try { if (xslService.isAvailable(xsl)) { org.w3c.dom.Document xml = XMLUtils.parseDocument(fedoraAccess.getDataStream(pid, ds), true); String text = xslService.transform(xml, xsl, this.localesProvider.get()); stringBuilder.append(text); } else { String xmltext = org.apache.commons.io.IOUtils .toString(fedoraAccess.getDataStream(pid, ds), Charset.forName("UTF-8")); stringBuilder.append(StringEscapeUtils.escapeHtml4(xmltext)); } } catch (cz.incad.kramerius.security.SecurityException e) { LOGGER.log(Level.INFO, e.getMessage()); } catch (Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } } else if (mime.equals("text/html")) { try { String xmltext = org.apache.commons.io.IOUtils.toString(fedoraAccess.getDataStream(pid, ds), Charset.forName("UTF-8")); stringBuilder.append(xmltext); } catch (cz.incad.kramerius.security.SecurityException e) { LOGGER.log(Level.INFO, e.getMessage()); } catch (Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } } } } return stringBuilder.toString(); }
From source file:com.cws.esolutions.security.quartz.PasswordExpirationNotifier.java
/** * @see org.quartz.Job#execute(org.quartz.JobExecutionContext) *///from w ww . ja va2 s . c o m public void execute(final JobExecutionContext context) { final String methodName = PasswordExpirationNotifier.CNAME + "#execute(final JobExecutionContext jobContext)"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("JobExecutionContext: {}", context); } final Map<String, Object> jobData = context.getJobDetail().getJobDataMap(); if (DEBUG) { DEBUGGER.debug("jobData: {}", jobData); } try { UserManager manager = UserManagerFactory .getUserManager(bean.getConfigData().getSecurityConfig().getUserManager()); if (DEBUG) { DEBUGGER.debug("UserManager: {}", manager); } List<String[]> accounts = manager.listUserAccounts(); if (DEBUG) { DEBUGGER.debug("accounts: {}", accounts); } if ((accounts == null) || (accounts.size() == 0)) { return; } Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, 30); Long expiryTime = cal.getTimeInMillis(); if (DEBUG) { DEBUGGER.debug("Calendar: {}", cal); DEBUGGER.debug("expiryTime: {}", expiryTime); } for (String[] account : accounts) { if (DEBUG) { DEBUGGER.debug("Account: {}", (Object) account); } List<Object> accountDetail = manager.loadUserAccount(account[0]); if (DEBUG) { DEBUGGER.debug("List<Object>: {}", accountDetail); } try { Email email = new SimpleEmail(); email.setHostName((String) jobData.get("mailHost")); email.setSmtpPort(Integer.parseInt((String) jobData.get("portNumber"))); if ((Boolean) jobData.get("isSecure")) { email.setSSLOnConnect(true); } if ((Boolean) jobData.get("isAuthenticated")) { email.setAuthenticator(new DefaultAuthenticator((String) jobData.get("username"), PasswordUtils.decryptText((String) (String) jobData.get("password"), (String) jobData.get("salt"), secConfig.getSecretAlgorithm(), secConfig.getIterations(), secConfig.getKeyBits(), secConfig.getEncryptionAlgorithm(), secConfig.getEncryptionInstance(), systemConfig.getEncoding()))); } email.setFrom((String) jobData.get("emailAddr")); email.addTo((String) accountDetail.get(6)); email.setSubject((String) jobData.get("messageSubject")); email.setMsg(String.format((String) jobData.get("messageBody"), (String) accountDetail.get(4))); if (DEBUG) { DEBUGGER.debug("SimpleEmail: {}", email); } email.send(); } catch (EmailException ex) { ERROR_RECORDER.error(ex.getMessage(), ex); } catch (SecurityException sx) { ERROR_RECORDER.error(sx.getMessage(), sx); } } } catch (UserManagementException umx) { ERROR_RECORDER.error(umx.getMessage(), umx); } }
From source file:org.castor.cache.distributed.OsCacheFactory.java
/** * Invoke method with given name and arguments having parameters of types * specified on the given target. Any possible exception will be catched and * IllegalStateException will be thrown instead. * //from w w w . j a v a2 s . co m * @param target The target object to invoke the method on. * @param name The name of the method to invoke. * @param types The types of the parameters. * @param arguments The parameters. * @return The result of the method invocation. */ private Object invokeMethod(final Object target, final String name, final Class<?>[] types, final Object[] arguments) { try { Method method = target.getClass().getMethod(name, types); return method.invoke(target, arguments); } catch (SecurityException e) { LOG.error("SecurityException", e); throw new IllegalStateException(e.getMessage()); } catch (NoSuchMethodException e) { LOG.error("NoSuchMethodException", e); throw new IllegalStateException(e.getMessage()); } catch (IllegalArgumentException e) { LOG.error("IllegalArgumentException", e); throw new IllegalStateException(e.getMessage()); } catch (IllegalAccessException e) { LOG.error("IllegalAccessException", e); throw new IllegalStateException(e.getMessage()); } catch (InvocationTargetException e) { LOG.error("InvocationTargetException", e); throw new IllegalStateException(e.getMessage()); } }
From source file:net.bubble.common.utils.BeanContextUtil.java
/** * ?cglib?</br>/*w w w .ja v a 2s . c o m*/ * Spring??AOP?cglib?? * @param proxy ? * @return Object * @throws CommonException cblib??? */ public Object getCglibProxyTargetObject(Object proxy) throws CommonException { try { Field field = proxy.getClass().getDeclaredField("CGLIB$CALLBACK_0"); field.setAccessible(true); Object dynamicAdvisedInterceptor = field.get(proxy); Field advised = dynamicAdvisedInterceptor.getClass().getDeclaredField("advised"); advised.setAccessible(true); return ((AdvisedSupport) advised.get(dynamicAdvisedInterceptor)).getTargetSource().getTarget(); } catch (SecurityException e) { logger.error(e.getMessage(), e); throw new CommonException("The method of object with cglib can't be read !", e); } catch (NoSuchFieldException e) { logger.error(e.getMessage(), e); throw new CommonException("Can't find field in cglib object !", e); } catch (IllegalArgumentException e) { logger.error(e.getMessage(), e); throw new CommonException("Inject parameter to cglib object has error !", e); } catch (IllegalAccessException e) { logger.error(e.getMessage(), e); throw new CommonException("Access cglib object has error !", e); } catch (Exception e) { logger.error(e.getMessage(), e); throw new CommonException("Get cglib target object has error !", e); } }