Skip to content

Commit

Permalink
Merge pull request #67 from /issues/66-backport-validation-error
Browse files Browse the repository at this point in the history
Backport fix of #65: Validation fails because of missing enclosing method
  • Loading branch information
romanstrobl authored Feb 20, 2019
2 parents 006cfa6 + a642123 commit 8b7624f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.lang.invoke.MethodHandles;

/**
* Controller class which handles user authentication.
Expand Down Expand Up @@ -87,8 +86,8 @@ private void initBinder(WebDataBinder binder) {
@RequestMapping(value = "/authenticate", method = RequestMethod.POST)
public @ResponseBody ObjectResponse<AuthenticationResponse> authenticate(@Valid @RequestBody ObjectRequest<AuthenticationRequest> request, BindingResult result) throws MethodArgumentNotValidException, DataAdapterRemoteException, AuthenticationFailedException {
if (result.hasErrors()) {
// Call of getEnclosingMethod() on class found using MethodHandles.lookup() returns a reference to current method
MethodParameter methodParam = new MethodParameter(MethodHandles.lookup().lookupClass().getEnclosingMethod(),0);
// Call of getEnclosingMethod() on new object returns a reference to current method
MethodParameter methodParam = new MethodParameter(new Object(){}.getClass().getEnclosingMethod(), 0);
logger.warn("The authenticate request failed due to validation errors");
throw new MethodArgumentNotValidException(methodParam, result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.lang.invoke.MethodHandles;

/**
* Controller class which handles SMS OTP authorization.
Expand Down Expand Up @@ -92,8 +91,8 @@ private void initBinder(WebDataBinder binder) {
@RequestMapping(value = "create", method = RequestMethod.POST)
public @ResponseBody ObjectResponse<CreateSMSAuthorizationResponse> createAuthorizationSMS(@Valid @RequestBody ObjectRequest<CreateSMSAuthorizationRequest> request, BindingResult result) throws MethodArgumentNotValidException, DataAdapterRemoteException, SMSAuthorizationFailedException, InvalidOperationContextException {
if (result.hasErrors()) {
// Call of getEnclosingMethod() on class found using MethodHandles.lookup() returns a reference to current method
MethodParameter methodParam = new MethodParameter(MethodHandles.lookup().lookupClass().getEnclosingMethod(),0);
// Call of getEnclosingMethod() on new object returns a reference to current method
MethodParameter methodParam = new MethodParameter(new Object(){}.getClass().getEnclosingMethod(), 0);
logger.warn("The createAuthorizationSMS request failed due to validation errors");
throw new MethodArgumentNotValidException(methodParam, result);
}
Expand Down

0 comments on commit 8b7624f

Please sign in to comment.