Skip to content

Commit

Permalink
SAK-31668 - Move org.sakaiproject out of tsugi-util (sakaiproject#3183)
Browse files Browse the repository at this point in the history
  • Loading branch information
csev authored Jan 3, 2017
1 parent 2a2abe5 commit 0804b1c
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
import org.slf4j.LoggerFactory;

import org.sakaiproject.basiclti.util.SakaiBLTIUtil;
import org.tsugi.basiclti.BasicLTIUtil;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.component.cover.ComponentManager;


/**
* Some Sakai Utility code for the Sakai LTI Provider
Expand All @@ -38,4 +47,47 @@ public static String getProviderLaunchUrl(String toolRegistration)
return SakaiBLTIUtil.getOurServerUrl() + "/imsblti/provider/"+toolRegistration;
}

public static final String EMAIL_TRUSTED_CONSUMER = "basiclti.provider.email.trusted.consumers";
public static final String HIGHLY_TRUSTED_CONSUMER = "basiclti.provider.highly.trusted.consumers";

public static boolean isHighlyTrustedConsumer(Map payload) {
String oauth_consumer_key = (String) payload.get("oauth_consumer_key");
boolean isHighlyTrustedConsumer = findTrustedConsumer(oauth_consumer_key, HIGHLY_TRUSTED_CONSUMER);

if (M_log.isDebugEnabled()) {
M_log.debug("Consumer=" + oauth_consumer_key);
M_log.debug("Trusted=" + isHighlyTrustedConsumer);
}
return isHighlyTrustedConsumer;
}

public static boolean isEmailTrustedConsumer(Map payload) {
String oauth_consumer_key = (String) payload.get("oauth_consumer_key");
return isEmailTrustedConsumer(oauth_consumer_key);
}

public static boolean isEmailTrustedConsumer(String oauth_consumer_key) {
boolean isEmailTrustedConsumer = findTrustedConsumer(oauth_consumer_key, EMAIL_TRUSTED_CONSUMER);

if (M_log.isDebugEnabled()) {
M_log.debug("Consumer=" + oauth_consumer_key);
M_log.debug("EmailTrusted=" + isEmailTrustedConsumer);
}
return isEmailTrustedConsumer;
}

private static boolean findTrustedConsumer(String oauth_consumer_key, String trustedConsumerProp) {
boolean isTrusted = false;
ServerConfigurationService cnf = (ServerConfigurationService) ComponentManager
.get(ServerConfigurationService.class);
final String trustedConsumersConfig = cnf.getString(trustedConsumerProp, null);
if (BasicLTIUtil.isNotBlank(trustedConsumersConfig)) {
List<String> consumersList = Arrays.asList(trustedConsumersConfig.split(":"));
if (consumersList.contains(oauth_consumer_key)) {
isTrusted = true;
}
}
return isTrusted;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tsugi.basiclti.BasicLTIProviderUtil;
import org.sakaiproject.basiclti.util.SakaiLTIProviderUtil;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -41,7 +41,7 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
String membershipsUrl = (String) job.get("memberships_url");
String consumerKey = (String) job.get("consumerkey");
String ltiVersion = (String) job.get("lti_version");
boolean isEmailTrustedConsumer= BasicLTIProviderUtil.isEmailTrustedConsumer(consumerKey);
boolean isEmailTrustedConsumer= SakaiLTIProviderUtil.isEmailTrustedConsumer(consumerKey);

siteMembershipsSynchroniser.synchroniseSiteMemberships(siteId, membershipsId, membershipsUrl, consumerKey, isEmailTrustedConsumer,ltiVersion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@

import org.tsugi.basiclti.BasicLTIConstants;
import org.tsugi.basiclti.BasicLTIUtil;
import org.tsugi.basiclti.BasicLTIProviderUtil;

import org.tsugi.casa.objects.Application;

Expand Down Expand Up @@ -340,7 +339,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
// site_id as is,
// ie without prefixing them with the oauth_consumer_key first.
// We also don't both checking their roles in the site.
boolean isTrustedConsumer = BasicLTIProviderUtil.isHighlyTrustedConsumer(payload);
boolean isTrustedConsumer = SakaiLTIProviderUtil.isHighlyTrustedConsumer(payload);

/*
* Get the list of email trusted consumers from sakai.properties. If the
Expand All @@ -350,7 +349,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
* acting as TP and TC referring to same user and can be uniquely
* identified by email address. more details SAK-29372
*/
boolean isEmailTrustedConsumer = BasicLTIProviderUtil.isEmailTrustedConsumer(payload);
boolean isEmailTrustedConsumer = SakaiLTIProviderUtil.isEmailTrustedConsumer(payload);

/*
* Checking if the email trusted consumer property and trusted consumer
Expand Down
24 changes: 23 additions & 1 deletion basiclti/tsugi-util/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ and make the process more opaque to the developer.

There is no Sakai-specific code but the code is developed and maintained in the
Sakai repository since it is so core to Sakai and heavily tested being part of
Sakai.
Sakai. Please do **not** put any org.sakaiproject dependencies to this folder
please use `basiclti-common` for code with org.sakaiproject dependencies.

This code is released in two ways. Within Sakai this code is normally released
as part of the Sakai build process:
Expand Down Expand Up @@ -85,3 +86,24 @@ The second-level API for tsugi-java is here:
https://github.com/csev/tsugi-java

The tsugi-java-servlet using both the tsugi-util and tsugi-java libraries.

Releasing tsugi-util to Sonatype
--------------------------------

Set up `settings.xml` as described above.

cd trunk/basiclti/tsugi-util
cp pom-tsugi.xml pom.xml
mvn compile install deploy
git checkout pom.xml


Check results of the deploy at:

https://oss.sonatype.org/#nexus-search;quick~tsugi-util

After a while the files migrate to:

https://oss.sonatype.org/content/repositories/snapshots/org/tsugi/


59 changes: 20 additions & 39 deletions basiclti/tsugi-util/pom-tsugi.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>basiclti</artifactId>
<groupId>org.sakaiproject.basiclti</groupId>
<version>12-SNAPSHOT</version>
</parent>
<!--
<name>Tsugi LTI Utilities (basiclti-util variant)</name>
<groupId>org.sakaiproject.basiclti</groupId>
<artifactId>basiclti-util</artifactId>
<organization>
<name>Tsugi Project</name>
<url>www.tsugi.org/</url>
</organization>
<inceptionYear>2009</inceptionYear>
<packaging>jar</packaging>
-->
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.tsugi</groupId>
<artifactId>tsugi-util</artifactId>
Expand All @@ -38,10 +21,19 @@
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>

<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
Expand All @@ -51,19 +43,18 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.3.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.3.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.3.5</version>
</dependency>
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>sakai-component-manager</artifactId>
</dependency>
</dependencies>


Expand Down Expand Up @@ -132,20 +123,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>fix</goal>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -164,6 +141,10 @@

</plugins>

<sourceDirectory>
src/java
</sourceDirectory>

<resources>
<resource>
<directory>src/main/resources</directory>
Expand Down
6 changes: 2 additions & 4 deletions basiclti/tsugi-util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<packaging>jar</packaging>

<dependencies>
<!-- This pom should *never* add any "org.sakaiproject" dependencies - any
Sakai-specific code needs to be placed in the basiclti-common folder -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
Expand All @@ -44,10 +46,6 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>sakai-component-manager</artifactId>
</dependency>
</dependencies>

<build>
Expand Down

This file was deleted.

0 comments on commit 0804b1c

Please sign in to comment.