@Test public void testWildcardedPath4() { TreeElement te; try { te = db.addResource("myPath/", ResourceList.class, null); } catch (ResourceAlreadyExistsException e) { te = db.getToplevelResource("mypath/"); } ResourcePermission rp = new ResourcePermission("*", te, Integer.MAX_VALUE); ResourcePermission rp2 = new ResourcePermission("path=myPath/-", "*"); assertFalse(rp2.implies(rp)); rp2 = new ResourcePermission("path=myPath-", "*"); assertFalse(rp2.implies(rp)); try { te = te.addChild("sub", StringResource.class, true); } catch (ResourceAlreadyExistsException e) { te = te.getChild("sub"); } rp = new ResourcePermission("*", te, Integer.MAX_VALUE); rp2 = new ResourcePermission("path=myPath/-", "*"); assertTrue(rp2.implies(rp)); rp = new ResourcePermission("*", te, Integer.MAX_VALUE); rp2 = new ResourcePermission("path=myPath/sub/-", "*"); assertFalse(rp2.implies(rp)); rp = new ResourcePermission("*", te, Integer.MAX_VALUE); rp2 = new ResourcePermission("path=myPath/sub-", "*"); assertFalse(rp2.implies(rp)); rp2 = new ResourcePermission("path=-", "*"); assertTrue(rp2.implies(rp)); try { te = te.addChild("sub", StringResource.class, true); } catch (ResourceAlreadyExistsException e) { te = te.getChild("sub"); } rp = new ResourcePermission("*", te, Integer.MAX_VALUE); rp2 = new ResourcePermission("path=myPath/-", "*"); assertTrue(rp2.implies(rp)); rp2 = new ResourcePermission("path=-", "*"); assertTrue(rp2.implies(rp)); }
@Override public boolean implies(Permission p) { if (!(p instanceof ResourcePermission)) return false; ResourcePermission qp = (ResourcePermission) p; int queriedActions = qp.actionsAsMask; if ((queriedActions & this.actionsAsMask) != queriedActions) { return false; } if (this.type != null) { if (this.type.equals(RESOURCE_LIST_CLASS_NAME)) { LOGGER.warn( "ResourcePermission should not be defined with ResourceList as type! Such a permission doesn't imply any ResourcePermission!"); return false; } if (qp.node == null) { if (qp.type != null && (qp.type.equals(RESOURCE_LIST_CLASS_NAME)) && !qp.actions.equals(CREATE) && !qp.actions.equals(ACTIVITY) && !qp.actions.equals(DELETE)) { LOGGER.warn( "ResourcePermission should be queried with ResourceList as type only at first creation of the resource! Such a permission doesn't imply any ResourcePermission!"); return false; } else if (qp.type != null && !(qp.type.equals(RESOURCE_LIST_CLASS_NAME)) && !this.type.equals(qp.type)) return false; } else { TreeElement parent = qp.node; boolean success = false; Class<?> cls = getClass(this.type); while (parent != null) { Class<?> parentCls = parent.getType(); if (parentCls == ResourceList.class) { parentCls = parent.getResourceListType(); if (parentCls == null) { success = true; break; } } if (cls != null && parentCls != null) { if (cls.isAssignableFrom(parentCls)) { success = true; break; } } else if (parent.getType().getName().equals(this.type)) { success = true; break; } parent = parent.getParent(); } if (!success) return false; } } if ((pathType != PathType.STAR_ONLY)) if ((pathType != PathType.MINUS_ONLY)) { String queryPath = qp.path; String grantPath = getGrantPath(queryPath); int glen = 0; if (grantPath != null) glen = grantPath.length(); boolean queryNotStartsWithGrant = true; try { queryNotStartsWithGrant = grantPath != null && queryPath != null && !queryPath.startsWith(grantPath); } catch (Exception e) { } boolean queryNotEqualsGrant = true; try { queryNotEqualsGrant = grantPath != null && queryPath != null && !queryPath.equals(grantPath); } catch (Exception e) { } boolean grantEndSlashNotMatchWithQuery = true; try { if (queryPath != null && queryPath.indexOf('/') != -1) { if ((queryPath.length() > glen)) { if (queryPath.charAt(glen) != '/') { grantEndSlashNotMatchWithQuery = true; } else { grantEndSlashNotMatchWithQuery = false; } } } else if (!queryNotEqualsGrant) { grantEndSlashNotMatchWithQuery = false; } } catch (Exception e) { } if (pathType != PathType.STAR || qp.pathType != PathType.STAR || queryNotStartsWithGrant || grantEndSlashNotMatchWithQuery) { if (pathType != PathType.STAR || qp.pathType != PathType.NO_WILDCARD || (queryNotEqualsGrant && (queryNotStartsWithGrant || grantEndSlashNotMatchWithQuery))) if (pathType != PathType.STAR || qp.pathType != PathType.MINUS || (queryNotEqualsGrant && (queryNotStartsWithGrant || grantEndSlashNotMatchWithQuery))) if (pathType != PathType.NO_WILDCARD || qp.pathType != PathType.NO_WILDCARD || (queryNotEqualsGrant)) if (pathType != PathType.MINUS || qp.pathType != PathType.STAR || (queryNotStartsWithGrant) || !queryNotEqualsGrant || grantEndSlashNotMatchWithQuery) if (pathType != PathType.MINUS || qp.pathType != PathType.NO_WILDCARD || (queryNotStartsWithGrant) || !queryNotEqualsGrant || grantEndSlashNotMatchWithQuery) if (pathType != PathType.MINUS || qp.pathType != PathType.MINUS || queryNotStartsWithGrant || grantEndSlashNotMatchWithQuery) return false; } } if ((qp.actionsAsMask & _CREATE) == 0) { if ((owner != null) && (!owner.equals(qp.owner))) return false; } if ((qp.actionsAsMask & (_CREATE | _ADDSUB)) != 0) { if (count != 0 && qp.count > count) return false; } return true; }
ResourcePermission extends Permission { @Override public boolean implies(Permission p) { if (!(p instanceof ResourcePermission)) return false; ResourcePermission qp = (ResourcePermission) p; int queriedActions = qp.actionsAsMask; if ((queriedActions & this.actionsAsMask) != queriedActions) { return false; } if (this.type != null) { if (this.type.equals(RESOURCE_LIST_CLASS_NAME)) { LOGGER.warn( "ResourcePermission should not be defined with ResourceList as type! Such a permission doesn't imply any ResourcePermission!"); return false; } if (qp.node == null) { if (qp.type != null && (qp.type.equals(RESOURCE_LIST_CLASS_NAME)) && !qp.actions.equals(CREATE) && !qp.actions.equals(ACTIVITY) && !qp.actions.equals(DELETE)) { LOGGER.warn( "ResourcePermission should be queried with ResourceList as type only at first creation of the resource! Such a permission doesn't imply any ResourcePermission!"); return false; } else if (qp.type != null && !(qp.type.equals(RESOURCE_LIST_CLASS_NAME)) && !this.type.equals(qp.type)) return false; } else { TreeElement parent = qp.node; boolean success = false; Class<?> cls = getClass(this.type); while (parent != null) { Class<?> parentCls = parent.getType(); if (parentCls == ResourceList.class) { parentCls = parent.getResourceListType(); if (parentCls == null) { success = true; break; } } if (cls != null && parentCls != null) { if (cls.isAssignableFrom(parentCls)) { success = true; break; } } else if (parent.getType().getName().equals(this.type)) { success = true; break; } parent = parent.getParent(); } if (!success) return false; } } if ((pathType != PathType.STAR_ONLY)) if ((pathType != PathType.MINUS_ONLY)) { String queryPath = qp.path; String grantPath = getGrantPath(queryPath); int glen = 0; if (grantPath != null) glen = grantPath.length(); boolean queryNotStartsWithGrant = true; try { queryNotStartsWithGrant = grantPath != null && queryPath != null && !queryPath.startsWith(grantPath); } catch (Exception e) { } boolean queryNotEqualsGrant = true; try { queryNotEqualsGrant = grantPath != null && queryPath != null && !queryPath.equals(grantPath); } catch (Exception e) { } boolean grantEndSlashNotMatchWithQuery = true; try { if (queryPath != null && queryPath.indexOf('/') != -1) { if ((queryPath.length() > glen)) { if (queryPath.charAt(glen) != '/') { grantEndSlashNotMatchWithQuery = true; } else { grantEndSlashNotMatchWithQuery = false; } } } else if (!queryNotEqualsGrant) { grantEndSlashNotMatchWithQuery = false; } } catch (Exception e) { } if (pathType != PathType.STAR || qp.pathType != PathType.STAR || queryNotStartsWithGrant || grantEndSlashNotMatchWithQuery) { if (pathType != PathType.STAR || qp.pathType != PathType.NO_WILDCARD || (queryNotEqualsGrant && (queryNotStartsWithGrant || grantEndSlashNotMatchWithQuery))) if (pathType != PathType.STAR || qp.pathType != PathType.MINUS || (queryNotEqualsGrant && (queryNotStartsWithGrant || grantEndSlashNotMatchWithQuery))) if (pathType != PathType.NO_WILDCARD || qp.pathType != PathType.NO_WILDCARD || (queryNotEqualsGrant)) if (pathType != PathType.MINUS || qp.pathType != PathType.STAR || (queryNotStartsWithGrant) || !queryNotEqualsGrant || grantEndSlashNotMatchWithQuery) if (pathType != PathType.MINUS || qp.pathType != PathType.NO_WILDCARD || (queryNotStartsWithGrant) || !queryNotEqualsGrant || grantEndSlashNotMatchWithQuery) if (pathType != PathType.MINUS || qp.pathType != PathType.MINUS || queryNotStartsWithGrant || grantEndSlashNotMatchWithQuery) return false; } } if ((qp.actionsAsMask & _CREATE) == 0) { if ((owner != null) && (!owner.equals(qp.owner))) return false; } if ((qp.actionsAsMask & (_CREATE | _ADDSUB)) != 0) { if (count != 0 && qp.count > count) return false; } return true; } }
ResourcePermission extends Permission { @Override public boolean implies(Permission p) { if (!(p instanceof ResourcePermission)) return false; ResourcePermission qp = (ResourcePermission) p; int queriedActions = qp.actionsAsMask; if ((queriedActions & this.actionsAsMask) != queriedActions) { return false; } if (this.type != null) { if (this.type.equals(RESOURCE_LIST_CLASS_NAME)) { LOGGER.warn( "ResourcePermission should not be defined with ResourceList as type! Such a permission doesn't imply any ResourcePermission!"); return false; } if (qp.node == null) { if (qp.type != null && (qp.type.equals(RESOURCE_LIST_CLASS_NAME)) && !qp.actions.equals(CREATE) && !qp.actions.equals(ACTIVITY) && !qp.actions.equals(DELETE)) { LOGGER.warn( "ResourcePermission should be queried with ResourceList as type only at first creation of the resource! Such a permission doesn't imply any ResourcePermission!"); return false; } else if (qp.type != null && !(qp.type.equals(RESOURCE_LIST_CLASS_NAME)) && !this.type.equals(qp.type)) return false; } else { TreeElement parent = qp.node; boolean success = false; Class<?> cls = getClass(this.type); while (parent != null) { Class<?> parentCls = parent.getType(); if (parentCls == ResourceList.class) { parentCls = parent.getResourceListType(); if (parentCls == null) { success = true; break; } } if (cls != null && parentCls != null) { if (cls.isAssignableFrom(parentCls)) { success = true; break; } } else if (parent.getType().getName().equals(this.type)) { success = true; break; } parent = parent.getParent(); } if (!success) return false; } } if ((pathType != PathType.STAR_ONLY)) if ((pathType != PathType.MINUS_ONLY)) { String queryPath = qp.path; String grantPath = getGrantPath(queryPath); int glen = 0; if (grantPath != null) glen = grantPath.length(); boolean queryNotStartsWithGrant = true; try { queryNotStartsWithGrant = grantPath != null && queryPath != null && !queryPath.startsWith(grantPath); } catch (Exception e) { } boolean queryNotEqualsGrant = true; try { queryNotEqualsGrant = grantPath != null && queryPath != null && !queryPath.equals(grantPath); } catch (Exception e) { } boolean grantEndSlashNotMatchWithQuery = true; try { if (queryPath != null && queryPath.indexOf('/') != -1) { if ((queryPath.length() > glen)) { if (queryPath.charAt(glen) != '/') { grantEndSlashNotMatchWithQuery = true; } else { grantEndSlashNotMatchWithQuery = false; } } } else if (!queryNotEqualsGrant) { grantEndSlashNotMatchWithQuery = false; } } catch (Exception e) { } if (pathType != PathType.STAR || qp.pathType != PathType.STAR || queryNotStartsWithGrant || grantEndSlashNotMatchWithQuery) { if (pathType != PathType.STAR || qp.pathType != PathType.NO_WILDCARD || (queryNotEqualsGrant && (queryNotStartsWithGrant || grantEndSlashNotMatchWithQuery))) if (pathType != PathType.STAR || qp.pathType != PathType.MINUS || (queryNotEqualsGrant && (queryNotStartsWithGrant || grantEndSlashNotMatchWithQuery))) if (pathType != PathType.NO_WILDCARD || qp.pathType != PathType.NO_WILDCARD || (queryNotEqualsGrant)) if (pathType != PathType.MINUS || qp.pathType != PathType.STAR || (queryNotStartsWithGrant) || !queryNotEqualsGrant || grantEndSlashNotMatchWithQuery) if (pathType != PathType.MINUS || qp.pathType != PathType.NO_WILDCARD || (queryNotStartsWithGrant) || !queryNotEqualsGrant || grantEndSlashNotMatchWithQuery) if (pathType != PathType.MINUS || qp.pathType != PathType.MINUS || queryNotStartsWithGrant || grantEndSlashNotMatchWithQuery) return false; } } if ((qp.actionsAsMask & _CREATE) == 0) { if ((owner != null) && (!owner.equals(qp.owner))) return false; } if ((qp.actionsAsMask & (_CREATE | _ADDSUB)) != 0) { if (count != 0 && qp.count > count) return false; } return true; } ResourcePermission(String filter, String actions);  ResourcePermission(String path, Class<? extends Resource> type, int maxNumber);  ResourcePermission(String action, TreeElement te, int maxNumber); }
ResourcePermission extends Permission { @Override public boolean implies(Permission p) { if (!(p instanceof ResourcePermission)) return false; ResourcePermission qp = (ResourcePermission) p; int queriedActions = qp.actionsAsMask; if ((queriedActions & this.actionsAsMask) != queriedActions) { return false; } if (this.type != null) { if (this.type.equals(RESOURCE_LIST_CLASS_NAME)) { LOGGER.warn( "ResourcePermission should not be defined with ResourceList as type! Such a permission doesn't imply any ResourcePermission!"); return false; } if (qp.node == null) { if (qp.type != null && (qp.type.equals(RESOURCE_LIST_CLASS_NAME)) && !qp.actions.equals(CREATE) && !qp.actions.equals(ACTIVITY) && !qp.actions.equals(DELETE)) { LOGGER.warn( "ResourcePermission should be queried with ResourceList as type only at first creation of the resource! Such a permission doesn't imply any ResourcePermission!"); return false; } else if (qp.type != null && !(qp.type.equals(RESOURCE_LIST_CLASS_NAME)) && !this.type.equals(qp.type)) return false; } else { TreeElement parent = qp.node; boolean success = false; Class<?> cls = getClass(this.type); while (parent != null) { Class<?> parentCls = parent.getType(); if (parentCls == ResourceList.class) { parentCls = parent.getResourceListType(); if (parentCls == null) { success = true; break; } } if (cls != null && parentCls != null) { if (cls.isAssignableFrom(parentCls)) { success = true; break; } } else if (parent.getType().getName().equals(this.type)) { success = true; break; } parent = parent.getParent(); } if (!success) return false; } } if ((pathType != PathType.STAR_ONLY)) if ((pathType != PathType.MINUS_ONLY)) { String queryPath = qp.path; String grantPath = getGrantPath(queryPath); int glen = 0; if (grantPath != null) glen = grantPath.length(); boolean queryNotStartsWithGrant = true; try { queryNotStartsWithGrant = grantPath != null && queryPath != null && !queryPath.startsWith(grantPath); } catch (Exception e) { } boolean queryNotEqualsGrant = true; try { queryNotEqualsGrant = grantPath != null && queryPath != null && !queryPath.equals(grantPath); } catch (Exception e) { } boolean grantEndSlashNotMatchWithQuery = true; try { if (queryPath != null && queryPath.indexOf('/') != -1) { if ((queryPath.length() > glen)) { if (queryPath.charAt(glen) != '/') { grantEndSlashNotMatchWithQuery = true; } else { grantEndSlashNotMatchWithQuery = false; } } } else if (!queryNotEqualsGrant) { grantEndSlashNotMatchWithQuery = false; } } catch (Exception e) { } if (pathType != PathType.STAR || qp.pathType != PathType.STAR || queryNotStartsWithGrant || grantEndSlashNotMatchWithQuery) { if (pathType != PathType.STAR || qp.pathType != PathType.NO_WILDCARD || (queryNotEqualsGrant && (queryNotStartsWithGrant || grantEndSlashNotMatchWithQuery))) if (pathType != PathType.STAR || qp.pathType != PathType.MINUS || (queryNotEqualsGrant && (queryNotStartsWithGrant || grantEndSlashNotMatchWithQuery))) if (pathType != PathType.NO_WILDCARD || qp.pathType != PathType.NO_WILDCARD || (queryNotEqualsGrant)) if (pathType != PathType.MINUS || qp.pathType != PathType.STAR || (queryNotStartsWithGrant) || !queryNotEqualsGrant || grantEndSlashNotMatchWithQuery) if (pathType != PathType.MINUS || qp.pathType != PathType.NO_WILDCARD || (queryNotStartsWithGrant) || !queryNotEqualsGrant || grantEndSlashNotMatchWithQuery) if (pathType != PathType.MINUS || qp.pathType != PathType.MINUS || queryNotStartsWithGrant || grantEndSlashNotMatchWithQuery) return false; } } if ((qp.actionsAsMask & _CREATE) == 0) { if ((owner != null) && (!owner.equals(qp.owner))) return false; } if ((qp.actionsAsMask & (_CREATE | _ADDSUB)) != 0) { if (count != 0 && qp.count > count) return false; } return true; } ResourcePermission(String filter, String actions);  ResourcePermission(String path, Class<? extends Resource> type, int maxNumber);  ResourcePermission(String action, TreeElement te, int maxNumber); int getActionsAsMask(); String getPath(); boolean isWced(); String getType(); int getCount(); @Override boolean implies(Permission p); @Override boolean equals(Object obj); @Override int hashCode(); @Override String getActions(); String toString(); }
ResourcePermission extends Permission { @Override public boolean implies(Permission p) { if (!(p instanceof ResourcePermission)) return false; ResourcePermission qp = (ResourcePermission) p; int queriedActions = qp.actionsAsMask; if ((queriedActions & this.actionsAsMask) != queriedActions) { return false; } if (this.type != null) { if (this.type.equals(RESOURCE_LIST_CLASS_NAME)) { LOGGER.warn( "ResourcePermission should not be defined with ResourceList as type! Such a permission doesn't imply any ResourcePermission!"); return false; } if (qp.node == null) { if (qp.type != null && (qp.type.equals(RESOURCE_LIST_CLASS_NAME)) && !qp.actions.equals(CREATE) && !qp.actions.equals(ACTIVITY) && !qp.actions.equals(DELETE)) { LOGGER.warn( "ResourcePermission should be queried with ResourceList as type only at first creation of the resource! Such a permission doesn't imply any ResourcePermission!"); return false; } else if (qp.type != null && !(qp.type.equals(RESOURCE_LIST_CLASS_NAME)) && !this.type.equals(qp.type)) return false; } else { TreeElement parent = qp.node; boolean success = false; Class<?> cls = getClass(this.type); while (parent != null) { Class<?> parentCls = parent.getType(); if (parentCls == ResourceList.class) { parentCls = parent.getResourceListType(); if (parentCls == null) { success = true; break; } } if (cls != null && parentCls != null) { if (cls.isAssignableFrom(parentCls)) { success = true; break; } } else if (parent.getType().getName().equals(this.type)) { success = true; break; } parent = parent.getParent(); } if (!success) return false; } } if ((pathType != PathType.STAR_ONLY)) if ((pathType != PathType.MINUS_ONLY)) { String queryPath = qp.path; String grantPath = getGrantPath(queryPath); int glen = 0; if (grantPath != null) glen = grantPath.length(); boolean queryNotStartsWithGrant = true; try { queryNotStartsWithGrant = grantPath != null && queryPath != null && !queryPath.startsWith(grantPath); } catch (Exception e) { } boolean queryNotEqualsGrant = true; try { queryNotEqualsGrant = grantPath != null && queryPath != null && !queryPath.equals(grantPath); } catch (Exception e) { } boolean grantEndSlashNotMatchWithQuery = true; try { if (queryPath != null && queryPath.indexOf('/') != -1) { if ((queryPath.length() > glen)) { if (queryPath.charAt(glen) != '/') { grantEndSlashNotMatchWithQuery = true; } else { grantEndSlashNotMatchWithQuery = false; } } } else if (!queryNotEqualsGrant) { grantEndSlashNotMatchWithQuery = false; } } catch (Exception e) { } if (pathType != PathType.STAR || qp.pathType != PathType.STAR || queryNotStartsWithGrant || grantEndSlashNotMatchWithQuery) { if (pathType != PathType.STAR || qp.pathType != PathType.NO_WILDCARD || (queryNotEqualsGrant && (queryNotStartsWithGrant || grantEndSlashNotMatchWithQuery))) if (pathType != PathType.STAR || qp.pathType != PathType.MINUS || (queryNotEqualsGrant && (queryNotStartsWithGrant || grantEndSlashNotMatchWithQuery))) if (pathType != PathType.NO_WILDCARD || qp.pathType != PathType.NO_WILDCARD || (queryNotEqualsGrant)) if (pathType != PathType.MINUS || qp.pathType != PathType.STAR || (queryNotStartsWithGrant) || !queryNotEqualsGrant || grantEndSlashNotMatchWithQuery) if (pathType != PathType.MINUS || qp.pathType != PathType.NO_WILDCARD || (queryNotStartsWithGrant) || !queryNotEqualsGrant || grantEndSlashNotMatchWithQuery) if (pathType != PathType.MINUS || qp.pathType != PathType.MINUS || queryNotStartsWithGrant || grantEndSlashNotMatchWithQuery) return false; } } if ((qp.actionsAsMask & _CREATE) == 0) { if ((owner != null) && (!owner.equals(qp.owner))) return false; } if ((qp.actionsAsMask & (_CREATE | _ADDSUB)) != 0) { if (count != 0 && qp.count > count) return false; } return true; } ResourcePermission(String filter, String actions);  ResourcePermission(String path, Class<? extends Resource> type, int maxNumber);  ResourcePermission(String action, TreeElement te, int maxNumber); int getActionsAsMask(); String getPath(); boolean isWced(); String getType(); int getCount(); @Override boolean implies(Permission p); @Override boolean equals(Object obj); @Override int hashCode(); @Override String getActions(); String toString(); static final String READ; static final String WRITE; static final String ADDSUB; static final String CREATE; static final String DELETE; static final String ACTIVITY; static final String ALLACTIONS; static final int _READ; static final int _WRITE; static final int _ADDSUB; static final int _CREATE; static final int _DELETE; static final int _ACTIVITY; static final int _ALLACTIONS; static final int _NOACTIONS; }