http://git-wip-us.apache.org/repos/asf/jena/blob/2c0454c6/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredRDFListImpl.java ---------------------------------------------------------------------- diff --git a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredRDFListImpl.java b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredRDFListImpl.java index 36c524f..3ad07ef 100644 --- a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredRDFListImpl.java +++ b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredRDFListImpl.java @@ -24,8 +24,8 @@ import java.util.List; import java.util.Set; import java.util.function.Function; -import org.apache.jena.graph.Node ; -import org.apache.jena.graph.Triple ; +import org.apache.jena.graph.Node; +import org.apache.jena.graph.Triple; import org.apache.jena.permissions.SecuredItem; import org.apache.jena.permissions.SecurityEvaluator; import org.apache.jena.permissions.SecurityEvaluator.Action; @@ -36,143 +36,54 @@ import org.apache.jena.permissions.model.SecuredRDFList; import org.apache.jena.permissions.model.SecuredRDFNode; import org.apache.jena.permissions.utils.RDFListIterator; import org.apache.jena.permissions.utils.RDFListSecFilter; -import org.apache.jena.rdf.model.* ; +import org.apache.jena.rdf.model.*; +import org.apache.jena.shared.AddDeniedException; +import org.apache.jena.shared.AuthenticationRequiredException; import org.apache.jena.shared.DeleteDeniedException; -import org.apache.jena.util.iterator.ExtendedIterator ; -import org.apache.jena.util.iterator.WrappedIterator ; -import org.apache.jena.vocabulary.RDF ; +import org.apache.jena.shared.ReadDeniedException; +import org.apache.jena.shared.UpdateDeniedException; +import org.apache.jena.util.iterator.ExtendedIterator; +import org.apache.jena.util.iterator.WrappedIterator; +import org.apache.jena.vocabulary.RDF; public class SecuredRDFListImpl extends SecuredResourceImpl implements - SecuredRDFList -{ + SecuredRDFList { // called plain node but still returns a secured node - private class PlainNodeMap implements Function<RDFList, RDFNode> - { + private class PlainNodeMap implements Function<RDFList, RDFNode> { @Override - public RDFNode apply( final RDFList o ) - { + public RDFNode apply(final RDFList o) { return SecuredRDFNodeImpl.getInstance(getModel(), o .getRequiredProperty(listFirst()).getObject()); } } - private class SecuredListMap implements Function<RDFList, SecuredRDFList> - { + private class SecuredListMap implements Function<RDFList, SecuredRDFList> { @Override - public SecuredRDFList apply( final RDFList o ) - { + public SecuredRDFList apply(final RDFList o) { return SecuredRDFListImpl.getInstance(getModel(), o); } } - private class SecuredNodeMap implements Function<RDFList, SecuredRDFNode> - { + private class SecuredNodeMap implements Function<RDFList, SecuredRDFNode> { private Property p; - public SecuredNodeMap(Property p) - { - this.p=p; + + public SecuredNodeMap(Property p) { + this.p = p; } - + @Override - public SecuredRDFNode apply( final RDFList o ) - { + public SecuredRDFNode apply(final RDFList o) { return SecuredRDFNodeImpl.getInstance(getModel(), o .getRequiredProperty(p).getObject()); } } - /* - * private class SecuredRDFListIterator implements Iterator<SecuredRDFList> - * { - * private SecuredRDFList current; - * private Boolean found; - * private final Set<Action> restrictions; - * - * private SecuredRDFListIterator( final Action restriction ) - * { - * this(SecurityEvaluator.Util.asSet(new Action[] { restriction })); - * } - * - * private SecuredRDFListIterator( final Set<Action> restrictions ) - * { - * this.current = SecuredRDFListImpl.this.holder.getSecuredItem(); - * this.restrictions = restrictions; - * } - * - * private boolean checkCandidate() - * { - * if (!endOfList()) - * { - * final SecNode candidate = current.getRequiredProperty(listFirst()) - * .getObject().asNode(); - * return getSecurityEvaluator().evaluate( - * restrictions, - * getModelNode(), - * new SecurityEvaluator.SecTriple(SecuredItemImpl - * .convert(current.asNode()), SecuredItemImpl - * .convert(RDF.first.asNode()), SecuredItemImpl - * .convert(candidate))); - * } - * return false; - * } - * - * private boolean endOfList() - * { - * return current.equals(listNil()); - * } - * - * @Override - * public boolean hasNext() - * { - * if ((found == null) && !endOfList()) - * { - * found = checkCandidate(); - * while (!found && !endOfList()) - * { - * incrementCurrent(); - * found = checkCandidate(); - * } - * } - * return found == null ? false : found; - * } - * - * private void incrementCurrent() - * { - * if (!endOfList()) - * { - * current = (SecuredRDFList) current - * .getRequiredProperty(listRest()).getResource() - * .as(RDFList.class); - * } - * } - * - * @Override - * public SecuredRDFList next() - * { - * if (hasNext()) - * { - * found = null; - * final SecuredRDFList retval = current; - * incrementCurrent(); - * return retval; - * } - * throw new NoSuchElementException(); - * } - * - * @Override - * public void remove() - * { - * throw new UnsupportedOperationException(); - * } - * - * } - */ /** * Get an instance of SecuredProperty * @@ -182,23 +93,19 @@ public class SecuredRDFListImpl extends SecuredResourceImpl implements * The rdfList to secure * @return The SecuredProperty */ - public static <T extends RDFList> SecuredRDFList getInstance( final SecuredModel securedModel, - final T rdfList ) - { - if (securedModel == null) - { + public static <T extends RDFList> SecuredRDFList getInstance( + final SecuredModel securedModel, final T rdfList) { + if (securedModel == null) { throw new IllegalArgumentException( "Secured securedModel may not be null"); } - if (rdfList == null) - { + if (rdfList == null) { throw new IllegalArgumentException("RDFList may not be null"); } // check that property has a securedModel. RDFList goodList = rdfList; - if (goodList.getModel() == null) - { + if (goodList.getModel() == null) { goodList = securedModel.createList(rdfList.asJavaList().iterator()); } @@ -208,10 +115,8 @@ public class SecuredRDFListImpl extends SecuredResourceImpl implements holder); // if we are going to create a duplicate proxy, just return this // one. - if (goodList instanceof SecuredRDFList) - { - if (checker.isEquivalent((SecuredRDFList) goodList)) - { + if (goodList instanceof SecuredRDFList) { + if (checker.isEquivalent((SecuredRDFList) goodList)) { return (SecuredRDFList) goodList; } } @@ -239,34 +144,28 @@ public class SecuredRDFListImpl extends SecuredResourceImpl implements private final ItemHolder<RDFList, SecuredRDFList> holder; - protected SecuredRDFListImpl( final SecuredModel securedModel, - final ItemHolder<RDFList, SecuredRDFList> holder ) - { + protected SecuredRDFListImpl(final SecuredModel securedModel, + final ItemHolder<RDFList, SecuredRDFList> holder) { super(securedModel, holder); this.holder = holder; } @Override - public void add( final RDFNode value ) - { + public void add(final RDFNode value) throws UpdateDeniedException, + AddDeniedException, AuthenticationRequiredException { checkUpdate(); checkCreateNewList(value, listNil()); holder.getBaseItem().add(value); } @Override - public SecuredRDFList append( final Iterator<? extends RDFNode> nodes ) - { + public SecuredRDFList append(final Iterator<? extends RDFNode> nodes) + throws ReadDeniedException, AuthenticationRequiredException { SecuredRDFList copy = copy(); - if (nodes.hasNext()) - { - if (((RDFList)copy.getBaseItem()).size()>0) -// if (copy.size() > 0) - { + if (nodes.hasNext()) { + if (((RDFList) copy.getBaseItem()).size() > 0) { copy.concatenate(copy.getModel().createList(nodes)); - } - else - { + } else { copy = copy.getModel().createList(nodes); } } @@ -274,18 +173,14 @@ public class SecuredRDFListImpl extends SecuredResourceImpl implements } @Override - public RDFList append( final RDFList list ) - { - if (holder.getBaseItem().isEmpty()) - { + public RDFList append(final RDFList list) throws ReadDeniedException, + AuthenticationRequiredException { + if (holder.getBaseItem().isEmpty()) { return list.size() == 0 ? ModelFactory.createDefaultModel() .createList() : list.copy(); - } - else - { + } else { final RDFList copy = copy(); - if (list.size() > 0) - { + if (list.size() > 0) { copy.concatenate(list.copy()); } return copy; @@ -293,44 +188,36 @@ public class SecuredRDFListImpl extends SecuredResourceImpl implements } @Override - public void apply( final ApplyFn fn ) - { + public void apply(final ApplyFn fn) throws ReadDeniedException, + AuthenticationRequiredException { // iterator() checks Read final ExtendedIterator<RDFNode> i = iterator(); - try - { - while (i.hasNext()) - { + try { + while (i.hasNext()) { fn.apply(i.next()); } - } - finally - { + } finally { i.close(); } } @Override - public void apply( final Set<Action> perms, final ApplyFn fn ) - { + public void apply(final Set<Action> perms, final ApplyFn fn) + throws ReadDeniedException, AuthenticationRequiredException { // iterator() checks Read final ExtendedIterator<RDFNode> i = iterator(perms); - try - { - while (i.hasNext()) - { + try { + while (i.hasNext()) { fn.apply(i.next()); } - } - finally - { + } finally { i.close(); } } @Override - public List<RDFNode> asJavaList() - { + public List<RDFNode> asJavaList() throws ReadDeniedException, + AuthenticationRequiredException { // iterator() checks Read return iterator().toList(); } @@ -341,21 +228,17 @@ public class SecuredRDFListImpl extends SecuredResourceImpl implements * @param val * @return the modified RDFList. */ - private RDFList baseRemove( final RDFList val ) - { + private RDFList baseRemove(final RDFList val) { RDFList prev = null; RDFList cell = holder.getBaseItem(); final boolean searching = true; - while (searching && !cell.isEmpty()) - { - if (cell.equals(val)) - { + while (searching && !cell.isEmpty()) { + if (cell.equals(val)) { // found the value to be removed final RDFList tail = cell.getTail(); - if (prev != null) - { + if (prev != null) { prev.setTail(tail); } @@ -363,9 +246,7 @@ public class SecuredRDFListImpl extends SecuredResourceImpl implements // return this unless we have removed the head element return (prev == null) ? tail : this; - } - else - { + } else { // not found yet prev = cell; cell = cell.getTail(); @@ -376,107 +257,79 @@ public class SecuredRDFListImpl extends SecuredResourceImpl implements return this; } - private void checkCreateNewList( final RDFNode value, final Resource tail ) - { - checkCreate(new Triple( - SecurityEvaluator.FUTURE, - listFirst().asNode(), + private void checkCreateNewList(final RDFNode value, final Resource tail) + throws AddDeniedException, AuthenticationRequiredException { + checkCreate(new Triple(SecurityEvaluator.FUTURE, listFirst().asNode(), value.asNode())); - checkCreate(new Triple( - SecurityEvaluator.FUTURE, - listRest().asNode(), + checkCreate(new Triple(SecurityEvaluator.FUTURE, listRest().asNode(), tail.asNode())); } - private Set<Statement> collectStatements( final Set<Action> actions ) - { + private Set<Statement> collectStatements(final Set<Action> actions) { final Set<Statement> stmts = new HashSet<Statement>(); final ExtendedIterator<RDFList> iter = WrappedIterator.create( new RDFListIterator(holder.getBaseItem())).filterKeep( new RDFListSecFilter<RDFList>(this, actions)); - try - { - while (iter.hasNext()) - { + try { + while (iter.hasNext()) { stmts.addAll(iter.next().listProperties().toSet()); } return stmts; - } - finally - { + } finally { iter.close(); } } @Override - public void concatenate( final Iterator<? extends RDFNode> nodes ) - { + public void concatenate(final Iterator<? extends RDFNode> nodes) + throws UpdateDeniedException, AddDeniedException, + AuthenticationRequiredException { checkUpdate(); - if (holder.getBaseItem().isEmpty()) - { + if (holder.getBaseItem().isEmpty()) { // concatenating list onto the empty list is an error throw new EmptyListUpdateException( "Tried to concatenate onto the empty list"); - } - else - { - - Triple t = new Triple( - SecurityEvaluator.FUTURE, - listFirst().asNode(), Node.ANY); - if (!canCreate(t)) - { + } else { + + Triple t = new Triple(SecurityEvaluator.FUTURE, listFirst() + .asNode(), Node.ANY); + if (!canCreate(t)) { final List<RDFNode> list = new ArrayList<RDFNode>(); - while (nodes.hasNext()) - { + while (nodes.hasNext()) { final RDFNode n = nodes.next(); - t = new Triple( - SecurityEvaluator.FUTURE, - listFirst().asNode(), n.asNode()); + t = new Triple(SecurityEvaluator.FUTURE, listFirst() + .asNode(), n.asNode()); checkCreate(t); list.add(n); } holder.getBaseItem().concatenate(list.iterator()); - } - else - { + } else { holder.getBaseItem().concatenate(nodes); } } } @Override - public void concatenate( final RDFList list ) - { + public void concatenate(final RDFList list) throws UpdateDeniedException, + AddDeniedException, AuthenticationRequiredException { checkUpdate(); - if (holder.getBaseItem().isEmpty()) - { + if (holder.getBaseItem().isEmpty()) { // concatenating list onto the empty list is an error throw new EmptyListUpdateException( "Tried to concatenate onto the empty list"); - } - else - { - Triple t = new Triple( - SecurityEvaluator.FUTURE, - listFirst().asNode(), Node.ANY); - if (!canCreate(t)) - { + } else { + Triple t = new Triple(SecurityEvaluator.FUTURE, listFirst() + .asNode(), Node.ANY); + if (!canCreate(t)) { final ExtendedIterator<RDFNode> iter = list.iterator(); - try - { - while (iter.hasNext()) - { - t = new Triple( - SecurityEvaluator.FUTURE, - listFirst().asNode(), - iter.next().asNode()); + try { + while (iter.hasNext()) { + t = new Triple(SecurityEvaluator.FUTURE, listFirst() + .asNode(), iter.next().asNode()); checkCreate(t); } - } - finally - { + } finally { iter.close(); } } @@ -485,8 +338,9 @@ public class SecuredRDFListImpl extends SecuredResourceImpl implements } @Override - public SecuredRDFList cons( final RDFNode value ) - { + public SecuredRDFList cons(final RDFNode value) + throws UpdateDeniedException, AddDeniedException, + AuthenticationRequiredException { checkUpdate(); checkCreateNewList(value, holder.getBaseItem()); return SecuredRDFListImpl.getInstance(getModel(), holder.getBaseItem() @@ -494,214 +348,177 @@ public class SecuredRDFListImpl extends SecuredResourceImpl implements } @Override - public boolean contains( final RDFNode value ) - { + public boolean contains(final RDFNode value) throws ReadDeniedException, + AuthenticationRequiredException { // iterator() checks Read final ExtendedIterator<RDFNode> iter = iterator(); - try - { - while (iter.hasNext()) - { - if (value.equals(iter.next())) - { + try { + while (iter.hasNext()) { + if (value.equals(iter.next())) { return true; } } return false; - } - finally - { + } finally { iter.close(); } } @Override - public SecuredRDFList copy() - { + public SecuredRDFList copy() throws ReadDeniedException, + AuthenticationRequiredException { SecuredRDFList retval = null; - if (canRead()) - { - final ExtendedIterator<RDFNode> iter = getSecuredRDFListIterator(Action.Read) - .mapWith( list -> list.getRequiredProperty(listFirst()).getObject()); - if (iter.hasNext()) - { + if (canRead()) { + final ExtendedIterator<RDFNode> iter = getSecuredRDFListIterator( + Action.Read).mapWith( + list -> list.getRequiredProperty(listFirst()).getObject()); + if (iter.hasNext()) { retval = getModel().createList(iter); - } - else - { + } else { retval = getModel().createList(); } - } - else - { + } else { retval = getModel().createList(); } return retval; } @Override - public SecuredRDFNode get( final int i ) - { + public SecuredRDFNode get(final int i) throws ReadDeniedException, + AuthenticationRequiredException { checkRead(); final ExtendedIterator<SecuredRDFNode> iter = getSecuredRDFListIterator( Action.Read).mapWith(new SecuredNodeMap(listFirst())); int idx = 0; - try - { - while (iter.hasNext()) - { - if (i == idx) - { + try { + while (iter.hasNext()) { + if (i == idx) { return iter.next(); - } - else - { + } else { idx++; iter.next(); } } throw new ListIndexException(); - } - finally - { + } finally { iter.close(); } } @Override - public SecuredRDFNode getHead() - { + public SecuredRDFNode getHead() throws ReadDeniedException, + AuthenticationRequiredException { checkRead(); - Statement s = holder.getBaseItem().getRequiredProperty( listFirst() ); - checkRead( s ); + Statement s = holder.getBaseItem().getRequiredProperty(listFirst()); + checkRead(s); return SecuredRDFNodeImpl.getInstance(getModel(), s.getObject()); } private ExtendedIterator<RDFList> getSecuredRDFListIterator( - final Action perm ) - { + final Action perm) { return WrappedIterator .create(new RDFListIterator(holder.getBaseItem())).filterKeep( new RDFListSecFilter<RDFList>(this, perm)); } private ExtendedIterator<RDFList> getSecuredRDFListIterator( - final Set<Action> perm ) - { + final Set<Action> perm) { return WrappedIterator .create(new RDFListIterator(holder.getBaseItem())).filterKeep( new RDFListSecFilter<RDFList>(this, perm)); } @Override - public boolean getStrict() - { + public boolean getStrict() { return holder.getBaseItem().getStrict(); } @Override - public SecuredRDFList getTail() - { + public SecuredRDFList getTail() throws ReadDeniedException, + AuthenticationRequiredException { checkRead(); - Statement s = holder.getBaseItem().getRequiredProperty( listRest() ); - checkRead( s ); - return SecuredRDFListImpl.getInstance(getModel(), s.getObject().as(RDFList.class)); + Statement s = holder.getBaseItem().getRequiredProperty(listRest()); + checkRead(s); + return SecuredRDFListImpl.getInstance(getModel(), + s.getObject().as(RDFList.class)); } @Override - public String getValidityErrorMessage() - { + public String getValidityErrorMessage() throws ReadDeniedException, + AuthenticationRequiredException { checkRead(); return holder.getBaseItem().getValidityErrorMessage(); } @Override - public int indexOf( final RDFNode value ) - { + public int indexOf(final RDFNode value) throws ReadDeniedException, + AuthenticationRequiredException { checkRead(); final ExtendedIterator<SecuredRDFNode> iter = getSecuredRDFListIterator( Action.Read).mapWith(new SecuredNodeMap(listFirst())); - try - { + try { int retval = 0; - while (iter.hasNext()) - { - if (value.equals(iter.next())) - { + while (iter.hasNext()) { + if (value.equals(iter.next())) { return retval; - } - else - { + } else { retval++; } } return -1; - } - finally - { + } finally { iter.close(); } } @Override - public int indexOf( final RDFNode value, final int start ) - { + public int indexOf(final RDFNode value, final int start) + throws ReadDeniedException, AuthenticationRequiredException { checkRead(); final ExtendedIterator<SecuredRDFNode> iter = getSecuredRDFListIterator( Action.Read).mapWith(new SecuredNodeMap(listFirst())); - try - { + try { int retval = 0; - while (iter.hasNext() && (retval < start)) - { + while (iter.hasNext() && (retval < start)) { iter.next(); retval++; } - while (iter.hasNext()) - { - if (value.equals(iter.next())) - { + while (iter.hasNext()) { + if (value.equals(iter.next())) { return retval; - } - else - { + } else { retval++; } } return -1; - } - finally - { + } finally { iter.close(); } } @Override - public boolean isEmpty() - { + public boolean isEmpty() throws ReadDeniedException, + AuthenticationRequiredException { checkRead(); final ExtendedIterator<RDFNode> iter = iterator(); - try - { + try { return !iter.hasNext(); - } - finally - { + } finally { iter.close(); } } @Override - public boolean isValid() - { + public boolean isValid() throws ReadDeniedException, + AuthenticationRequiredException { checkRead(); return holder.getBaseItem().isValid(); } @Override - public ExtendedIterator<RDFNode> iterator() - { + public ExtendedIterator<RDFNode> iterator() throws ReadDeniedException, + AuthenticationRequiredException { checkRead(); return getSecuredRDFListIterator(Action.Read).mapWith( new PlainNodeMap()); @@ -709,8 +526,8 @@ public class SecuredRDFListImpl extends SecuredResourceImpl implements } @Override - public ExtendedIterator<RDFNode> iterator( final Set<Action> constraints ) - { + public ExtendedIterator<RDFNode> iterator(final Set<Action> constraints) + throws ReadDeniedException, AuthenticationRequiredException { checkRead(); final Set<Action> req = new HashSet<Action>(constraints); req.add(Action.Read); @@ -718,44 +535,38 @@ public class SecuredRDFListImpl extends SecuredResourceImpl implements } - public Class<? extends RDFList> listAbstractionClass() - { + public Class<? extends RDFList> listAbstractionClass() { return RDFList.class; } - public Property listFirst() - { + public Property listFirst() { return m_listFirst; } - public Resource listNil() - { + public Resource listNil() { return m_listNil; } - public Property listRest() - { + public Property listRest() { return m_listRest; } - public Resource listType() - { + public Resource listType() { return m_listType; } @Override - public <T> ExtendedIterator<T> mapWith( final Function<RDFNode, T> fn ) - { + public <T> ExtendedIterator<T> mapWith(final Function<RDFNode, T> fn) + throws ReadDeniedException, AuthenticationRequiredException { return iterator().mapWith(fn); } @Override - public Object reduce( final ReduceFn fn, final Object initial ) - { + public Object reduce(final ReduceFn fn, final Object initial) + throws ReadDeniedException, AuthenticationRequiredException { Object acc = initial; - for (final Iterator<RDFNode> i = iterator(); i.hasNext();) - { + for (final Iterator<RDFNode> i = iterator(); i.hasNext();) { acc = fn.reduce(i.next(), acc); } @@ -763,15 +574,14 @@ public class SecuredRDFListImpl extends SecuredResourceImpl implements } @Override - public Object reduce( final Set<Action> requiredActions, final ReduceFn fn, - final Object initial ) throws - EmptyListException, ListIndexException, InvalidListException - { + public Object reduce(final Set<Action> requiredActions, final ReduceFn fn, + final Object initial) throws EmptyListException, + ListIndexException, InvalidListException, ReadDeniedException, + AuthenticationRequiredException { Object acc = initial; final Set<Action> perms = new HashSet<Action>(requiredActions); perms.add(Action.Read); - for (final Iterator<RDFNode> i = iterator(perms); i.hasNext();) - { + for (final Iterator<RDFNode> i = iterator(perms); i.hasNext();) { acc = fn.reduce(i.next(), acc); } @@ -779,48 +589,38 @@ public class SecuredRDFListImpl extends SecuredResourceImpl implements } @Override - public RDFList remove( final RDFNode val ) - { + public RDFList remove(final RDFNode val) throws UpdateDeniedException, + DeleteDeniedException, AuthenticationRequiredException { checkUpdate(); RDFList cell = null; boolean denied = false; - if (!canDelete(new Triple(Node.ANY, listFirst().asNode(), val.asNode()))) - { + if (!canDelete(new Triple(Node.ANY, listFirst().asNode(), val.asNode()))) { // iterate over the deletable items final ExtendedIterator<RDFList> iter = getSecuredRDFListIterator(Action.Delete);// .mapWith(new // SecuredListMap()); - while (iter.hasNext()) - { + while (iter.hasNext()) { cell = iter.next(); if (val.equals(cell.getRequiredProperty(listFirst()) - .getObject())) - { + .getObject())) { if (canDelete(new Triple(cell.asNode(), listFirst() - .asNode(), val.asNode()))) - { + .asNode(), val.asNode()))) { return SecuredRDFListImpl.getInstance(getModel(), baseRemove(cell)); - } - else - { + } else { denied = true; } } } - if (denied) - { - throw new DeleteDeniedException(SecuredItem.Util.triplePermissionMsg(getModelNode())); - } - else - { + if (denied) { + throw new DeleteDeniedException( + SecuredItem.Util.triplePermissionMsg(getModelNode())); + } else { return this; } - } - else - { + } else { return SecuredRDFListImpl.getInstance(getModel(), holder .getBaseItem().remove(val)); } @@ -828,21 +628,19 @@ public class SecuredRDFListImpl extends SecuredResourceImpl implements @Override @Deprecated - public void removeAll() - { + public void removeAll() throws UpdateDeniedException, + AuthenticationRequiredException { removeList(); } @Override - public SecuredRDFList removeHead() - { + public SecuredRDFList removeHead() throws UpdateDeniedException, + DeleteDeniedException, AuthenticationRequiredException { checkUpdate(); final ExtendedIterator<SecuredRDFList> iter = getSecuredRDFListIterator( Action.Read).mapWith(new SecuredListMap()); - try - { - if (!iter.hasNext()) - { + try { + if (!iter.hasNext()) { throw new EmptyListException( "Attempted to delete the head of a nil list"); } @@ -851,39 +649,27 @@ public class SecuredRDFListImpl extends SecuredResourceImpl implements checkDelete(s); return SecuredRDFListImpl.getInstance(getModel(), baseRemove(cell)); - } - finally - { + } finally { iter.close(); } } @Override - public void removeList() - { + public void removeList() throws UpdateDeniedException, + AuthenticationRequiredException { checkUpdate(); final Triple t = new Triple(Node.ANY, listFirst().asNode(), Node.ANY); - /* - * if (!canRead(t)) - * { - * throw new EmptyListException( - * "Attempted to delete the head of a nil list" ); - * } - */ + // have to be able to read and delete to delete all. final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Delete, Action.Read }); - if (getSecurityEvaluator().evaluate(getSecurityEvaluator().getPrincipal(), perms, this.getModelNode(), - t)) - { + if (getSecurityEvaluator().evaluate( + getSecurityEvaluator().getPrincipal(), perms, + this.getModelNode(), t)) { holder.getBaseItem().removeList(); - } - else - { - for (final Statement s : collectStatements(perms)) - { - if (canDelete(s)) - { + } else { + for (final Statement s : collectStatements(perms)) { + if (canDelete(s)) { s.remove(); } } @@ -891,19 +677,17 @@ public class SecuredRDFListImpl extends SecuredResourceImpl implements } @Override - public SecuredRDFNode replace( final int i, final RDFNode value ) - { + public SecuredRDFNode replace(final int i, final RDFNode value) + throws UpdateDeniedException, AuthenticationRequiredException, + ListIndexException { checkUpdate(); final SecuredNodeMap map = new SecuredNodeMap(listFirst()); final ExtendedIterator<SecuredRDFList> iter = getSecuredRDFListIterator( Action.Read).mapWith(new SecuredListMap()); int idx = 0; - try - { - while (iter.hasNext()) - { - if (i == idx) - { + try { + while (iter.hasNext()) { + if (i == idx) { final SecuredRDFList list = iter.next(); final SecuredRDFNode retval = map.apply(list); final Triple t = new Triple(list.asNode(), listFirst() @@ -914,90 +698,73 @@ public class SecuredRDFListImpl extends SecuredResourceImpl implements final RDFList base = (RDFList) list.getBaseItem(); base.getRequiredProperty(listFirst()).changeObject(value); return retval; - } - else - { + } else { idx++; iter.next(); } } throw new ListIndexException(); - } - finally - { + } finally { iter.close(); } } @Override - public boolean sameListAs( final RDFList list ) - { + public boolean sameListAs(final RDFList list) throws ReadDeniedException, + AuthenticationRequiredException { checkRead(); ExtendedIterator<RDFNode> thisIter = null; ExtendedIterator<RDFNode> thatIter = null; - try - { + try { thisIter = iterator(); thatIter = list.iterator(); - while (thisIter.hasNext() && thatIter.hasNext()) - { + while (thisIter.hasNext() && thatIter.hasNext()) { final RDFNode thisN = thisIter.next(); final RDFNode thatN = thatIter.next(); - if ((thisN == null) || !thisN.equals(thatN)) - { + if ((thisN == null) || !thisN.equals(thatN)) { // not equal at this position return false; } } return !(thisIter.hasNext() || thatIter.hasNext()); - } - finally - { - if (thisIter != null) - { + } finally { + if (thisIter != null) { thisIter.close(); } - if (thatIter != null) - { + if (thatIter != null) { thatIter.close(); } } } @Override - public SecuredRDFNode setHead( final RDFNode value ) - { + public SecuredRDFNode setHead(final RDFNode value) + throws EmptyListException, AuthenticationRequiredException { final ExtendedIterator<SecuredRDFList> iter = getSecuredRDFListIterator( Action.Read).mapWith(new SecuredListMap()); - try - { - if (iter.hasNext()) - { + try { + if (iter.hasNext()) { return replace(0, value); - } - else - { + } else { throw new EmptyListException( "Tried to set the head of an empty list"); } - } - finally - { + } finally { iter.close(); } } @Override - public void setStrict( final boolean strict ) - { + public void setStrict(final boolean strict) throws UpdateDeniedException, + AuthenticationRequiredException { checkUpdate(); holder.getBaseItem().setStrict(strict); } @Override - public SecuredRDFList setTail( final RDFList tail ) - { + public SecuredRDFList setTail(final RDFList tail) + throws UpdateDeniedException, AuthenticationRequiredException { checkUpdate(); final Statement rest = holder.getBaseItem().getRequiredProperty( @@ -1014,18 +781,16 @@ public class SecuredRDFListImpl extends SecuredResourceImpl implements } @Override - public int size() - { + public int size() throws ReadDeniedException, + AuthenticationRequiredException { checkRead(); final Triple t = new Triple(Node.ANY, listFirst().asNode(), Node.ANY); - if (canRead(t)) - { + if (canRead(t)) { return holder.getBaseItem().size(); } final ExtendedIterator<RDFNode> iter = iterator(); int i = 0; - while (iter.hasNext()) - { + while (iter.hasNext()) { i++; iter.next(); } @@ -1033,12 +798,11 @@ public class SecuredRDFListImpl extends SecuredResourceImpl implements } @Override - public SecuredRDFList with( final RDFNode value ) - { + public SecuredRDFList with(final RDFNode value) + throws UpdateDeniedException, AddDeniedException, + AuthenticationRequiredException { checkUpdate(); - checkCreate(new Triple( - SecurityEvaluator.FUTURE, - listFirst().asNode(), + checkCreate(new Triple(SecurityEvaluator.FUTURE, listFirst().asNode(), value.asNode())); return SecuredRDFListImpl.getInstance(getModel(), holder.getBaseItem() .with(value));
http://git-wip-us.apache.org/repos/asf/jena/blob/2c0454c6/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredRDFNodeImpl.java ---------------------------------------------------------------------- diff --git a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredRDFNodeImpl.java b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredRDFNodeImpl.java index aba6977..fa640e5 100644 --- a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredRDFNodeImpl.java +++ b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredRDFNodeImpl.java @@ -20,42 +20,40 @@ package org.apache.jena.permissions.model.impl; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import org.apache.jena.enhanced.UnsupportedPolymorphismException ; -import org.apache.jena.graph.FrontsNode ; -import org.apache.jena.graph.Node ; +import org.apache.jena.enhanced.UnsupportedPolymorphismException; +import org.apache.jena.graph.FrontsNode; +import org.apache.jena.graph.Node; import org.apache.jena.permissions.impl.ItemHolder; import org.apache.jena.permissions.impl.SecuredItemImpl; import org.apache.jena.permissions.model.SecuredModel; import org.apache.jena.permissions.model.SecuredRDFNode; import org.apache.jena.permissions.model.SecuredUnsupportedPolymorphismException; -import org.apache.jena.rdf.model.Literal ; -import org.apache.jena.rdf.model.Model ; -import org.apache.jena.rdf.model.RDFNode ; -import org.apache.jena.rdf.model.Resource ; +import org.apache.jena.rdf.model.Literal; +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.RDFNode; +import org.apache.jena.rdf.model.Resource; +import org.apache.jena.shared.AuthenticationRequiredException; +import org.apache.jena.shared.ReadDeniedException; /** * Implementation of SecuredRDFNode to be used by a SecuredItemInvoker proxy. */ public abstract class SecuredRDFNodeImpl extends SecuredItemImpl implements - SecuredRDFNode -{ + SecuredRDFNode { /** * * @param securedModel * the Secured Model to use. - * @param rdfNode the node to secure. + * @param rdfNode + * the node to secure. * @return the secured RDFNode */ - public static SecuredRDFNode getInstance( final SecuredModel securedModel, - final RDFNode rdfNode ) - { - if (rdfNode instanceof Literal) - { + public static SecuredRDFNode getInstance(final SecuredModel securedModel, + final RDFNode rdfNode) { + if (rdfNode instanceof Literal) { return SecuredLiteralImpl.getInstance(securedModel, (Literal) rdfNode); - } - else - { + } else { return SecuredResourceImpl.getInstance(securedModel, (Resource) rdfNode); } @@ -75,12 +73,10 @@ public abstract class SecuredRDFNodeImpl extends SecuredItemImpl implements * @param holder * the item holder that will contain this SecuredRDFNode. */ - protected SecuredRDFNodeImpl( final SecuredModel securedModel, - final ItemHolder<? extends RDFNode, ? extends SecuredRDFNode> holder ) - { + protected SecuredRDFNodeImpl(final SecuredModel securedModel, + final ItemHolder<? extends RDFNode, ? extends SecuredRDFNode> holder) { super(securedModel, holder); - if (holder.getBaseItem().getModel() == null) - { + if (holder.getBaseItem().getModel() == null) { throw new IllegalArgumentException(String.format( "Holder base item (%s) must have a securedModel", holder .getBaseItem().getClass())); @@ -89,113 +85,84 @@ public abstract class SecuredRDFNodeImpl extends SecuredItemImpl implements this.holder = holder; } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") @Override - public <T extends RDFNode> T as( final Class<T> view ) - { + public <T extends RDFNode> T as(final Class<T> view) + throws ReadDeniedException, AuthenticationRequiredException, + SecuredUnsupportedPolymorphismException { checkRead(); // see if the base Item can as T baseAs = holder.getBaseItem().as(view); - - if (view.equals(SecuredRDFNodeImpl.class) - || view.equals(RDFNode.class)) - { - return (T) this; - } - final Method m = getConstructor(view); - if (m == null) - { - throw new SecuredUnsupportedPolymorphismException(this, view); - } - try - { - return (T) m.invoke(null, securedModel, holder.getBaseItem() - .as(view)); - } - catch (final UnsupportedPolymorphismException e) - { - throw new SecuredUnsupportedPolymorphismException(this, view); - } - catch (final IllegalArgumentException e) - { - throw new RuntimeException(e); - } - catch (final IllegalAccessException e) - { - throw new RuntimeException(e); - } - catch (final InvocationTargetException e) - { - throw new RuntimeException(e); - } - /* - else - { + + if (view.equals(SecuredRDFNodeImpl.class) || view.equals(RDFNode.class)) { + return (T) this; + } + final Method m = getConstructor(view); + if (m == null) { + throw new SecuredUnsupportedPolymorphismException(this, view); + } + try { + return (T) m.invoke(null, securedModel, + holder.getBaseItem().as(view)); + } catch (final UnsupportedPolymorphismException e) { throw new SecuredUnsupportedPolymorphismException(this, view); + } catch (final IllegalArgumentException e) { + throw new RuntimeException(e); + } catch (final IllegalAccessException e) { + throw new RuntimeException(e); + } catch (final InvocationTargetException e) { + throw new RuntimeException(e); } - */ } @Override - public Node asNode() - { + public Node asNode() throws ReadDeniedException, + AuthenticationRequiredException { checkRead(); return holder.getBaseItem().asNode(); } @Override - public <T extends RDFNode> boolean canAs( final Class<T> view ) - { + public <T extends RDFNode> boolean canAs(final Class<T> view) + throws ReadDeniedException, AuthenticationRequiredException { checkRead(); // see if the base Item can as - if (holder.getBaseItem().canAs(view)) - { + if (holder.getBaseItem().canAs(view)) { return getConstructor(view) != null; } return false; } - private <T extends RDFNode> Method getConstructor( final Class<T> view ) - { + private <T extends RDFNode> Method getConstructor(final Class<T> view) { String classNm = SecuredRDFNodeImpl.class.getName(); classNm = String.format("%s.Secured%sImpl", classNm.substring(0, classNm.lastIndexOf(".")), view.getSimpleName()); - try - { + try { final Class<?> c = Class.forName(classNm); return c.getDeclaredMethod("getInstance", SecuredModel.class, view); - } - catch (final ClassNotFoundException e) - { + } catch (final ClassNotFoundException e) { return null; - } - catch (final SecurityException e) - { + } catch (final SecurityException e) { return null; - } - catch (final NoSuchMethodException e) - { + } catch (final NoSuchMethodException e) { return null; } } @Override - public SecuredModel getModel() - { + public SecuredModel getModel() { return securedModel; } @Override - public RDFNode inModel( final Model m ) - { + public RDFNode inModel(final Model m) throws ReadDeniedException, + AuthenticationRequiredException { checkRead(); - if (securedModel.equals(m)) - { + if (securedModel.equals(m)) { return this; } - if (m instanceof SecuredModel) - { + if (m instanceof SecuredModel) { return SecuredRDFNodeImpl.getInstance((SecuredModel) m, holder .getBaseItem().inModel(m)); } @@ -203,51 +170,55 @@ public abstract class SecuredRDFNodeImpl extends SecuredItemImpl implements } @Override - public boolean isAnon() - { + public boolean isAnon() { return holder.getBaseItem().isAnon(); } @Override - public boolean isLiteral() - { + public boolean isLiteral() { return holder.getBaseItem().isLiteral(); } @Override - public boolean isResource() - { + public boolean isResource() { return holder.getBaseItem().isResource(); } @Override - public boolean isURIResource() - { + public boolean isURIResource() { return holder.getBaseItem().isURIResource(); } /** - * An RDFNode is equal to another enhanced node n iff the underlying - * nodes are equal. We generalise to allow the other object to be any class - * implementing asNode, because we allow other implemementations of - * Resource, at least in principle. - * This is deemed to be a complete and correct interpretation of RDFNode - * equality, which is why this method has been marked final. - * - * @param o An object to test for equality with this node - * @return True if o is equal to this node. - */ - @Override final public boolean equals( Object o ) - { - checkRead(); - return o instanceof FrontsNode && asNode().equals(((FrontsNode) o).asNode()); - } - - /** - * The hash code of an RDFnode is defined to be the same as the underlying node. - * @return The hashcode as an int - */ - @Override final public int hashCode() { - return holder.getBaseItem().asNode().hashCode(); - } + * An RDFNode is equal to another enhanced node n iff the underlying nodes + * are equal. We generalise to allow the other object to be any class + * implementing asNode, because we allow other implemementations of + * Resource, at least in principle. This is deemed to be a complete and + * correct interpretation of RDFNode equality, which is why this method has + * been marked final. + * + * @param o + * An object to test for equality with this node + * @return True if o is equal to this node. + * @throws ReadDeniedException + * @throws AuthenticationRequiredException + */ + @Override + final public boolean equals(Object o) throws ReadDeniedException, + AuthenticationRequiredException { + checkRead(); + return o instanceof FrontsNode + && asNode().equals(((FrontsNode) o).asNode()); + } + + /** + * The hash code of an RDFnode is defined to be the same as the underlying + * node. + * + * @return The hashcode as an int + */ + @Override + final public int hashCode() { + return holder.getBaseItem().asNode().hashCode(); + } } http://git-wip-us.apache.org/repos/asf/jena/blob/2c0454c6/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredReifiedStatementImpl.java ---------------------------------------------------------------------- diff --git a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredReifiedStatementImpl.java b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredReifiedStatementImpl.java index b085598..de4759e 100644 --- a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredReifiedStatementImpl.java +++ b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredReifiedStatementImpl.java @@ -22,15 +22,16 @@ import org.apache.jena.permissions.impl.SecuredItemInvoker; import org.apache.jena.permissions.model.SecuredModel; import org.apache.jena.permissions.model.SecuredReifiedStatement; import org.apache.jena.permissions.model.SecuredStatement; -import org.apache.jena.rdf.model.ReifiedStatement ; +import org.apache.jena.rdf.model.ReifiedStatement; +import org.apache.jena.shared.AuthenticationRequiredException; +import org.apache.jena.shared.ReadDeniedException; /** * Implementation of SecuredReifiedStatement to be used by a SecuredItemInvoker * proxy. */ public class SecuredReifiedStatementImpl extends SecuredResourceImpl implements - SecuredReifiedStatement -{ + SecuredReifiedStatement { /** * Get an instance of SecuredReifiedStatement * @@ -41,15 +42,12 @@ public class SecuredReifiedStatementImpl extends SecuredResourceImpl implements * @return SecuredReifiedStatement */ public static SecuredReifiedStatement getInstance( - final SecuredModel securedModel, final ReifiedStatement stmt ) - { - if (securedModel == null) - { + final SecuredModel securedModel, final ReifiedStatement stmt) { + if (securedModel == null) { throw new IllegalArgumentException( "Secured securedModel may not be null"); } - if (stmt == null) - { + if (stmt == null) { throw new IllegalArgumentException("Statement may not be null"); } final ItemHolder<ReifiedStatement, SecuredReifiedStatement> holder = new ItemHolder<ReifiedStatement, SecuredReifiedStatement>( @@ -58,10 +56,8 @@ public class SecuredReifiedStatementImpl extends SecuredResourceImpl implements securedModel, holder); // if we are going to create a duplicate proxy, just return this // one. - if (stmt instanceof SecuredReifiedStatement) - { - if (checker.isEquivalent((SecuredReifiedStatement) stmt)) - { + if (stmt instanceof SecuredReifiedStatement) { + if (checker.isEquivalent((SecuredReifiedStatement) stmt)) { return (SecuredReifiedStatement) stmt; } } @@ -82,15 +78,14 @@ public class SecuredReifiedStatementImpl extends SecuredResourceImpl implements */ protected SecuredReifiedStatementImpl( final SecuredModel securedModel, - final ItemHolder<? extends ReifiedStatement, ? extends SecuredReifiedStatement> holder ) - { + final ItemHolder<? extends ReifiedStatement, ? extends SecuredReifiedStatement> holder) { super(securedModel, holder); this.holder = holder; } @Override - public SecuredStatement getStatement() - { + public SecuredStatement getStatement() throws ReadDeniedException, + AuthenticationRequiredException { checkRead(); return SecuredStatementImpl.getInstance(getModel(), holder .getBaseItem().getStatement()); http://git-wip-us.apache.org/repos/asf/jena/blob/2c0454c6/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredResourceImpl.java ---------------------------------------------------------------------- diff --git a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredResourceImpl.java b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredResourceImpl.java index 2db14e6..e28815b 100644 --- a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredResourceImpl.java +++ b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredResourceImpl.java @@ -17,10 +17,10 @@ */ package org.apache.jena.permissions.model.impl; -import org.apache.jena.datatypes.RDFDatatype ; -import org.apache.jena.graph.Node ; -import org.apache.jena.graph.NodeFactory ; -import org.apache.jena.graph.Triple ; +import org.apache.jena.datatypes.RDFDatatype; +import org.apache.jena.graph.Node; +import org.apache.jena.graph.NodeFactory; +import org.apache.jena.graph.Triple; import org.apache.jena.permissions.SecuredItem; import org.apache.jena.permissions.SecurityEvaluator.Action; import org.apache.jena.permissions.impl.ItemHolder; @@ -29,17 +29,19 @@ import org.apache.jena.permissions.model.SecuredModel; import org.apache.jena.permissions.model.SecuredResource; import org.apache.jena.permissions.model.SecuredStatement; import org.apache.jena.permissions.utils.PermStatementFilter; -import org.apache.jena.rdf.model.* ; -import org.apache.jena.shared.PropertyNotFoundException ; +import org.apache.jena.rdf.model.*; +import org.apache.jena.shared.AddDeniedException; +import org.apache.jena.shared.AuthenticationRequiredException; +import org.apache.jena.shared.PropertyNotFoundException; import org.apache.jena.shared.ReadDeniedException; -import org.apache.jena.util.iterator.ExtendedIterator ; +import org.apache.jena.shared.UpdateDeniedException; +import org.apache.jena.util.iterator.ExtendedIterator; /** * Implementation of SecuredResource to be used by a SecuredItemInvoker proxy. */ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements - SecuredResource -{ + SecuredResource { /** * Get a SecuredResource. * @@ -49,33 +51,26 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements * The resource to secure. * @return The SecuredResource */ - public static SecuredResource getInstance( final SecuredModel securedModel, - final Resource resource ) - { - if (securedModel == null) - { + public static SecuredResource getInstance(final SecuredModel securedModel, + final Resource resource) { + if (securedModel == null) { throw new IllegalArgumentException( "Secured securedModel may not be null"); } - if (resource == null) - { + if (resource == null) { throw new IllegalArgumentException("Resource may not be null"); } - if (resource.isLiteral()) - { + if (resource.isLiteral()) { throw new IllegalArgumentException("Resource may not be a literal"); } // check that resource has a securedModel. Resource goodResource = resource; - if (goodResource.getModel() == null) - { + if (goodResource.getModel() == null) { final Node n = resource.asNode(); - if (resource.isAnon()) - { - goodResource = securedModel.createResource(new AnonId(n.getBlankNodeId())); - } - else - { + if (resource.isAnon()) { + goodResource = securedModel.createResource(new AnonId(n + .getBlankNodeId())); + } else { goodResource = securedModel.createResource(n.getURI()); } } @@ -87,10 +82,8 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements securedModel, holder); // if we are going to create a duplicate proxy, just return this // one. - if (goodResource instanceof SecuredResource) - { - if (checker.isEquivalent((SecuredResource) goodResource)) - { + if (goodResource instanceof SecuredResource) { + if (checker.isEquivalent((SecuredResource) goodResource)) { return (SecuredResource) goodResource; } } @@ -113,8 +106,7 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements */ protected SecuredResourceImpl( final SecuredModel securedModel, - final ItemHolder<? extends Resource, ? extends SecuredResource> holder ) - { + final ItemHolder<? extends Resource, ? extends SecuredResource> holder) { super(securedModel, holder); this.holder = holder; } @@ -125,8 +117,7 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements * @return This resource to permit cascading. */ @Override - public SecuredResource abort() - { + public SecuredResource abort() { holder.getBaseItem().abort(); return holder.getSecuredItem(); } @@ -134,93 +125,127 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements /** * Add the property <code>p</code> with the typed-literal value * <code>o</code> to this resource, <i>ie</i> add (this, p, typed(o)) to - * this's securedModel. Answer - * this resource. The typed literal is equal to one constructed by using + * this's securedModel. Answer this resource. The typed literal is equal to + * one constructed by using * <code>this.getModel().createTypedLiteral(o)</code>. + * + * @throws UpdadeDeniedException + * @throws AddDeniedException + * @throws AuthenticationRequiredException */ @Override - public SecuredResource addLiteral( final Property p, final boolean o ) - { - return addProperty( p, ResourceFactory.createTypedLiteral(o) ); + public SecuredResource addLiteral(final Property p, final boolean o) + throws UpdateDeniedException, AddDeniedException, + AuthenticationRequiredException { + return addProperty(p, ResourceFactory.createTypedLiteral(o)); } /** * Add the property <code>p</code> with the typed-literal value * <code>o</code> to this resource, <i>ie</i> add (this, p, typed(o)) to - * this's securedModel. Answer - * this resource. The typed literal is equal to one constructed by using + * this's securedModel. Answer this resource. The typed literal is equal to + * one constructed by using * <code>this.getModel().createTypedLiteral(o)</code>. + * + * @throws UpdadeDeniedException + * @throws AddDeniedException + * @throws AuthenticationRequiredException */ @Override - public SecuredResource addLiteral( final Property p, final char o ) - { - return addProperty( p, ResourceFactory.createTypedLiteral(o)); + public SecuredResource addLiteral(final Property p, final char o) + throws UpdateDeniedException, AddDeniedException, + AuthenticationRequiredException { + return addProperty(p, ResourceFactory.createTypedLiteral(o)); } /** * Add the property <code>p</code> with the typed-literal value * <code>o</code> to this resource, <i>ie</i> add (this, p, typed(o)) to - * this's securedModel. Answer - * this resource. The typed literal is equal to one constructed by using + * this's securedModel. Answer this resource. The typed literal is equal to + * one constructed by using * <code>this.getModel().createTypedLiteral(o)</code>. + * + * @throws UpdadeDeniedException + * @throws AddDeniedException + * @throws AuthenticationRequiredException */ @Override - public SecuredResource addLiteral( final Property value, final double d ) - { - return addProperty( value, ResourceFactory.createTypedLiteral(d)); + public SecuredResource addLiteral(final Property value, final double d) + throws UpdateDeniedException, AddDeniedException, + AuthenticationRequiredException { + return addProperty(value, ResourceFactory.createTypedLiteral(d)); } /** * Add the property <code>p</code> with the typed-literal value * <code>o</code> to this resource, <i>ie</i> add (this, p, typed(o)) to - * this's securedModel. Answer - * this resource. The typed literal is equal to one constructed by using + * this's securedModel. Answer this resource. The typed literal is equal to + * one constructed by using * <code>this.getModel().createTypedLiteral(o)</code>. + * + * @throws UpdadeDeniedException + * @throws AddDeniedException + * @throws AuthenticationRequiredException */ @Override - public SecuredResource addLiteral( final Property value, final float d ) - { - return addProperty( value, ResourceFactory.createTypedLiteral(d) ); + public SecuredResource addLiteral(final Property value, final float d) + throws UpdateDeniedException, AddDeniedException, + AuthenticationRequiredException { + return addProperty(value, ResourceFactory.createTypedLiteral(d)); } /** * Add the property <code>p</code> with the pre-constructed Literal value * <code>o</code> to this resource, <i>ie</i> add (this, p, o) to this's * securedModel. Answer this resource. <b>NOTE</b> thjat this is distinct - * from the - * other addLiteral methods in that the Literal is not turned into a - * Literal. + * from the other addLiteral methods in that the Literal is not turned into + * a Literal. + * + * @throws UpdadeDeniedException + * @throws AddDeniedException + * @throws AuthenticationRequiredException */ @Override - public SecuredResource addLiteral( final Property p, final Literal o ) - { - return addProperty( p, o ); + public SecuredResource addLiteral(final Property p, final Literal o) + throws UpdateDeniedException, AddDeniedException, + AuthenticationRequiredException { + return addProperty(p, o); } /** * Add the property <code>p</code> with the typed-literal value * <code>o</code> to this resource, <i>ie</i> add (this, p, typed(o)) to - * this's securedModel. Answer - * this resource. The typed literal is equal to one constructed by using + * this's securedModel. Answer this resource. The typed literal is equal to + * one constructed by using * <code>this.getModel().createTypedLiteral(o)</code>. + * + * @throws UpdadeDeniedException + * @throws AddDeniedException + * @throws AuthenticationRequiredException */ @Override - public SecuredResource addLiteral( final Property p, final long o ) - { - return addProperty( p, ResourceFactory.createTypedLiteral(o)); + public SecuredResource addLiteral(final Property p, final long o) + throws UpdateDeniedException, AddDeniedException, + AuthenticationRequiredException { + return addProperty(p, ResourceFactory.createTypedLiteral(o)); } /** * Add the property <code>p</code> with the typed-literal value * <code>o</code> to this resource, <i>ie</i> add (this, p, typed(o)) to - * this's securedModel. Answer - * this resource. The typed literal is equal to one constructed by using + * this's securedModel. Answer this resource. The typed literal is equal to + * one constructed by using * <code>this.getModel().createTypedLiteral(o)</code>. + * + * @throws UpdadeDeniedException + * @throws AddDeniedException + * @throws AuthenticationRequiredException */ @Override - public SecuredResource addLiteral( final Property p, final Object o ) - { - return addProperty( p, ResourceFactory.createTypedLiteral(o)); + public SecuredResource addLiteral(final Property p, final Object o) + throws UpdateDeniedException, AddDeniedException, + AuthenticationRequiredException { + return addProperty(p, ResourceFactory.createTypedLiteral(o)); } /** @@ -236,10 +261,14 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements * @param o * The value of the property to be added. * @return This resource to allow cascading calls. + * @throws UpdadeDeniedException + * @throws AddDeniedException + * @throws AuthenticationRequiredException */ @Override - public SecuredResource addProperty( final Property p, final RDFNode o ) - { + public SecuredResource addProperty(final Property p, final RDFNode o) + throws UpdateDeniedException, AddDeniedException, + AuthenticationRequiredException { checkUpdate(); checkCreate(new Triple(holder.getBaseItem().asNode(), p.asNode(), o.asNode())); @@ -260,11 +289,15 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements * @param o * The value of the property to be added. * @return This resource to allow cascading calls. + * @throws UpdadeDeniedException + * @throws AddDeniedException + * @throws AuthenticationRequiredException */ @Override - public SecuredResource addProperty( final Property p, final String o ) - { - return addProperty( p, o, ""); + public SecuredResource addProperty(final Property p, final String o) + throws UpdateDeniedException, AddDeniedException, + AuthenticationRequiredException { + return addProperty(p, o, ""); } /** @@ -282,11 +315,15 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements * @param datatype * The datatype * @return This resource to allow cascading calls. + * @throws UpdadeDeniedException + * @throws AddDeniedException + * @throws AuthenticationRequiredException */ @Override - public SecuredResource addProperty( final Property p, final String lexicalForm, - final RDFDatatype datatype ) - { + public SecuredResource addProperty(final Property p, + final String lexicalForm, final RDFDatatype datatype) + throws UpdateDeniedException, AddDeniedException, + AuthenticationRequiredException { checkUpdate(); final Literal l = ResourceFactory.createTypedLiteral(lexicalForm, datatype); @@ -311,27 +348,28 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements * @param l * the language of the property * @return This resource to allow cascading calls. + * @throws UpdadeDeniedException + * @throws AddDeniedException + * @throws AuthenticationRequiredException */ @Override - public SecuredResource addProperty( final Property p, final String o, - final String l ) - { + public SecuredResource addProperty(final Property p, final String o, + final String l) throws UpdateDeniedException, AddDeniedException, + AuthenticationRequiredException { checkUpdate(); checkCreate(new Triple(holder.getBaseItem().asNode(), p.asNode(), - NodeFactory.createLiteral(o, l, false))); + NodeFactory.createLiteral(o, l, false))); holder.getBaseItem().addProperty(p, o, l); return holder.getSecuredItem(); } @Override - public Literal asLiteral() - { + public Literal asLiteral() { throw new LiteralRequiredException(asNode()); } @Override - public SecuredResource asResource() - { + public SecuredResource asResource() { return holder.getSecuredItem(); } @@ -341,24 +379,34 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements * @return This resource to permit cascading. */ @Override - public SecuredResource begin() - { + public SecuredResource begin() { holder.getBaseItem().begin(); return holder.getSecuredItem(); } - public boolean canReadProperty( final Node p ) - { + /** + * @param p The property to test. + * @return true if p can be read as a property with an ANY value + * @throws ReadDeniedException + * @throws AuthenticationRequiredException + */ + public boolean canReadProperty(final Node p) throws ReadDeniedException, + AuthenticationRequiredException { return canRead(new Triple(holder.getBaseItem().asNode(), p, Node.ANY)); } - protected void checkReadProperty( final Node p ) - { - if (!canReadProperty(p)) - { - throw new ReadDeniedException(SecuredItem.Util.triplePermissionMsg(getModelNode()), - new Triple(holder.getBaseItem().asNode(), p, - Node.ANY)); + /** + * + * @param p + * @throws ReadDeniedException + * @throws AuthenticationRequiredException + */ + protected void checkReadProperty(final Node p) throws ReadDeniedException, + AuthenticationRequiredException { + if (!canReadProperty(p)) { + throw new ReadDeniedException( + SecuredItem.Util.triplePermissionMsg(getModelNode()), + new Triple(holder.getBaseItem().asNode(), p, Node.ANY)); } } @@ -368,8 +416,7 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements * @return This resource to permit cascading. */ @Override - public SecuredResource commit() - { + public SecuredResource commit() { holder.getBaseItem().commit(); return holder.getSecuredItem(); } @@ -389,10 +436,12 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements * </p> * * @return A unique id for an anonymous resource. + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public AnonId getId() - { + public AnonId getId() throws ReadDeniedException, + AuthenticationRequiredException { checkRead(); return holder.getBaseItem().getId(); @@ -402,10 +451,12 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements * Returns the name of this resource within its namespace. * * @return The name of this property within its namespace. + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public String getLocalName() - { + public String getLocalName() throws ReadDeniedException, + AuthenticationRequiredException { checkRead(); return holder.getBaseItem().getLocalName(); } @@ -414,75 +465,68 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements * Returns the namespace associated with this resource. * * @return The namespace for this property. + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public String getNameSpace() - { + public String getNameSpace() throws ReadDeniedException, + AuthenticationRequiredException { checkRead(); return holder.getBaseItem().getNameSpace(); } /** * Answer some statement (this, p, O) in the associated securedModel. If - * there are - * several - * such statements, any one of them may be returned. If no such statements - * exist, - * null is returned - in this is differs from getRequiredProperty. + * there are several such statements, any one of them may be returned. If no + * such statements exist, null is returned - in this is differs from + * getRequiredProperty. * * @param p * the property sought * @return a statement (this, p, O), or null if no such statements exist * here + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public SecuredStatement getProperty( final Property p ) - { + public SecuredStatement getProperty(final Property p) + throws ReadDeniedException, AuthenticationRequiredException { checkRead(); final ExtendedIterator<Statement> iter = holder.getBaseItem() .listProperties(p) .filterKeep(new PermStatementFilter(Action.Read, this)); - try - { - if (iter.hasNext()) - { + try { + if (iter.hasNext()) { return org.apache.jena.permissions.model.impl.SecuredStatementImpl .getInstance(getModel(), iter.next()); - } - else - { + } else { return null; } - } - finally - { + } finally { iter.close(); } } /** - * Answer some resource R for which this.hasProperty( p, R ), - * or null if no such R exists. + * Answer some resource R for which this.hasProperty( p, R ), or null if no + * such R exists. + * + * @throws AuthenticationRequiredException */ @Override - public SecuredResource getPropertyResourceValue( final Property p ) - { + public SecuredResource getPropertyResourceValue(final Property p) + throws AuthenticationRequiredException { final SecuredStatementIterator iter = listProperties(p); - try - { - while (iter.hasNext()) - { + try { + while (iter.hasNext()) { final Statement s = iter.next(); - if (s.getObject().isResource()) - { + if (s.getObject().isResource()) { return SecuredResourceImpl.getInstance(getModel(), s .getObject().asResource()); } } return null; - } - finally - { + } finally { iter.close(); } } @@ -503,55 +547,54 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements * @return some (this, p, ?O) statement if one exists * @throws PropertyNotFoundException * if no such statement found + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public SecuredStatement getRequiredProperty( final Property p ) - throws PropertyNotFoundException - { + public SecuredStatement getRequiredProperty(final Property p) + throws PropertyNotFoundException, ReadDeniedException, + AuthenticationRequiredException { checkRead(); final ExtendedIterator<Statement> iter = holder.getBaseItem() .listProperties(p) .filterKeep(new PermStatementFilter(Action.Read, this)); - try - { - if (iter.hasNext()) - { + try { + if (iter.hasNext()) { return org.apache.jena.permissions.model.impl.SecuredStatementImpl .getInstance(getModel(), iter.next()); - } - else - { + } else { throw new PropertyNotFoundException(p); } - } - finally - { + } finally { iter.close(); } - // return org.apache.jena.security.model.impl.Factory.getInstance( - // this, holder.getBaseItem().getRequiredProperty(p)); } /** * Return the URI of the resource, or null if it's a bnode. * * @return The URI of the resource, or null if it's a bnode. + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public String getURI() - { + public String getURI() throws ReadDeniedException, + AuthenticationRequiredException { checkRead(); return holder.getBaseItem().getURI(); } /** - * Answer true iff this resource has the value <code>o</code> for - * property <code>p</code>. <code>o</code> is interpreted as - * a typed literal with the appropriate RDF type. + * Answer true iff this resource has the value <code>o</code> for property + * <code>p</code>. <code>o</code> is interpreted as a typed literal with the + * appropriate RDF type. + * + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public boolean hasLiteral( final Property p, final boolean o ) - { + public boolean hasLiteral(final Property p, final boolean o) + throws ReadDeniedException, AuthenticationRequiredException { checkRead(); checkRead(new Triple(holder.getBaseItem().asNode(), p.asNode(), ResourceFactory.createTypedLiteral(o).asNode())); @@ -559,13 +602,16 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements } /** - * Answer true iff this resource has the value <code>o</code> for - * property <code>p</code>. <code>o</code> is interpreted as - * a typed literal with the appropriate RDF type. + * Answer true iff this resource has the value <code>o</code> for property + * <code>p</code>. <code>o</code> is interpreted as a typed literal with the + * appropriate RDF type. + * + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public boolean hasLiteral( final Property p, final char o ) - { + public boolean hasLiteral(final Property p, final char o) + throws ReadDeniedException, AuthenticationRequiredException { checkRead(); checkRead(new Triple(holder.getBaseItem().asNode(), p.asNode(), ResourceFactory.createTypedLiteral(o).asNode())); @@ -573,13 +619,16 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements } /** - * Answer true iff this resource has the value <code>o</code> for - * property <code>p</code>. <code>o</code> is interpreted as - * a typed literal with the appropriate RDF type. + * Answer true iff this resource has the value <code>o</code> for property + * <code>p</code>. <code>o</code> is interpreted as a typed literal with the + * appropriate RDF type. + * + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public boolean hasLiteral( final Property p, final double o ) - { + public boolean hasLiteral(final Property p, final double o) + throws ReadDeniedException, AuthenticationRequiredException { checkRead(); checkRead(new Triple(holder.getBaseItem().asNode(), p.asNode(), ResourceFactory.createTypedLiteral(o).asNode())); @@ -587,13 +636,16 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements } /** - * Answer true iff this resource has the value <code>o</code> for - * property <code>p</code>. <code>o</code> is interpreted as - * a typed literal with the appropriate RDF type. + * Answer true iff this resource has the value <code>o</code> for property + * <code>p</code>. <code>o</code> is interpreted as a typed literal with the + * appropriate RDF type. + * + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public boolean hasLiteral( final Property p, final float o ) - { + public boolean hasLiteral(final Property p, final float o) + throws ReadDeniedException, AuthenticationRequiredException { checkRead(); checkRead(new Triple(holder.getBaseItem().asNode(), p.asNode(), ResourceFactory.createTypedLiteral(o).asNode())); @@ -601,13 +653,16 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements } /** - * Answer true iff this resource has the value <code>o</code> for - * property <code>p</code>. <code>o</code> is interpreted as - * a typed literal with the appropriate RDF type. + * Answer true iff this resource has the value <code>o</code> for property + * <code>p</code>. <code>o</code> is interpreted as a typed literal with the + * appropriate RDF type. + * + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public boolean hasLiteral( final Property p, final long o ) - { + public boolean hasLiteral(final Property p, final long o) + throws ReadDeniedException, AuthenticationRequiredException { checkRead(); checkRead(new Triple(holder.getBaseItem().asNode(), p.asNode(), ResourceFactory.createTypedLiteral(o).asNode())); @@ -615,13 +670,16 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements } /** - * Answer true iff this resource has the value <code>o</code> for - * property <code>p</code>. <code>o</code> is interpreted as - * a typed literal with the appropriate RDF type. + * Answer true iff this resource has the value <code>o</code> for property + * <code>p</code>. <code>o</code> is interpreted as a typed literal with the + * appropriate RDF type. + * + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public boolean hasLiteral( final Property p, final Object o ) - { + public boolean hasLiteral(final Property p, final Object o) + throws ReadDeniedException, AuthenticationRequiredException { checkRead(); checkRead(new Triple(holder.getBaseItem().asNode(), p.asNode(), ResourceFactory.createTypedLiteral(o).asNode())); @@ -633,22 +691,21 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements * * @param p * The property sought. - * @return true if and only if this resource has at least one - * value for the property. + * @return true if and only if this resource has at least one value for the + * property. + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public boolean hasProperty( final Property p ) - { + public boolean hasProperty(final Property p) throws ReadDeniedException, + AuthenticationRequiredException { checkRead(); final ExtendedIterator<Statement> iter = holder.getBaseItem() .listProperties(p) .filterKeep(new PermStatementFilter(Action.Read, this)); - try - { + try { return iter.hasNext(); - } - finally - { + } finally { iter.close(); } } @@ -660,22 +717,20 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements * The property sought. * @param o * The value of the property sought. - * @return true if and only if this resource has property p with - * value o. + * @return true if and only if this resource has property p with value o. + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public boolean hasProperty( final Property p, final RDFNode o ) - { + public boolean hasProperty(final Property p, final RDFNode o) + throws ReadDeniedException, AuthenticationRequiredException { checkRead(); final ExtendedIterator<Statement> iter = holder.getBaseItem() .getModel().listStatements(this, p, o) .filterKeep(new PermStatementFilter(Action.Read, this)); - try - { + try { return iter.hasNext(); - } - finally - { + } finally { iter.close(); } } @@ -687,22 +742,20 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements * The property sought. * @param o * The value of the property sought. - * @return true if and only if this resource has property p with - * value o. + * @return true if and only if this resource has property p with value o. + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public boolean hasProperty( final Property p, final String o ) - { + public boolean hasProperty(final Property p, final String o) + throws ReadDeniedException, AuthenticationRequiredException { checkRead(); final ExtendedIterator<Statement> iter = holder.getBaseItem() .getModel().listStatements(this, p, o) .filterKeep(new PermStatementFilter(Action.Read, this)); - try - { + try { return iter.hasNext(); - } - finally - { + } finally { iter.close(); } } @@ -716,41 +769,41 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements * The value of the property sought. * @param l * The language of the property sought. - * @return true if and only if this resource has property p with - * value o. + * @return true if and only if this resource has property p with value o. + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public boolean hasProperty( final Property p, final String o, final String l ) - { + public boolean hasProperty(final Property p, final String o, final String l) + throws ReadDeniedException, AuthenticationRequiredException { checkRead(); final Literal ll = holder.getBaseItem().getModel().createLiteral(o, l); final ExtendedIterator<Statement> iter = holder.getBaseItem() .getModel().listStatements(this, p, ll) .filterKeep(new PermStatementFilter(Action.Read, this)); - try - { + try { return iter.hasNext(); - } - finally - { + } finally { iter.close(); } } /** - * Answer true iff this Resource is a URI resource with the given URI. - * Using this is preferred to using getURI() and .equals(). + * Answer true iff this Resource is a URI resource with the given URI. Using + * this is preferred to using getURI() and .equals(). + * + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public boolean hasURI( final String uri ) - { + public boolean hasURI(final String uri) throws ReadDeniedException, + AuthenticationRequiredException { checkRead(); return holder.getBaseItem().hasURI(uri); } @Override - public Resource inModel( final Model m ) - { + public Resource inModel(final Model m) { return (Resource) super.inModel(m); } @@ -764,10 +817,12 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements * </p> * * @return An iterator over all the statements about this object. + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override public SecuredStatementIterator listProperties() - { + throws ReadDeniedException, AuthenticationRequiredException { checkRead(); return new SecuredStatementIterator(getModel(), holder.getBaseItem() .listProperties()); @@ -784,10 +839,12 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements * @param p * The predicate sought. * @return An iterator over the statements. + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public SecuredStatementIterator listProperties( final Property p ) - { + public SecuredStatementIterator listProperties(final Property p) + throws ReadDeniedException, AuthenticationRequiredException { checkRead(); return new SecuredStatementIterator(getModel(), holder.getBaseItem() .listProperties(p)); @@ -801,29 +858,25 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements * @param p * the property to remove * @return this resource, to permit cascading + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public SecuredResource removeAll( final Property p ) - { + public SecuredResource removeAll(final Property p) + throws ReadDeniedException, AuthenticationRequiredException { checkUpdate(); if (!canDelete(new Triple(holder.getBaseItem().asNode(), p.asNode(), - Node.ANY))) - { + Node.ANY))) { final StmtIterator iter = holder.getBaseItem().listProperties(p); - try - { - if (!iter.hasNext()) - { + try { + if (!iter.hasNext()) { // thre arn't any to delete -- so return return holder.getSecuredItem(); } - while (iter.hasNext()) - { + while (iter.hasNext()) { checkDelete(iter.next().asTriple()); } - } - finally - { + } finally { iter.close(); } } @@ -836,29 +889,25 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements * securedModel. * * @return This resource to permit cascading. + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public SecuredResource removeProperties() - { + public SecuredResource removeProperties() throws ReadDeniedException, + AuthenticationRequiredException { checkUpdate(); if (!canDelete(new Triple(holder.getBaseItem().asNode(), Node.ANY, - Node.ANY))) - { + Node.ANY))) { final StmtIterator iter = holder.getBaseItem().listProperties(); - try - { - if (!iter.hasNext()) - { + try { + if (!iter.hasNext()) { // thre arn't any to delete -- so return return holder.getSecuredItem(); } - while (iter.hasNext()) - { + while (iter.hasNext()) { checkDelete(iter.next().asTriple()); } - } - finally - { + } finally { iter.close(); } } @@ -869,22 +918,19 @@ public class SecuredResourceImpl extends SecuredRDFNodeImpl implements /** * Return a string representation of the resource. * - * Returns the URI of the resource unless the resource is anonymous - * in which case it returns the id of the resource enclosed in square - * brackets. + * Returns the URI of the resource unless the resource is anonymous in which + * case it returns the id of the resource enclosed in square brackets. * - * @return Return a string representation of the resource. - * if it is anonymous. + * @return Return a string representation of the resource. if it is + * anonymous. */ @Override - public String toString() - { + public String toString() { return holder.getBaseItem().toString(); } @Override - public Object visitWith( final RDFVisitor rv ) - { + public Object visitWith(final RDFVisitor rv) { return isAnon() ? rv.visitBlank(this, getId()) : rv.visitURI(this, getURI()); } http://git-wip-us.apache.org/repos/asf/jena/blob/2c0454c6/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredSelector.java ---------------------------------------------------------------------- diff --git a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredSelector.java b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredSelector.java index a6593e8..906a542 100644 --- a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredSelector.java +++ b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredSelector.java @@ -18,63 +18,58 @@ package org.apache.jena.permissions.model.impl; import org.apache.jena.permissions.SecuredItem; -import org.apache.jena.rdf.model.* ; +import org.apache.jena.rdf.model.*; +import org.apache.jena.shared.AuthenticationRequiredException; +import org.apache.jena.shared.ReadDeniedException; -public class SecuredSelector implements Selector -{ +public class SecuredSelector implements Selector { private final SecuredItem securedItem; private final Selector selector; - public SecuredSelector( final SecuredItem securedItem ) - { + public SecuredSelector(final SecuredItem securedItem) { this(securedItem, new SimpleSelector()); } - public SecuredSelector( final SecuredItem securedItem, - final Selector selector ) - { + public SecuredSelector(final SecuredItem securedItem, + final Selector selector) { this.securedItem = securedItem; this.selector = selector; } @Override - public RDFNode getObject() - { + public RDFNode getObject() { return selector.getObject(); } @Override - public Property getPredicate() - { + public Property getPredicate() { return selector.getPredicate(); } @Override - public Resource getSubject() - { + public Resource getSubject() { return selector.getSubject(); } @Override - public boolean isSimple() - { + public boolean isSimple() { return selector.isSimple(); } /** * This method is designed to be over ridden by subclasses to define - * application - * specific constraints on the statements selected. + * application specific constraints on the statements selected. * * @param s * the statement to be tested * @return true if the statement satisfies the constraint + * @throws ReadDeniedException + * @throws AuthenticationRequiredException */ @Override - public boolean test( final Statement s ) - { - if (securedItem.canRead(s)) - { + public boolean test(final Statement s) throws ReadDeniedException, + AuthenticationRequiredException { + if (securedItem.canRead(s)) { return selector.test(s); } return false;
