Skip to content

Commit

Permalink
SAK-29150 Return site role if trusted consumer.
Browse files Browse the repository at this point in the history
If a launch is from a trusted consumer, just return the user's site
role rather than mapping the lti role.
  • Loading branch information
adrianfish committed Mar 12, 2015
1 parent a42cd86 commit b5d8646
Showing 1 changed file with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,6 @@ public void setSiteService(SiteService siteService) {

public Map.Entry<String, String> mapLTIRole(Map payload, User user, Site site, boolean trustedConsumer) throws LTIException {

String ltiRole = null;

if (!trustedConsumer) {
ltiRole = (String) payload.get(BasicLTIConstants.ROLES);
if (ltiRole == null) {
ltiRole = "";
} else {
ltiRole = ltiRole.toLowerCase();
}
}

if (M_log.isDebugEnabled()) {
M_log.debug("ltiRole=" + ltiRole);
}

// Check if the user is a member of the site already
boolean userExistsInSite = false;
try {
Expand All @@ -73,6 +58,26 @@ public Map.Entry<String, String> mapLTIRole(Map payload, User user, Site site, b
throw new LTIException( "launch.site.user.missing", "user_id="+user.getId()+ ", siteId="+site.getId(), null);
}

String ltiRole = null;

if (trustedConsumer) {
// If the launch is from a trusted consumer, just return the user's
// role in the site. No need to map.
Member member = site.getMember(user.getId());
return new AbstractMap.SimpleImmutableEntry(ltiRole, member.getRole().getId());
} else {
ltiRole = (String) payload.get(BasicLTIConstants.ROLES);
if (ltiRole == null) {
ltiRole = "";
} else {
ltiRole = ltiRole.toLowerCase();
}
}

if (M_log.isDebugEnabled()) {
M_log.debug("ltiRole=" + ltiRole);
}

try {
site = siteService.getSite(site.getId());
Set<Role> roles = site.getRoles();
Expand Down

0 comments on commit b5d8646

Please sign in to comment.