-
Notifications
You must be signed in to change notification settings - Fork 6
NFC-47 NFC support for web-eid example #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: web-eid-mobile
Are you sure you want to change the base?
Conversation
102c405
to
5108d00
Compare
1da9ec5
to
d3edcb7
Compare
b519373
to
81dea4d
Compare
323499f
to
b18fa03
Compare
81dea4d
to
44ebf84
Compare
Signed-off-by: Sander Kondratjev <[email protected]>
44ebf84
to
123e619
Compare
|
} catch (IOException e) { | ||
throw new BadCredentialsException("Unable to authenticate the Web eID authentication token", e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There can be two separate problem cases here, either an invalid token or a technical problem with the request reader. These should perhaps throw separate exceptions:
} catch (IOException e) { | |
throw new BadCredentialsException("Unable to authenticate the Web eID authentication token", e); | |
} catch (JacksonException e) { | |
throw new BadCredentialsException("Unable to parse the Web eID authentication token", e); | |
} catch (IOException e) { | |
throw new AuthenticationServiceException("I/O error while reading the Web eID authentication token", e); |
private static final Logger LOG = LoggerFactory.getLogger(WebEidAjaxLoginProcessingFilter.class); | ||
private final ObjectReader OBJECT_READER = new ObjectMapper().readerFor(AuthTokenDTO.class); | ||
private final SecurityContextRepository securityContextRepository; | ||
private final ObjectReader OBJECT_READER = new ObjectMapper().readerFor(WebEidAuthToken.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private final ObjectReader OBJECT_READER = new ObjectMapper().readerFor(WebEidAuthToken.class); | |
private static final ObjectReader OBJECT_READER = new ObjectMapper().readerFor(WebEidAuthToken.class); |
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult) throws IOException, ServletException { | ||
super.successfulAuthentication(request, response, chain, authResult); | ||
securityContextRepository.saveContext(SecurityContextHolder.getContext(), request, response); | ||
private WebEidAuthToken parseWebEidAuthToken(HttpServletRequest request) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private WebEidAuthToken parseWebEidAuthToken(HttpServletRequest request) { | |
private static WebEidAuthToken parseWebEidAuthToken(HttpServletRequest request) { |
final String contentType = request.getHeader(HttpHeaders.CONTENT_TYPE); | ||
if (contentType == null || !contentType.startsWith(MediaType.APPLICATION_JSON_VALUE)) { | ||
LOG.warn("Content type not supported: {}", contentType); | ||
throw new AuthenticationServiceException("Content type not supported: " + contentType); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's extract content type validation to separate method as well:
final String contentType = request.getHeader(HttpHeaders.CONTENT_TYPE); | |
if (contentType == null || !contentType.startsWith(MediaType.APPLICATION_JSON_VALUE)) { | |
LOG.warn("Content type not supported: {}", contentType); | |
throw new AuthenticationServiceException("Content type not supported: " + contentType); | |
} | |
requireJsonContentType(request); |
requireJsonContentType()
might look as follows (untested, please verify):
private static void requireJsonContentType(HttpServletRequest request) {
try {
MediaType contentType = MediaType.parseMediaType(request.getContentType());
if (!MediaType.APPLICATION_JSON.equalsTypeAndSubtype(contentType)) {
LOG.warn("Content type not supported: {}", contentType);
throw new AuthenticationServiceException("Content type not supported: " + contentType);
}
} catch (InvalidMediaTypeException e) {
LOG.warn("Invalid content type", e);
throw new AuthenticationServiceException("Invalid content type", e);
}
}
Signed-off-by: Sander Kondratjev [email protected]