Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
dgunda1 authored Sep 15, 2020
2 parents 32bc95c + b60a2d6 commit ac3a22f
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 9 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
# i2b2-pm-cas
[Atlanta Clinical and Translational Science Institute (ACTSI)](http://www.actsi.org), [Emory University](http://www.emory.edu), Atlanta, GA
[Georgia Clinical and Translational Science Alliance (Georgia CTSA)](http://www.georgiactsa.org), [Emory University](http://www.emory.edu), Atlanta, GA

## What does it do?
This is a stock i2b2 1.7.08b project management (PM) cell, patched with support for delegating authentication to a server that implements [version 2 of the CAS protocol](https://apereo.github.io/cas/5.0.x/protocol/CAS-Protocol-V2-Specification.html) for single sign-on.
This is a stock i2b2 1.7.12a project management (PM) cell, patched with support for delegating authentication to a server that implements [version 2 of the CAS protocol](https://apereo.github.io/cas/5.0.x/protocol/CAS-Protocol-V2-Specification.html) for single sign-on.


The code is adapted from similar code for an older version of i2b2 by Dan Connolly found at https://bitbucket.org/DanC/i2b2-pm-cas.

## Version history

### Version 1.3
Updated i2b2 version to 1.7.12a.

### Version 1.2
Updated i2b2 version to 1.7.09c.

### Version 1.1
Updated i2b2 version to 1.7.08b.

### Version 1.0
Initial release.
Initial release using i2b2 version 1.7.05.


## CAS implementations supported
We expect any full implementation of version 2 of the CAS protocol to work. In particular, the implementation must support proxying. The following implementations of CAS are known to work:
Expand Down
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<path refid="common-classpath" />
<pathelement location="${classes}" />
<pathelement location="lib/jcifs-1.3.3.jar" />
<pathelement location="lib/servlet-api.jar" />
<pathelement location="../${i2b2CommonProject}/dist/i2b2Common-core.jar" />
<pathelement location="../${i2b2CommonProject}/lib/smbj-0.9.1.jar" />

Expand Down Expand Up @@ -190,4 +191,3 @@
</target>

</project>

Binary file added lib/servlet-api.jar
Binary file not shown.
133 changes: 130 additions & 3 deletions src/edu/harvard/i2b2/pm/delegate/ServicesHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
*/
package edu.harvard.i2b2.pm.delegate;


import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.net.InetAddress;
import java.sql.Connection;
import java.sql.DriverManager;

import java.util.ArrayList;
import java.util.Date;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;

import java.util.Set;
import java.util.Calendar;

Expand Down Expand Up @@ -100,11 +101,36 @@
public class ServicesHandler extends RequestHandler {
private ProjectType projectInfo = null;
private ServicesMessage getServicesMsg = null;

private MessageContext context = null;

protected static final String CONFIG_PATHNAME="/etc/eureka/application.properties";
protected static final String CAS_URL_PROPERTY_NAME = "cas.url";
protected static final String CAS_DEFAULT_URL = "https://localhost:8443/cas-server/";
protected static final Properties appProperties = new Properties();
static {
try {
FileReader fr = new FileReader(CONFIG_PATHNAME);
appProperties.load(fr);
String readCasUrl = appProperties.getProperty(CAS_URL_PROPERTY_NAME);
if (readCasUrl == null) {
appProperties.setProperty(CAS_URL_PROPERTY_NAME, CAS_DEFAULT_URL);
} else if (!readCasUrl.endsWith("/")) {
appProperties.setProperty(CAS_URL_PROPERTY_NAME, readCasUrl + "/");
}
fr.close();
fr = null;
} catch (FileNotFoundException ex) {
appProperties.setProperty(CAS_URL_PROPERTY_NAME, CAS_DEFAULT_URL);
} catch (IOException ex) {
throw new IllegalStateException("Error reading CAS integration configuration file " + CONFIG_PATHNAME, ex);
}
}
public ServicesHandler(ServicesMessage servicesMsg) throws I2B2Exception{
log.debug("Setting the servicesMsg");

getServicesMsg = servicesMsg;
context = MessageContext.getCurrentMessageContext();
System.out.println("+MessageContext+"+context);
//setDbInfo(servicesMsg.getRequestMessageType().getMessageHeader());
}

Expand All @@ -114,6 +140,7 @@ private void saveLoginAttempt(PMDbDao pmDb, String username, String attempt)
pmDb.setLoginAttempt(username, attempt );

}



protected UserType validateSuppliedPassword (String username, String password, Hashtable param, boolean skipValidation) throws Exception
Expand Down Expand Up @@ -732,6 +759,7 @@ else if (name.equals("get_project_request"))
// throw new Exception (ee.getMessage());
ee.printStackTrace();


MessageHeaderType messageHeader = MessageFactory.createResponseMessageHeader(getServicesMsg.getRequestMessageType().getMessageHeader());
responseMessageType = MessageFactory.doBuildErrorResponse(messageHeader,
ee.getMessage());
Expand All @@ -752,6 +780,7 @@ private String runUserLogin(PMDbDao pmDb, String caller, UserLoginType value) {
try {



List response = null;
try {
response = pmDb.getUserLogin(value, caller);
Expand All @@ -771,6 +800,7 @@ private String runUserLogin(PMDbDao pmDb, String caller, UserLoginType value) {
}
//everything is good so just return the same session key and the other info


MessageHeaderType messageHeader = MessageFactory.createResponseMessageHeader(getServicesMsg.getRequestMessageType().getMessageHeader());
responseMessageType = MessageFactory.createBuildResponse(messageHeader,users);

Expand All @@ -786,6 +816,7 @@ private String runUserLogin(PMDbDao pmDb, String caller, UserLoginType value) {
ee.getMessage());
}


String responseVdo = "DONE";
try {
responseVdo = MessageFactory.convertToXMLString(responseMessageType);
Expand All @@ -803,6 +834,7 @@ private String runGetAllDatasource(PMDbDao pmDb, String project, String caller)

List<DataSource> response = new ArrayList<DataSource>();


//List<DataSource> availableDatasources = new ArrayList<DataSource>();
try {

Expand Down Expand Up @@ -2447,7 +2479,101 @@ private String runGetUserConfiguration(PMDbDao pmDb, GetUserConfigurationType us

}


/*private String getUsername()
{
String username = null;
try{
System.out.println("Inside user name");
//stub._getServiceContext().getCurrentOperationContext().getMessageContext("In");
//context = MessageContext.getCurrentMessageContext();
System.out.println("context:"+context);
HttpServletRequest request = (HttpServletRequest) context.getProperty("transport.http.servletRequest");
String ticketVal = null ;
if(request != null)
{
ticketVal = request.getParameter("ticket");
System.out.println("ticketVal++"+ticketVal);
}
System.out.println("+++request+++"+request);
log.debug("+++request+++"+request);
log.info("+++request+++"+request);
String addr = "";
addr = appProperties.getProperty(CAS_URL_PROPERTY_NAME) + "proxyValidate?"
+ "service=" + URLEncoder.encode("http://localhost:9090"+request.getRequestURI().toString(), "UTF-8")
+ "&ticket="+ticketVal;
log.debug("CAS validation address: " + addr);
System.out.println("FORWARD ADDRESS++++++++:"+addr);
log.debug("FORWARD ADDRESS++++++++:"+addr);
log.info("FORWARD ADDRESS++++++++:"+addr);
BufferedReader body = URLOpener.open(addr);
try {
StringBuilder builder = new StringBuilder();
String line;
while ((line = body.readLine()) != null) {
builder.append(line);
}
String response = builder.toString();
System.out.println("+++++response+++:"+response);
int start = response.indexOf("<cas:authenticationSuccess");
if (start > -1) {
start = response.indexOf(">", start);
if (start < 0) {
log.error("Unexpected response from CAS: " + response);
throw new Exception("EINTERNAL");
}
start += 1;
start = response.indexOf("<cas:user", start);
if (start < 0) {
log.error("Unexpected response from CAS: " + response);
throw new Exception("EINTERNAL");
} else {
start = response.indexOf(">", start);
if (start < 0) {
log.error("Unexpected response from CAS: " + response);
throw new Exception("EINTERNAL");
}
start += 1;
int finish = response.indexOf("</cas:user", start);
if (finish < 0) {
log.error("Unexpected response from CAS: " + response);
throw new Exception("EINTERNAL");
} else {
username = response.substring(start, finish).trim();
}
}
} else {
if (response.contains("<cas:authenticationFailure")) {
log.debug("CAS authentication result negative");
throw new Exception("EAUTHENTICATION");
} else {
log.error("Unexpected response from CAS: " + response);
throw new Exception("EINTERNAL");
}
}
log.debug("CAS authenticated user:" + username);
}finally {
if (body != null) {
try {
body.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
}
}catch(Exception e)
{
e.printStackTrace();
}
return username;
}*/




Expand All @@ -2459,3 +2585,4 @@ private String runGetUserConfiguration(PMDbDao pmDb, GetUserConfigurationType us




4 changes: 3 additions & 1 deletion src/edu/harvard/i2b2/pm/ws/PMService.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public OMElement getServices(OMElement getPMDataElement)
*/

OMElement returnElement = null;


if (getPMDataElement == null) {
log.error("Incoming PM request is null");
Expand Down Expand Up @@ -264,6 +264,7 @@ public OMElement getServices(OMElement getPMDataElement)
log.debug("middle setRequestHandler");



log.debug("end setRequestHandler");


Expand All @@ -290,6 +291,7 @@ public OMElement getServices(OMElement getPMDataElement)
} else {
t.wait();
}

}
pmDataResponse = er.getOutputString();

Expand Down
2 changes: 1 addition & 1 deletion src/edu/harvard/i2b2/pm/ws/ServicesMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ServicesMessage(String requestPdo) throws I2B2Exception {

log.debug("Finished unmarshall of XML");
this.reqMessageType = (RequestMessageType) jaxbElement.getValue();
} catch (JAXBUtilException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
Expand Down

0 comments on commit ac3a22f

Please sign in to comment.