Package org.springframework.security.web.authentication

# Class HttpMessageConverterAuthenticationSuccessHandler

java.lang.Object
org.springframework.security.web.authentication.HttpMessageConverterAuthenticationSuccessHandler

All Implemented Interfaces:
  `AuthenticationSuccessHandler`

public final class HttpMessageConverterAuthenticationSuccessHandler extends Object implements AuthenticationSuccessHandler
An `AuthenticationSuccessHandler` that writes a JSON response with the redirect URL and an authenticated status similar to: `{ "redirectUrl": "/user/profile", "authenticated": true }`

Since:
  6.4

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static final class`
`HttpMessageConverterAuthenticationSuccessHandler.AuthenticationSuccess`
A response object used to write the JSON response for successful authentication.

## Constructor Summary

Constructors
Constructor
Description
`HttpMessageConverterAuthenticationSuccessHandler()`

## Method Summary

Modifier and Type
Method
Description
`void`
`onAuthenticationSuccess(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.security.core.Authentication authentication)`
Called when a user has been successfully authenticated.
`void`
`setConverter(org.springframework.http.converter.HttpMessageConverter<Object> converter)`
Sets the `GenericHttpMessageConverter` to write to the response.
`void`
`setRequestCache(RequestCache requestCache)`
Sets the `RequestCache` to use.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.springframework.security.web.authentication.AuthenticationSuccessHandler

`onAuthenticationSuccess`

## Constructor Details

### HttpMessageConverterAuthenticationSuccessHandler

public HttpMessageConverterAuthenticationSuccessHandler()

## Method Details

### setConverter

public void setConverter(org.springframework.http.converter.HttpMessageConverter<Object> converter)
Sets the `GenericHttpMessageConverter` to write to the response. The default is `MappingJackson2HttpMessageConverter`.

Parameters:
  `converter` - the `GenericHttpMessageConverter` to use. Cannot be null.

### setRequestCache

public void setRequestCache(RequestCache requestCache)
Sets the `RequestCache` to use. The default is `HttpSessionRequestCache`.

Parameters:
  `requestCache` - the `RequestCache` to use. Cannot be null

### onAuthenticationSuccess

public void onAuthenticationSuccess(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.security.core.Authentication authentication) throws IOException, jakarta.servlet.ServletException
Description copied from interface: `AuthenticationSuccessHandler`
Called when a user has been successfully authenticated.

Specified by:
  `onAuthenticationSuccess` in interface `AuthenticationSuccessHandler`
Parameters:
  `request` - the request which caused the successful authentication
  `response` - the response
  `authentication` - the `Authentication` object which was created during the authentication process.
Throws:
  `IOException`
  `jakarta.servlet.ServletException`