Skip to content

Commit

Permalink
remove UserLoginInfo password and old style password login
Browse files Browse the repository at this point in the history
  • Loading branch information
jcschaff committed Jul 16, 2024
1 parent 126bde7 commit efcb5ab
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 250 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ private static Hashtable<KeyValue, UserLoginInfo> doQuery(String connectURL,Stri
}
String userkey = rset.getString("userkey");
if(userLoginInfo == null || !userLoginInfo.getUserName().equals(userid)){
userLoginInfo = new UserLoginInfo(userid,DigestedPassword.createAlreadyDigested(rset.getString("digestpw")));
userLoginInfo = new UserLoginInfo(userid);
userLoginInfo.setUser(new User(userid, new KeyValue(userkey)));
}
VCSimulationIdentifier vcSimulationIdentifier = new VCSimulationIdentifier(simJobSimRef, userLoginInfo.getUser());
Expand Down Expand Up @@ -1005,7 +1005,7 @@ private static void runSim(SimIDAndJobID simIDAndJobID) throws Exception{
return;
}
VCSimulationIdentifier vcSimulationIdentifier = new VCSimulationIdentifier(simIDAndJobID.simID, simIDAndJobID.user);
UserLoginInfo userLoginInfo = new UserLoginInfo(simIDAndJobID.user.getName(), new DigestedPassword("xoxoxox"));
UserLoginInfo userLoginInfo = new UserLoginInfo(simIDAndJobID.user.getName());
//getVcellClient().getClientServerManager().getConnectionStatus()
VCellConnection vcellConnection = userConnections.get(simIDAndJobID.user);
try{
Expand Down
2 changes: 1 addition & 1 deletion vcell-api/src/main/java/org/vcell/rest/VCellApiMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public void onException(Exception e) {
String pathPrefixV0 = PropertyLoader.getRequiredProperty(PropertyLoader.vcellServerPrefixV0);
HealthService healthService = new HealthService(restEventService, "localhost", port, pathPrefixV0,
bIgnoreCertProblemsForHealthService, bIgnoreHostMismatchForHealthService,
testUserInfo.userid, testUserInfo.digestedPassword0);
testUserInfo);
AdminService adminService = new AdminService(adminDbTopLevel, databaseServerImpl);
RpcService rpcService = new RpcService(vcMessagingService_int);
WadlApplication app = new VCellApiApplication(restDatabaseService, userService, rpcService, restEventService, adminService, templateConfiguration, healthService, javascriptDir);
Expand Down
24 changes: 11 additions & 13 deletions vcell-api/src/main/java/org/vcell/rest/health/HealthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
import org.apache.logging.log4j.Logger;
import org.vcell.rest.events.RestEventService;
import org.vcell.util.BigString;
import org.vcell.util.document.KeyValue;
import org.vcell.util.document.UserLoginInfo;
import org.vcell.util.document.*;
import org.vcell.util.document.UserLoginInfo.DigestedPassword;
import org.vcell.util.document.VCInfoContainer;

import cbit.rmi.event.MessageEvent;
import cbit.rmi.event.SimulationJobStatusEvent;
Expand Down Expand Up @@ -109,20 +107,18 @@ static NagiosStatus Unknown(Long elapsedTime_MS, String message) {
final String pathPrefixV0;
final boolean bIgnoreCertProblems;
final boolean bIgnoreHostMismatch;
final String testUserid;
final DigestedPassword testPassword;
final UserInfo testUserinfo;

public HealthService(RestEventService eventService, String host, int port, String pathPrefixV0,
boolean bIgnoreCertProblems, boolean bIgnoreHostMismatch,
String testUserid, DigestedPassword testPassword) {
UserInfo testUserinfo) {
this.eventService = eventService;
this.host = host;
this.port = port;
this.pathPrefixV0 = pathPrefixV0;
this.bIgnoreCertProblems = bIgnoreCertProblems;
this.bIgnoreHostMismatch = bIgnoreHostMismatch;
this.testUserid = testUserid;
this.testPassword = testPassword;
this.testUserinfo = testUserinfo;
}

private long simStartEvent() {
Expand Down Expand Up @@ -208,9 +204,10 @@ private void loginLoop() {
while (true) {
long id = loginStartEvent();
try {
UserLoginInfo userLoginInfo = new UserLoginInfo(testUserid, testPassword);
UserLoginInfo userLoginInfo = new UserLoginInfo(testUserinfo.getApiUserInfo().userid);
userLoginInfo.setUser(new User(testUserinfo.userid, testUserinfo.id));
RemoteProxyVCellConnectionFactory vcellConnectionFactory = new RemoteProxyVCellConnectionFactory(host, port, pathPrefixV0);
VCellConnection vcellConnection = vcellConnectionFactory.createDepricatedVCellConnection(userLoginInfo);
VCellConnection vcellConnection = vcellConnectionFactory.createVCellConnection(userLoginInfo);
VCInfoContainer vcInfoContainer = vcellConnection.getUserMetaDbServer().getVCInfoContainer();
loginSuccess(id);
}catch (Throwable e) {
Expand All @@ -229,14 +226,15 @@ private void runsimLoop() {
Thread.sleep(SIMULATION_LOOP_START_DELAY);
} catch (InterruptedException e1) {
}
UserLoginInfo userLoginInfo = new UserLoginInfo(testUserid, testPassword);
UserLoginInfo userLoginInfo = new UserLoginInfo(testUserinfo.userid);
userLoginInfo.setUser(new User(testUserinfo.userid, testUserinfo.id));
while (true) {
long id = simStartEvent();
KeyValue savedBioModelKey = null;
VCSimulationIdentifier runningSimId = null;
try {
RemoteProxyVCellConnectionFactory vcellConnectionFactory = new RemoteProxyVCellConnectionFactory(host, port, pathPrefixV0);
VCellConnection vcellConnection = vcellConnectionFactory.createDepricatedVCellConnection(userLoginInfo);
VCellConnection vcellConnection = vcellConnectionFactory.createVCellConnection(userLoginInfo);

String vcmlString = IOUtils.toString(getClass().getResourceAsStream("/TestTemplate.vcml"));

Expand Down Expand Up @@ -311,7 +309,7 @@ public void setMessage(String message) { }
// cleanup
try {
RemoteProxyVCellConnectionFactory vcellConnectionFactory = new RemoteProxyVCellConnectionFactory(host, port, pathPrefixV0);
VCellConnection vcellConnection = vcellConnectionFactory.createDepricatedVCellConnection(userLoginInfo);
VCellConnection vcellConnection = vcellConnectionFactory.createVCellConnection(userLoginInfo);
if (runningSimId!=null) {
try {
vcellConnection.getSimulationController().stopSimulation(runningSimId);
Expand Down
2 changes: 1 addition & 1 deletion vcell-api/src/main/java/org/vcell/rest/rpc/RpcRestlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void handle(Request req, Response response) {
VCellApiApplication vcellApiApplication = (VCellApiApplication)getApplication();
RpcService rpcService = vcellApiApplication.getRpcService();
serializableResultObject = rpcService.sendRpcMessage(
queue, vcRpcRequest, new Boolean(rpcBody.returnedRequired), specialProperties, specialValues, new UserLoginInfo(username,null));
queue, vcRpcRequest, rpcBody.returnedRequired, specialProperties, specialValues, new UserLoginInfo(username));
}
byte[] serializedResultObject = VCellApiClient.toCompressedSerialized(serializableResultObject);
response.setStatus(Status.SUCCESS_OK, "rpc method="+method+" succeeded");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public SimulationRep startSimulation(BiomodelSimulationStartServerResource resou
}
VCMessageSession rpcSession = vcMessagingService.createProducerSession();
try {
UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName(),null);
UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName());
try {
userLoginInfo.setUser(vcellUser);
} catch (Exception e) {
Expand Down Expand Up @@ -214,7 +214,7 @@ public SimulationRep stopSimulation(BiomodelSimulationStopServerResource resourc
}
VCMessageSession rpcSession = vcMessagingService.createProducerSession();
try {
UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName(),null);
UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName());
try {
userLoginInfo.setUser(vcellUser);
} catch (Exception e) {
Expand All @@ -234,7 +234,7 @@ public DataSetMetadata getDataSetMetadata(SimDataServerResource resource, User v
if (vcellUser==null){
vcellUser = VCellApiApplication.DUMMY_USER;
}
UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName(),null);
UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName());
String simId = resource.getAttribute(VCellApiApplication.SIMDATAID); // resource.getRequestAttributes().get(VCellApiApplication.SIMDATAID);
KeyValue simKey = new KeyValue(simId);
SimulationRep simRep = getSimulationRep(simKey);
Expand All @@ -259,7 +259,7 @@ public DataSetTimeSeries getDataSetTimeSeries(SimDataValuesServerResource resour
if (vcellUser==null){
vcellUser = VCellApiApplication.DUMMY_USER;
}
UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName(),null);
UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName());
String simId = resource.getAttribute(VCellApiApplication.SIMDATAID); // resource.getRequestAttributes().get(VCellApiApplication.SIMDATAID);
String jobIndexString = resource.getAttribute(VCellApiApplication.JOBINDEX); // resource.getRequestAttributes().get(VCellApiApplication.SIMDATAID);
KeyValue simKey = new KeyValue(simId);
Expand Down Expand Up @@ -748,7 +748,7 @@ public SimpleJobStatus[] query(SimulationTasksServerResource resource, User vcel
}
VCMessageSession rpcSession = vcMessagingService.createProducerSession();
try {
UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName(),null);
UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName());
try {
userLoginInfo.setUser(vcellUser);
} catch (Exception e) {
Expand Down Expand Up @@ -813,7 +813,7 @@ public SimulationStatusRepresentation[] query(SimulationStatusServerResource res
//
VCMessageSession rpcSession = vcMessagingService.createProducerSession();
try {
UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName(),null);
UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName());
try {
userLoginInfo.setUser(vcellUser);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,45 +466,6 @@ public SimulationTaskRepresentation[] stopSimulation(String bmId, String simKey)
return simulationTaskRepresentations;
}

public AccessTokenRepresentation deprecatedAuthenticate(String userid, String password, boolean alreadyDigested) throws ClientProtocolException, IOException {
// hash the password
String digestedPassword = (alreadyDigested)?(password):createdDigestPassword(password);

HttpGet httpget = new HttpGet(getApiUrlPrefix()+"/access_token?user_id="+userid+"&user_password="+digestedPassword+"&client_id="+clientID);

if (lg.isInfoEnabled()) {
lg.info("Executing request to retrieve access_token " + httpget.getRequestLine());
}

String responseBody = httpclient.execute(httpget, new VCellStringResponseHandler("authenticate()", httpget));
String accessTokenJson = responseBody;
if (lg.isInfoEnabled()) {
lg.info("returned: "+accessTokenJson);
}

Gson gson = new Gson();
AccessTokenRepresentation accessTokenRep = gson.fromJson(accessTokenJson,AccessTokenRepresentation.class);

BasicCredentialsProvider basicCredsProvider = new BasicCredentialsProvider();
basicCredsProvider.setCredentials(
new AuthScope(httpHost.getHostName(),httpHost.getPort()),
new UsernamePasswordCredentials("access_token", accessTokenRep.getToken()));

// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(httpHost, basicAuth);

// Add AuthCache to the execution context
httpClientContext = HttpClientContext.create();
// httpClientContext.setCredentialsProvider(basicCredsProvider);
// httpClientContext.setAuthCache(authCache);
httpClientContext.setUserToken(accessTokenRep.token);

return accessTokenRep;
}

public void createDefaultQuarkusClient(boolean bIgnoreCertProblems){
apiClient = new ApiClient(){{
if (bIgnoreCertProblems){setHttpClientBuilder(CustomApiClientCode.createInsecureHttpClientBuilder());};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public static void main(String[] args) {
String password = args[3];

vcellApiClient = new VCellApiClient(host,port,pathPrefix_v0);

vcellApiClient.deprecatedAuthenticate(username,password,false);
vcellApiClient.authenticate(false);

// test /biomodel[? query string]
BiomodelRepresentation[] biomodelReps = vcellApiClient.getBioModels(new BioModelsQuerySpec());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static ClientServerInfo createFileBasedServerInfo() {

public static ClientServerInfo createLocalServerInfo(String userName) {
ClientServerInfo csi = new ClientServerInfo(ServerType.SERVER_LOCAL, ClientServerInfo.apiHost, ClientServerInfo.isHTTP ? 80 : 443,
ClientServerInfo.v0PathPrefix, new UserLoginInfo(userName, null));
ClientServerInfo.v0PathPrefix, new UserLoginInfo(userName));
return csi;
}

Expand All @@ -64,7 +64,7 @@ public UserLoginInfo getUserLoginInfo(){
}

public static ClientServerInfo createRemoteServerInfo(String apihost, Integer apiport, String pathPrefix_v0, String userName) {
ClientServerInfo csi = new ClientServerInfo(ServerType.SERVER_REMOTE,apihost,apiport,pathPrefix_v0,new UserLoginInfo(userName, null));
ClientServerInfo csi = new ClientServerInfo(ServerType.SERVER_REMOTE,apihost,apiport,pathPrefix_v0,new UserLoginInfo(userName));
return csi;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,6 @@ public RemoteProxyVCellConnectionFactory(
}
}

public VCellConnection createDepricatedVCellConnection(UserLoginInfo userLoginInfo) throws ConnectionException {
try {
AccessTokenRepresentation accessTokenRep = this.vcellApiClient.deprecatedAuthenticate(userLoginInfo.getUserName(), userLoginInfo.getDigestedPassword().getString(),true);
userLoginInfo.setUser(new User(accessTokenRep.userId, new KeyValue(accessTokenRep.getUserKey())));
return new LocalVCellConnectionMessaging(userLoginInfo,rpcSender);
} catch (IOException e) {
throw new ConnectionException("failed to connect: "+e.getMessage(), e);
}
}

@Override
public VCellConnection createVCellConnection(UserLoginInfo userLoginInfo) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.io.IOException;

public interface VCellConnectionFactory {
VCellConnection createDepricatedVCellConnection(UserLoginInfo userLoginInfo) throws ConnectionException, AuthenticationException, IOException;
VCellConnection createVCellConnection(UserLoginInfo userLoginInfo) throws ConnectionException;
Auth0ConnectionUtils getAuth0ConnectionUtils();
}
Loading

0 comments on commit efcb5ab

Please sign in to comment.