|
38 | 38 | import org.springframework.http.MediaType; |
39 | 39 | import org.springframework.security.authentication.AuthenticationManager; |
40 | 40 | import org.springframework.security.authentication.AuthenticationServiceException; |
| 41 | +import org.springframework.security.authentication.BadCredentialsException; |
41 | 42 | import org.springframework.security.core.Authentication; |
42 | 43 | import org.springframework.security.core.AuthenticationException; |
43 | 44 | import org.springframework.security.core.context.SecurityContextHolder; |
@@ -69,21 +70,29 @@ public WebEidAjaxLoginProcessingFilter( |
69 | 70 |
|
70 | 71 | @Override |
71 | 72 | public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) |
72 | | - throws AuthenticationException, IOException { |
| 73 | + throws AuthenticationException { |
73 | 74 | final String contentType = request.getHeader(HttpHeaders.CONTENT_TYPE); |
74 | 75 | if (contentType == null || !contentType.startsWith(MediaType.APPLICATION_JSON_VALUE)) { |
75 | 76 | LOG.warn("Content type not supported: {}", contentType); |
76 | 77 | throw new AuthenticationServiceException("Content type not supported: " + contentType); |
77 | 78 | } |
78 | 79 |
|
79 | 80 | LOG.info("attemptAuthentication(): Reading request body"); |
80 | | - final WebEidAuthToken webEidAuthToken = OBJECT_READER.readValue(request.getReader()); |
| 81 | + final WebEidAuthToken webEidAuthToken = parseWebEidAuthToken(request); |
81 | 82 | LOG.info("attemptAuthentication(): Creating token"); |
82 | 83 | final PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(null, webEidAuthToken); |
83 | 84 | LOG.info("attemptAuthentication(): Calling authentication manager"); |
84 | 85 | return getAuthenticationManager().authenticate(token); |
85 | 86 | } |
86 | 87 |
|
| 88 | + private WebEidAuthToken parseWebEidAuthToken(HttpServletRequest request) { |
| 89 | + try { |
| 90 | + return OBJECT_READER.readValue(request.getReader()); |
| 91 | + } catch (IOException e) { |
| 92 | + throw new BadCredentialsException("Unable to authenticate the Web eID authentication token", e); |
| 93 | + } |
| 94 | + } |
| 95 | + |
87 | 96 | @Override |
88 | 97 | protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult) throws IOException, ServletException { |
89 | 98 | super.successfulAuthentication(request, response, chain, authResult); |
|
0 commit comments