CCM NG: More secured collections (not tested yet)
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3752 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
80eeb7960a
commit
f6f2923e1e
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.security;
|
||||||
|
|
||||||
|
import org.libreccm.core.CcmObject;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
* @param <K>
|
||||||
|
* @param <V>
|
||||||
|
*/
|
||||||
|
class SecuredEntry<K, V extends CcmObject> implements Map.Entry<K, V> {
|
||||||
|
|
||||||
|
private final Map.Entry<K, V> entry;
|
||||||
|
private final SecuredHelper<V> securedHelper;
|
||||||
|
|
||||||
|
public SecuredEntry(final Map.Entry<K, V> entry,
|
||||||
|
final SecuredHelper<V> securedHelper) {
|
||||||
|
this.entry = entry;
|
||||||
|
this.securedHelper = securedHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public K getKey() {
|
||||||
|
return entry.getKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public V getValue() {
|
||||||
|
return securedHelper.canAccess(entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public V setValue(final V value) {
|
||||||
|
return securedHelper.canAccess(entry.setValue(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.security;
|
||||||
|
|
||||||
|
import org.libreccm.core.CcmObject;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
class SecuredEntryIterator<E extends Map.Entry<K, V>, K, V extends CcmObject>
|
||||||
|
implements Iterator<E> {
|
||||||
|
|
||||||
|
private final Iterator<E> iterator;
|
||||||
|
private final SecuredHelper<V> securedHelper;
|
||||||
|
|
||||||
|
public SecuredEntryIterator(final Iterator<E> iterator,
|
||||||
|
final SecuredHelper<V> securedHelper) {
|
||||||
|
this.iterator = iterator;
|
||||||
|
this.securedHelper = securedHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return iterator.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public E next() {
|
||||||
|
return (E) new SecuredEntry<>(iterator.next(), securedHelper);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,155 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.security;
|
||||||
|
|
||||||
|
import com.arsdigita.util.UncheckedWrapperException;
|
||||||
|
|
||||||
|
import org.libreccm.cdi.utils.CdiLookupException;
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.libreccm.core.CcmObject;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
class SecuredEntrySet<E extends Map.Entry<K, V>, K, V extends CcmObject>
|
||||||
|
implements Set<E> {
|
||||||
|
|
||||||
|
private final Set<E> set;
|
||||||
|
private final String requiredPrivilege;
|
||||||
|
private final SecuredHelper<V> securedHelper;
|
||||||
|
|
||||||
|
public SecuredEntrySet(final Set<E> set,
|
||||||
|
final String requiredPrivilege,
|
||||||
|
final SecuredHelper<V> securedHelper) {
|
||||||
|
this.set = set;
|
||||||
|
this.requiredPrivilege = requiredPrivilege;
|
||||||
|
this.securedHelper = securedHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return set.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return set.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(final Object object) {
|
||||||
|
return set.contains(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<E> iterator() {
|
||||||
|
return new SecuredEntryIterator<>(set.iterator(), securedHelper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public Object[] toArray() {
|
||||||
|
final PermissionChecker permissionChecker;
|
||||||
|
final CdiUtil cdiUtil = new CdiUtil();
|
||||||
|
try {
|
||||||
|
permissionChecker = cdiUtil.findBean(
|
||||||
|
PermissionChecker.class);
|
||||||
|
} catch (CdiLookupException ex) {
|
||||||
|
throw new UncheckedWrapperException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Object[] entries = set.toArray();
|
||||||
|
for (int i = 0; i < entries.length; i++) {
|
||||||
|
final E entry = (E) entries[i];
|
||||||
|
if (!permissionChecker.isPermitted(requiredPrivilege,
|
||||||
|
entry.getValue())) {
|
||||||
|
entries[i] = securedHelper.generateAccessDeniedObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T> T[] toArray(final T[] array) {
|
||||||
|
final PermissionChecker permissionChecker;
|
||||||
|
final CdiUtil cdiUtil = new CdiUtil();
|
||||||
|
try {
|
||||||
|
permissionChecker = cdiUtil.findBean(
|
||||||
|
PermissionChecker.class);
|
||||||
|
} catch (CdiLookupException ex) {
|
||||||
|
throw new UncheckedWrapperException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
final E[] entries = (E[]) set.toArray(array);
|
||||||
|
for (int i = 0; i < entries.length; i++) {
|
||||||
|
if (!permissionChecker.isPermitted(requiredPrivilege,
|
||||||
|
entries[i].getValue())) {
|
||||||
|
entries[i] = (E) securedHelper.generateAccessDeniedObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (T[]) entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean add(final E element) {
|
||||||
|
return set.add(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean remove(final Object object) {
|
||||||
|
return set.remove(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsAll(final Collection<?> collection) {
|
||||||
|
return set.containsAll(collection);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addAll(final Collection<? extends E> collection) {
|
||||||
|
return set.addAll(collection);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean retainAll(final Collection<?> collection) {
|
||||||
|
return set.retainAll(collection);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeAll(final Collection<?> collection) {
|
||||||
|
return set.removeAll(collection);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
set.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,117 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.security;
|
||||||
|
|
||||||
|
import com.arsdigita.util.UncheckedWrapperException;
|
||||||
|
|
||||||
|
import org.libreccm.cdi.utils.CdiLookupException;
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.libreccm.core.CcmObject;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
* @param <K>
|
||||||
|
* @param <V>
|
||||||
|
*/
|
||||||
|
public class SecuredMap<K, V extends CcmObject> implements Map<K, V> {
|
||||||
|
|
||||||
|
private final Map<K, V> map;
|
||||||
|
private final Class<V> clazz;
|
||||||
|
private final String requiredPrivilege;
|
||||||
|
private final SecuredHelper<V> securedHelper;
|
||||||
|
|
||||||
|
public SecuredMap(final Map<K, V> map,
|
||||||
|
final Class<V> clazz,
|
||||||
|
final String requiredPrivilege) {
|
||||||
|
this.map = map;
|
||||||
|
this.clazz = clazz;
|
||||||
|
this.requiredPrivilege = requiredPrivilege;
|
||||||
|
this.securedHelper = new SecuredHelper<>(clazz, requiredPrivilege);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return map.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return map.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsKey(final Object key) {
|
||||||
|
return map.containsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean containsValue(final Object value) {
|
||||||
|
return map.containsValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public V get(final Object key) {
|
||||||
|
return securedHelper.canAccess(map.get(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public V put(final K key, final V value) {
|
||||||
|
return map.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public V remove(final Object key) {
|
||||||
|
return map.remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void putAll(final Map<? extends K, ? extends V> map) {
|
||||||
|
this.map.putAll(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
map.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<K> keySet() {
|
||||||
|
return map.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<V> values() {
|
||||||
|
return new SecuredCollection<>(map.values(), clazz, requiredPrivilege);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<Entry<K, V>> entrySet() {
|
||||||
|
return new SecuredEntrySet<>(map.entrySet(),
|
||||||
|
requiredPrivilege,
|
||||||
|
securedHelper);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,158 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.security;
|
||||||
|
|
||||||
|
import org.libreccm.core.CcmObject;
|
||||||
|
|
||||||
|
import java.util.NavigableMap;
|
||||||
|
import java.util.NavigableSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
* @param <K>
|
||||||
|
* @param <V>
|
||||||
|
*/
|
||||||
|
public class SecuredNavigableMap<K, V extends CcmObject>
|
||||||
|
extends SecuredSortedMap<K, V>
|
||||||
|
implements NavigableMap<K, V> {
|
||||||
|
|
||||||
|
private final NavigableMap<K, V> navigableMap;
|
||||||
|
private final Class<V> clazz;
|
||||||
|
private final String requiredPrivilege;
|
||||||
|
private final SecuredHelper<V> securedHelper;
|
||||||
|
|
||||||
|
public SecuredNavigableMap(final NavigableMap<K, V> navigableMap,
|
||||||
|
final Class<V> clazz,
|
||||||
|
final String requiredPrivilege) {
|
||||||
|
super(navigableMap, clazz, requiredPrivilege);
|
||||||
|
this.navigableMap = navigableMap;
|
||||||
|
this.clazz = clazz;
|
||||||
|
this.requiredPrivilege = requiredPrivilege;
|
||||||
|
securedHelper = new SecuredHelper<>(clazz, requiredPrivilege);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entry<K, V> lowerEntry(final K key) {
|
||||||
|
return new SecuredEntry<>(navigableMap.lowerEntry(key), securedHelper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public K lowerKey(final K key) {
|
||||||
|
return navigableMap.lowerKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entry<K, V> floorEntry(final K key) {
|
||||||
|
return new SecuredEntry<>(navigableMap.floorEntry(key), securedHelper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public K floorKey(final K key) {
|
||||||
|
return navigableMap.floorKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entry<K, V> ceilingEntry(final K key) {
|
||||||
|
return new SecuredEntry<>(navigableMap.ceilingEntry(key), securedHelper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public K ceilingKey(final K key) {
|
||||||
|
return navigableMap.ceilingKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entry<K, V> higherEntry(final K key) {
|
||||||
|
return new SecuredEntry<>(navigableMap.higherEntry(key), securedHelper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public K higherKey(final K key) {
|
||||||
|
return navigableMap.higherKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entry<K, V> firstEntry() {
|
||||||
|
return new SecuredEntry<>(navigableMap.firstEntry(), securedHelper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entry<K, V> lastEntry() {
|
||||||
|
return new SecuredEntry<>(navigableMap.lastEntry(), securedHelper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entry<K, V> pollFirstEntry() {
|
||||||
|
return new SecuredEntry<>(navigableMap.pollFirstEntry(), securedHelper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entry<K, V> pollLastEntry() {
|
||||||
|
return new SecuredEntry<>(navigableMap.pollLastEntry(), securedHelper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NavigableMap<K, V> descendingMap() {
|
||||||
|
return new SecuredNavigableMap<>(navigableMap.descendingMap(),
|
||||||
|
clazz,
|
||||||
|
requiredPrivilege);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NavigableSet<K> navigableKeySet() {
|
||||||
|
return navigableMap.navigableKeySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NavigableSet<K> descendingKeySet() {
|
||||||
|
return navigableMap.descendingKeySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NavigableMap<K, V> subMap(final K fromKey,
|
||||||
|
final boolean fromInclusive,
|
||||||
|
final K toKey,
|
||||||
|
final boolean toInclusive) {
|
||||||
|
return new SecuredNavigableMap<>(navigableMap.subMap(fromKey,
|
||||||
|
fromInclusive,
|
||||||
|
toKey,
|
||||||
|
toInclusive),
|
||||||
|
clazz,
|
||||||
|
requiredPrivilege);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NavigableMap<K, V> headMap(final K toKey,
|
||||||
|
final boolean inclusive) {
|
||||||
|
return new SecuredNavigableMap<>(navigableMap.headMap(toKey, inclusive),
|
||||||
|
clazz,
|
||||||
|
requiredPrivilege);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NavigableMap<K, V> tailMap(final K fromKey,
|
||||||
|
final boolean inclusive) {
|
||||||
|
return new SecuredNavigableMap<>(navigableMap.tailMap(fromKey,
|
||||||
|
inclusive),
|
||||||
|
clazz,
|
||||||
|
requiredPrivilege);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.security;
|
||||||
|
|
||||||
|
import org.libreccm.core.CcmObject;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.SortedMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
* @param <K>
|
||||||
|
* @param <V>
|
||||||
|
*/
|
||||||
|
public class SecuredSortedMap<K, V extends CcmObject>
|
||||||
|
extends SecuredMap<K, V>
|
||||||
|
implements SortedMap<K, V> {
|
||||||
|
|
||||||
|
private final SortedMap<K, V> sortedMap;
|
||||||
|
private final Class<V> clazz;
|
||||||
|
private final String requiredPrivilege;
|
||||||
|
|
||||||
|
public SecuredSortedMap(final SortedMap<K, V> sortedMap,
|
||||||
|
final Class<V> clazz,
|
||||||
|
final String requiredPrivilege) {
|
||||||
|
super(sortedMap, clazz, requiredPrivilege);
|
||||||
|
this.sortedMap = sortedMap;
|
||||||
|
this.clazz = clazz;
|
||||||
|
this.requiredPrivilege = requiredPrivilege;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Comparator<? super K> comparator() {
|
||||||
|
return sortedMap.comparator();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SortedMap<K, V> subMap(final K fromKey, final K toKey) {
|
||||||
|
return new SecuredSortedMap<>(sortedMap.subMap(fromKey, toKey),
|
||||||
|
clazz,
|
||||||
|
requiredPrivilege);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SortedMap<K, V> headMap(final K toKey) {
|
||||||
|
return new SecuredSortedMap<>(sortedMap.headMap(toKey),
|
||||||
|
clazz,
|
||||||
|
requiredPrivilege);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SortedMap<K, V> tailMap(final K fromKey) {
|
||||||
|
return new SecuredSortedMap<>(sortedMap.tailMap(fromKey),
|
||||||
|
clazz,
|
||||||
|
requiredPrivilege);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public K firstKey() {
|
||||||
|
return sortedMap.firstKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public K lastKey() {
|
||||||
|
return sortedMap.lastKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -44,7 +44,7 @@ public class SecuredSortedSet<E extends CcmObject>
|
||||||
this.set = set;
|
this.set = set;
|
||||||
this.clazz = clazz;
|
this.clazz = clazz;
|
||||||
this.requiredPrivilege = requiredPrivilege;
|
this.requiredPrivilege = requiredPrivilege;
|
||||||
this.securedHelper = new SecuredHelper(clazz, requiredPrivilege);
|
this.securedHelper = new SecuredHelper<>(clazz, requiredPrivilege);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -53,23 +53,23 @@ public class SecuredSortedSet<E extends CcmObject>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SortedSet<E> subSet(final E element1,
|
public SortedSet<E> subSet(final E fromElement,
|
||||||
final E element2) {
|
final E toElement) {
|
||||||
return new SecuredSortedSet<>(set.subSet(element1, element2),
|
return new SecuredSortedSet<>(set.subSet(fromElement, toElement),
|
||||||
clazz,
|
clazz,
|
||||||
requiredPrivilege);
|
requiredPrivilege);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SortedSet<E> headSet(final E element) {
|
public SortedSet<E> headSet(final E toElement) {
|
||||||
return new SecuredSortedSet<>(set.headSet(element),
|
return new SecuredSortedSet<>(set.headSet(toElement),
|
||||||
clazz,
|
clazz,
|
||||||
requiredPrivilege);
|
requiredPrivilege);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SortedSet<E> tailSet(final E element) {
|
public SortedSet<E> tailSet(final E fromElement) {
|
||||||
return new SecuredSortedSet<>(set.tailSet(element),
|
return new SecuredSortedSet<>(set.tailSet(fromElement),
|
||||||
clazz,
|
clazz,
|
||||||
requiredPrivilege);
|
requiredPrivilege);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue