Skip to content

Commit

Permalink
SAK-32629 Rubrics doesn't need to use the webservice getI18nPropertie…
Browse files Browse the repository at this point in the history
…s in the SqkqiI18n.java as admin (sakaiproject#4524)
  • Loading branch information
ddelblanco authored and jonespm committed Jun 29, 2017
1 parent 46a0eaa commit a9cc083
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4945,6 +4945,3 @@ rubrics.instance.layouts[classic].enabled=false
rubrics.integration.token-secret=12345678900909091234
# The path to the sakai webservices to retrieve info from Sakai
rubrics.integration.sakai-rest-url=http://localhost:8080/sakai-ws/rest/
# The user with access to the webservices. Must be admin to check session status for expired JWTs.
rubrics.integration.sakai-admin-user=admin
rubrics.integration.sakai-admin-password=admin
7 changes: 2 additions & 5 deletions rubrics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ spring.datasource.username=sakai
spring.datasource.password=sakai
rubrics.integration.sakai-rest-url=http://sakai-core:8080/sakai-ws/rest/
rubrics.integration.sakai-admin-user=admin
rubrics.integration.sakai-admin-password=admin
rubrics.integration.token-secret=<Unique secret to support JWT signing>
```
Expand All @@ -242,9 +240,8 @@ Rubrics can be loaded into the same database as Sakai core, or a
separate database. The spring.datasource settings above must be
configured either way.

NOTE: The Sakai web services requires admin access, so the configuration
should be locked down to the IP address or hostname restriction of the
appropriate interface per Sakai web services configuration.
NOTE: The Sakai web services requires access, so the configuration
should allow at least localhost to access
```
webservices.allowlogin=true
webservices.allow=localhost
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ public class RubricsIntegrationConfiguration {
@NotNull
String sakaiRestUrl;

@NotNull
String sakaiAdminUser;

@NotNull
String sakaiAdminPassword;

@NotNull
String tokenSecret;
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public class TranslationsController {
public Translations translations(@RequestParam("lang-code") String langCode) {

try {
String sakaisession = getSakaiSession();
Translations translations = getSakaiTranslation(langCode,sakaisession);
Translations translations = getSakaiTranslation(langCode);
return translations;

}catch(Exception ex){
Expand All @@ -64,57 +63,14 @@ public Translations translations(@RequestParam("lang-code") String langCode) {
}

/**
* Returns the session string for admin user
* Returns the translations for rubrics
* @return
*/
public String getSakaiSession() throws IOException {
public Translations getSakaiTranslation(String langCode) throws IOException {


try{
String adminUser = rubricsConfiguration.getIntegration().getSakaiAdminUser();
String adminPassword = rubricsConfiguration.getIntegration().getSakaiAdminPassword();
URL url = new URL(rubricsConfiguration.getIntegration().getSakaiRestUrl() + "login/login?id="+adminUser+"&pw="+adminPassword);

HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");

if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}

BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));

String output;
String result="";
if ((output = br.readLine()) != null) {
result = output;
}
conn.disconnect();
return result;

} catch (MalformedURLException e) {

//log.warn("Error getting a rubric association " + e.getMessage());
return null;

} catch (IOException e) {

//log.warn("Error getting a rubric association" + e.getMessage());
return null;
}
}

/**
* Returns the session string for admin user
* @return
*/
public Translations getSakaiTranslation(String langCode, String session) throws IOException {


try{
URL url = new URL(rubricsConfiguration.getIntegration().getSakaiRestUrl() + "i18n/getI18nProperties?sessionid=" + session + "&locale=" + langCode + "&resourceclass=org.sakaiproject.rubrics.logic.api.RubricsService&resourcebundle=rubricsMessages");
URL url = new URL(rubricsConfiguration.getIntegration().getSakaiRestUrl() + "i18n/getI18nProperties?locale=" + langCode + "&resourceclass=org.sakaiproject.rubrics.logic.api.RubricsService&resourcebundle=rubricsMessages");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");

Expand Down
2 changes: 0 additions & 2 deletions rubrics/services/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,3 @@ rubrics.instance.layouts[classic].enabled=false

rubrics.integration.token-secret=12345678900909091234
rubrics.integration.sakai-rest-url=http://localhost:8080/sakai-ws/rest/
rubrics.integration.sakai-admin-user=admin
rubrics.integration.sakai-admin-password=admin
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class SakaiI18n extends AbstractWebService {
*Returns the content of the specified properties file in a defined language
* and returns the default value if the key doesn't exists in that lanaguage.
*
* @param sessionid id of a valid session
* @param locale the language to return in IETF BCP 47 language tag string (samples: es-ES, jap)
* @param resourceClass Where to find the properties files (Samples: org.sakaiproject.rubrics.logic.RubricsService or org.sakaiproject.sharedI18n.SharedProperties)
* @param resourceBundle The bundle itself (Samples: rubricsMessages, or org.sakaiproject.sharedI18n.bundle.shared)
Expand All @@ -61,16 +60,10 @@ public class SakaiI18n extends AbstractWebService {
@Produces("text/plain")
@GET
public String getI18nProperties(
@WebParam(name = "sessionid", partName = "sessionid") @QueryParam("sessionid") String sessionid,
@WebParam(name = "locale", partName = "locale") @QueryParam("locale") String locale,
@WebParam(name = "resourceclass", partName = "resourceclass") @QueryParam("resourceclass") String resourceClass,
@WebParam(name = "resourcebundle", partName = "resourcebundle") @QueryParam("resourcebundle") String resourceBundle) {

Session session = establishSession(sessionid);
if (!securityService.isSuperUser()) {
LOG.warn("NonSuperUser trying to access to translations: " + session.getUserId());
throw new RuntimeException("NonSuperUser trying to access to translations: " + session.getUserId());
}
try {
StringBuilder lines = new StringBuilder();
//Convert the locale string in a Locale object
Expand Down

0 comments on commit a9cc083

Please sign in to comment.