Skip to content

Commit 9199f61

Browse files
committed
Making the LtiLaunchVerifier aspect poincut broader
1 parent da3ab44 commit 9199f61

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

src/main/java/org/imsglobal/aspect/LtiLaunchVerifier.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import org.imsglobal.basiclti.BasicLTIUtil;
1313
import 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
}

src/main/java/org/imsglobal/basiclti/LtiUser.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ public class LtiUser {
1515
public LtiUser(HttpServletRequest request) {
1616
this.id = request.getParameter("user_id");
1717
this.roles = new LinkedList<>();
18-
for(String role : request.getParameter("roles").split(",")){
19-
this.roles.add(role.trim());
18+
if(request.getParameter("roles") != null) {
19+
for (String role : request.getParameter("roles").split(",")) {
20+
this.roles.add(role.trim());
21+
}
2022
}
2123
}
2224

0 commit comments

Comments
 (0)