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