Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow http for testing and rethrow exception so partial bags aren't created #7139

Merged
merged 8 commits into from Aug 11, 2020
18 changes: 13 additions & 5 deletions src/main/java/edu/harvard/iq/dataverse/DataverseSession.java
Expand Up @@ -59,11 +59,19 @@ public User getUser() {
}

public void setUser(User aUser) {
logSvc.log(
new ActionLogRecord(ActionLogRecord.ActionType.SessionManagement,(aUser==null) ? "logout" : "login")
.setUserIdentifier((aUser!=null) ? aUser.getIdentifier() : (user!=null ? user.getIdentifier() : "") ));
//#3254 - change session id when user changes
SessionUtil.changeSessionId((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());

FacesContext context = FacesContext.getCurrentInstance();
// Log the login/logout and Change the session id if we're using the UI and have
// a session, versus an API call with no session - (i.e. /admin/submitToArchive()
// which sets the user in the session to pass it through to the underlying command)
if(context != null) {
logSvc.log(
new ActionLogRecord(ActionLogRecord.ActionType.SessionManagement,(aUser==null) ? "logout" : "login")
.setUserIdentifier((aUser!=null) ? aUser.getIdentifier() : (user!=null ? user.getIdentifier() : "") ));

//#3254 - change session id when user changes
SessionUtil.changeSessionId((HttpServletRequest) context.getExternalContext().getRequest());
}
this.user = aUser;
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/api/Admin.java
Expand Up @@ -1675,6 +1675,10 @@ public Response submitDatasetVersionToArchive(@PathParam("id") String dsid, @Pat

try {
AuthenticatedUser au = findAuthenticatedUserOrDie();
// Note - the user is being set in the session so it becomes part of the
// DataverseRequest and is sent to the back-end command where it is used to get
// the API Token which is then used to retrieve files (e.g. via S3 direct
// downloads) to create the Bag
session.setUser(au);
Dataset ds = findDatasetOrDie(dsid);

Expand Down
Expand Up @@ -56,6 +56,7 @@
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
Expand Down Expand Up @@ -158,6 +159,7 @@ public BagGenerator(OREMap oreMap, String dataciteXml) throws JsonSyntaxExceptio
SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);

Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", sslConnectionFactory).build();
cm = new PoolingHttpClientConnectionManager(registry);

Expand Down Expand Up @@ -567,8 +569,8 @@ private void processContainer(JsonObject item, String currentPath) throws IOExce
}

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.severe("Failed to read " + childPath);
throw e;
} finally {
IOUtils.closeQuietly(inputStream);
}
Expand Down