Search in sources :

Example 1 with SecuredStatement

use of org.apache.jena.permissions.model.SecuredStatement in project jena by apache.

the class SecuredResourceImpl method getRequiredProperty.

/**
	 * Get a property value of this resource.
	 * 
	 * <p>
	 * The securedModel associated with the resource instance is searched for
	 * statements whose subject is this resource and whose predicate is p. If
	 * such a statement is found, it is returned. If several such statements are
	 * found, any one may be returned. If no such statements are found, an
	 * exception is thrown.
	 * </p>
	 * 
	 * @param p
	 *            The property sought.
	 * @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, ReadDeniedException, AuthenticationRequiredException {
    checkRead();
    final ExtendedIterator<Statement> iter = holder.getBaseItem().listProperties(p).filterKeep(new PermStatementFilter(Action.Read, this));
    try {
        if (iter.hasNext()) {
            return org.apache.jena.permissions.model.impl.SecuredStatementImpl.getInstance(getModel(), iter.next());
        } else {
            throw new PropertyNotFoundException(p);
        }
    } finally {
        iter.close();
    }
}
Also used : PermStatementFilter(org.apache.jena.permissions.utils.PermStatementFilter) PropertyNotFoundException(org.apache.jena.shared.PropertyNotFoundException) SecuredStatement(org.apache.jena.permissions.model.SecuredStatement)

Example 2 with SecuredStatement

use of org.apache.jena.permissions.model.SecuredStatement in project jena by apache.

the class SecuredResourceImpl method getProperty.

/**
	 * 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.
	 * 
	 * @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) throws ReadDeniedException, AuthenticationRequiredException {
    checkRead();
    final ExtendedIterator<Statement> iter = holder.getBaseItem().listProperties(p).filterKeep(new PermStatementFilter(Action.Read, this));
    try {
        if (iter.hasNext()) {
            return org.apache.jena.permissions.model.impl.SecuredStatementImpl.getInstance(getModel(), iter.next());
        } else {
            return null;
        }
    } finally {
        iter.close();
    }
}
Also used : PermStatementFilter(org.apache.jena.permissions.utils.PermStatementFilter) SecuredStatement(org.apache.jena.permissions.model.SecuredStatement)

Example 3 with SecuredStatement

use of org.apache.jena.permissions.model.SecuredStatement in project jena by apache.

the class SecuredResourceImpl method getProperty.

@Override
public SecuredStatement getProperty(Property p, String lang) throws ReadDeniedException, AuthenticationRequiredException {
    checkRead();
    final ExtendedIterator<Statement> iter = holder.getBaseItem().listProperties(p, lang).filterKeep(new PermStatementFilter(Action.Read, this));
    try {
        if (iter.hasNext()) {
            return org.apache.jena.permissions.model.impl.SecuredStatementImpl.getInstance(getModel(), iter.next());
        } else {
            return null;
        }
    } finally {
        iter.close();
    }
}
Also used : PermStatementFilter(org.apache.jena.permissions.utils.PermStatementFilter) SecuredStatement(org.apache.jena.permissions.model.SecuredStatement)

Example 4 with SecuredStatement

use of org.apache.jena.permissions.model.SecuredStatement in project jena by apache.

the class SecuredResourceImpl method getRequiredProperty.

@Override
public SecuredStatement getRequiredProperty(Property p, String lang) throws PropertyNotFoundException, ReadDeniedException, AuthenticationRequiredException {
    checkRead();
    final ExtendedIterator<Statement> iter = holder.getBaseItem().listProperties(p, lang).filterKeep(new PermStatementFilter(Action.Read, this));
    try {
        if (iter.hasNext()) {
            return org.apache.jena.permissions.model.impl.SecuredStatementImpl.getInstance(getModel(), iter.next());
        } else {
            throw new PropertyNotFoundException(p);
        }
    } finally {
        iter.close();
    }
}
Also used : PermStatementFilter(org.apache.jena.permissions.utils.PermStatementFilter) PropertyNotFoundException(org.apache.jena.shared.PropertyNotFoundException) SecuredStatement(org.apache.jena.permissions.model.SecuredStatement)

Example 5 with SecuredStatement

use of org.apache.jena.permissions.model.SecuredStatement in project jena by apache.

the class SecuredStatementImpl method getInstance.

/**
 * get a SecuredStatement
 *
 * @param securedModel The secured model that provides the security context
 * @param stmt         The statement to secure.
 * @return the SecuredStatement
 */
public static SecuredStatement getInstance(final SecuredModel securedModel, final Statement stmt) {
    if (securedModel == null) {
        throw new IllegalArgumentException("Secured securedModel may not be null");
    }
    if (stmt == null) {
        throw new IllegalArgumentException("Statement may not be null");
    }
    final ItemHolder<Statement, SecuredStatement> holder = new ItemHolder<>(stmt);
    final SecuredStatementImpl checker = new SecuredStatementImpl(securedModel, holder);
    // one.
    if (stmt instanceof SecuredStatement) {
        if (checker.isEquivalent((SecuredStatement) stmt)) {
            return (SecuredStatement) stmt;
        }
    }
    return holder.setSecuredItem(new SecuredItemInvoker(holder.getBaseItem().getClass(), checker));
}
Also used : SecuredStatement(org.apache.jena.permissions.model.SecuredStatement) ItemHolder(org.apache.jena.permissions.impl.ItemHolder) SecuredItemInvoker(org.apache.jena.permissions.impl.SecuredItemInvoker) Statement(org.apache.jena.rdf.model.Statement) ReifiedStatement(org.apache.jena.rdf.model.ReifiedStatement) SecuredStatement(org.apache.jena.permissions.model.SecuredStatement) SecuredReifiedStatement(org.apache.jena.permissions.model.SecuredReifiedStatement)

Aggregations

SecuredStatement (org.apache.jena.permissions.model.SecuredStatement)5 PermStatementFilter (org.apache.jena.permissions.utils.PermStatementFilter)4 PropertyNotFoundException (org.apache.jena.shared.PropertyNotFoundException)2 ItemHolder (org.apache.jena.permissions.impl.ItemHolder)1 SecuredItemInvoker (org.apache.jena.permissions.impl.SecuredItemInvoker)1 SecuredReifiedStatement (org.apache.jena.permissions.model.SecuredReifiedStatement)1 ReifiedStatement (org.apache.jena.rdf.model.ReifiedStatement)1 Statement (org.apache.jena.rdf.model.Statement)1