Using AJAX to make a request in a separate Java application environment with Tomcat

Two of my web applications are built in Java using Spring Security. Each application has its own WAR file and is deployed on a separate context:

localhost:8080/my-app1
localhost:8080/my-app2

However, when attempting to make an AJAX call from my-app1 to a controller in my-app2, I encounter an error stating that my session has expired. This issue arises because the user is authenticated in my-app1 but not in my-app2.

Are there any possible workarounds for this scenario?

Answer ā„–1

Here are two possible solutions I've come up with:

  1. The more secure option: Save an 'id session' in the database for both applications and pass this id in the call. Validate the id on the second application to proceed with the call.
  2. The less secure option: Configure Spring to skip validating the user session for this specific call (url mapping) on my-app2.

I also stumbled upon this resource: Any way to share session state between different applications in tomcat?

Answer ā„–2

One suggestion is to save a login token as a cookie on the browser for both app1 and app2, using the same domain (e.g. localhost). This way, the token will be sent to the backend for authentication in both applications.

The login token can include an encrypted username that the server can decrypt, along with a hashed password for validation purposes.

This concept is similar to the token-based remember me feature in Spring Security.

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

What is the best way to utilize the date in an Airbnb reservation without including the time - only the date?

I am currently utilizing the Airbnb DateRange picker in a React project. <DateRangePicker startDate={this.state.startDate} // momentPropTypes.momentObj or null, startDateId="your_unique_start_date_id" // PropTypes.string.isRequired, endDate ...

Unable to set up cordova using npm version 5.6.0

I'm encountering issues trying to install Cordova on my Linux system (Deepin 15.5). Can anyone offer assistance? $ sudo npm install -g ionic /usr/local/bin/ionic -> /usr/local/lib/node_modules/ionic/bin/ionic npm WARN optional SKIPPING OPTIONAL ...

The inheritance of JavaScript objects results in one object overwriting another inherited object

Seeking guidance on the optimal approach to enable multiple objects to inherit from a parent while having their own prototype functions in nodeJS. The following files are part of the setup: ParserA_file var ParentParser = require('Pare ...

Refresh cookies on monitor using Vue.js

I am in the process of implementing cookies on my website. Initially, I have set up the cookies to be initialized with an empty object when the component is mounted. The goal is to update the cookie whenever the object data changes, but unfortunately, it&a ...

Can a middleware function in Node.js be executed asynchronously?

I've developed a middleware function to validate user access tokens (JWT) ... in case the JWT has expired, I automatically generate a new access token using the user's refresh token (if it is also valid). As my user base grows, I anticipate that ...

What is the best way to retrieve all string constants from HTML or JSX code?

UPDATE: I recently developed my own babel plugin CLI tool named i18nize-react :D I am currently in the process of translating an existing react application from English to another language. The string constants in the JSX are all hardcoded. Is there a sim ...

Monitor fetch() API calls and responses in JavaScript

Iā€™m looking to intercept fetch API requests and responses using JavaScript. Specifically, I want to be able to capture the request URL before it is sent and also intercept the response once it has been received. The code below demonstrates how to inter ...

Creating a sort button in HTML that can efficiently sort various divs within a table is a useful tool for enhancing user experience

My HTML table is populated with various <td> elements. How can I arrange these divs based on IMDb rating, TomatoMeter, etc... [ CSS code is not provided below ] <table> <tr class="row"> <td class="column"> <br> ...

Eavesdrop on the import function in Node.js

I have a unit test where I need to confirm if the SUT makes a call to require with a specific parameter. The module under test has the following implementation: module.exports = function () { require('foo'); }; Now, I am trying to create a te ...

Unable to scrape text using Selenium

I encountered an issue while working with Selenium WebDriver in Java. The code below works fine without using element.click();: public static void main(String[] args) { try { File output = new File("outputs/Output.txt"); FileWriter fw = ...

Node and Express fail to set cookie when used with Nginx server

I am encountering an issue with setting a cookie in my Node app using Express. The cookie sets successfully in the local environment (http), but when deployed to production (https), although I can see the cookie in the response, it is not actually being se ...

Encountering an undefined property error while using Reactjs

I made an attempt to retrieve data using an ajax request, but I am uncertain about the correctness of my code. Here is the code snippet: interface IProps { data: IScheduler; } interface IState { list: IScheduler; } export default class Page extends ...

VueJS does not support certain characters in its JavaScript replace function

In my current situation, I am utilizing the replace method in the following manner: <code v-html="'/<try>/'.replace(/(?:\r\n|\r|\n)/g, 'testing')"></code> As I work with a longer string t ...

How can I load 3-D models in three.js by specifying file content instead of the file path?

I'm looking to develop an interactive online model viewer that allows users to easily upload and view models without having to manually edit the source code. Unfortunately, most browsers restrict access to file paths, but can still read file contents. ...

Efficient ways to send both table rows and columns in a single parameter using ajax

I am seeking a way to efficiently send all selected row values from a table as a single parameter in an AJAX request. Below is the current code where I am sending them one by one using a forEach statement, which can impact performance when dealing with a l ...

Sorting by price using the ng-repeat directive is not suitable for this

Utilizing angular's ng-repeat along with orderBy on a product catalog page to sort the products based on a select change. The ordering by name using orderBy works as expected, however, when it comes to price it sorts like this: 1,10,11,12,13,14,2,3,4 ...

Counting the number of PHP inputs in a field

Hello, I am using a PHP script from Steve Dawson's website. To display the output on my HTML page, I am utilizing this AJAX script: <script> $.ajax({ type:'GET', url:'http://www.solariserat.se/count.php', data: ...

Finding a specific element within a Node.js application requires pinpointing and isolating

I have a dynamic table that displays user information, with each row containing an update icon and a delete icon. When the delete icon is clicked, I need to delete the corresponding user record. The challenge is identifying which user's delete icon ha ...

Store the information in the user interface of React by converting it into a file format

Currently, I am retrieving data from an API and downloading a specific file. My goal is to store this same file in the public directory within my react application. https://i.sstatic.net/bS8Z4.png this.state = { fileDownloadUrl: null, fileName ...

The "flickering" effect of the div is like a dance, moving gracefully between fade outs and

I am encountering a similar issue as described in this thread: same problem (fiddle: original fiddle). However, I am still learning JavaScript and struggling to apply the solution provided because my HTML code is slightly different. Can someone please assi ...