SecuredItemImpl implements SecuredItem { @Override public boolean canCreate() throws AuthenticationRequiredException { final CacheKey key = new CacheKey(Action.Create, modelNode); Boolean retval = cacheGet(key); if (retval == null) { retval = securityEvaluator.evaluate( securityEvaluator.getPrincipal(), Action.Create, modelNode); cachePut(key, retval); } return retval; } protected  SecuredItemImpl(final SecuredItem securedItem,
			final ItemHolder<?, ?> holder); protected  SecuredItemImpl(final SecurityEvaluator securityEvaluator,
			final String modelURI, final ItemHolder<?, ?> holder); static void decrementUse(); static void incrementUse(); @Override String toString(); @Override boolean canCreate(); @Override boolean canCreate(final Triple triple); @Override boolean canCreate(final FrontsTriple frontsTriple); @Override boolean canDelete(); @Override boolean canDelete(final Triple triple); @Override boolean canDelete(final FrontsTriple frontsTriple); @Override boolean canRead(); @Override boolean canRead(final Triple triple); @Override boolean canRead(final FrontsTriple frontsTriple); @Override boolean canUpdate(); @Override boolean canUpdate(final Triple f, final Triple t); @Override boolean canUpdate(final FrontsTriple from, final FrontsTriple to); @Override boolean equals(final Object o); @Override int hashCode(); @Override Object getBaseItem(); @Override String getModelIRI(); @Override Node getModelNode(); @Override SecurityEvaluator getSecurityEvaluator(); @Override boolean isEquivalent(final SecuredItem securedItem); static int MAX_CACHE; static final ThreadLocal<LRUMap<CacheKey, Boolean>> CACHE; static final ThreadLocal<Integer> COUNT; }
@Test public void canCreate() { when( evaluator.getPrincipal() ).thenReturn( PRINCIPAL ); when( evaluator.evaluate( anyObject(), any(SecurityEvaluator.Action.class), any(Node.class), any(Triple.class))).thenReturn( Boolean.TRUE); assertTrue( securedItemImpl.canCreate( Triple.ANY ) ); verify( evaluator ).evaluate( principal.capture(), action.capture(), modelNode.capture(), triple.capture()); Triple t = triple.getValue(); assertEquals( Node.ANY, t.getSubject() ); assertEquals( Node.ANY, t.getPredicate() ); assertEquals( Node.ANY, t.getObject() ); Node n = modelNode.getValue(); assertEquals( NodeFactory.createURI( "urn:name" ), n ); Object p = principal.getValue(); assertEquals( PRINCIPAL, p ); Action a = action.getValue(); assertEquals( Action.Create, a ); reset( evaluator ); when( evaluator.getPrincipal() ).thenReturn( PRINCIPAL ); when( evaluator.evaluate( anyObject(), any(SecurityEvaluator.Action.class), any(Node.class), any(Triple.class))).thenReturn( Boolean.TRUE); Triple target = new Triple( SecurityEvaluator.FUTURE, Node.ANY, Var.alloc( "var")); assertTrue( securedItemImpl.canCreate( target ) ); verify( evaluator ).evaluate( principal.capture(), action.capture(), modelNode.capture(), triple.capture()); t = triple.getValue(); assertEquals( SecurityEvaluator.FUTURE, t.getSubject() ); assertEquals( Node.ANY, t.getPredicate() ); assertEquals( SecurityEvaluator.VARIABLE, t.getObject() ); n = modelNode.getValue(); assertEquals( NodeFactory.createURI( "urn:name" ), n ); p = principal.getValue(); assertEquals( PRINCIPAL, p ); a = action.getValue(); assertEquals( Action.Create, a ); }