How about receiving a sweet treat as a reward for logging in successfully?

In my Angular App, users are required to login and authenticate. However, upon logging in, they are redirected to a separate URL and service that is not integrated within the Angular template. This setup is beyond my control and I am unable to make any changes to it.

The app's main URL is located at

Upon login, users are directed to the following login URL (which further redirects to a Spring CAS URL)

This URL eventually redirects to

.

After successful authentication, users are redirected back to the original app page. However, I am in need of extracting the cookie containing the username of the logged-in user.

This particular cookie is linked to the response from

and not the primary app URL. How can I retrieve this specific cookie, ideally using ngCookie?

Here is the relevant backend code for handling this process:

@RequestMapping(method = RequestMethod.GET, value = "/login", headers = "Accept=application/json")
public @ResponseBody HttpServletResponse login(HttpServletRequest request, HttpServletResponse response) {
    // toLog(Level.INFO, "Logging user in.");
    String referingURL = request.getHeader("referer");
    _LOG.debug("Referer: " + referingURL);
    try {
        String user = "123456789";
        user = SecurityUtils.getCurrentUsername();
        Cookie userCookie = new Cookie("USERNAME", user);
        userCookie.setSecure(true);
        response.addCookie(userCookie);
        response.sendRedirect(referingURL);
        return response;
    } catch (Exception e) {
        // toLog(Level.ERROR, "Error logging user in", e);
        throw new ResourceNotFoundException(e);
    }
}

I specifically want to access the 'userCookie' mentioned in the above code snippet.

In simpler terms,

The URL

contains a response cookie with the key 'USERNAME' holding the desired username value.

Since the app resides on , I aim to extract the aforementioned cookie.

Answer №1

CAS does not store user login information in cookies. Instead, it generates a Ticket Granting Cookie (TGC) for single sign-on sessions. This cookie does not contain any details about the authenticated user.

In order to determine the identity of the logged-in user, you need to validate a Service Ticket. This ticket is included in the URL of your application when CAS redirects you back after logging in. Your backend infrastructure should include a CAS Client that can verify this ticket with CAS/serviceValidate and store the username in a session. You can then choose how to transfer this information to your frontend.

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

I am attempting to develop a basic express application, but it doesn't appear to be functioning as expected

I am currently working on developing a straightforward express application. However, I am facing network errors when trying to access it through my browser at localhost:3000 while the application is running in the console. The root cause of this issue elud ...

jQuery's Same Origin Policy compared to the Browser's Policy when using OData

I am currently developing an AJAX application that interacts with an OData endpoint. Through my experimentation with the Netflix OData feed, I have encountered a puzzling issue: Whenever I send an .ajax() request to a specific URL (for instance, ), I rece ...

Tips for handling the response after a view has been submitted on Slack using Bolt.js

Hey there! I added a simple shortcut to retrieve data from an input, but I'm facing an issue after submitting the view. The response payload is not received and the view doesn't update to give feedback to the user. Check out my code below: const ...

Issues with Angular $http service retrieving data from a .JSON file

Below is the code snippet for my http service: app.controller('StoreController', ['$http', function($http){ var store = this; store.products = []; $http.get('/store-products.json').then(function(data){ sto ...

Is there a way to incorporate timeouts when waiting for a response in Axios using Typescript?

Can someone assist me in adjusting my approach to waiting for an axios response? I'm currently sending a request to a WebService and need to wait for the response before capturing the return and calling another method. I attempted to utilize async/aw ...

Angular's NgShoppingCart is designed in such a way that items stored in the localStorage are automatically cleared out

I am currently working on an Angular project using version 8.0.0. To integrate a shopping cart feature into my Angular project, I decided to incorporate the NgShoppingCart library by following the instructions provided here. After adding the library in m ...

AngularJS routing always displays 'index.html#!' in the URL

In my AngularJS app within a website project in Visual Studio, I am utilizing ui-router. The issue is that it only functions with the route http://localhost/index.html#!/my-page, when what I desire is for the route to simply be http://localhost/my-page. I ...

Customizing the appearance of columns in an antd table

Below is the table column configuration I am working with, where notes are rendered using a custom function: fieldDefs: (results, isJsonData) => [ { title: 'Notes', name: 'notesHTML', table: { render: SectionNotes, sear ...

Using ng-click to trigger a function call within another function - a step-by-step guide

var vm = this; vm.dt_data = []; vm.item = {}; vm.edit = edit; vm.dtOptions = DTOptionsBuilder.newOptions() .withOption('initComplete', function() { ...

Exploring the world of React and Material Ui

As I delve into working with Material Ui in React, I am encountering difficulties when trying to customize the components. For instance, let's take a look at an example of the AppBar: import React from 'react'; import AppBar from 'mat ...

Sort array of objects alphabetically and move objects with value to the beginning

I have a dataset that consists of different arrays of objects. When I log myData, the output looks something like this: [ { name: 'Cdb', image: 'xxx', coll: 'xxx' }, { name: 'Bcd', image: &a ...

Encountering an error in Angular UI when trying to utilize the $modal within my service dependency injection, causing

I have encountered a problem with my AngularJS and UI-Bootstrap code. In the following service, I am injecting $modal but it is showing as undefined. Interestingly, when I inject $modal into a controller instead, everything works perfectly. Can someone ex ...

What options do I have for sorting through my inventory using the search feature?

Having some trouble setting up isotope filtering on my search bar. I have managed to get the Isotope function working on checkboxes, but for some reason, my search bar isn't functioning as expected. I found a solution online for filtering results bas ...

Incorporate AngularJS page/controller into a Blazor Razor Page

Our team is in the process of modernizing our AngularJS app by incorporating Blazor webassembly. Initially, I believed that loading an AngularJS controller and page would be seamless as long as all the necessary javascript libraries were loaded. After int ...

Tips for retrieving multiple values or an array from an AJAX request?

Is there a correct way to pass multiple sets (strings) of data back after executing an ajax call in php? I understand that echo is typically used to send a single string of data back, but what if I need to send multiple strings? And how should I handle th ...

Transferring UTM parameters to a different page via a button click

Is there a way to extract parameters from a URL after the "?" and add them to a button's href in order to redirect to another landing page? I want to transfer UTM parameters to another page using JavaScript within the button. Original Homepage: Dest ...

Reorder div elements using jQuery with two specific criteria

On my website, I have implemented a method for sorting divs (.ligne) with different sorting options: by name, date, status, and type. The jQuery code I've written works well, but I want to refine it further to make it lighter. When clicking on each h ...

File in Node JS appears to be empty upon reading

My goal is to track the location of tweets in separate JSON files for each Twitter ID I monitor. The code snippet below is executed for every tweet, creating a new JSON file for each unique ID and appending the location data: console.log("@ " + tweet.user. ...

Leveraging an Array of Objects in JavaScript

Need help with my JavaScript code! I want to adjust the date in a Date object by adding specific days and then save it. Here is what I have so far: let orderIdDateCorrectionDict = [ { "orderId": "2020053100", "dayCorrection": -146 }, { "orderId" ...

Tips for maintaining cookies between two URLs in ASP.NET

Is there a way to pass the cookie values to another URL within the same domain? I have two URLs under the same domain - one for authentication and one for data retrieval. After successfully authenticating with the first URL, I need to use the authenticatio ...