Skip to content

Commit

Permalink
Merge pull request #6 from mlibrary/issue-working5
Browse files Browse the repository at this point in the history
change to logging, and other changes.
  • Loading branch information
blancoj committed May 6, 2024
2 parents 1a88165 + 7f61a2e commit 2e2fe39
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,17 @@ public List<Group> getSpecialGroups(Context context, HttpServletRequest request)
}
else
{
// UM Change. For now don't put people in the NotBio group
// This will guarantee that RequestItem files are requested to
// everyone except the Admins.

//Group notbioGroup = Group.findByName(context, "NotBio");
Group notbioGroup = groupService.findByName(context, "NotBio");
// Group notbioGroup = groupService.findByName(context, "NotBio");
// Append to list of elligible groups
bioId = notbioGroup.getID();
count++;
// bioId = notbioGroup.getID();
// count++;

LOGGER.info ("OIDC: In: NotBio " + bioId.toString());
// LOGGER.info ("OIDC: In: NotBio " + bioId.toString());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.dspace.services.ConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;

import org.apache.commons.lang3.ArrayUtils;

/**
* Broker for ChoiceAuthority plugins, and for other information configured
* about the choice aspect of authority control for a metadata field.
Expand Down Expand Up @@ -569,6 +571,16 @@ public DSpaceControlledVocabularyIndex getVocabularyIndex(String nameVocab) {
init();
ChoiceAuthority source = this.getChoiceAuthorityByAuthorityName(nameVocab);
if (source != null && source instanceof DSpaceControlledVocabulary) {

// First, check if this vocabulary index is disabled
String[] vocabulariesDisabled = configurationService
.getArrayProperty("webui.browse.vocabularies.disabled");
if (vocabulariesDisabled != null && ArrayUtils.contains(vocabulariesDisabled, nameVocab)) {
// Discard this vocabulary browse index
return null;
}


Set<String> metadataFields = new HashSet<>();
Map<String, List<String>> formsToFields = this.authoritiesFormDefinitions.get(nameVocab);
for (Map.Entry<String, List<String>> formToField : formsToFields.entrySet()) {
Expand Down
122 changes: 68 additions & 54 deletions dspace-api/src/main/java/org/dspace/usage/UsageEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
import org.dspace.services.model.Request;
import org.dspace.utils.DSpace;
import org.dspace.services.factory.DSpaceServicesFactory;

import org.apache.logging.log4j.Logger;

/**
* @author Mark Diggory (mdiggory at atmire.com)
*/
public class UsageEvent extends Event {


private static Logger log = org.apache.logging.log4j.LogManager.getLogger(UsageEvent.class);

public static enum Action {
VIEW("view"),
CREATE("create"),
Expand Down Expand Up @@ -130,40 +133,41 @@ private static String checkParams(Action action, Context context, DSpaceObject o
return eventName.toString();
}


// This one is used by view_bitstream_details
public Context getContextSpecial() {

HttpServletRequest request = null;
RequestService requestService = new DSpace().getRequestService();
// HttpServletRequest request = null;
// RequestService requestService = new DSpace().getRequestService();

Request currentRequest = requestService.getCurrentRequest();
if ( currentRequest != null)
{
request = currentRequest.getHttpServletRequest();
}
// Request currentRequest = requestService.getCurrentRequest();
// if ( currentRequest != null)
// {
// request = currentRequest.getHttpServletRequest();
// }

// Set the session ID
context.setExtraLogInfo("session_id="
+ request.getSession().getId());

// Set the session ID and IP address
String referer = request.getHeader( "Referer" );
//String ip = request.getRemoteAddr();
String ip = request.getHeader("X-Forwarded-For");
if (useProxies == null) {
useProxies = DSpaceServicesFactory.getInstance().getConfigurationService().getBooleanProperty("useProxies", false);
}
if(useProxies && request.getHeader("X-Forwarded-For") != null)
{
/* This header is a comma delimited list */
for(String xfip : request.getHeader("X-Forwarded-For").split(","))
{
if(!request.getHeader("X-Forwarded-For").contains(ip))
{
ip = xfip.trim();
}
}
}
// This is how I get the true IP
String ip = getRequest().getRemoteAddr();
String referer = this.referrer;

// String ip = request.getHeader("X-Forwarded-For");
// if (useProxies == null) {
// useProxies = DSpaceServicesFactory.getInstance().getConfigurationService().getBooleanProperty("useProxies", false);
// }
// if(useProxies && request.getHeader("X-Forwarded-For") != null)
// {
// /* This header is a comma delimited list */
// for(String xfip : request.getHeader("X-Forwarded-For").split(","))
// {
// if(!request.getHeader("X-Forwarded-For").contains(ip))
// {
// ip = xfip.trim();
// }
// }
// }

context.setExtraLogInfo("session_id=" + request.getSession().getId() + ":ip_addr=" + ip + ":referer=" + referer);

Expand All @@ -173,42 +177,52 @@ public Context getContextSpecial() {
return context;
}

// This one is used by view_item_details
// For item you want to indicate INSIDE/OUTSIDE status.
public Context getContextSpecialItem() {

HttpServletRequest request = null;
// HttpServletRequest request = null;

RequestService requestService = new DSpace().getRequestService();
// RequestService requestService = new DSpace().getRequestService();

Request currentRequest = requestService.getCurrentRequest();
if ( currentRequest != null)
{
request = currentRequest.getHttpServletRequest();
}
// Request currentRequest = requestService.getCurrentRequest();
// if ( currentRequest != null)
// {
// log.info("REFITEM: currentRequest is null");
// request = currentRequest.getHttpServletRequest();
// }

// This is how I get the true IP
String ip = getRequest().getRemoteAddr();
String referer = this.referrer;

if ( ( referer == null ) || ( referer.isEmpty() ) )
{
referer = "null";
}

// Set the session ID
context.setExtraLogInfo("session_id="
+ request.getSession().getId());

// Set the session ID and IP address
String referer = request.getHeader( "Referer" );
//String ip = request.getRemoteAddr();
String ip = request.getHeader("X-Forwarded-For");
if (useProxies == null) {
useProxies = DSpaceServicesFactory.getInstance().getConfigurationService().getBooleanProperty("useProxies", false);
}
if(useProxies && request.getHeader("X-Forwarded-For") != null)
{
/* This header is a comma delimited list */
for(String xfip : request.getHeader("X-Forwarded-For").split(","))
{
if(!request.getHeader("X-Forwarded-For").contains(ip))
{
ip = xfip.trim();
}
}
}
+ getRequest().getSession().getId());

// UM Change
// This did not get me the ip address. I think this is the old way of doing it.
// String ip = request.getHeader("X-Forwarded-For");
// if (useProxies == null) {
// useProxies = DSpaceServicesFactory.getInstance().getConfigurationService().getBooleanProperty("useProxies", false);
// }
// if(useProxies && request.getHeader("X-Forwarded-For") != null)
// {
// /* This header is a comma delimited list */
// for(String xfip : request.getHeader("X-Forwarded-For").split(","))
// {
// if(!request.getHeader("X-Forwarded-For").contains(ip))
// {
// ip = xfip.trim();
// }
// }
// }
// End UM Change

String InsideOutside;
if ( referer != null )
Expand Down

0 comments on commit 2e2fe39

Please sign in to comment.