Spring Security OAuth2 - Is it possible to using client form login instead of the authorization server's form login?
By : user3348529
Date : March 29 2020, 07:55 AM
|
Spring Security OAuth 2 with form login
By : Dylan R
Date : March 29 2020, 07:55 AM
|
How to configure Spring Boot and Spring Security to support both form login and Google OAuth2 login
By : laxpro2001
Date : March 29 2020, 07:55 AM
|
Spring security configure 2 kind of login behaviors - ajax response JSON & form login redirect new page
By : Kareem Yousry
Date : March 29 2020, 07:55 AM
around this issue Just think of simply hack by submitting additional parameter in the login form or Ajax code :
<input type="hidden" name="responseJson" value="true"/>
String responseJson = request.getParameter("responseJson");
if (responseJson != null && responseJson.equals("true")){
response.setContentType("text/json");
PrintWriter out = response.getWriter();
out.print(jsonObjectAboutFailLogin.toString());
out.flush();
}
|
Spring with two security configurations - failed API login redirects to form login page. How to change?
By : user3427607
Date : March 29 2020, 07:55 AM
should help you out I added an @Override of unsuccessfulAuthentication() to my Authentication filter The grandparent class (AbstractAuthenticationProcessingFilter) has a method for unsuccessful authentications (i.e. AuthenticationException) which delegates to an authentication failure handler class. I could have created my own custom authentication failure handler, but instead decided to simply override the unsuccessfulAuthentication method with some code that sends back a response with a 401 status and a JSON error message: code :
@Override
protected void unsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException {
// TODO: enrich/improve error messages
response.setStatus(response.SC_UNAUTHORIZED);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.setCharacterEncoding(StandardCharsets.UTF_8.toString());
response.getWriter().write("{\"error\": \"authentication error?\"}");
}
public class RESTAuthenticationEntryPoint implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException {
// TODO: enrich/improve error messages
response.setStatus(response.SC_UNAUTHORIZED);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.setCharacterEncoding(StandardCharsets.UTF_8.toString());
response.getWriter().write("{\"error\": \"unauthorized?\"}");
}
}
@Configuration
@Order(1)
public static class APISecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
JWTAuthenticationFilter jwtAuthenticationFilter = new JWTAuthenticationFilter(authenticationManager());
jwtAuthenticationFilter.setFilterProcessesUrl("/api/login");
http.antMatcher("/api/**")
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.csrf().disable()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.exceptionHandling()
.authenticationEntryPoint(new RESTAuthenticationEntryPoint())
.and()
.addFilter(jwtAuthenticationFilter)
.addFilter(new JWTAuthorizationFilter(authenticationManager()));
}
}
|