Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into solr-wfs-indexing
Browse files Browse the repository at this point in the history
Conflicts:
	.gitignore
	web-ui/src/main/resources/catalog/components/search/formfields/FormFieldsDirective.js
	web-ui/src/main/resources/catalog/components/viewer/gfi/GetFeatureInfoDirective.js
  • Loading branch information
fgravin committed May 30, 2016
2 parents 7e582f3 + 4a38332 commit c2321d1
Show file tree
Hide file tree
Showing 2,367 changed files with 10,444 additions and 452,063 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.java]
indent_size = 4

[*.md]
indent_size = 2
trim_trailing_whitespace = false
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,6 @@ datadir_*
solr/solr-config/solr-*
web/src/main/webapp/WEB-INF/data/harvester_*
camel-harvesters/wfsfeature-harvester/logs
web/src/main/webapp/doc
web/src/main/webapp/WEB-INF/data/data/backup
schemas/*/doc/*/*.rst
34 changes: 29 additions & 5 deletions common/src/main/java/org/fao/geonet/utils/Xml.java
Original file line number Diff line number Diff line change
Expand Up @@ -1008,10 +1008,33 @@ public static Number selectNumber(Element xml, String xpath, List<Namespace> the
* @return
*/
public static Set<String> filterElementValues(Element element,
ElementFilter elementFilter,
String elementName,
Namespace elementNamespace,
String attributeName) {
ElementFilter elementFilter,
String elementName,
Namespace elementNamespace,
String attributeName) {
return filterElementValues(element, elementFilter, elementName, elementNamespace, attributeName, null);
}

/**
* Search in metadata all matching element for the filter
* and return a list of uuid separated by or to be used in a
* search on uuid. Extract uuid from matched element if
* elementName is null or from the elementName child.
*
* @param element
* @param elementFilter Filter to get element descendants
* @param elementName Child element to get value from. If null, filtered element value is returned
* @param elementNamespace
* @param attributeName Attribute name to get value from. If null, TODO: improve
* @param attributeNamespace
* @return
*/
public static Set<String> filterElementValues(Element element,
ElementFilter elementFilter,
String elementName,
Namespace elementNamespace,
String attributeName,
Namespace attributeNamespace) {
@SuppressWarnings("unchecked")
Iterator<Element> i = element.getDescendants(elementFilter);
Set<String> values = new HashSet<String>();
Expand All @@ -1022,7 +1045,8 @@ public static Set<String> filterElementValues(Element element,
e.getText() :
(attributeName == null ?
e.getChildText(elementName, elementNamespace) :
e.getAttributeValue(attributeName)
(attributeNamespace == null)?e.getAttributeValue(attributeName):
e.getAttributeValue(attributeName, attributeNamespace)
);
if (uuid != null && !uuid.isEmpty()) {
values.add(uuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public Source resolve(String href, String base) throws TransformerException {
final Path basePath = IO.toPath(new URI(base));
Path parent = basePath.getParent();
if(parent == null) {
throw new RuntimeException(basePath.getFileName() +
throw new RuntimeException(basePath.getFileName() +
" does not have parent");
}
resolvedResource = parent.resolve(href);
Expand All @@ -122,6 +122,9 @@ public Source resolve(String href, String base) throws TransformerException {
return toPathInputSource(resolvedResource);
}
}
} catch (RuntimeException e) {
throw e;

} catch (Exception e) {
// ignore
}
Expand Down
9 changes: 9 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,15 @@
<artifactId>jsoup</artifactId>
<version>0.2.2</version>
</dependency>


<!-- OWASP Enterprise Security API -->
<dependency>
<groupId>org.owasp.esapi</groupId>
<artifactId>esapi</artifactId>
<version>2.1.0</version>
</dependency>

</dependencies>

<build>
Expand Down
90 changes: 47 additions & 43 deletions core/src/main/java/jeeves/guiservices/session/Get.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,49 +75,53 @@ public void init(Path appPath, ServiceConfig params) throws Exception
public Element exec(Element params, ServiceContext context) throws Exception
{
UserSession session = context.getUserSession();

String sUsername = session.getUsername();
String sName = session.getName();
String sSurname = session.getSurname();
Profile sProfile = session.getProfile();

if (sUsername == null)
sUsername = Profile.Guest.name();

if (sName == null)
sName = sUsername;

if (sSurname == null)
sSurname = "";

if (sProfile == null)
sProfile = Profile.Guest;

Element userId = new Element("userId") .addContent(session.getUserId());
Element username = new Element("username").addContent(sUsername);
Element name = new Element("name") .addContent(sName);
Element surname = new Element("surname") .addContent(sSurname);
Element profile = new Element("profile") .addContent(sProfile.name());

Element sEl = new Element(Jeeves.Elem.SESSION)
.addContent(userId)
.addContent(username)
.addContent(name)
.addContent(surname)
.addContent(profile);

if (groupName != null)
{
Map<?, Element> group = (Map<?, Element>)session.getProperty(groupName);
if (group != null)
{
Element gEl = new Element(groupName);
for (Element child : group.values()) {
if (outFields == null || outFields.contains(child.getName()))
gEl.addContent((Element)child.clone());
}
sEl.addContent(gEl);
}
Element sEl = new Element(Jeeves.Elem.SESSION);

if(session != null) {

String sUsername = session.getUsername();
String sName = session.getName();
String sSurname = session.getSurname();
Profile sProfile = session.getProfile();

if (sUsername == null)
sUsername = Profile.Guest.name();

if (sName == null)
sName = sUsername;

if (sSurname == null)
sSurname = "";

if (sProfile == null)
sProfile = Profile.Guest;

Element userId = new Element("userId") .addContent(session.getUserId());
Element username = new Element("username").addContent(sUsername);
Element name = new Element("name") .addContent(sName);
Element surname = new Element("surname") .addContent(sSurname);
Element profile = new Element("profile") .addContent(sProfile.name());

sEl
.addContent(userId)
.addContent(username)
.addContent(name)
.addContent(surname)
.addContent(profile);

if (groupName != null)
{
Map<?, Element> group = (Map<?, Element>)session.getProperty(groupName);
if (group != null)
{
Element gEl = new Element(groupName);
for (Element child : group.values()) {
if (outFields == null || outFields.contains(child.getName()))
gEl.addContent((Element)child.clone());
}
sEl.addContent(gEl);
}
}
}
return sEl;
}
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/jeeves/server/context/ServiceContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ public ServiceContext(final String service, final ConfigurableApplicationContext
public Path getUploadDir() { return getBean(GeonetworkDataDirectory.class).getUploadDir(); }
public int getMaxUploadSize() { return _maxUploadSize; }

/**
* Warning: this may return a null value if the user is a crawler!!
* @return the user session stored on httpsession
*/
public UserSession getUserSession() { return _userSession; }
public ProfileManager getProfileManager() { return getBean(ProfileManager.class); }

Expand Down
113 changes: 69 additions & 44 deletions core/src/main/java/jeeves/server/dispatchers/ServiceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,45 @@

package jeeves.server.dispatchers;

import java.io.ByteArrayOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.eclipse.jetty.io.EofException;
import org.fao.geonet.ApplicationContextHolder;
import org.fao.geonet.Constants;
import org.fao.geonet.NodeInfo;
import org.fao.geonet.Util;
import org.fao.geonet.exceptions.JeevesException;
import org.fao.geonet.exceptions.NotAllowedEx;
import org.fao.geonet.exceptions.ServiceNotFoundEx;
import org.fao.geonet.exceptions.ServiceNotMatchedEx;
import org.fao.geonet.kernel.GeonetworkDataDirectory;
import org.fao.geonet.utils.BLOB;
import org.fao.geonet.utils.BinaryFile;
import org.fao.geonet.utils.IO;
import org.fao.geonet.utils.Log;
import org.fao.geonet.utils.SOAPUtil;
import org.fao.geonet.utils.Xml;
import org.jdom.Element;
import org.springframework.context.ConfigurableApplicationContext;

import com.yammer.metrics.core.TimerContext;

import jeeves.component.ProfileManager;
import jeeves.constants.ConfigFile;
import jeeves.constants.Jeeves;
Expand All @@ -43,38 +81,6 @@
import jeeves.server.sources.ServiceRequest.OutputMethod;
import jeeves.server.sources.http.HttpServiceRequest;
import jeeves.server.sources.http.JeevesServlet;
import org.eclipse.jetty.io.EofException;
import org.fao.geonet.ApplicationContextHolder;
import org.fao.geonet.Constants;
import org.fao.geonet.NodeInfo;
import org.fao.geonet.Util;
import org.fao.geonet.exceptions.JeevesException;
import org.fao.geonet.exceptions.NotAllowedEx;
import org.fao.geonet.exceptions.ServiceNotFoundEx;
import org.fao.geonet.exceptions.ServiceNotMatchedEx;
import org.fao.geonet.kernel.GeonetworkDataDirectory;
import org.fao.geonet.utils.BLOB;
import org.fao.geonet.utils.BinaryFile;
import org.fao.geonet.utils.IO;
import org.fao.geonet.utils.Log;
import org.fao.geonet.utils.SOAPUtil;
import org.fao.geonet.utils.Xml;
import org.jdom.Element;
import org.springframework.context.ConfigurableApplicationContext;

import java.io.ByteArrayOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

//=============================================================================
public class ServiceManager {
Expand All @@ -91,7 +97,15 @@ public class ServiceManager {
private boolean defaultLocal;
private JeevesServlet servlet;
private boolean startupError = false;
private Map<String, String> startupErrors;
private Map<String, String> startupErrors;

/**
* Detect crawlers. Useful to avoid creating sessions for them.
*/
public static final String BOT_REGEXP = ".*(bot|crawler|baiduspider|80legs|ia_archiver|"
+ "voyager|yahoo! slurp|mediapartners-google).*";
private Pattern regex = Pattern.compile(BOT_REGEXP, Pattern.CASE_INSENSITIVE);



@PersistenceContext
Expand Down Expand Up @@ -361,20 +375,31 @@ public ServiceContext createServiceContext(String name, String lang, HttpServlet

String ip = request.getRemoteAddr();

final HttpSession httpSession = request.getSession(true);
UserSession session = (UserSession) httpSession.getAttribute(Jeeves.Elem.SESSION);
if (session == null) {
session = new UserSession();

httpSession.setAttribute(Jeeves.Elem.SESSION, session);
session.setsHttpSession(httpSession);
boolean notCrawler = true;

if (Log.isDebugEnabled(Log.REQUEST)) {
Log.debug(Log.REQUEST, "Session created for client : " + ip);
String userAgent = request.getHeader("user-agent");

if(StringUtils.isNotBlank(userAgent)) {
Matcher m = regex.matcher(userAgent);
notCrawler = !m.find();
}

if(notCrawler) {
final HttpSession httpSession = request.getSession(true);
UserSession session = (UserSession) httpSession.getAttribute(Jeeves.Elem.SESSION);
if (session == null) {
session = new UserSession();

httpSession.setAttribute(Jeeves.Elem.SESSION, session);
session.setsHttpSession(httpSession);

if (Log.isDebugEnabled(Log.REQUEST)) {
Log.debug(Log.REQUEST, "Session created for client : " + ip);
}
}

context.setUserSession(session);
}

context.setUserSession(session);
return context;
}

Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/org/fao/geonet/kernel/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -3434,6 +3435,10 @@ public Object doInTransaction(TransactionStatus transaction) throws Throwable {

}

public void forceIndexChanges() throws IOException {
getSearchManager().forceIndexChanges();
}

public int batchDeleteMetadataAndUpdateIndex(Specification<Metadata> specification) throws Exception {
final List<Integer> idsOfMetadataToDelete = getMetadataRepository().findAllIdsBy(specification);

Expand Down
Loading

0 comments on commit c2321d1

Please sign in to comment.