2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
18 package org.collectionspace.services.report.nuxeo;
20 import java.sql.Connection;
21 import java.sql.SQLException;
22 import java.sql.Statement;
23 import java.util.List;
25 import org.collectionspace.services.common.ServiceMain;
26 import org.collectionspace.services.common.api.Tools;
27 import org.collectionspace.services.common.init.IInitHandler;
28 import org.collectionspace.services.common.init.InitHandler;
29 import org.collectionspace.services.common.storage.DatabaseProductType;
30 import org.collectionspace.services.common.storage.JDBCTools;
32 import org.collectionspace.services.config.service.InitHandler.Params.Field;
33 import org.collectionspace.services.config.service.InitHandler.Params.Property;
34 import org.collectionspace.services.config.service.ServiceBindingType;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
40 * ReportPostInitHandler, post-init action to add grant reader access to DB
42 * In the configuration file, looks for a single Field declaration
43 * with a param value that has the name of the reader account/role.
44 * If not specified, it will assume 'reader';
46 * $LastChangedRevision: 5103 $
47 * $LastChangedDate: 2011-06-23 16:50:06 -0700 (Thu, 23 Jun 2011) $
49 public class ReportPostInitHandler extends InitHandler implements IInitHandler {
51 final Logger logger = LoggerFactory.getLogger(ReportPostInitHandler.class);
53 public static final String READER_ROLE_NAME_KEY = "readerRoleName";
54 public static final String DEFAULT_READER_ROLE_NAME = "reader" + ServiceMain.getInstance().getCspaceInstanceId();
55 private String readerRoleName = DEFAULT_READER_ROLE_NAME;
57 /** See the class javadoc for this class: it shows the syntax supported in the configuration params.
60 public void onRepositoryInitialized(String dataSourceName,
61 String repositoryName,
62 String cspaceInstanceId,
63 ServiceBindingType sbt,
65 List<Property> propertyList) throws Exception {
66 //Check for existing privileges, and if not there, grant them
67 for(Property prop : propertyList) {
68 if(READER_ROLE_NAME_KEY.equals(prop.getKey())) {
69 String value = prop.getValue();
70 if(Tools.notEmpty(value) && !DEFAULT_READER_ROLE_NAME.equals(value)){
71 readerRoleName = value + ServiceMain.getInstance().getCspaceInstanceId();
72 logger.debug("ReportPostInitHandler: overriding readerRoleName default value to use: "
77 String privilegeName = JDBCTools.DATABASE_SELECT_PRIVILEGE_NAME;
78 JDBCTools.grantPrivilegeToDatabaseUser(dataSourceName, repositoryName, cspaceInstanceId, privilegeName, readerRoleName);