Skip to content

Commit

Permalink
changed PID server to be the treaty server instead of the ITWorks tes…
Browse files Browse the repository at this point in the history
…t one
  • Loading branch information
lmatteis committed Nov 2, 2012
1 parent e4fbf3f commit 867ec4a
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 43 deletions.
10 changes: 7 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<id>jboss</id>
<url>http://repository.jboss.org/maven2/</url>
</repository>
<repository>
<id>mvnrepo</id>
<url>http://mvnrepository.googlecode.com/svn/repo</url>
</repository>
</repositories>
<properties>
<cxf.version>2.2.2</cxf.version>
Expand Down Expand Up @@ -144,9 +148,9 @@
</dependency>

<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>


Expand Down
Binary file modified src/main/java/org/sgrp/singer/db/.UserManager.java.swp
Binary file not shown.
1 change: 1 addition & 0 deletions src/main/java/org/sgrp/singer/db/OrderEmailManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public void generateProviderEmail(int orderid, PIDMemberForm membForm, HashMap<S
HashMap<String, ArrayList<String>> cMap = eMap.get(pemail);
try {
String providerHTML = getProviderHTMLMessage(membForm, cMap, orderid, comments, smta);
pemail = "[email protected]";
boolean sent = MailUtils.sendOrderMail(pemail, "Germplasm request #"+orderid+" through SINGER - PLEASE DO NOT RESPOND TO THIS EMAIL ", providerHTML);
System.out.println("Email Sent " + sent +" to "+pemail+"\n"+providerHTML);
} catch (Exception e) {
Expand Down
69 changes: 50 additions & 19 deletions src/main/java/org/sgrp/singer/db/UserManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.sgrp.singer.db;

import java.net.*;
import java.io.*;
import java.util.*;

import java.net.MalformedURLException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
Expand All @@ -10,6 +14,8 @@
import java.sql.Statement;
import java.util.Map;

import org.apache.log4j.Logger;

import javax.servlet.http.HttpSession;

import org.apache.xmlrpc.XmlRpcException;
Expand All @@ -21,9 +27,13 @@
import org.sgrp.singer.indexer.Keywords;
import org.sgrp.singer.xmlrpc.DrupalXmlRpcService;

import org.json.*;

public class UserManager {
public static UserManager mgr;

private static Logger LOG = Logger.getLogger("");

public void saveUser(MemberForm memb) throws SQLException {
if (memb == null) { throw new SQLException(ResourceManager.getString("save.user.null")); }
Connection conn = null;
Expand Down Expand Up @@ -200,28 +210,50 @@ public MemberForm getUser(String userId) throws SQLException {
* @throws XmlRpcException
* @throws Exception
*/
public PIDMemberForm loginPID (String userId, String password) throws InvalidKeyException, IllegalStateException, NoSuchAlgorithmException, MalformedURLException, XmlRpcException
public PIDMemberForm loginPID (String userId, String password)
{
PIDMemberForm member = new PIDMemberForm();
//final String serviceURL = "http://mls.planttreaty.org/itt/services/xmlrpc";
final String serviceURL = "http://mls.planttreaty.org/Ex_itt/services/xmlrpc";
//final String serviceURL = "http://mls.planttreaty.org/Ex_itt/services/xmlrpc";
//final String serviceURL = "http://www.itworks.it/itt/index.php?r=extsys/getUserDetails&esUsername=SINGER&esPassword=F3rrar1n0&username=" + userId + "&password=" + password;
final String serviceURL = "https://mls.planttreaty.org/itt/index.php?r=extsys/getUserDetails&esUsername=SINGER&esPassword=F3rrar1n0&username=" + userId + "&password=" + password;
DrupalXmlRpcService service;
try
{
service = new DrupalXmlRpcService("www.singer.cgiar.org", "73f568378f65c59b3c264186311602b4", serviceURL);
service.connect();
Integer uid = service.login(userId, password);

Map<String,String> userDetails = ((Map<String,String>)((Object[])service.getUserDetails(uid))[0]);

member.setNfname(userDetails.get(AccessionConstants.USER_FIRST_NAME));
member.setNlname(userDetails.get(AccessionConstants.USER_LAST_NAME));
// make request to the treaty server
URL pidServer = new URL(serviceURL);
URLConnection pidConn = pidServer.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
pidConn.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null)
response.append(inputLine);

in.close();

// parse the json response
JSONObject obj = new JSONObject(response.toString());
if(obj.has("errorCode")) {
throw new Exception(obj.getString("errorMessage"));
}

// login successful
member.setNfname(obj.getString("name"));
member.setNlname(obj.getString("surname"));
member.setNemail(null);
member.setNCompany(null);
member.setNType(userDetails.get(AccessionConstants.USER_TYPE));
String cty = userDetails.get(AccessionConstants.USER_COUNTRY);
member.setNCountry(Keywords.getInstance().getAllOrigMap().get(AccessionConstants.COUNTRY+cty.toLowerCase()));
member.setNuserpid(userDetails.get(AccessionConstants.USER_PID));
member.setNType(obj.getString("type"));
//String cty = userDetails.get(AccessionConstants.USER_COUNTRY);
member.setNCountry(obj.getString("country"));
member.setNuserpid(obj.getString("pid"));

member.setNShippingAddress(obj.getString("shipAddress"));
member.setNZip(null);
member.setNCity(null);
/*
if(userDetails.get(AccessionConstants.USER_ADDRESS_TO_USE).equals("Another"))
{
member.setNShippingAddress(userDetails.get(AccessionConstants.USER_SHIPPING_ADDRESS));
Expand All @@ -234,17 +266,16 @@ public PIDMemberForm loginPID (String userId, String password) throws InvalidKey
member.setNZip(userDetails.get(AccessionConstants.USER_POSTAL_CODE));
member.setNCity(userDetails.get(AccessionConstants.USER_CITY));
}
member.setNemail(userDetails.get(AccessionConstants.USER_MAIL));
*/
member.setNemail(obj.getString("email"));
member.setValidated(true);

service.logout();
}
//This Exception is raised when the authentication failed
catch (XmlRpcException e)
catch (Exception e)
{
//e.printStackTrace();
member.setValidated(false);
throw e;
return null;
}

return member;
Expand Down
Binary file not shown.
34 changes: 13 additions & 21 deletions src/main/java/org/sgrp/singer/form/LoginPIDForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,19 @@ public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest htt

if (!isNull(getUserid()) && !isNull(getUpassword()))
{
try
{
memberDetails = UserManager.getInstance().loginPID(getUserid(), getUpassword());
}
catch (Exception e)
{
if (e instanceof XmlRpcException && "Wrong username or password.".equals(e.getMessage()))
{
/*If the user is not registered by the PID, we check if he is an ancient SINGER member*/
if(UserManager.getInstance().loginValid(getUserid(), getUpassword()))
{
errors.add("oldLogin", ErrorConstants.getActionMessage(ErrorConstants.ERROR_OLD_SINGER_LOGIN));
}
else
{
errors.add("error", ErrorConstants.getActionMessage(ErrorConstants.ERROR_INVALID_LOGIN));
}
}
else
LOG.error(e);
}
//LOG.info("login info: " + getUserid() + " --- " + getUpassword());
memberDetails = UserManager.getInstance().loginPID(getUserid(), getUpassword());
if(memberDetails == null) {
/*If the user is not registered by the PID, we check if he is an ancient SINGER member*/
if(UserManager.getInstance().loginValid(getUserid(), getUpassword()))
{
errors.add("oldLogin", ErrorConstants.getActionMessage(ErrorConstants.ERROR_OLD_SINGER_LOGIN));
}
else
{
errors.add("error", ErrorConstants.getActionMessage(ErrorConstants.ERROR_INVALID_LOGIN));
}
}
}

if (errors.size() > 0) {
Expand Down

0 comments on commit 867ec4a

Please sign in to comment.