]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
0f45f2fd1682110c1cf449c0fc69878da84ddcd2
[tmp/jakarta-migration.git] /
1 /**
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:
5
6  *  http://www.collectionspace.org
7  *  http://wiki.collectionspace.org
8
9  *  Copyright 2009 University of California at Berkeley
10
11  *  Licensed under the Educational Community License (ECL), Version 2.0.
12  *  You may not use this file except in compliance with this License.
13
14  *  You may obtain a copy of the ECL 2.0 License at
15
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17  */
18 package org.collectionspace.services.report.nuxeo;
19
20 import java.sql.Connection;
21 import java.sql.SQLException;
22 import java.sql.Statement;
23 import java.util.List;
24
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;
31
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;
35
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39 /**
40  * ReportPostInitHandler, post-init action to add grant reader access to DB
41  * 
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'; 
45  * 
46  * $LastChangedRevision: 5103 $
47  * $LastChangedDate: 2011-06-23 16:50:06 -0700 (Thu, 23 Jun 2011) $
48  */
49 public class ReportPostInitHandler extends InitHandler implements IInitHandler {
50
51     final Logger logger = LoggerFactory.getLogger(ReportPostInitHandler.class);
52    
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;
56     
57     /** See the class javadoc for this class: it shows the syntax supported in the configuration params.
58      */
59     @Override
60     public void onRepositoryInitialized(String dataSourceName,
61                 String repositoryName,
62                 String cspaceInstanceId,
63                 ServiceBindingType sbt, 
64                 List<Field> fields, 
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: "
73                                 + value);
74                 }
75             }
76         }
77         String privilegeName = JDBCTools.DATABASE_SELECT_PRIVILEGE_NAME;
78         JDBCTools.grantPrivilegeToDatabaseUser(dataSourceName, repositoryName, cspaceInstanceId, privilegeName, readerRoleName);
79     }
80     
81
82 }