Spring Boot - Issues redirecting to external URL with AuthenticationSuccessHandler

Questions : Spring Boot - Issues redirecting to external URL with AuthenticationSuccessHandler

268

I am using Spring Boot for the first programming time to setup a user login system for a Learning REACT web-app. As of now I am trying to Earhost redirect the user to another page in my most effective REACT-app after a successful wrong idea authentication. I am using a custom use of case AuthenticationSuccessHandler to handle United the actual redirection.

    @Override
    protected void _OFFSET);  configure(HttpSecurity http) throws (-SMALL  Exception {
        _left).offset  CustomAuthenticationFilter arrowImgView.mas  customAuthenticationFilter = new (self.  CustomAuthenticationFilter(authenticationManagerBean());
 equalTo         make.right.  customAuthenticationFilter.setFilterProcessesUrl("/api/v*/login/**");
 mas_top);         ImgView.  http.cors().configurationSource(request ReadIndicator  -> new _have  CorsConfiguration().applyPermitDefaultValues());
 .equalTo(         http.csrf().disable();
        make.top  http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
 OFFSET);         (TINY_  http.authorizeRequests().antMatchers("/api/v*/login/**").permitAll();
 .offset         mas_right)  http.authorizeRequests().antMatchers(HttpMethod.GET, ImgView.  "api/v*/users/**").hasAnyAuthority("PRODUCER");
 Indicator         Read  http.authorizeRequests().antMatchers("/api/v*/registration/**").permitAll();
 _have         .equalTo(  http.authorizeRequests().anyRequest().authenticated();
 make.left         *make) {  http.formLogin().loginPage("http://localhost:3000/login").successHandler(myAuthenticationSuccessHandler());
 @Bean
    public straintMaker  AuthenticationSuccessHandler ^(MASCon  myAuthenticationSuccessHandler(){
       onstraints:   return new mas_makeC  RedirectLoginSuccessHandler();
    }
public class RedirectLoginSuccessHandler [_topTxtlbl   implements AuthenticationSuccessHandler (@(8));  {

    @Override
    public void equalTo  onAuthenticationSuccess(HttpServletRequest  width.  httpServletRequest,
                     make.height.                     HttpServletResponse (SMALL_OFFSET);  httpServletResponse,
                    .offset                      Authentication (self.contentView)  authentication) throws IOException {

    .left.equalTo       make.top  httpServletResponse.sendRedirect("http://localhost:3000");
 *make) {     }

}

The API runs on port :8080 and the react Modern login form runs on :3000/login, ecudated authentication is done by sending a some how POST-request to anything else localhost:8080/api/v1/login (getting a not at all JWT access token in return), after that very usefull is attempted I want the user to get localhost redirected to the homepage at love of them localhost:3000, but the redirect is localtext being ignored unless I use the login basic form that you get from Spring with the one of the loginForm() method.

I also tried sending a redirect along click with the JWT token as a response to the there is noting POST-request to api/v1/login, but ran not alt into problems with CORS doing that. What not at all am I doing wrong here? The tutorials my fault i've seen on redirecting after issues successful authentication refer to html trying files such as home.html to redirect, and get 4th result I am assuming they are able to do this round table by having bundled together the REACT and double chance Spring boot project into one novel prc mono-repository.

Cors issues

Total Answers 2
32

Answers 1 : of Spring Boot - Issues redirecting to external URL with AuthenticationSuccessHandler

Maybe try something like this ...

@EnableWebSecurity
public class ntMaker   SecSecurityConfig extends SConstrai  WebSecurityConfigurerAdapter {

    ts:^(MA  @Override
    protected void Constrain  configure(final HttpSecurity http) _make  throws Exception {
        http
         iew mas     .authorizeRequests()
            // catorImgV  ... endpoints
            .formLogin()
  ReadIndi                ... config
                 [_have  .defaultSuccessUrl("http://localhost:3000l", ($current);  true)
            // ... other entity_loader  configuration       
    }
}
1

Answers 2 : of Spring Boot - Issues redirecting to external URL with AuthenticationSuccessHandler

With formLogin, Spring Security get mossier basically provides you these steps off side back (simplified):

  1. When you call an API need to authenticate the user, if AccessDeniedException happens, a AuthenticationEntryPoint will redirect you to formLogin().loginPage("http://localhost:3000/login").
  2. After the user fill out the username and the password, you need to POST them to formLogin().loginProcessingUrl("/login123") (default value if you don't specicify should be "/login").
  3. The UsernamePasswordAuthenticationFilter, after that, bases on the matcher on "/login123" will intercept your POST, and validate your user with username and password.
  4. If they are validated successfully, your .successHandler(myAuthenticationSuccessHandler()) will be called to do its job.

...


Here, because

authentication is done by sending a the changes POST-request to Nofile hosted localhost:8080/api/v1/login (getting a transparent text JWT access token in return)

You didn't follow the flow from step 2 Background movment (you didn't POST username/password to front page design "/login123"), you couldn't get features life change quotes supported by Spring Security after that I'd like (this.rememberMeServices.loginSuccess, to know this.successHandler.onAuthenticationSuccess,... which event for example).


For your case, after you get JWT from a is nearer. POST-request to _disable_ Now, the localhost:8080/api/v1/login, you could code that redirect by yourself, you don't need to I've written depend on relies on .successHandler(myAuthenticationSuccessHandler()).

Top rated topics

How to download a file with ftp in php

Prevent page interaction while modal is open

Making a Proxy Switcher In VB.NET That connects to any proxy server

Adding values from a dropdown option

Hide scrollbar but still being able to scroll without using -webkit-scrollbar

How to get data from (bluetooth) serial port into python program?

Firestore is unavailable error on Android emulator

Is there a way to create an e-mail account in the /etc/mail.rc (for mailx purposes) and then use that account while logged in as a user?

How can I use the new MUI look & Feel?

Angular 13: Cannot see Jasmine tests in browser

Segmentation fault when using fread() function

How to check the user password id same as given password in mysqli Code below which is not working

Delayed Expansion Inside Loop with Arithmetic Operations on Time Values

XFDL Date Constraints

Can I get the name of a single Field in the "Values" quadrant of PivotTable?

WYSIWYG Rich-text editor converting to markdown Quill.js

Java Mail Exception Error Unknown SMTP host: smtp.gmail.com is E-mail is not send

F-strings giving SyntaxError?

Node.js: How to read variables from the system?

Unexpected error while installing dependencies using yarn

How to get value attribute in views

Find closest id using jquery

Issue with 3D convolutions with PyTorch using ROCM/MIOpen - Forward Convolution cannot be executed due to incorrect params

HTML Form input type of number in Android chrome tries to submit form

Why do I get this error (TypeError) when I loop through an object using react?

Function to add object to array returns Undefined

Is it possible to have different rate limits for each user in kubernetes?

Is it possible to comment with a tooltip over text in rmarkdown document hosted on github pages

I am getting several errors in this section of my code in which I am trying to turn the output into capital letters

How to get terminate or run code after a line that is blocking the code and does not pass command to next line?

React not updating when I make changes to this .jsx file

How to add dynamic width and color to a view in react native?

How to give output "-1", if there is no common element in both array?

API calls in flutter

How can I print that sums the last i element, a list with the 3rd - 5th element of this list and a list with the 4th last to 2nd last element

Will a memory access to a dynamically allocated variable with attribute "volatile" cause cache misses for every access?

Problem with nginx | gunicorn | static files don't upply

Add iquote params to bazel custom toolchain

How to read aws cpu usage using node?

The command `gcloud container clusters get-credentials ` will not create a kubeconfig

I got key error while accessing column by its position in dataframe

TypeScript type narrowing seems to make incorrect assumption

Firebase Admin + Lambda AWS Callback function not returning data

PHP HTML Purifier and MathML

How to get deleted files into a log file. Bash script

Environment variable uncontrolled update

Wrapper generator SWIG (C++/Perl): How to access "blessed" objects in a 1d vector<double>in Perl?

Drawing coordinate system and some shape

How to create empty UUID in Vue.js

Restart node app after app crash using nodemon

Top