mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-15 06:49:56 +00:00
bug5197: explicit subtype of SecurityOperation for those ReplicatingCache operations not requiring explicit replication
This commit is contained in:
1 parent
ea5b77b563
commit
55fe32d209
6 files changed
+92
-17
No files matched your search
@@ -14,6 +14,9 @@ import org.apache.shiro.cache.CacheException;
|
||||
import org.apache.shiro.session.Session;
|
||||
|
||||
import com.sap.sse.common.Named;
|
||||
import com.sap.sse.security.operations.ClearReplicatingCacheOperation;
|
||||
import com.sap.sse.security.operations.PutToReplicatingCacheOperation;
|
||||
import com.sap.sse.security.operations.RemoveFromReplicatingCacheOperation;
|
||||
|
||||
/**
|
||||
* A {@link Cache}s whose modifying operations are replicated. This works by intercepting the writing operations
|
||||
@@ -68,10 +71,8 @@ public class ReplicatingCache<K, V> implements Cache<K, V>, Named {
|
||||
}
|
||||
}
|
||||
V result = cache.put(key, value);
|
||||
final String myName = name;
|
||||
if (store && value instanceof Session) {
|
||||
securityService.replicate(s->
|
||||
s.getCacheManager().getCache(myName).put(key, value));
|
||||
securityService.replicate(new PutToReplicatingCacheOperation<K, V>(getName(), key, value));
|
||||
securityService.storeSession(getName(), (Session) value);
|
||||
}
|
||||
return result;
|
||||
@@ -93,9 +94,7 @@ public class ReplicatingCache<K, V> implements Cache<K, V>, Named {
|
||||
@Override
|
||||
public V remove(K key) throws CacheException {
|
||||
V result = cache.remove(key);
|
||||
final String myName = name;
|
||||
securityService.replicate(s->
|
||||
s.getCacheManager().getCache(myName).remove(key));
|
||||
securityService.replicate(new RemoveFromReplicatingCacheOperation<K>(getName(), key));
|
||||
if (result instanceof Session) {
|
||||
securityService.removeSession(getName(), (Session) result);
|
||||
}
|
||||
@@ -105,10 +104,7 @@ public class ReplicatingCache<K, V> implements Cache<K, V>, Named {
|
||||
@Override
|
||||
public void clear() throws CacheException {
|
||||
cache.clear();
|
||||
final String myName = name;
|
||||
securityService.replicate(s->{
|
||||
s.getCacheManager().getCache(myName).clear(); return null;
|
||||
});
|
||||
securityService.replicate(new ClearReplicatingCacheOperation(getName()));
|
||||
securityService.removeAllSessions(getName());
|
||||
}
|
||||
|
||||
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
package com.sap.sse.security.operations;
|
||||
|
||||
import com.sap.sse.security.impl.ReplicableSecurityService;
|
||||
|
||||
public class ClearReplicatingCacheOperation
|
||||
implements SecurityOperationNotRequiringExplicitTransitiveReplication<Void> {
|
||||
private static final long serialVersionUID = -5773023000924245582L;
|
||||
private final String cacheName;
|
||||
|
||||
public ClearReplicatingCacheOperation(String cacheName) {
|
||||
super();
|
||||
this.cacheName = cacheName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void internalApplyTo(ReplicableSecurityService toState) throws Exception {
|
||||
toState.getCacheManager().getCache(cacheName).clear();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
package com.sap.sse.security.operations;
|
||||
|
||||
import com.sap.sse.security.impl.ReplicableSecurityService;
|
||||
|
||||
public class PutToReplicatingCacheOperation<K, V>
|
||||
implements SecurityOperationNotRequiringExplicitTransitiveReplication<Object> {
|
||||
private static final long serialVersionUID = -9018465352648434564L;
|
||||
private final String cacheName;
|
||||
private final K key;
|
||||
private final V value;
|
||||
|
||||
public PutToReplicatingCacheOperation(String cacheName, K key, V value) {
|
||||
super();
|
||||
this.cacheName = cacheName;
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object internalApplyTo(ReplicableSecurityService toState) throws Exception {
|
||||
return toState.getCacheManager().getCache(cacheName).put(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.sap.sse.security.operations;
|
||||
|
||||
import com.sap.sse.security.impl.ReplicableSecurityService;
|
||||
|
||||
public class RemoveFromReplicatingCacheOperation<K>
|
||||
implements SecurityOperationNotRequiringExplicitTransitiveReplication<Object> {
|
||||
private static final long serialVersionUID = -1754187358645381535L;
|
||||
private final String cacheName;
|
||||
private final K key;
|
||||
|
||||
public RemoveFromReplicatingCacheOperation(String cacheName, K key) {
|
||||
super();
|
||||
this.cacheName = cacheName;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object internalApplyTo(ReplicableSecurityService toState) throws Exception {
|
||||
return toState.getCacheManager().getCache(cacheName).remove(key);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,11 +4,4 @@ import com.sap.sse.replication.OperationWithResult;
|
||||
import com.sap.sse.security.impl.ReplicableSecurityService;
|
||||
|
||||
public interface SecurityOperation<ResultType> extends OperationWithResult<ReplicableSecurityService, ResultType> {
|
||||
/**
|
||||
* By default, the security-related operations will perform an update on the receiving replica that in turn
|
||||
* will trigger replication of this change transitively.
|
||||
*/
|
||||
default boolean isRequiresExplicitTransitiveReplication() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.sap.sse.security.operations;
|
||||
|
||||
/**
|
||||
* To be implemented by those {@link SecurityOperation}s that do not require explicit transitive replication.
|
||||
* This interface has a default implementation for the {@link #isRequiresExplicitTransitiveReplication()} method
|
||||
* that always returns {@code false}.
|
||||
*
|
||||
* @author Axel Uhl (D043530)
|
||||
*
|
||||
* @param <ResultType>
|
||||
*/
|
||||
public interface SecurityOperationNotRequiringExplicitTransitiveReplication<ResultType> extends SecurityOperation<ResultType> {
|
||||
/**
|
||||
* By default, the security-related operations will perform an update on the receiving replica that in turn
|
||||
* will trigger replication of this change transitively.
|
||||
*/
|
||||
default boolean isRequiresExplicitTransitiveReplication() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user