Maintain the Http Connection request header active when using Angular with Spring Security

During the process of converting my AngularJS project into Angular 4, I encountered an issue with maintaining the Http connection after logging into the application.

The request I am making is:

POST /myapp-services/login.html?username=admin&password=admin

After submitting the login form in both versions of Angular, I receive a response code of 202. The main difference I noticed is related to the Connection header. In AngularJS, there is no connection: close, but in Angular 4, this header is present. The problem arises in Angular 4 where I am unable to proceed with subsequent requests as it keeps redirecting me back to login.html repeatedly. My goal is to authenticate the user before sending any requests to the server. What could be causing this issue?

In Angular 4, I have configured proxy.config as follows:

{
    "/myapp-services":{
        "target":"https://localhost:8443/",
        "secure":false,
        "loglevel":"debug"
    }
}

Below are the comparison of response and request headers in both versions.

AngularJS:

General:

Request URL: https://localhost:8443/myapp-services/login.html?username=admin&password=admin
Request Method: POST
Status Code: 200 OK
Remote Address: [::1]:8443
Referrer Policy: no-referrer-when-downgrade

Response Headers:

Access-Control-Allow-Headers: x-requested-with, Content-Type
Access-Control-Allow-Methods: POST, GET, PUT, OPTIONS, DELETE
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Length: 0
Date: Tue, 10 Jul 2018 08:27:03 GMT
Expires: 0
Pragma: no-cache
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=9A05186F8DF53656747EDFA7567E7A4E; Path=/myapp-services; Secure; HttpOnly
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block

Request Headers:

Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,hi;q=0.8,es;q=0.7
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 0
Cookie: JSESSIONID=07CB8F42CB8B582768E0813C18AA733F
Host: localhost:8443
Origin: https://localhost:8443
Pragma: no-cache
Referer: https://localhost:8443/myapp-services/login.html
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36

Angular 4:

General:

Request URL: http://localhost:4200/myapp-services/login.html?username=admin&password=admin
Request Method: POST
Status Code: 200 OK
Remote Address: 127.0.0.1:4200
Referrer Policy: no-referrer-when-downgrade

Response Headers:

access-control-allow-headers: x-requested-with, Content-Type
access-control-allow-methods: POST, GET, PUT, OPTIONS, DELETE
access-control-allow-origin: *
access-control-max-age: 3600
cache-control: no-cache, no-store, max-age=0, must-revalidate
connection: close
content-length: 0
date: Tue, 10 Jul 2018 08:30:04 GMT
expires: 0
pragma: no-cache
server: Apache-Coyote/1.1
set-cookie: JSESSIONID=02F1318A13C4A08CA3A0D4E9E1816E5A; Path=/myapp-services; Secure; HttpOnly
strict-transport-security: max-age=31536000 ; includeSubDomains
x-content-type-options: nosniff
x-frame-options: DENY
X-Powered-By: Express
x-xss-protection: 1; mode=block

Request Headers:

Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,hi;q=0.8,es;q=0.7
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 0
Content-Type: application/json
Host: localhost:4200
Origin: http://localhost:4200
Pragma: no-cache
Referer: http://localhost:4200/login
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
X-Requested-With: XMLHttpRequest

Answer №1

The problem I encountered was related to SSL configuration. My server was set up with HTTPS, but I was transmitting data over HTTP. To resolve this issue, I had to enable SSL in my Angular application. By starting the server with SSL enabled using the command

ng serve --proxy-config proxy.config.json --ssl true
, I was able to successfully transmit data securely.

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

Updating an array by adding or removing items

I am attempting to create a method for deleting and adding items to an array, but I need easy-to-use delete and add methods since I am unfamiliar with TypeScript. export class NgForComponent implements OnInit { Numbers: number[]; constructor() { ...

Obtaining the unprocessed route path in Angular

I am looking for a way to trace the base routes of my Angular application, without including specific IDs and parameters in the URL. For example, instead of displaying pets/123/edit in the URL, I would like to see pets/:petId/edit as a string that I can u ...

Have the validation state classes (such as .has-error) been removed from Bootstrap 5?

I've noticed that the validation state classes (.has-success, .has-warning, etc) seem to have been removed in bootstrap 5 as they are not working anymore and I can't find them in the bootstrap.css file. Before, I could easily use these classes w ...

Error in Typescript: Property 'timeLog' is not recognized on type 'Console'

ERROR in src/app/utils/indicator-drawer.utils.ts:119:25 - error TS2339: Property 'timeLog' does not exist on type 'Console'. 119 console.timeLog("drawing") I am currently working with Typescript and Angular. I have ...

The Framework of Storing Data in Angular 2

Embarking on a new project for a corporate client, I find myself in the initial stages of making fundamental architectural decisions. While my background lies with .NET applications, WPF and Flash, this new venture requires web delivery, leading me to cons ...

Struggling with setting up the onChange function in a Next.js application

After successfully writing and testing the code here, I encountered an error preventing me from building it. Please review the code for any issues. I am attempting to set onChange to handle user input in a text field. Currently using onChange={onChange}, ...

Unraveling the mysteries of an undefined entity

When the variable response is undefined, attempting to retrieve its property status will result in an error: Error: Unable to access property 'status' of undefined const { response, response: { status }, request, config, } = error as A ...

Getting information from the firebase database

I'm currently working on a web application that utilizes Firebase database. I'm encountering difficulties when trying to access the elements that are labeled as encircled. Can anyone offer any guidance or suggestions? Here is the code snippet I& ...

Tips for positioning a mat-form-field beside an h1 tag

I've been attempting to place an h1 next to a mat-form-field from Angular Material, but I'm encountering some difficulties. Here's what I've attempted so far: <div class="mat-elevation-z8"> <mat-form-field> <mat-l ...

Tips for resolving the error message "What to do when reportWebVitals can't be located

Having some trouble with importing reportWebVitals for my React 18 application that is based on WebPack 5. Below is a snippet of my index.tsx file: import React from 'react'; import ReactDOM from 'react-dom/client'; import './style ...

Can TypeScript be set up to include undefined as a potential type in optional chains?

Today, I encountered a bug that I believe should have been caught by the type system. Let me illustrate with an example: function getModel(): Model { /* ... */ } function processModelName(name: string) { return name.replace('x', 'y& ...

Ensure that all files with the extension ".ts" take precedence and are imported

I am facing an issue with my component as I have two files associated with it: app/components/SomeButton.ts app/components/SomeButton.tsx The .ts file contains most of the logic and code, while the .tsx file extends the .ts and only contains the ren ...

I am looking to include both a space and a comma in the State dropdown value in an Angular application

I am facing an issue with my dropdown in Angular 9. When the State is more than one, it displays without any space between them. I want it to show like: Licensed State:ARCA I need like: AR, CA This is the code I have so far: <ng-c ...

Utilizing proxies and leveraging the power of the Map collection in tandem

I have been exploring the Map collection and came across the [[MapData]] internal slot, which led me to utilize Reflect for trapping purposes. After some trial and error, I came up with the following code snippet: const map = new Map(); const proxiedMap ...

When using videojs, I have the ability to include a Text Track event handler, however, there is currently no option to remove it

I implemented a listener for the 'cuechange' event on a Text Track and it's functioning correctly. However, I am unable to figure out how to remove this listener. I have attempted the instructions below to remove the listener, but it continu ...

What is the best way to include a select HTML element as an argument in an onSubmit form function call?

I am currently facing an issue where I am attempting to pass HTML elements of a form through the submit function as parameters. I have been able to successfully retrieve the nameInput element using #nameInput, but when trying to access the select element ( ...

Angular Placeholder Positioned at the Top

Hello, I am a beginner in Angular and need to create an input field that looks like this: https://i.sstatic.net/LUXfJ.png Everything is going fine except for the Vorname placeholder at the top. How can I place it there? Currently, I am utilizing Angular ...

How can you detect when a user clicks outside of a bootstrap modal dialog in Angular?

Is there a way to detect when a user clicks outside of a Bootstrap modal dialog? <!-- EXPANDED MODAL --> <div class="modal fade" id="itinerary" tabindex="-1" role="dialog" aria-labelledby="modal-large-label"> <div class="modal-dial ...

Using Typescript to automatically infer strongly-typed recursive index types

Commencing with an Animal interface and a detailed map of animals residing on my farm: export interface Animal { species: string; edible: boolean; } export interface FarmMap{ [key: string]: Animal; } Everything seems to be running smoothly. Here ...

Utilizing enum values as a data type for efficiency

Having an enum called AudioActionTypes: export enum AudioActionTypes { UpdateMusicData = 'UPDATE_MUSIC_DATA', UpdateVoiceData = 'UPDATE_VOICE_DATA', UpdateSoundData = 'UPDATE_SOUND_DATA', } There is a function that disp ...