33 |
33 |
import java.util.Date;
|
34 |
34 |
import java.util.HashMap;
|
35 |
35 |
import java.util.HashSet;
|
36 |
|
import java.util.Iterator;
|
37 |
36 |
import java.util.List;
|
38 |
37 |
import java.util.Map;
|
39 |
38 |
import java.util.Set;
|
... | ... | |
62 |
61 |
import edu.ucsb.nceas.metacat.IdentifierManager;
|
63 |
62 |
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
|
64 |
63 |
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlException;
|
65 |
|
import edu.ucsb.nceas.metacat.dataone.D1NodeService;
|
66 |
64 |
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
67 |
65 |
import edu.ucsb.nceas.metacat.shared.ServiceException;
|
68 |
66 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
|
... | ... | |
72 |
70 |
|
73 |
71 |
private static Logger logMetacat = Logger.getLogger(SyncAccessPolicy.class);
|
74 |
72 |
|
75 |
|
protected static int MAXIMUM_DB_RECORD_COUNT;
|
76 |
|
|
77 |
|
static {
|
78 |
|
try {
|
79 |
|
MAXIMUM_DB_RECORD_COUNT = Integer.valueOf(PropertyService
|
80 |
|
.getProperty("database.webResultsetSize"));
|
81 |
|
} catch (Exception e) {
|
82 |
|
logMetacat.warn("Could not set MAXIMUM_DB_RECORD_COUNT", e);
|
83 |
|
}
|
84 |
|
}
|
85 |
|
|
86 |
73 |
/**
|
87 |
74 |
* Synchronize access policy (from system metadata) of d1 member node with
|
88 |
75 |
* the corresponding controlling node.
|
... | ... | |
102 |
89 |
* @throws AccessionNumberException
|
103 |
90 |
* @throws NumberFormatException
|
104 |
91 |
*/
|
105 |
|
public List<Identifier> sync(ObjectList objList) throws ServiceFailure,
|
|
92 |
private List<Identifier> sync(ObjectList objList) throws ServiceFailure,
|
106 |
93 |
InvalidToken, NotAuthorized, NotFound, NotImplemented,
|
107 |
94 |
McdbDocNotFoundException, InvalidRequest, VersionMismatch,
|
108 |
95 |
NumberFormatException, AccessionNumberException, SQLException, Exception {
|
109 |
96 |
|
110 |
97 |
AccessPolicy cnAccessPolicy = null;
|
111 |
|
String guid = null;
|
112 |
98 |
AccessPolicy mnAccessPolicy = null;
|
113 |
99 |
Identifier pid = new Identifier();
|
114 |
100 |
ObjectInfo objInfo = null;
|
... | ... | |
131 |
117 |
objInfo = objList.getObjectInfo(i);
|
132 |
118 |
pid = objInfo.getIdentifier();
|
133 |
119 |
|
134 |
|
logMetacat.debug("Getting SM for pid: " + pid.getValue() + " i: "
|
135 |
|
+ i);
|
|
120 |
logMetacat.debug("Getting SM for pid: " + pid.getValue() + " i: " + i);
|
136 |
121 |
try {
|
137 |
122 |
// Get sm, access policy for requested localId
|
138 |
123 |
mnSysMeta = IdentifierManager.getInstance().getSystemMetadata(
|
... | ... | |
140 |
125 |
} catch (McdbDocNotFoundException e) {
|
141 |
126 |
logMetacat.error("Error syncing access policy of pid: "
|
142 |
127 |
+ pid.getValue() + " pid not found: " + e.getMessage());
|
|
128 |
continue;
|
143 |
129 |
} catch (Exception e) {
|
144 |
130 |
logMetacat.error("Error syncing access policy of pid: "
|
145 |
|
+ pid.getValue() + e.getMessage());
|
|
131 |
+ pid.getValue() + ". Message: " + e.getMessage());
|
|
132 |
continue;
|
146 |
133 |
}
|
147 |
134 |
|
148 |
|
logMetacat
|
149 |
|
.debug("Getting access policy for pid: " + pid.getValue());
|
|
135 |
logMetacat.debug("Getting access policy for pid: " + pid.getValue());
|
150 |
136 |
|
151 |
137 |
mnAccessPolicy = mnSysMeta.getAccessPolicy();
|
152 |
138 |
|
... | ... | |
183 |
169 |
+ pid.getValue()
|
184 |
170 |
+ " user not authorized: "
|
185 |
171 |
+ na.getMessage());
|
186 |
|
throw na;
|
|
172 |
//throw na;
|
|
173 |
continue;
|
187 |
174 |
} catch (ServiceFailure sf) {
|
188 |
175 |
logMetacat
|
189 |
176 |
.error("Error syncing CN with access policy of pid: "
|
190 |
177 |
+ pid.getValue()
|
191 |
178 |
+ " Service failure: "
|
192 |
179 |
+ sf.getMessage());
|
193 |
|
throw sf;
|
|
180 |
//throw sf;
|
|
181 |
continue;
|
194 |
182 |
} catch (Exception e) {
|
195 |
183 |
logMetacat
|
196 |
184 |
.error("Error syncing CN with access policy of pid: "
|
197 |
185 |
+ pid.getValue() + e.getMessage());
|
198 |
|
throw e;
|
|
186 |
//throw e;
|
|
187 |
continue;
|
199 |
188 |
}
|
|
189 |
} else {
|
|
190 |
logMetacat.warn("Skipping pid: " + pid.getValue());
|
200 |
191 |
}
|
201 |
192 |
logMetacat.debug("Done syncing access policy for pid: " + pid.getValue());
|
202 |
193 |
}
|
... | ... | |
232 |
223 |
SystemMetadata sm = new SystemMetadata();
|
233 |
224 |
|
234 |
225 |
int start = 0;
|
235 |
|
int count = guidsToSync.size();
|
236 |
|
int total = count;
|
|
226 |
int count = 0; //guidsToSync.size();
|
237 |
227 |
|
238 |
228 |
objList.setStart(start);
|
239 |
|
objList.setCount(count);
|
240 |
|
objList.setTotal(total);
|
241 |
229 |
|
242 |
230 |
// Convert the guids to d1 objects, as this is what
|
243 |
231 |
// IdentifierManager.getInstance().querySystemMetadata returns in
|
... | ... | |
246 |
234 |
for (String guid : guidsToSync) {
|
247 |
235 |
try {
|
248 |
236 |
sm = IdentifierManager.getInstance().getSystemMetadata(guid);
|
|
237 |
count++;
|
249 |
238 |
} catch (Exception e) {
|
250 |
239 |
logMetacat.error("Error syncing access policy of pid: " + guid
|
251 |
|
+ e.getMessage());
|
|
240 |
+ ". Message: " + e.getMessage());
|
|
241 |
continue;
|
252 |
242 |
}
|
253 |
243 |
|
254 |
244 |
ObjectInfo oi = new ObjectInfo();
|
... | ... | |
261 |
251 |
oi.setSize(sm.getSize());
|
262 |
252 |
objList.addObjectInfo(oi);
|
263 |
253 |
}
|
|
254 |
|
|
255 |
int total = count;
|
|
256 |
objList.setCount(count);
|
|
257 |
objList.setTotal(total);
|
264 |
258 |
|
265 |
259 |
syncedPids = sync(objList);
|
266 |
260 |
return syncedPids;
|
... | ... | |
281 |
275 |
Boolean replicaStatus = false; // return only pids for which this mn is
|
282 |
276 |
// authoritative
|
283 |
277 |
Integer start = 0;
|
284 |
|
Integer count = MAXIMUM_DB_RECORD_COUNT;
|
|
278 |
Integer count = Integer.valueOf(PropertyService.getProperty("database.webResultsetSize"));
|
285 |
279 |
|
286 |
280 |
ObjectList objsToSync = IdentifierManager.getInstance()
|
287 |
281 |
.querySystemMetadata(startTime, endTime, objectFormatId,
|
... | ... | |
367 |
361 |
Subject s1 = entry.getKey();
|
368 |
362 |
// Perms that the user holds
|
369 |
363 |
Set<Permission> p1 = entry.getValue();
|
370 |
|
logMetacat
|
371 |
|
.debug("Checking access policy of user: " + s1.getValue());
|
|
364 |
logMetacat.debug("Checking access policy of user: " + s1.getValue());
|
372 |
365 |
|
373 |
366 |
// Does this user exist in both access policies?
|
374 |
367 |
if (userPerms2.containsKey(s1)) {
|
... | ... | |
388 |
381 |
return true;
|
389 |
382 |
}
|
390 |
383 |
|
|
384 |
/**
|
|
385 |
* Run pid synch script on the given pids
|
|
386 |
* Each argument is an individual pid
|
|
387 |
* because pids cannot contain whitespace.
|
|
388 |
* @param args
|
|
389 |
* @throws Exception
|
|
390 |
*/
|
391 |
391 |
public static void main(String[] args) throws Exception {
|
392 |
392 |
|
393 |
|
ArrayList<String> guids = null;
|
394 |
|
SyncAccessPolicy syncAP = new SyncAccessPolicy();
|
395 |
|
|
396 |
393 |
// set up the properties based on the test/deployed configuration of the
|
397 |
394 |
// workspace
|
398 |
|
SortedProperties testProperties = new SortedProperties(
|
399 |
|
"test/test.properties");
|
|
395 |
SortedProperties testProperties = new SortedProperties("test/test.properties");
|
400 |
396 |
testProperties.load();
|
401 |
|
String metacatContextDir = testProperties
|
402 |
|
.getProperty("metacat.contextDir");
|
|
397 |
String metacatContextDir = testProperties.getProperty("metacat.contextDir");
|
403 |
398 |
PropertyService.getInstance(metacatContextDir + "/WEB-INF");
|
|
399 |
|
|
400 |
ArrayList<String> guids = null;
|
|
401 |
SyncAccessPolicy syncAP = new SyncAccessPolicy();
|
404 |
402 |
|
405 |
403 |
if (args.length > 0) {
|
406 |
404 |
try {
|
407 |
|
guids = new ArrayList<String>(Arrays.asList(args[0]
|
408 |
|
.split("\\s*,\\s*")));
|
409 |
|
logMetacat.debug("Trying to syncing access policy for pids: "
|
410 |
|
+ args[0]);
|
411 |
|
syncAP.sync(guids);
|
|
405 |
guids = new ArrayList<String>(Arrays.asList(args));
|
|
406 |
logMetacat.warn("Trying to syncing access policy for " + args.length + " pids");
|
|
407 |
List<Identifier> synchedPids = syncAP.sync(guids);
|
|
408 |
logMetacat.warn("Sunk access policies for " + synchedPids.size() + " pids");
|
412 |
409 |
} catch (Exception e) {
|
413 |
|
System.err.println("Error syncing pids: " + args[0]
|
414 |
|
+ " Exception " + e.getMessage());
|
|
410 |
logMetacat.error("Error syncing pids, message: " + e.getMessage(), e);
|
415 |
411 |
System.exit(1);
|
416 |
412 |
}
|
417 |
413 |
}
|
Couple modifications:
-use "pid" throughout so as not to confuse docids and pids
-ensure any failures in the set do not prevent synching for other pids in the set