Revision: 2830 http://archive-access.svn.sourceforge.net/archive-access/?rev=2830&view=rev Author: alexoz Date: 2009-10-23 05:29:09 +0000 (Fri, 23 Oct 2009) Log Message: ----------- FEATURE: Add convenience methods for checking requests that have multiple groups. Modified Paths: -------------- trunk/archive-access/projects/access-control/access-control/src/main/java/org/archive/accesscontrol/AccessControlClient.java Modified: trunk/archive-access/projects/access-control/access-control/src/main/java/org/archive/accesscontrol/AccessControlClient.java =================================================================== --- trunk/archive-access/projects/access-control/access-control/src/main/java/org/archive/accesscontrol/AccessControlClient.java 2009-10-23 05:28:37 UTC (rev 2829) +++ trunk/archive-access/projects/access-control/access-control/src/main/java/org/archive/accesscontrol/AccessControlClient.java 2009-10-23 05:29:09 UTC (rev 2830) @@ -46,6 +46,22 @@ this(new CachingRuleDao(oracleUrl), new CachingRobotClient()); } + private String getPolicy(String url, Rule rule) + throws RobotsUnavailableException { + if (robotLookupsEnabled && rule != null && "robots".equals(rule.getPolicy())) { + try { + if (robotClient.isRobotPermitted(url, robotUserAgent)) { + return "allow"; + } else { + return "block"; + } + } catch (IOException e) { + throw new RobotsUnavailableException(e); + } + } + return rule.getPolicy(); + } + /** * Return the best-matching policy for the requested document. * @@ -63,24 +79,34 @@ * @throws RuleOracleUnavailableException */ public String getPolicy(String url, Date captureDate, Date retrievalDate, - String who) throws RobotsUnavailableException, RuleOracleUnavailableException { - Rule matchingRule = getRule(url, captureDate, retrievalDate, who); - - if (robotLookupsEnabled && matchingRule != null && "robots".equals(matchingRule.getPolicy())) { - try { - if (robotClient.isRobotPermitted(url, robotUserAgent)) { - return "allow"; - } else { - return "block"; - } - } catch (IOException e) { - throw new RobotsUnavailableException(e); - } - } - return matchingRule.getPolicy(); + String who) throws RobotsUnavailableException, + RuleOracleUnavailableException { + return getPolicy(url, getRule(url, captureDate, retrievalDate, who)); } /** + * Return the best-matching policy for the requested document. + * + * @param url + * URL of the requested document. + * @param captureDate + * Date the document was archived. + * @param retrievalDate + * Date of retrieval (usually now). + * @param groups + * Group names of the user accessing the document. + * @return Access-control policy that should be enforced. eg "robots", + * "block" or "allow". + * @throws RobotsUnavailableException + * @throws RuleOracleUnavailableException + */ + public String getPolicy(String url, Date captureDate, Date retrievalDate, + Collection<String> groups) throws RobotsUnavailableException, + RuleOracleUnavailableException { + return getPolicy(url, getRule(url, captureDate, retrievalDate, groups)); + } + + /** * Return the most specific matching rule for the requested document. * * @param url @@ -108,7 +134,42 @@ return matchingRule; } + /** + * Return the most specific matching rule for the requested document. + * + * @param url + * URL of the requested document. + * @param captureDate + * Date the document was archived. + * @param retrievalDate + * Date of retrieval (usually now). + * @param groups + * Group names of the user accessing the document. + * @return + * @throws RuleOracleUnavailableException + */ + public Rule getRule(String url, Date captureDate, Date retrievalDate, + Collection<String> groups) + throws RuleOracleUnavailableException { + Rule bestRule = null; + for (String who: groups) { + Rule rule = getRule(url, captureDate, retrievalDate, who); + + /* We compare policies not the rules themselves as + * a user should have full access to something one of their + * groups has access to, even if another group they are + * member of does not. + */ + if (bestRule == null || + rule.getPolicyId().compareTo(bestRule.getPolicyId()) < 0) { + bestRule = rule; + } + } + return bestRule; + } + + /** * This method allows the client to prepare for lookups from a given set of * urls. This can warm up a cache and/or enable a mass data transfer to be done in This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |