IllegalAccessException, NoSuchFieldException, SecurityException {
String subject = AuthUtils.getSubject(request.getHeader(AuthUtils.AUTH_HEADER_KEY));
Optional<User> foundUser = dao.findById(Long.parseLong(subject));
if (!foundUser.isPresent()) {
return Response.status(Status.NOT_FOUND).entity(new ErrorMessage(NOT_FOUND_MSG))
.build();
}
User userToUnlink = foundUser.get();
// check that the user is not trying to unlink the only sign-in method
if (userToUnlink.getSignInMethodCount() == 1) {
return Response.status(Status.BAD_REQUEST)
.entity(new ErrorMessage(String.format(UNLINK_ERROR_MSG, provider))).build();
}
try {
userToUnlink.setProviderId(Provider.valueOf(provider.toUpperCase()), null);
} catch (IllegalArgumentException e) {