*.log.*
cspace-app-perflog.csv
.flattened-pom.xml
+bin
+*.diff
+logged_schemas
+logs
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License. -->
-<Context antiResourceLocking="false" privileged="true" path="/cspace-services"
+<Context antiResourceLocking="false" privileged="true" failCtxIfServletStartFails="true" path="/cspace-services"
docBase="cspace-services">
<!-- Disable HTTP Session persistence between restart since webengine session objects are not serializable -->
* https://source.collectionspace.org/collection-space/LICENSE.txt
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *//**
- * This document is a part of the source code and related artifacts
- * for CollectionSpace, an open source collections management system
- * for museums and related institutions:
-
- * http://www.collectionspace.org
- * http://wiki.collectionspace.org
-
- * Copyright 2009 University of California at Berkeley
-
- * Licensed under the Educational Community License (ECL), Version 2.0.
- * You may not use this file except in compliance with this License.
-
- * You may obtain a copy of the ECL 2.0 License at
-
- * https://source.collectionspace.org/collection-space/LICENSE.txt
-
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
salt = realm.getSalt(username);
requireSSO = realm.isRequireSSO(username);
tenants = getTenants(username);
+ if (tenants == null || tenants.isEmpty()) {
+ String msg = String.format("The account '%s' is not associated with any tenants. " +
+ "Please contact your administrator.", username);
+ throw new AccountException(msg);
+ }
grantedAuthorities = getAuthorities(username);
}
catch (AccountNotFoundException e) {
CSpaceUser cspaceUser = getUser();
if (cspaceUser != null) {
- result = getCurrentTenant().getId();
+ if (getCurrentTenant() != null) {
+ result = getCurrentTenant().getId();
+ }
} else {
String username = getUserId();
if (username.equals(AuthN.ANONYMOUS_USER)) {
<target name="import" depends="import-unix,import-windows"
description="import authorization" />
<target name="import-unix" if="osfamily-unix" depends="setup_hibernate.cfg">
- <exec executable="mvn" failonerror="true">
+ <exec executable="mvn" failonerror="true"> <!-- To debug, change command here mvn to 'mvnDebug' -->
<arg value="exec:java" />
<arg value="-f" />
<arg value="${basedir}/pom.xml" />
public static void main(String [] args) {
String username = "collectionspace.lyrasis@gmail.com";
- String password = "CSpace11-GG";
+ String password = "bogus_password";
String recipient = "remillet@gmail.com";
Properties props = new Properties();
//celebrate success
initFailed = false;
} catch (Exception e) {
+ newInstance.release(); // attempt to release resources acquired during initialization attempt
instance = null;
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
if (result.contains("{{link}}") == false) {
- logger.warn("The tenant's password reset message does not contain a required '{{link}}' marker.");
+ logger.error("The tenant's password reset message does not contain a required '{{link}}' marker.");
result = null;
}
// to specify sort ordering, pagination, etc.
//
MultivaluedMap<String, String> queryParameters = this.getQueryParams();
- if (queryParameters != null) {
+ if (queryParameters != null && !queryParameters.isEmpty()) {
docFilter.setSortOrder(queryParameters);
docFilter.setPagination(queryParameters);
String workflowWhereClause = buildWorkflowWhereClause(queryParameters);
String propName, boolean qualify) {
List<String> values = new ArrayList<String>();
ServiceObjectType objectType = serviceBinding.getObject();
- List<ObjectPartType> objectPartTypes = objectType.getPart();
- for (ObjectPartType objectPartType : objectPartTypes) {
- List<PropertyType> propNodeList = objectPartType.getProperties();
- PropertyItemUtils.getPropertyValuesByNameInNodeList(propNodeList,
- propName, (qualify?(objectPartType.getLabel()+":"):null), values);
- }
+ if (objectType != null) {
+ List<ObjectPartType> objectPartTypes = objectType.getPart();
+ for (ObjectPartType objectPartType : objectPartTypes) {
+ List<PropertyType> propNodeList = objectPartType.getProperties();
+ PropertyItemUtils.getPropertyValuesByNameInNodeList(propNodeList, propName,
+ (qualify ? objectPartType.getLabel() + ":" : null), values);
+ }
+ }
return values;
}
return this.getList(parentCtx, parentCtx.getUriInfo());
}
+ @Override
public RelationsCommonList getList(ServiceContext<PoxPayloadIn, PoxPayloadOut> parentCtx, UriInfo uriInfo) {
MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
public final static String TYPE_SCHEMA_NAME = COMMON_SCHEMA_NAME;
public final static String TYPE_FIELD_NAME = IRelationsManager.RELATIONSHIP_TYPE;
- public final static String AFFECTS_TYPE = RelationshipType.AFFECTS.toString();
- public final static String BROADER_TYPE = RelationshipType.HAS_BROADER.toString();
+ public final static String AFFECTS_TYPE = RelationshipType.AFFECTS.value();
+ public final static String BROADER_TYPE = RelationshipType.HAS_BROADER.value();
}
/**
* Create a database user, if that user doesn't already exist.
*
- * @param conn a database connection.
+ * @param dataSourceName the datasource for the connection
+ * @param repositoryName the repository name for the connection
+ * @param cspaceInstanceId the cspace instance id for the connection
* @param dbType a database product type.
* @param username the name of the database user to create.
* @param userPW the initial password for that database user.
*/
public static void createNewDatabaseUser(String dataSourceName, String repositoryName,
String cspaceInstanceId, DatabaseProductType dbType, String username, String userPW) throws Exception {
- Statement stmt = null;
- Connection conn = null;
if (dbType != DatabaseProductType.POSTGRESQL) {
throw new UnsupportedOperationException("createNewDatabaseUser only supports PostgreSQL");
}
- try {
+
+ String sql = null;
+ try (Connection conn = getConnection(dataSourceName, repositoryName, cspaceInstanceId);
+ Statement stmt = conn.createStatement()) {
if (hasDatabaseUser(dataSourceName, repositoryName, cspaceInstanceId, dbType, username)) {
- if (logger.isDebugEnabled()) {
- logger.debug("User: " + username + " already exists.");
- }
+ logger.debug("User: {} already exists.", username);
} else {
- conn = getConnection(dataSourceName, repositoryName, cspaceInstanceId);
- stmt = conn.createStatement();
- String sql = "CREATE ROLE " + username + " WITH PASSWORD '" + userPW + "' LOGIN";
+ sql = "CREATE ROLE " + username + " WITH PASSWORD '" + userPW + "' LOGIN";
stmt.executeUpdate(sql);
- if (logger.isDebugEnabled()) {
- logger.debug("Created User: " + username);
- }
+ logger.debug("Created User: {}", username);
}
} catch (Exception e) {
- logger.error("createNewDatabaseUser failed on exception: " + e.getLocalizedMessage());
+ logger.error("createNewDatabaseUser failed with exception:", e);
throw e;
- } finally {
- try {
- if (stmt != null) {
- stmt.close();
- }
- if (conn != null) {
- conn.close();
- }
- } catch (SQLException sqle) {
- // nothing we can do here except log
- logger.warn("SQL Exception when closing statement/connection: " + sqle.getLocalizedMessage());
- }
}
}
import java.util.Hashtable;
import java.util.Iterator;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.util.Enumeration;
+
+import javax.management.JMException;
import javax.servlet.ServletContext;
import org.apache.catalina.util.ServerInfo;
private volatile boolean initialized = false; // use volatile for lazy
// initialization in
// singleton
+ private ClassLoader classLoader;
public NuxeoFrameworkBootstrap fb;
private ServletContext servletContext;
private RepositoryClientConfigType repositoryClientConfig;
+ nuxeoHomeDir.getCanonicalPath());
}
- ClassLoader cl = NuxeoConnectorEmbedded.class.getClassLoader();
+ classLoader = NuxeoConnectorEmbedded.class.getClassLoader();
- fb = new NuxeoFrameworkBootstrap(cl, nuxeoHomeDir);
+ fb = new NuxeoFrameworkBootstrap(classLoader, nuxeoHomeDir);
fb.setHostName("Tomcat");
fb.setHostVersion(ServerInfo.getServerNumber());
fb.initialize();
- fb.start(new MutableClassLoaderDelegate(cl));
+ fb.start(new MutableClassLoaderDelegate(classLoader));
// Test to see if we can connect to the default repository
boolean transactionStarted = false;
try {
Repository defaultRepo = Framework.getService(RepositoryManager.class).getDefaultRepository();
coreSession = CoreInstance.openCoreSession(defaultRepo.getName(), new SystemPrincipal(null));
- } catch (Throwable t) {
+ } catch (Throwable t) {
logger.error(t.getMessage());
throw new RuntimeException("Could not start the Nuxeo EP Framework", t);
} finally {
}
}
+ private void stopNuxeoEP() {
+ try {
+ fb.stop(new MutableClassLoaderDelegate(classLoader));
+ Enumeration<Driver> drivers = DriverManager.getDrivers();
+ while (drivers.hasMoreElements()) {
+ Driver driver = drivers.nextElement();
+ try {
+ DriverManager.deregisterDriver(driver);
+ logger.info("Deregister JDBC driver: {}", driver);
+ } catch (SQLException e) {
+ logger.error("Error deregistering JDBC driver {}", driver, e);
+ }
+ }
+ } catch (IllegalArgumentException | ReflectiveOperationException | JMException e) {
+ logger.error("CollectionSpace was unable to shutdown Nuxeo cleanly.", e);
+ }
+ }
+
+
/**
* release releases resources occupied by Nuxeo remoting client runtime
*
if (initialized == true) {
try {
client.tryDisconnect();
+ stopNuxeoEP();
} catch (Exception e) {
logger.error("Failed to disconnect Nuxeo connection.", e);
throw e;
return getPropertyValuesByName(propItems, propName, qualPrefix, null);
}
- /**
- * @param propNodeList the Item list to search for the named property
- * @param propName the name of the property of interest
- * @param qualPrefix a namespace qualifier prefix (with ':') to prepend, or null
- * @param values and existing list to append values to. If null, a new one will be created.
- * @return values, or that is null, a new List of string values found for the named property
- */
- public static List<String> getPropertyValuesByName(
- List<PropertyItemType> propItems, String propName, String qualPrefix,
- List<String> values ) {
-
- if (values == null) {
- values = new ArrayList<String>();
- }
+ /**
+ * @param propName the name of the property of interest
+ * @param qualPrefix a namespace qualifier prefix (with ':') to prepend, or null
+ * @param values and existing list to append values to. If null, a new one will be created.
+ * @return values, or that is null, a new List of string values found for the named property
+ */
+ public static List<String> getPropertyValuesByName(
+ List<PropertyItemType> propItems, String propName, String qualPrefix,
+ List<String> values ) {
+
+ if (values == null) {
+ values = new ArrayList<String>();
+ }
- if (propItems != null) {
- for (PropertyItemType propItem : propItems) {
- if (propName.equals(propItem.getKey())) {
- // TODO - the trim() belongs here, not down a few lines.
- String value = propItem.getValue();
+ if (propItems != null) {
+ for (PropertyItemType propItem : propItems) {
+ if (propName.equals(propItem.getKey())) {
+ // TODO - the trim() belongs here, not down a few lines.
+ String value = propItem.getValue();
- if (value != null) {
- values.add((qualPrefix != null) ? (qualPrefix + value) : value.trim());
- }
+ if (value != null) {
+ values.add((qualPrefix != null) ? (qualPrefix + value) : value.trim());
}
}
}
-
- return values;
}
+ return values;
+ }
+
/**
* @param propNodeList the wrapping list node from JAXB
* @param propName the property to set