CCM NG: Some documentation for the secured iterator
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3749 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
0e3ee46988
commit
d4b5194612
|
|
@ -29,13 +29,16 @@ import org.libreccm.core.CcmObject;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Iterator implementation for {@link CcmObject}s which checks if the current
|
||||||
|
* subject is permitted to access an object before returning it.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
* @param <E>
|
* @param <E>
|
||||||
*/
|
*/
|
||||||
public class SecuredIterator<E extends CcmObject> implements Iterator<E> {
|
public class SecuredIterator<E extends CcmObject> implements Iterator<E> {
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(SecuredIterator.class);
|
private static final Logger LOGGER = LogManager.getLogger(
|
||||||
|
SecuredIterator.class);
|
||||||
|
|
||||||
private final Iterator<E> iterator;
|
private final Iterator<E> iterator;
|
||||||
|
|
||||||
|
|
@ -43,6 +46,14 @@ public class SecuredIterator<E extends CcmObject> implements Iterator<E> {
|
||||||
|
|
||||||
private final String requiredPrivilege;
|
private final String requiredPrivilege;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new secured iterator which secures the provided iterator.
|
||||||
|
*
|
||||||
|
* @param iterator The iterator to secure.
|
||||||
|
* @param clazz The base class of the objects returned by the
|
||||||
|
* iterator.
|
||||||
|
* @param requiredPrivilege The privilege required to access the objects.
|
||||||
|
*/
|
||||||
public SecuredIterator(final Iterator<E> iterator,
|
public SecuredIterator(final Iterator<E> iterator,
|
||||||
final Class<E> clazz,
|
final Class<E> clazz,
|
||||||
final String requiredPrivilege) {
|
final String requiredPrivilege) {
|
||||||
|
|
@ -51,15 +62,35 @@ public class SecuredIterator<E extends CcmObject> implements Iterator<E> {
|
||||||
this.requiredPrivilege = requiredPrivilege;
|
this.requiredPrivilege = requiredPrivilege;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*
|
||||||
|
* @return @inheritDoc
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return iterator.hasNext();
|
return iterator.hasNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the next object of the current subject it permitted to access it
|
||||||
|
* or a special "Access denied" object if not.
|
||||||
|
*
|
||||||
|
* The method gets the next object from the wrapped {@code Iterator} and
|
||||||
|
* checks if the current subject has a permission granting the privilege
|
||||||
|
* provided to the constructor on the object. If the current subject is
|
||||||
|
* permitted to access the object the object is returned. Otherwise a
|
||||||
|
* placeholder object is created using the {@link Class#newInstance()}
|
||||||
|
* method on the {@code Class} provided to the constructor. The
|
||||||
|
* {@link CcmObject#displayName} of these placeholder objects is set the
|
||||||
|
* {@code Access denied}.
|
||||||
|
*
|
||||||
|
* @return The next object or a special "Access denied" placeholder object.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public E next() {
|
public E next() {
|
||||||
final CdiUtil cdiUtil = new CdiUtil();
|
final CdiUtil cdiUtil = new CdiUtil();
|
||||||
final PermissionChecker permissionChecker ;
|
final PermissionChecker permissionChecker;
|
||||||
try {
|
try {
|
||||||
permissionChecker = cdiUtil.findBean(
|
permissionChecker = cdiUtil.findBean(
|
||||||
PermissionChecker.class);
|
PermissionChecker.class);
|
||||||
|
|
@ -77,7 +108,8 @@ public class SecuredIterator<E extends CcmObject> implements Iterator<E> {
|
||||||
|
|
||||||
return placeholder;
|
return placeholder;
|
||||||
} catch (InstantiationException | IllegalAccessException ex) {
|
} catch (InstantiationException | IllegalAccessException ex) {
|
||||||
LOGGER.error("Failed to create placeholder object. Returing null.", ex);
|
LOGGER.error(
|
||||||
|
"Failed to create placeholder object. Returing null.", ex);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue