1212import org .imsglobal .basiclti .BasicLTIUtil ;
1313import org .imsglobal .basiclti .LtiVerificationResult ;
1414
15+ import java .util .ArrayList ;
16+ import java .util .List ;
17+
1518/**
1619 *
1720 * @author pgray
@@ -25,13 +28,43 @@ public LtiLaunchVerifier(LtiKeySecretService ltiKeySecretService) {
2528 this .keyService = ltiKeySecretService ;
2629 }
2730
28- @ Around ("@annotation(launch) && execution(* *(javax.servlet.http.HttpServletRequest+, org.imsglobal.basiclti.LtiVerificationResult)) && args(request,result)" )
29- public Object verifyLtiLaunch (ProceedingJoinPoint pjp , Lti launch , HttpServletRequest request , LtiVerificationResult result ) throws Throwable {
31+ //@Around("@annotation(launch) && execution(* *(javax.servlet.http.HttpServletRequest+, org.imsglobal.basiclti.LtiVerificationResult, ..)) && args(request, result)")
32+ @ Around ("@annotation(launch)" )
33+ public Object verifyLtiLaunch (ProceedingJoinPoint pjp , Lti launch ) throws Throwable {
34+ HttpServletRequest request = null ;
35+ for (Object arg : pjp .getArgs ()) {
36+ if (HttpServletRequest .class .isInstance (arg )) {
37+ request = (HttpServletRequest ) arg ;
38+ }
39+ }
40+ if (request == null ){
41+ throw new IllegalStateException (getErrorMessageForArgumentClass ("HttpServletRequest" , pjp .getSignature ().toLongString ()));
42+ }
3043
44+ System .out .println ("checking lti params..." );
3145 String oauthSecret = keyService .getSecretForKey (request .getParameter ("oauth_consumer_key" ));
32- result = BasicLTIUtil .validateMessage (request , request .getRequestURL ().toString (), oauthSecret );
46+ LtiVerificationResult ltiResult = BasicLTIUtil .validateMessage (request , request .getRequestURL ().toString (), oauthSecret );
47+
48+ Boolean ltiVerificationResultExists = false ;
49+ //This array will hold the arguments to the join point, so we can pass them along to the advised function.
50+ List <Object > args = new ArrayList <>(pjp .getArgs ().length );
51+ for (Object arg : pjp .getArgs ()) {
52+ if (arg .getClass ().equals (LtiVerificationResult .class )) {
53+ args .add (ltiResult );
54+ ltiVerificationResultExists = true ;
55+ } else {
56+ args .add (arg );
57+ }
58+ }
59+ if (!ltiVerificationResultExists ){
60+ throw new IllegalStateException (getErrorMessageForArgumentClass ("LtiVerificationResult" , pjp .getSignature ().toLongString ()));
61+ }
62+
63+ return pjp .proceed (args .toArray ());
64+ }
3365
34- return pjp .proceed (new Object [] {request , result });
66+ public String getErrorMessageForArgumentClass (String argumentClass , String signature ){
67+ return "The LtiLaunchVerifier instance cannot find the " + argumentClass + " argument on method: " + signature + ", are you sure it was declared?" ;
3568 }
3669
3770}
0 commit comments