Skip to content

Commit

Permalink
SAK-29328 - Put the new constants in place and make a valid launch.
Browse files Browse the repository at this point in the history
  • Loading branch information
csev committed Jul 13, 2015
1 parent 0797336 commit 7f26f51
Show file tree
Hide file tree
Showing 9 changed files with 492 additions and 356 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ public interface LTIService {
*/
public Map<String, Object> getTool(String url);

/**
*
* @param tool
* @param siteId
* @return
*/
public String getToolLaunch(Map<String, Object> tool, String siteId);

/**
*
* @param key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,38 @@ public static void addSiteInfo(Properties props, Properties lti2subst, Site site
setProperty(props, BasicLTIConstants.LAUNCH_PRESENTATION_RETURN_URL, returnUrl);
}

public static void addUserInfo(Properties ltiProps, Properties lti2subst, Map<String, Object> tool)
{
int releasename = getInt(tool.get(LTIService.LTI_SENDNAME));
int releaseemail = getInt(tool.get(LTIService.LTI_SENDEMAILADDR));

User user = UserDirectoryService.getCurrentUser();
if ( user != null )
{
setProperty(ltiProps,BasicLTIConstants.USER_ID,user.getId());
setProperty(lti2subst,LTI2Vars.USER_ID,user.getId());
setProperty(ltiProps,BasicLTIConstants.LIS_PERSON_SOURCEDID,user.getEid());
setProperty(lti2subst,LTI2Vars.USER_USERNAME,user.getEid());
if ( releasename == 1 ) {
setProperty(ltiProps,BasicLTIConstants.LIS_PERSON_NAME_GIVEN,user.getFirstName());
setProperty(ltiProps,BasicLTIConstants.LIS_PERSON_NAME_FAMILY,user.getLastName());
setProperty(ltiProps,BasicLTIConstants.LIS_PERSON_NAME_FULL,user.getDisplayName());
setProperty(lti2subst,LTI2Vars.PERSON_NAME_GIVEN,user.getFirstName());
setProperty(lti2subst,LTI2Vars.PERSON_NAME_FAMILY,user.getLastName());
setProperty(lti2subst,LTI2Vars.PERSON_NAME_FULL,user.getDisplayName());
}
if ( releaseemail == 1 ) {
setProperty(ltiProps,BasicLTIConstants.LIS_PERSON_CONTACT_EMAIL_PRIMARY,user.getEmail());
setProperty(lti2subst,LTI2Vars.PERSON_EMAIL_PRIMARY,user.getEmail());
// Only send the display ID if it's different to the EID.
// the anonymous user has a null EID.
if (user.getEid() != null && !user.getEid().equals(user.getDisplayId())) {
setProperty(ltiProps,BasicLTIConstants.EXT_SAKAI_PROVIDER_DISPLAYID,user.getDisplayId());
}
}
}
}

public static void addRoleInfo(Properties props, Properties lti2subst, String context, String roleMapProp)
{
String theRole = "Learner";
Expand Down Expand Up @@ -846,9 +878,12 @@ public static String[] postLaunchHTML(Map<String, Object> content, Map<String,Ob
return postLaunchHTML(toolProps, ltiProps, rb);
}

// An LTI 2.0 Registration launch
// This must return an HTML message as the [0] in the array
// If things are successful - the launch URL is in [1]
/**
* An LTI 2.0 Registration launch
*
* This must return an HTML message as the [0] in the array
* If things are successful - the launch URL is in [1]
*/
public static String[] postRegisterHTML(Long deployKey, Map<String,Object> tool, ResourceLoader rb, String placementId)
{
if ( tool == null ) {
Expand Down Expand Up @@ -896,9 +931,12 @@ public static String[] postRegisterHTML(Long deployKey, Map<String,Object> tool,
return retval;
}

// An LTI 2.0 ReRegistration launch
// This must return an HTML message as the [0] in the array
// If things are successful - the launch URL is in [1]
/**
* An LTI 2.0 ReRegistration launch
*
* This must return an HTML message as the [0] in the array
* If things are successful - the launch URL is in [1]
*/
public static String[] postReRegisterHTML(Long deployKey, Map<String,Object> deploy, ResourceLoader rb, String placementId)
{
if ( deploy == null ) {
Expand Down Expand Up @@ -947,6 +985,85 @@ public static String[] postReRegisterHTML(Long deployKey, Map<String,Object> dep
return retval;
}

/**
* An LTI 2.0 ContentItemSelectionRequest launch
*
* This must return an HTML message as the [0] in the array
* If things are successful - the launch URL is in [1]
*/
public static String[] postContentItemSelectionRequest(Long toolKey, Map<String,Object> tool, ResourceLoader rb, String placementId)
{
if ( tool == null ) {
return postError("<p>" + getRB(rb, "error.tool.missing" ,"Tool is missing or improperly configured.")+"</p>" );
}

String launch_url = (String) tool.get("launch");
if ( launch_url == null ) return postError("<p>" + getRB(rb, "error.tool.noreg" ,"This tool is has no launch url.")+"</p>" );

String consumerkey = (String) tool.get(LTIService.LTI_CONSUMERKEY);
String secret = (String) tool.get(LTIService.LTI_SECRET);

// If secret is encrypted, decrypt it
secret = decryptSecret(secret);

if ( secret == null || consumerkey == null) {
return postError("<p>" + getRB(rb, "error.tool.partial" ,"Tool is incomplete, missing a key and secret.")+"</p>" );
}

// Start building up the properties
Properties ltiProps = new Properties();

setProperty(ltiProps, BasicLTIConstants.LTI_VERSION, BasicLTIConstants.LTI_VERSION_1);
setProperty(ltiProps, BasicLTIUtil.BASICLTI_SUBMIT, getRB(rb, "launch.button", "Press to Launch External Tool"));
setProperty(ltiProps, BasicLTIConstants.LTI_MESSAGE_TYPE, LTI2Messages.CONTENT_ITEM_SELECTION_REQUEST);

setProperty(ltiProps, BasicLTIConstants.ACCEPT_MEDIA_TYPES, "application/vnd.ims.lti.v1.ltilink");
setProperty(ltiProps, BasicLTIConstants.ACCEPT_PRESENTATION_DOCUMENT_TARGETS, "iframe,window"); // Nice to add overlay
setProperty(ltiProps, BasicLTIConstants.ACCEPT_UNSIGNED, "false");
setProperty(ltiProps, BasicLTIConstants.ACCEPT_MULTIPLE, "false");
setProperty(ltiProps, BasicLTIConstants.ACCEPT_COPY_ADVICE, "false"); // ???
setProperty(ltiProps, BasicLTIConstants.AUTO_CREATE, "true");
setProperty(ltiProps, BasicLTIConstants.CAN_CONFIRM, "false");
// setProperty(ltiProps, BasicLTIConstants.TITLE, "");
// setProperty(ltiProps, BasicLTIConstants.TEXT, "");
setProperty(ltiProps, BasicLTIConstants.DATA, toolKey+"");

String serverUrl = getOurServerUrl();
setProperty(ltiProps, BasicLTIConstants.CONTENT_ITEM_RETURN_URL, serverUrl + "/portal/tool/"+placementId+"?panel=PostConfig&id="+toolKey);

// This must always be there
String context = (String) tool.get(LTIService.LTI_SITE_ID);
Site site = null;
try {
site = SiteService.getSite(context);
} catch (Exception e) {
dPrint("No site/page associated with Launch context="+context);
return postError("<p>" + getRB(rb, "error.site.missing" ,"Cannot load site.")+context+"</p>" );
}

Properties lti2subst = new Properties();

addGlobalData(site, ltiProps, lti2subst, rb);
addSiteInfo(ltiProps, lti2subst, site);
addRoleInfo(ltiProps, lti2subst, context, (String)tool.get("rolemap"));
addUserInfo(ltiProps, lti2subst, tool);

int debug = getInt(tool.get(LTIService.LTI_DEBUG));
debug = 1;

Map<String,String> extra = new HashMap<String,String> ();
ltiProps = BasicLTIUtil.signProperties(ltiProps, launch_url, "POST",
consumerkey, secret, null, null, null, extra);

M_log.debug("signed ltiProps="+ltiProps);

boolean dodebug = debug == 1;
String postData = BasicLTIUtil.postLaunchHTML(ltiProps, launch_url, dodebug, extra);

String [] retval = { postData, launch_url };
return retval;
}

// This must return an HTML message as the [0] in the array
// If things are successful - the launch URL is in [1]
public static String[] postLaunchHTML(String placementId, ResourceLoader rb)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
function is_lti_request() {
$good_message_type = $_REQUEST["lti_message_type"] == "basic-lti-launch-request" ||
$_REQUEST["lti_message_type"] == "ToolProxyReregistrationRequest" ||
$_REQUEST["lti_message_type"] == "ContentItemSelection";
$_REQUEST["lti_message_type"] == "ContentItemSelectionRequest";
$good_lti_version = $_REQUEST["lti_version"] == "LTI-1p0" || $_REQUEST["lti_version"] == "LTI-2p0";
if ($good_message_type and $good_lti_version ) return(true);
return false;
Expand Down
Loading

0 comments on commit 7f26f51

Please sign in to comment.