package include.auth;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import village.webservice.VillageServiceInterfaceProxy;
public class Validation {
/**
* Function checks if session identifier is valid.
*
* @param sid session identifier
* @return name of user or null
*/
public String validate (String sid){
database.Session ses = null;
String result = null;
String server;
include.net.Server serv = new include.net.Server();
System.out.println("[Validation] Executing function 'validate'. Parameters");
System.out.println("[Validation] sid: " + sid + "'");
try {
InitialContext ctx = new InitialContext();
ses = (database.Session) ctx.lookup("ear3/CMPSession/local");
} catch (NamingException e) {
e.printStackTrace();
}
server = sid.substring(sid.indexOf('@') + 1);
if (serv.isMyName(server)) {
System.out.println("[Validation] Local execution.");
result = ses.getLogin(Integer.parseInt(sid.substring(0, sid.indexOf('@'))));
if (result != null)
result = result + '@' + server;
}
else {
System.out.println("[Validation] Remote execution.");
VillageServiceInterfaceProxy prox = new VillageServiceInterfaceProxy();
village.webservice.VillageServiceInterface iface =
prox.setEndpoint("http://"+server+prox.villagePort+prox.villageSuffix);
try {
result = iface.validateSession(sid);
}
catch(Exception cex){
System.out.println("error");
cex.printStackTrace();
}
}
System.out.println("[Validation] Function 'validate' returned value: '" + result + "'");
return result;
}
}