List of usage examples for java.lang SecurityException getMessage
public String getMessage()
From source file:org.siyapath.task.TaskProcessor.java
/** * Process the task using instantiated java class generated through reflection *//* ww w . j a v a 2s .c o m*/ private void processTask() { try { log.info("Starting the task: " + task.getTaskID()); taskInstance.setData(task.getTaskData()); taskInstance.process(); // taskInstance.setMetaData(String.valueOf(context.getNodeResource().getNodeInfo().getNodeId())); byte[] finalResult = taskInstance.getResults(); taskResult.setResults(finalResult); taskResult.setStatus(TaskStatus.COMPLETED); log.debug("Task processing is successful. ID: " + task.getTaskID()); } catch (SecurityException e) { siyapathSecurityManager.disable("secpass"); log.error("Task Processing aborted due to an attempt of illegal operation: " + e.getMessage()); taskResult.setStatus(TaskStatus.ABORTED_SECURITY); taskResult.setResults("<aborted_security_error>".getBytes()); } catch (ExceptionInInitializerError e) { siyapathSecurityManager.disable("secpass"); if (e.getCause() instanceof SecurityException) { log.error("Task Processing aborted due to an attempt of illegal operation: " + e.getMessage()); taskResult.setStatus(TaskStatus.ABORTED_SECURITY); taskResult.setResults("<aborted_security_error>".getBytes()); } log.error("Task Processing aborted due to an error: " + e.getMessage()); taskResult.setStatus(TaskStatus.ABORTED_SECURITY); taskResult.setResults("<aborted_error>".getBytes()); } catch (Exception e) { siyapathSecurityManager.disable("secpass"); log.error("Task Processing aborted due to an error: " + e.getMessage()); taskResult.setStatus(TaskStatus.ABORTED_SECURITY); taskResult.setResults("<aborted_error>".getBytes()); } }
From source file:com.rapidminer.operator.ScriptingOperator.java
@Override public void doWork() throws OperatorException { String script = getParameterAsString(PARAMETER_SCRIPT); if (getParameterAsBoolean(PARAMETER_STANDARD_IMPORTS)) { StringBuffer imports = new StringBuffer(); imports.append("import com.rapidminer.example.*;\n"); imports.append("import com.rapidminer.example.set.*;\n"); imports.append("import com.rapidminer.example.table.*;\n"); imports.append("import com.rapidminer.operator.*;\n"); imports.append("import com.rapidminer.tools.Tools;\n"); imports.append("import java.util.*;\n"); script = imports.toString() + script; }//from w w w.j a v a2s . co m List<IOObject> input = inExtender.getData(IOObject.class, false); Object result; try { // cache access is synchronized on a per-script basis to prevent Execute Script // inside a loop to start many parsings at the same time Object lock; synchronized (LOCK_MAP) { lock = LOCK_MAP.get(script); if (lock == null) { lock = new Object(); LOCK_MAP.put(script, lock); } } Script cachedScript; synchronized (lock) { cachedScript = SCRIPT_CACHE.get(script); if (cachedScript == null) { // use the delegator which is capable of handling multi-threaded access as // binding GroovyShell shell = new GroovyShell(Plugin.getMajorClassLoader(), new ConcurrentBindingDelegator()); GroovyCodeSource codeSource = new GroovyCodeSource(script, "customScript", GROOVY_DOMAIN); codeSource.setCachable(false); cachedScript = shell.parse(codeSource); SCRIPT_CACHE.put(script, cachedScript); } } // even though we cache the script, we need to use a new binding for each execution to // avoid multiple concurrent scripts running on the same/editing the same binding cachedScript.getBinding().setVariable("input", input); cachedScript.getBinding().setVariable("operator", this); // run the script via the delegator result = cachedScript.run(); } catch (SecurityException e) { throw new UserError(this, e, "scriptingOperator_security", e.getMessage()); } catch (GroovyBugError e) { if (e.getCause() instanceof SecurityException) { throw new UserError(this, e.getCause(), "scriptingOperator_security", e.getCause().getMessage()); } else { throw new UserError(this, e, 945, "Groovy", e); } } catch (Throwable e) { throw new UserError(this, e, 945, "Groovy", e, ExceptionUtils.getStackTrace(e)); } if (result instanceof Object[]) { outExtender.deliver(Arrays.asList((IOObject[]) result)); } else if (result instanceof List) { List<IOObject> results = new LinkedList<IOObject>(); for (Object single : (List<?>) result) { if (single instanceof IOObject) { results.add((IOObject) single); } else { getLogger().warning("Unknown result type: " + single); } } outExtender.deliver(results); } else { if (result != null) { if (result instanceof IOObject) { outExtender.deliver(Collections.singletonList((IOObject) result)); } else { getLogger().warning("Unknown result: " + result.getClass() + ": " + result); } } } }
From source file:org.fao.geonet.api.records.MetadataApi.java
@ApiOperation(value = "Get record related resources", nickname = "getAssociated", notes = "Retrieve related services, datasets, onlines, thumbnails, sources, ... " + "to this records.<br/>" + "<a href='http://geonetwork-opensource.org/manuals/trunk/eng/users/user-guide/associating-resources/index.html'>More info</a>") @RequestMapping(value = "/{metadataUuid}/related", method = RequestMethod.GET, produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) @ResponseStatus(HttpStatus.OK)// w w w . j av a 2s . c o m @ApiResponses(value = { @ApiResponse(code = 200, message = "Return the associated resources."), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_CAN_VIEW) }) @ResponseBody public RelatedResponse getRelated( @ApiParam(value = API_PARAM_RECORD_UUID, required = true) @PathVariable String metadataUuid, @ApiParam(value = "Type of related resource. If none, all resources are returned.", required = false) @RequestParam(defaultValue = "") RelatedItemType[] type, @ApiParam(value = "Start offset for paging. Default 1. Only applies to related metadata records (ie. not for thumbnails).", required = false) @RequestParam(defaultValue = "1") int start, @ApiParam(value = "Number of rows returned. Default 100.") @RequestParam(defaultValue = "100") int rows, HttpServletRequest request) throws Exception { AbstractMetadata md; try { md = ApiUtils.canViewRecord(metadataUuid, request); } catch (SecurityException e) { Log.debug(API.LOG_MODULE_NAME, e.getMessage(), e); throw new NotAllowedException(ApiParams.API_RESPONSE_NOT_ALLOWED_CAN_VIEW); } String language = languageUtils.getIso3langCode(request.getLocales()); // TODO PERF: ByPass XSL processing and create response directly // At least for related metadata and keep XSL only for links final ServiceContext context = ApiUtils.createServiceContext(request); Element raw = new Element("root").addContent(Arrays.asList( new Element("gui").addContent(Arrays.asList(new Element("language").setText(language), new Element("url").setText(context.getBaseUrl()))), MetadataUtils.getRelated(context, md.getId(), md.getUuid(), type, start, start + rows, true))); GeonetworkDataDirectory dataDirectory = context.getBean(GeonetworkDataDirectory.class); Path relatedXsl = dataDirectory.getWebappDir().resolve("xslt/services/metadata/relation.xsl"); final Element transform = Xml.transform(raw, relatedXsl); RelatedResponse response = (RelatedResponse) Xml.unmarshall(transform, RelatedResponse.class); return response; }
From source file:org.fao.geonet.api.records.MetadataApi.java
@ApiOperation(value = "Get a metadata record", notes = "Depending on the accept header the appropriate formatter is used. " + "When requesting a ZIP, a MEF version 2 file is returned. " + "When requesting HTML, the default formatter is used.", nickname = "getRecord") @RequestMapping(value = "/{metadataUuid:.+}", method = RequestMethod.GET, consumes = { MediaType.ALL_VALUE }, produces = { MediaType.TEXT_HTML_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_XHTML_XML_VALUE, MediaType.APPLICATION_JSON_VALUE, "application/pdf", "application/zip", MEF_V1_ACCEPT_TYPE, MEF_V2_ACCEPT_TYPE, MediaType.ALL_VALUE }) @ApiResponses(value = { @ApiResponse(code = 200, message = "Return the record."), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_CAN_VIEW), @ApiResponse(code = 404, message = ApiParams.API_RESPONSE_RESOURCE_NOT_FOUND) }) public String getRecord( @ApiParam(value = API_PARAM_RECORD_UUID, required = true) @PathVariable String metadataUuid, @ApiParam(value = "Accept header should indicate which is the appropriate format " + "to return. It could be text/html, application/xml, application/zip, ..." + "If no appropriate Accept header found, the XML format is returned.", required = true) @RequestHeader(value = HttpHeaders.ACCEPT, defaultValue = MediaType.APPLICATION_XML_VALUE, required = false) String acceptHeader, HttpServletResponse response, HttpServletRequest request) throws Exception { try {//from ww w . j av a 2s .co m ApiUtils.canViewRecord(metadataUuid, request); } catch (SecurityException e) { Log.debug(API.LOG_MODULE_NAME, e.getMessage(), e); throw new NotAllowedException(ApiParams.API_RESPONSE_NOT_ALLOWED_CAN_VIEW); } List<String> accept = Arrays.asList(acceptHeader.split(",")); String defaultFormatter = "xsl-view"; if (accept.contains(MediaType.TEXT_HTML_VALUE) || accept.contains(MediaType.APPLICATION_XHTML_XML_VALUE) || accept.contains("application/pdf")) { return "forward:" + (metadataUuid + "/formatters/" + defaultFormatter); } else if (accept.contains(MediaType.APPLICATION_XML_VALUE) || accept.contains(MediaType.APPLICATION_JSON_VALUE)) { return "forward:" + (metadataUuid + "/formatters/xml"); } else if (accept.contains("application/zip") || accept.contains(MEF_V1_ACCEPT_TYPE) || accept.contains(MEF_V2_ACCEPT_TYPE)) { return "forward:" + (metadataUuid + "/formatters/zip"); } else { // FIXME this else is never reached because any of the accepted medias match one of the previous if conditions. response.setHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_XHTML_XML_VALUE); //response.sendRedirect(metadataUuid + "/formatters/" + defaultFormatter); return "forward:" + (metadataUuid + "/formatters/" + defaultFormatter); } }
From source file:com.example.scandevice.GeofenceTransitionsIntentService.java
/** * Handles incoming intents.//from ww w .jav a2s .c o m * @param intent sent by Location Services. This Intent is provided to Location * Services (inside a PendingIntent) when addGeofences() is called. */ @Override protected void onHandleIntent(Intent intent) { initializeLocationManager(); try { mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, LOCATION_INTERVAL, LOCATION_DISTANCE, mLocationListeners[0]); } catch (java.lang.SecurityException ex) { Log.i(TAG, "fail to request location update, ignore", ex); } catch (IllegalArgumentException ex) { Log.d(TAG, "network provider does not exist, " + ex.getMessage()); } GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); if (geofencingEvent.hasError()) { Log.w(TAG, "hasError"); return; } // Get the transition type. int geofenceTransition = geofencingEvent.getGeofenceTransition(); // Test that the reported transition was of interest. if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER || geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) { // Get the geofences that were triggered. A single event can trigger multiple geofences. List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Get the transition details as a String. String geofenceTransitionDetails = getGeofenceTransitionDetails(this, geofenceTransition, triggeringGeofences); // Send notification and log the transition details. sendNotification(geofenceTransitionDetails); Log.i(TAG, geofenceTransitionDetails); } else { // Log the error. Log.e(TAG, getString(R.string.geofence_transition_invalid_type, geofenceTransition)); } }
From source file:opendap.noaa_s3.RemoteResource.java
public void writeResourceToFile(File targetFile) throws IOException { log.debug("writeResourceToFile() - targetFile: '{}'", targetFile); File parent = targetFile.getParentFile(); if (!parent.exists()) { try {/* w w w . j a v a2 s.com*/ boolean madeIt = parent.mkdirs(); if (!madeIt) { String msg = "Unable to create the directory path: '" + parent + "'."; log.error("writeResourceToFile() - " + msg); throw new IOException(msg); } } catch (SecurityException e) { String msg = "This process does not have permission to create the directory path: '" + parent + "' msg: " + e.getMessage(); log.error("writeResourceToFile() -" + msg); throw new IOException(msg); } } String url = getResourceUrl(); log.debug("writeResourceToFile() - resource url: '{}'", url); if (!targetFile.exists()) { log.debug("Attempting to create target file: '{}'", targetFile.getAbsolutePath()); targetFile.createNewFile(); } FileOutputStream target_os = null; InputStream resource_is = null; try { target_os = new FileOutputStream(targetFile); resource_is = getRemoteHttpResourceAsStream(); IOUtils.copy(resource_is, target_os); } finally { if (resource_is != null) resource_is.close(); if (target_os != null) target_os.close(); } }
From source file:info.magnolia.cms.beans.config.ConfigLoader.java
/** * Initialize a ConfigLoader instance. All the supplied parameters will be set in * <code>info.magnolia.cms.beans.runtime.SystemProperty</code> * @param context ServletContext// w w w .j ava2 s . co m * @param config contains initialization parameters * @see SystemProperty */ public ConfigLoader(ServletContext context, Map config) { String rootDir = context.getRealPath(StringUtils.EMPTY); if (log.isInfoEnabled()) { log.info("Assuming paths relative to {}", rootDir); //$NON-NLS-1$ } SystemProperty.setProperty(SystemProperty.MAGNOLIA_APP_ROOTDIR, rootDir); // load mgnl-beans.properties first InputStream mgnlbeansStream = getClass().getResourceAsStream(MGNL_BEANS_PROPERTIES); if (mgnlbeansStream != null) { Properties mgnlbeans = new Properties(); try { mgnlbeans.load(mgnlbeansStream); } catch (IOException e) { log.error("Unable to load {} due to an IOException: {}", MGNL_BEANS_PROPERTIES, e.getMessage()); } finally { IOUtils.closeQuietly(mgnlbeansStream); } for (Iterator iter = mgnlbeans.keySet().iterator(); iter.hasNext();) { String key = (String) iter.next(); SystemProperty.setProperty(key, mgnlbeans.getProperty(key)); } } else { log.warn( "{} not found in the classpath. Check that all the needed implementation classes are defined in your custom magnolia.properties file.", MGNL_BEANS_PROPERTIES); } Iterator it = config.entrySet().iterator(); while (it.hasNext()) { Map.Entry param = (Map.Entry) it.next(); SystemProperty.setProperty((String) param.getKey(), (String) param.getValue()); } if (StringUtils.isEmpty(System.getProperty("java.security.auth.login.config"))) { //$NON-NLS-1$ try { System.setProperty("java.security.auth.login.config", Path //$NON-NLS-1$ .getAbsoluteFileSystemPath("WEB-INF/config/jaas.config")); //$NON-NLS-1$ } catch (SecurityException se) { log.error("Failed to set java.security.auth.login.config, check application server settings"); //$NON-NLS-1$ log.error(se.getMessage(), se); log.info("Aborting startup"); return; } } else { if (log.isInfoEnabled()) { log.info("JAAS config file set by parent container or some other application"); //$NON-NLS-1$ log.info("Config in use " + System.getProperty("java.security.auth.login.config")); //$NON-NLS-1$ //$NON-NLS-2$ log.info( "Please make sure JAAS config has all necessary modules (refer config/jaas.config) configured"); //$NON-NLS-1$ } } this.load(context); }
From source file:br.liveo.ndrawer.ui.fragment.MainFragment.java
private void updateEvent(String event) { RequestEpcisCapture erc = new RequestEpcisCapture(); String eventDate = new SimpleDateFormat("yyyy-MM-dd").format((System.currentTimeMillis())); String eventTime = new SimpleDateFormat("HH:mm:ss").format((System.currentTimeMillis())); Location location = null;/*from ww w . ja va2 s .co m*/ try { if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) location = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location == null && mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } catch (SecurityException ex) { Log.i("Timer:", ex.getMessage()); } String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<!DOCTYPE project>\n" + "<epcis:EPCISDocument xmlns:epcis=\"urn:epcglobal:epcis:xsd:1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" + " creationDate=\"2015-01-03T11:30:47.0Z\" schemaVersion=\"1.1\" xmlns:car=\"BiPortalGs1.xsd\">\n" + " <EPCISBody>\n" + " <EventList>\n" + " <ObjectEvent>\n" + " <!-- When -->\n" + " <eventTime>" + eventDate + "T" + eventTime + ".116-10:00</eventTime>\n" + " <eventTimeZoneOffset>-10:00</eventTimeZoneOffset>\n" + " <!-- When! -->\n" + "\n" + " <!-- What -->\n" + " <epcList>\n" + " <epc>urn:epc:id:sgtin:1234567.123456.01</epc>\n" + " </epcList>\n" + " <!-- What!-->\n" + "\n" + " <!-- Add, Observe, Delete -->\n" + " <action>ADD</action>\n" + "\n" + " <!-- Why -->\n" + " <bizStep>urn:epcglobal:cbv:bizstep:" + event + "</bizStep>\n" + " <disposition>urn:epcglobal:cbv:disp:user_accessible</disposition>\n" + " <!-- Why! -->\n" + "\n" + " <!-- Where -->\n" + " <bizLocation>\n" + " <id>urn:epc:id:sgln:7654321.54321.1234</id>\n" + " <extension>\n" + " <geo>" + location.getLatitude() + "," + location.getLongitude() + "</geo>\n" + " </extension>\n" + " </bizLocation>\n" + " <!-- Where! -->\n" + " </ObjectEvent>\n" + " </EventList>\n" + " </EPCISBody>\n" + "</epcis:EPCISDocument>"; erc.execute(xml); }
From source file:org.fao.geonet.api.records.MetadataApi.java
@ApiOperation(value = "Get a metadata record as ZIP", notes = "Metadata Exchange Format (MEF) is returned. MEF is a ZIP file containing " + "the metadata as XML and some others files depending on the version requested. " + "See http://geonetwork-opensource.org/manuals/trunk/eng/users/annexes/mef-format.html.", nickname = "getRecordAsZip") @RequestMapping(value = "/{metadataUuid}/formatters/zip", method = RequestMethod.GET, consumes = { MediaType.ALL_VALUE }, produces = { "application/zip", MEF_V1_ACCEPT_TYPE, MEF_V2_ACCEPT_TYPE }) @ApiResponses(value = { @ApiResponse(code = 200, message = "Return the record."), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_CAN_VIEW) }) public @ResponseBody void getRecordAsZip( @ApiParam(value = API_PARAM_RECORD_UUID, required = true) @PathVariable String metadataUuid, @ApiParam(value = "MEF file format.", required = false) @RequestParam(required = false, defaultValue = "FULL") MEFLib.Format format, @ApiParam(value = "With related records (parent and service).", required = false) @RequestParam(required = false, defaultValue = "true") boolean withRelated, @ApiParam(value = "Resolve XLinks in the records.", required = false) @RequestParam(required = false, defaultValue = "true") boolean withXLinksResolved, @ApiParam(value = "Preserve XLink URLs in the records.", required = false) @RequestParam(required = false, defaultValue = "false") boolean withXLinkAttribute, @RequestParam(required = false, defaultValue = "true") boolean addSchemaLocation, @RequestHeader(value = HttpHeaders.ACCEPT, defaultValue = "application/x-gn-mef-2-zip") String acceptHeader, HttpServletResponse response, HttpServletRequest request) throws Exception { ApplicationContext appContext = ApplicationContextHolder.get(); GeonetworkDataDirectory dataDirectory = appContext.getBean(GeonetworkDataDirectory.class); AbstractMetadata metadata;/* w w w. jav a 2 s . co m*/ try { metadata = ApiUtils.canViewRecord(metadataUuid, request); } catch (SecurityException e) { Log.debug(API.LOG_MODULE_NAME, e.getMessage(), e); throw new NotAllowedException(ApiParams.API_RESPONSE_NOT_ALLOWED_CAN_VIEW); } Path stylePath = dataDirectory.getWebappDir().resolve(Geonet.Path.SCHEMAS); Path file = null; ServiceContext context = ApiUtils.createServiceContext(request); MEFLib.Version version = MEFLib.Version.find(acceptHeader); if (version == MEFLib.Version.V1) { // This parameter is deprecated in v2. boolean skipUUID = false; file = MEFLib.doExport(context, metadataUuid, format.toString(), skipUUID, withXLinksResolved, withXLinkAttribute, addSchemaLocation); } else { Set<String> tmpUuid = new HashSet<String>(); tmpUuid.add(metadataUuid); // MEF version 2 support multiple metadata record by file. if (withRelated) { // Adding children in MEF file // Creating request for services search Element childRequest = new Element("request"); childRequest.addContent(new Element("parentUuid").setText(metadataUuid)); childRequest.addContent(new Element("to").setText("1000")); // Get children to export - It could be better to use GetRelated service TODO Set<String> childs = MetadataUtils.getUuidsToExport(metadataUuid, request, childRequest); if (childs.size() != 0) { tmpUuid.addAll(childs); } // Creating request for services search Element servicesRequest = new Element(Jeeves.Elem.REQUEST); servicesRequest .addContent(new Element(org.fao.geonet.constants.Params.OPERATES_ON).setText(metadataUuid)); servicesRequest.addContent(new Element(org.fao.geonet.constants.Params.TYPE).setText("service")); // Get linked services for export Set<String> services = MetadataUtils.getUuidsToExport(metadataUuid, request, servicesRequest); if (services.size() != 0) { tmpUuid.addAll(services); } } Log.info(Geonet.MEF, "Building MEF2 file with " + tmpUuid.size() + " records."); file = MEFLib.doMEF2Export(context, tmpUuid, format.toString(), false, stylePath, withXLinksResolved, withXLinkAttribute, false, addSchemaLocation); } response.setHeader(HttpHeaders.CONTENT_DISPOSITION, String.format("inline; filename=\"%s.zip\"", metadata.getUuid())); response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(Files.size(file))); response.setContentType(acceptHeader); FileUtils.copyFile(file.toFile(), response.getOutputStream()); }
From source file:it.smartcommunitylab.aac.controller.AuthController.java
/** * Callback for mobile 2-factor authentication. * @param req// w ww .j a v a 2 s . c o m * @param res * @param provider * @return */ @RequestMapping("/mobile2factor-callback/{provider}") public ModelAndView mobile2FactorCallback(HttpServletRequest req, HttpServletResponse res, @PathVariable String provider) { AACOAuthRequest oauthRequest = (AACOAuthRequest) req.getSession() .getAttribute(Config.SESSION_ATTR_AAC_OAUTH_REQUEST); if (oauthRequest == null) { return new ModelAndView("redirect:/logout"); } try { mobileAuthManager.callback2FactorCheck(req); oauthRequest.setMobile2FactorConfirmed(); } catch (SecurityException e) { logger.error("mobile 2 factor auth failed: " + e.getMessage()); } return new ModelAndView("forward:/eauth/" + oauthRequest.getAuthority()); }