use of org.vcell.util.AuthenticationException in project vcell by virtualcell.
the class ClientServerManager method connectToServer.
/**
* Insert the method's description here.
* Creation date: (5/12/2004 4:48:13 PM)
*/
private VCellConnection connectToServer(InteractiveContext requester) {
VCellThreadChecker.checkRemoteInvocation();
VCellConnection newVCellConnection = null;
VCellConnectionFactory vcConnFactory = null;
String badConnStr = "";
try {
switch(getClientServerInfo().getServerType()) {
case SERVER_REMOTE:
{
String apihost = getClientServerInfo().getApihost();
Integer apiport = getClientServerInfo().getApiport();
try {
badConnStr += apihost + ":" + apiport;
vcConnFactory = new RemoteProxyVCellConnectionFactory(apihost, apiport, getClientServerInfo().getUserLoginInfo());
setConnectionStatus(new ClientConnectionStatus(getClientServerInfo().getUsername(), apihost, apiport, ConnectionStatus.INITIALIZING));
newVCellConnection = vcConnFactory.createVCellConnection();
} catch (AuthenticationException ex) {
throw ex;
}
break;
}
case SERVER_LOCAL:
{
new PropertyLoader();
LocalVCellConnectionService localVCellConnectionService = VCellServiceHelper.getInstance().loadService(LocalVCellConnectionService.class);
vcConnFactory = localVCellConnectionService.getLocalVCellConnectionFactory(getClientServerInfo().getUserLoginInfo());
setConnectionStatus(new ClientConnectionStatus(getClientServerInfo().getUsername(), null, null, ConnectionStatus.INITIALIZING));
newVCellConnection = vcConnFactory.createVCellConnection();
break;
}
}
requester.clearConnectWarning();
reconnectStat = ReconnectStatus.NOT;
} catch (AuthenticationException aexc) {
aexc.printStackTrace(System.out);
requester.showErrorDialog(aexc.getMessage());
} catch (ConnectionException cexc) {
String msg = badConnectMessage(badConnStr) + "\n" + cexc.getMessage();
cexc.printStackTrace(System.out);
ErrorUtils.sendRemoteLogMessage(getClientServerInfo().getUserLoginInfo(), msg);
if (reconnectStat != ReconnectStatus.SUBSEQUENT) {
requester.showConnectWarning(msg);
}
} catch (Exception exc) {
exc.printStackTrace(System.out);
String msg = badConnectMessage(badConnStr) + "\nException:\n" + exc.getMessage();
ErrorUtils.sendRemoteLogMessage(getClientServerInfo().getUserLoginInfo(), msg);
requester.showErrorDialog(msg);
}
return newVCellConnection;
}
use of org.vcell.util.AuthenticationException in project vcell by virtualcell.
the class AmplistorUtilsTest method test.
@Test
public void test() throws Exception {
//
// Create amplistor full access credential
//
AmplistorCredential amplistorCredential = getAmplistorCredential();
// must set this property in eclipse debug configuration
if (amplistorCredential.userName == null || amplistorCredential.password == null) {
throw new Exception("Amplistor full access credential required for test");
}
//
// Define Amplistor test dir
//
final String AMPLI_REST_TEST_DIR = "Ampli_REST_Test_Dir";
String dirNameURL = AmplistorUtils.DEFAULT_AMPLI_SERVICE_VCELL_URL + AMPLI_REST_TEST_DIR;
//
// Define Local test dir and file
//
Random rand = new Random();
byte[] rndBytes = new byte[10000];
rand.nextBytes(rndBytes);
File tmpDir = Files.createTempDirectory("rnd_").toFile();
File[] tmpFiles = new File[NUMFILES];
final String SIMID_PREFIX = "SimID_";
for (int i = 0; i < NUMFILES; i++) {
tmpFiles[i] = File.createTempFile(SIMID_PREFIX + i + "_0_", ".rndbin", tmpDir);
FileOutputStream fos = new FileOutputStream(tmpFiles[i]);
BufferedOutputStream bos = new BufferedOutputStream(fos);
bos.write(rndBytes);
bos.close();
}
//
try {
deleteDirAndAllFiles(dirNameURL, amplistorCredential);
} catch (FileNotFoundException e) {
// this is OK, ignore
}
//
// Create test dir on amplistor
//
AmplistorUtils.createDir(dirNameURL, amplistorCredential);
//
// Upload rnd file
//
Hashtable<File, Exception> failures = AmplistorUtils.uploadFilesOperation(tmpDir, new URL(dirNameURL), amplistorCredential);
if (failures != null) {
throw new Exception("Upload failed " + failures.values().iterator().next().getMessage());
}
//
// List amplistor test dir we created and populated
//
ArrayList<String> fileNames = AmplistorUtils.listDir(dirNameURL, null, amplistorCredential);
if (fileNames.size() != NUMFILES) {
throw new Exception("Expected " + NUMFILES + " files but got " + fileNames.size());
}
for (String fileName : fileNames) {
System.out.println("listing:" + fileName);
}
String file0url = dirNameURL + "/" + fileNames.get(0);
//
if (!AmplistorUtils.bFileExists(new URL(file0url), amplistorCredential)) {
throw new Exception("Expected " + file0url + " 'bFileExist' to be true");
}
//
// check filter returns correct results
//
AmplistorUtils.AmplistorFileNameMatcher onlyTheseMatchingFiles = new AmplistorUtils.AmplistorFileNameMatcher() {
@Override
public boolean accept(String fileName) {
return fileName.equals(tmpFiles[0].getName());
}
};
ArrayList<String> filteredNames = AmplistorUtils.listDir(dirNameURL, onlyTheseMatchingFiles, amplistorCredential);
if (filteredNames.size() != 1 || !filteredNames.get(0).equals(tmpFiles[0].getName())) {
throw new Exception("Filter test failed, expecting 1==" + filteredNames.size() + " and " + tmpFiles[0].getName() + "==" + (filteredNames.size() == 0 ? "null" : filteredNames.get(0)));
}
//
// set metadata on first file (this is done during upload using lastmodified of file but do it again to demonstrate)
//
Calendar calendar = Calendar.getInstance();
calendar.set(2010, 2, 3, 5, 15, 30);
calendar.set(Calendar.MILLISECOND, 0);
System.out.println("Set Custom Modification time----- " + calendar.getTime());
// AmplistorUtils.setFileMetaData(dirNameURL+"/"+tmpFiles[0].getName(), amplistorCredential, SimulationData.AmplistorHelper.CUSTOM_FILE_MODIFICATION_DATE, tmpFiles[0].lastModified()/1000+".0");
AmplistorUtils.setFileMetaData(file0url, amplistorCredential, AmplistorUtils.CUSTOM_FILE_MODIFICATION_DATE, calendar.getTime().getTime() / 1000 + ".0");
//
// Print the http header info for one of the uploaded files
//
AmplistorUtils.AmpliCustomHeaderHelper ampliCustomHeaderHelper = AmplistorUtils.printHeaderFields(file0url, amplistorCredential);
if (ampliCustomHeaderHelper.customModification == null || !ampliCustomHeaderHelper.customModification.equals(calendar.getTime())) {
throw new Exception("Queried custom modification date " + ampliCustomHeaderHelper.customModification + " does not match set custom modification date " + calendar.getTime());
}
//
// Download 1 of the files
//
byte[] downloadBytes = AmplistorUtils.getObjectData(file0url, amplistorCredential);
//
if (downloadBytes.length != tmpFiles[0].length() || rndBytes.length != downloadBytes.length) {
throw new Exception("round trip file sizes are different local = " + tmpFiles[0].length() + " remote = " + downloadBytes.length + " memory = " + rndBytes.length);
}
FileInputStream fis = new FileInputStream(tmpFiles[0]);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis = new DataInputStream(bis);
byte[] localBytes = new byte[rndBytes.length];
dis.readFully(localBytes);
dis.close();
if (!Arrays.equals(localBytes, downloadBytes) || !Arrays.equals(rndBytes, downloadBytes)) {
throw new Exception("download bytes not match local bytes after round trip");
}
//
// Check special SimID parsing for delete
//
HashSet<KeyValue> doNotDeleteTheseSimKeys = new HashSet<KeyValue>();
doNotDeleteTheseSimKeys.add(new KeyValue("0"));
doNotDeleteTheseSimKeys.add(new KeyValue("1"));
long numDeleted = AmplistorUtils.deleteSimFilesNotInHash(dirNameURL, doNotDeleteTheseSimKeys, false, amplistorCredential).size();
if (numDeleted != (NUMFILES - doNotDeleteTheseSimKeys.size())) {
throw new Exception("Expected to delete " + (NUMFILES - doNotDeleteTheseSimKeys.size()) + " but deleted " + numDeleted);
}
//
// remove one of the remaining files on amplistor
//
AmplistorUtils.deleteFilesOperation(new String[] { tmpFiles[0].getName() }, dirNameURL, amplistorCredential);
//
if (AmplistorUtils.bFileExists(new URL(dirNameURL + "/" + tmpFiles[0].getName()), amplistorCredential)) {
throw new Exception("Expected " + dirNameURL + "/" + tmpFiles[0].getName() + " 'bFileExist' to be false");
}
//
try {
AmplistorUtils.deleteFilesOperation(new String[] { "blahblah" }, dirNameURL, amplistorCredential);
throw new Exception("We shouldn't have gotten here, Expecting FileNotFoundException");
} catch (FileNotFoundException e) {
// ignore, this should happen
}
//
// there should be 1 file left
//
int numleft = AmplistorUtils.listDir(dirNameURL, null, amplistorCredential).size();
if (numleft != 1) {
throw new Exception("Expecting 1 file in list but got " + numleft);
}
//
// Remove test from amplistor
//
// do not ignore FileNotFound
deleteDirAndAllFiles(dirNameURL, amplistorCredential);
//
// vcell_logs Amplistor test
//
//
// try to upload to vcell_logs without credentials
//
AmplistorUtils.uploadFile(new URL(AmplistorUtils.DEFAULT_AMPLI_VCELL_LOGS_URL), tmpFiles[0], null);
//
try {
AmplistorUtils.listDir(AmplistorUtils.DEFAULT_AMPLI_VCELL_LOGS_URL, null, null);
throw new Exception("Souldn't have gotten here, Expecting failure to get vcell_logs with no authentication");
} catch (AuthenticationException e) {
// ignore, this should happen
}
//
// try to get dir list from vcell_logs with credentials (should succeed)
//
ArrayList<String> vcell_logs_dirlist = AmplistorUtils.listDir(AmplistorUtils.DEFAULT_AMPLI_VCELL_LOGS_URL, null, amplistorCredential);
System.out.println("Found " + vcell_logs_dirlist.size() + " files in vcell_logs directory");
//
try {
AmplistorUtils.deleteFilesOperation(new String[] { tmpFiles[0].getName() }, AmplistorUtils.DEFAULT_AMPLI_VCELL_LOGS_URL, null);
throw new Exception("Souldn't have gotten here, Expecting failure to get vcell_logs with no authentication");
} catch (AuthenticationException e) {
// ignore, this should happen
}
//
// try to delete file from vcell_logs with credentials (should succeed)
//
AmplistorUtils.deleteFilesOperation(new String[] { tmpFiles[0].getName() }, AmplistorUtils.DEFAULT_AMPLI_VCELL_LOGS_URL, amplistorCredential);
//
try {
for (int i = 0; i < NUMFILES; i++) {
tmpFiles[i].delete();
}
tmpDir.delete();
} catch (Exception e) {
// ignore, not part of test
}
}
use of org.vcell.util.AuthenticationException in project vcell by virtualcell.
the class ClientServerManager method connectToServer.
/**
* Insert the method's description here.
* Creation date: (5/12/2004 4:48:13 PM)
*/
private VCellConnection connectToServer(InteractiveContext requester, boolean bShowErrors) {
BeanUtils.updateDynamicClientProperties();
VCellThreadChecker.checkRemoteInvocation();
VCellConnection newVCellConnection = null;
VCellConnectionFactory vcConnFactory = null;
String badConnStr = "";
try {
try {
switch(getClientServerInfo().getServerType()) {
case SERVER_REMOTE:
{
String apihost = getClientServerInfo().getApihost();
Integer apiport = getClientServerInfo().getApiport();
try {
badConnStr += apihost + ":" + apiport;
vcConnFactory = new RemoteProxyVCellConnectionFactory(apihost, apiport, getClientServerInfo().getUserLoginInfo());
setConnectionStatus(new ClientConnectionStatus(getClientServerInfo().getUsername(), apihost, apiport, ConnectionStatus.INITIALIZING));
newVCellConnection = vcConnFactory.createVCellConnection();
} catch (AuthenticationException ex) {
throw ex;
}
break;
}
case SERVER_LOCAL:
{
new PropertyLoader();
LocalVCellConnectionService localVCellConnectionService = VCellServiceHelper.getInstance().loadService(LocalVCellConnectionService.class);
vcConnFactory = localVCellConnectionService.getLocalVCellConnectionFactory(getClientServerInfo().getUserLoginInfo());
setConnectionStatus(new ClientConnectionStatus(getClientServerInfo().getUsername(), null, null, ConnectionStatus.INITIALIZING));
newVCellConnection = vcConnFactory.createVCellConnection();
break;
}
}
requester.clearConnectWarning();
reconnectStat = ReconnectStatus.NOT;
} catch (Exception e) {
e.printStackTrace();
if (bShowErrors) {
throw e;
}
}
} catch (AuthenticationException aexc) {
aexc.printStackTrace(System.out);
requester.showErrorDialog(aexc.getMessage());
} catch (ConnectionException cexc) {
String msg = badConnectMessage(badConnStr) + "\n" + cexc.getMessage();
cexc.printStackTrace(System.out);
ErrorUtils.sendRemoteLogMessage(getClientServerInfo().getUserLoginInfo(), msg);
if (reconnectStat != ReconnectStatus.SUBSEQUENT) {
requester.showConnectWarning(msg);
}
} catch (HttpResponseException httpexc) {
httpexc.printStackTrace(System.out);
if (httpexc.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
requester.showErrorDialog("Invalid Userid or Password\n\n" + httpexc.getMessage());
} else {
String msg = "Exception: " + httpexc.getMessage() + "\n\n" + badConnectMessage(badConnStr);
ErrorUtils.sendRemoteLogMessage(getClientServerInfo().getUserLoginInfo(), msg);
requester.showErrorDialog(msg);
}
} catch (Exception exc) {
exc.printStackTrace(System.out);
String msg = "Exception: " + exc.getMessage() + "\n\n" + badConnectMessage(badConnStr);
ErrorUtils.sendRemoteLogMessage(getClientServerInfo().getUserLoginInfo(), msg);
requester.showErrorDialog(msg);
}
return newVCellConnection;
}
use of org.vcell.util.AuthenticationException in project vcell by virtualcell.
the class AmplistorUtils method ampliCheckOP.
private static CheckOPHelper ampliCheckOP(URL httpURL, AmplistorCredential amplistorCredential, AMPLI_OP_METHOD ampliOpMethod, String authorizationResponse, AMPLI_OP_KIND ampliOpKind, HashMap<String, String> metaData) throws Exception {
HttpURLConnection httpURLConnection = null;
CheckOPHelper checkOPHelper = null;
try {
httpURLConnection = ampliOperationConnection(httpURL, ampliOpMethod, authorizationResponse, ampliOpKind, metaData);
int responseCode = httpURLConnection.getResponseCode();
// System.out.println("Status code: " + responseCode);
if (responseCode == HttpURLConnection.HTTP_UNAUTHORIZED && amplistorCredential == null) {
throw new AuthenticationException("Authentication required but no credentials available");
} else if (responseCode == HttpURLConnection.HTTP_UNAUTHORIZED && authorizationResponse == null) {
// System.out.println("Responding to Amplistor server authentication request...");
String authorizationRequestNew = respondToChallenge(httpURLConnection, amplistorCredential, ampliOpMethod);
httpURLConnection.disconnect();
return ampliCheckOP(httpURL, amplistorCredential, ampliOpMethod, authorizationRequestNew, ampliOpKind, metaData);
} else if (responseCode == HttpURLConnection.HTTP_UNAUTHORIZED && authorizationResponse != null) {
throw new AuthenticationException("User " + amplistorCredential.userName + " authentication failed for URL=" + httpURL);
} else if (responseCode == HttpURLConnection.HTTP_NOT_FOUND && (ampliOpMethod == AMPLI_OP_METHOD.GET || ampliOpMethod == AMPLI_OP_METHOD.DELETE)) {
throw new FileNotFoundException("File not found " + httpURL);
} else if (responseCode == HttpURLConnection.HTTP_OK && ampliOpMethod == AMPLI_OP_METHOD.GET && ampliOpKind == AMPLI_OP_KIND.DIR) {
checkOPHelper = new CheckOPHelper(getResponseXML(httpURLConnection), httpURLConnection);
} else if (responseCode == HttpURLConnection.HTTP_OK && ampliOpMethod == AMPLI_OP_METHOD.GET && ampliOpKind == AMPLI_OP_KIND.FILE) {
checkOPHelper = new CheckOPHelper(null, httpURLConnection);
} else if ((ampliOpMethod == AMPLI_OP_METHOD.PUT && responseCode != HttpURLConnection.HTTP_OK && responseCode != HttpURLConnection.HTTP_CREATED) || (ampliOpMethod == AMPLI_OP_METHOD.DELETE && responseCode != HttpURLConnection.HTTP_NO_CONTENT) || (ampliOpMethod == AMPLI_OP_METHOD.GET && responseCode != HttpURLConnection.HTTP_OK)) {
throw new Exception("Unexpected response code=" + responseCode + " from amplistor for URL=" + httpURL);
}
return checkOPHelper;
} finally {
if (httpURLConnection != null && checkOPHelper == null) {
httpURLConnection.disconnect();
}
}
}
use of org.vcell.util.AuthenticationException in project vcell by virtualcell.
the class LocalVCellConnectionFactory method createVCellConnection.
/**
* This method was created in VisualAge.
* @return cbit.vcell.server.VCellConnection
*/
public VCellConnection createVCellConnection() throws AuthenticationException, ConnectionException {
try {
if (connectionFactory == null) {
connectionFactory = DatabaseService.getInstance().createConnectionFactory();
}
KeyFactory keyFactory = connectionFactory.getKeyFactory();
LocalVCellConnection.setDatabaseResources(connectionFactory, keyFactory);
AdminDBTopLevel adminDbTopLevel = new AdminDBTopLevel(connectionFactory);
boolean bEnableRetry = false;
boolean isLocal = true;
User user = adminDbTopLevel.getUser(userLoginInfo.getUserName(), userLoginInfo.getDigestedPassword(), bEnableRetry, isLocal);
if (user != null) {
userLoginInfo.setUser(user);
} else {
throw new AuthenticationException("failed to authenticate as user " + userLoginInfo.getUserName());
}
DatabaseServerImpl databaseServerImpl = new DatabaseServerImpl(connectionFactory, keyFactory);
boolean bCache = false;
Cachetable cacheTable = null;
DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(cacheTable, new File(PropertyLoader.getRequiredProperty(PropertyLoader.primarySimDataDirInternalProperty)), new File(PropertyLoader.getRequiredProperty(PropertyLoader.secondarySimDataDirInternalProperty)));
SimulationDatabaseDirect simulationDatabase = new SimulationDatabaseDirect(adminDbTopLevel, databaseServerImpl, bCache);
ExportServiceImpl exportServiceImpl = new ExportServiceImpl();
LocalVCellConnection vcConn = new LocalVCellConnection(userLoginInfo, simulationDatabase, dataSetControllerImpl, exportServiceImpl);
linkHDFLib();
return vcConn;
} catch (Throwable exc) {
lg.error(exc.getMessage(), exc);
throw new ConnectionException(exc.getMessage());
}
}
Aggregations