Security Concerns When Invoking a Signed Java Applet via JavaScript

In my Java Applet, there is a method titled SaveToFile(String text):

public Boolean SaveToFile(String text)
{
    File file = new File("c:\\myFile.txt");

    if (!file.exists()) {
        file.createNewFile();
    }

    file.setReadable(true);
    file.setWritable(true);
    FileWriter fw = new FileWriter(file.getAbsoluteFile());
    BufferedWriter bw = new BufferedWriter(fw);
    bw.write(text);
    bw.close();
    return true;
}

When I trigger this method from a button within the applet, it successfully creates the file. However, when calling this method from JavaScript, an exception occurs:

access denied (java.io.FilePermission c:\myFile.txt read)

What steps can be taken to resolve this exception?

Answer №1

Resolved the issue by implementing AccessController:

    public Boolean WriteToTextFile(String content)
    {
    final String textContent = content;
    return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {

            @Override
            public Boolean run()
            {
    
    File file = new File("c:\\myFile.txt");

    // Create the file if it does not exist
    if ( !file.exists( ) )
    {
        file.createNewFile( );
    }

    file.setReadable(true);
    file.setWritable(true);
    FileWriter fw = new FileWriter( file.getAbsoluteFile( ) );
    BufferedWriter bw = new BufferedWriter( fw );
    bw.write( textContent );
    bw.close( );
    return true;
    } }
 });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The computed properties in Vue are not receiving any values when an array is passed using v-bind

Embarking on my Vue journey with a simple example, I am attempting to calculate the sum of items based on the provided data. If you wish to explore the complete example, it can be accessed in this jsffile. Here is the component structure: Vue.component(&a ...

Revive the design of a website

As I work on creating my own homepage, I came across someone else's page that I really liked. I decided to download the page source and open it locally in my browser. However, I noticed that while the contents were all there, the style (frames, positi ...

Reinitializing AngularJS form controls

Check out this codepen example: http://codepen.io/anon/pen/EjKqbW I'm trying to reset the form elements when the user clicks on "Reset". The div elements f1,f2,f3 should be hidden and the searchText box cleared. However, the reset button is not trig ...

Designing a cylinder with an angled base

I am looking to generate a unique cylinder with a slanted bottom shape using three.js. I have explored the documentation but did not come across any built-in features for creating this specific geometry. I attempted to cut the cylinder with a slanted pla ...

Utilizing $.when to merge AJAX requests and then passing the resulting data to a designated function

I am struggling with sending data between functions and using $.when in my JavaScript code. I have separate functions and AJAX calls that update content on the page, but they need to load together on page load. Despite trying various solutions to combine A ...

Comparing .innerHTML with createElement() | Exploring setAttribute() versus the Direct method*

Someone mentioned that this approach was not considered "proper", but I didn't pay much attention to it until I encountered a run-time error in IE9. Now, I need help converting the code to utilize object properties instead. What is the reason behind i ...

My debug Keystore file has gone missing

After creating an app without a specific Keystore file, I released it using the default debug keystore file from the bin folder. Now that I have changed my laptop and operating system, I still have the same code and project in Eclipse. However, when I ma ...

Creating a seamless onscroll effect

Can someone please help me achieve the same smooth scrolling effect seen on these websites: I appreciate your assistance in making my website's scroll as seamless as these examples. Thank you! ...

AngularJS POST request encounters failure: Preflight response contains improperly formatted HTTP status code 404

I have encountered a persistent issue with microframeworks while attempting to perform a simple POST request. Despite trying multiple frameworks, none of them seem to handle the POST request properly: Here is an example using AngularJS on the client side: ...

Symbol positioned beside the text in a react-select multiple label

Currently utilizing the react-select library, I am attempting to display icons next to the text of each label that can be added or removed using multiSelect. const data = [ { label: <svg /> && 'keyword one', value: 'keyword o ...

Retrieve the most recent version based on the provided ID and date within the array

I am working with an array of JavaScript objects that have specific properties: _id, isVersionFrom, createdAt. The _id and isVersionFrom properties store MongoDB _ids (with isVersionFrom being false for the original object), while createdAt stores a timest ...

Arranging a numerical array alongside a String array to create a scoreboard

I am in the process of developing a game and need to create a scoreboard for it. The challenge I am facing is implementing a sorting algorithm that can arrange the scores in descending order, specifically using a bubble sort algorithm. However, the issue I ...

Switch Button JavaScript Library

My project involves creating a mobile website with a simple interaction where clicking on a div opens another div underneath it. The HTML structure consists of two stacked divs, with the CSS for the bottom div initially set to 'none'. Using JavaS ...

api for enhancing images in Laravel app through preview, enlarge, and zoom functionalities

As I work on my website, I aim to display images in a compact space, such as within a 300x300 <div>. What I envision is the ability for users to preview or enlarge these images upon clicking, allowing for a closer and more detailed view. For exampl ...

Set a delay for an AJAX request using jQuery

Is it possible to incorporate a setTimeout function into this ajax call? Here's the code snippet: jQuery.ajax({ type : "POST", url : dir+"all/money/myFile.php", data : "page="+data.replace(/\&/g, '^'), suc ...

The unexpected token "[ ]" was encountered while assigning a numerical value to an array

Hey everyone, I have a question that's been bothering me and I can't seem to find the answer anywhere. I'm currently learning pure JavaScript and although I am familiar with several other programming languages, I keep running into an issue ...

Tips on personalizing the "host" header when using Java HTTP client

Below is the code I am currently using: HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("http://127.0.0.1:8081/")) .header("Host", "test.example.com") .build(); client.send(request ...

Unable to integrate multiple webpack projects: Uncaught SyntaxError occurs due to a missing closing parenthesis after the argument list

My website features a section where clients can track their projects. One aspect of the site involves viewing a blueprint created using THREE.js and bundled with webpack. I have been tasked with adding another type of blueprint to the site. I have success ...

Customizing Headers in Spring Integration for Dynamic Processing

When a user logs in during Spring-integration Http request, a dynamic header parameter needs to be added. For example, if user "A" is logged in and makes an Http request, an additional dynamic 1 header should be included. For other users, the key should re ...

Unable to configure raycaster layers within Three.js framework

While attempting to configure the raycaster layer to only cast on a single layer, as outlined in the threejs documentation: - I encountered the following error Uncaught TypeError: Cannot read properties of undefined (reading 'set') What could b ...