portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r1678139 [2/3] - in /portals/jetspeed-2/portal/trunk: components/jetspeed-cm/src/main/java/org/apache/jetspeed/cache/impl/ components/jetspeed-profiler/src/test/resources/ components/jetspeed-security/src/main/java/org/apache/jetspeed/secur...
Date Thu, 07 May 2015 06:48:07 GMT
Added: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/cache/JSPMCacheImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/cache/JSPMCacheImpl.java?rev=1678139&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/cache/JSPMCacheImpl.java (added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/cache/JSPMCacheImpl.java Thu May  7 06:48:06 2015
@@ -0,0 +1,411 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.security.spi.impl.cache;
+
+import org.apache.jetspeed.cache.DistributedCacheObject;
+import org.apache.jetspeed.cache.JetspeedCache;
+import org.apache.jetspeed.cache.JetspeedCacheEventAdapter;
+import org.apache.jetspeed.cache.JetspeedCacheEventListener;
+import org.apache.jetspeed.cache.impl.EhCacheDistributedElementImpl;
+import org.apache.jetspeed.cache.impl.EhCacheDistributedImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * JSPMCacheImpl - JetspeedSecurityPersistenceManager cache
+ *
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id: $
+ */
+public class JSPMCacheImpl implements JSPMCache
+{
+    private static final Logger log = LoggerFactory.getLogger(JSPMCacheImpl.class);
+
+    // distributed instance caches
+    private EhCacheDistributedImpl principalCache;
+    private EhCacheDistributedImpl permissionCache;
+    private EhCacheDistributedImpl domainCache;
+
+    // distributed instance cache listeners
+    private JetspeedCacheEventListener principalCacheListener;
+    private JetspeedCacheEventListener permissionCacheListener;
+    private JetspeedCacheEventListener domainCacheListener;
+
+    // local query caches
+    private JSPMQueryEhCacheImpl principalQueryCache;
+    private JSPMQueryEhCacheImpl associationQueryCache;
+    private JSPMQueryEhCacheImpl passwordCredentialQueryCache;
+    private JSPMQueryEhCacheImpl permissionQueryCache;
+    private JSPMQueryEhCacheImpl domainQueryCache;
+
+    /**
+     * Create JSPMCache component instance.
+     *
+     * @param principalCache distributed principal instance cache
+     * @param permissionCache distributed permission instance cache
+     * @param domainCache distributed domain instance cache
+     * @param principalQueryCache local principal query cache
+     * @param associationQueryCache local principal association query cache
+     * @param passwordCredentialQueryCache local principal password credential query cache
+     * @param permissionQueryCache local permission query cache
+     * @param domainQueryCache local domain query cache
+     */
+    public JSPMCacheImpl(EhCacheDistributedImpl principalCache,
+                         EhCacheDistributedImpl permissionCache,
+                         EhCacheDistributedImpl domainCache,
+                         JSPMQueryEhCacheImpl principalQueryCache,
+                         JSPMQueryEhCacheImpl associationQueryCache,
+                         JSPMQueryEhCacheImpl passwordCredentialQueryCache,
+                         JSPMQueryEhCacheImpl permissionQueryCache,
+                         JSPMQueryEhCacheImpl domainQueryCache)
+    {
+        this.principalCache = principalCache;
+        this.permissionCache = permissionCache;
+        this.domainCache = domainCache;
+
+        this.principalQueryCache = principalQueryCache;
+        this.associationQueryCache = associationQueryCache;
+        this.passwordCredentialQueryCache = passwordCredentialQueryCache;
+        this.permissionQueryCache = permissionQueryCache;
+        this.domainQueryCache = domainQueryCache;
+    }
+
+    /**
+     * Initialize caches and listeners.
+     */
+    public void initialize()
+    {
+        // principal cache listener
+        principalCacheListener = new JetspeedCacheEventAdapter()
+        {
+            @Override
+            public void notifyElementRemoved(JetspeedCache cache, boolean local, Object key, Object element)
+            {
+                // removed notification sent on remove and update:
+                // clear query cache elements base on principal id
+                if (key instanceof Long)
+                {
+                    long principalId = (Long)key;
+                    principalQueryCache.evictPrincipal(principalId);
+                    associationQueryCache.evictPrincipal(principalId);
+                    passwordCredentialQueryCache.evictPrincipal(principalId);
+                    permissionQueryCache.evictPrincipal(principalId);
+                }
+            }
+        };
+        principalCache.addEventListener(principalCacheListener, false);
+
+        // permission cache listener
+        permissionCacheListener = new JetspeedCacheEventAdapter()
+        {
+            @Override
+            public void notifyElementRemoved(JetspeedCache cache, boolean local, Object key, Object element)
+            {
+                // removed notification sent on remove and update:
+                // clear query cache elements base on permission id
+                if (key instanceof Long)
+                {
+                    long permissionId = (Long)key;
+                    principalQueryCache.evictPermission(permissionId);
+                    permissionQueryCache.evictPermission(permissionId);
+                }
+            }
+        };
+        permissionCache.addEventListener(permissionCacheListener, false);
+
+        // domain cache listener
+        domainCacheListener = new JetspeedCacheEventAdapter()
+        {
+            @Override
+            public void notifyElementRemoved(JetspeedCache cache, boolean local, Object key, Object element)
+            {
+                // removed notification sent on remove and update:
+                // clear query cache elements base on domain id
+                if (key instanceof Long)
+                {
+                    long domainId = (Long)key;
+                    principalQueryCache.evictDomain(domainId);
+                    associationQueryCache.evictDomain(domainId);
+                    passwordCredentialQueryCache.evictDomain(domainId);
+                    domainQueryCache.evictDomain(domainId);
+                }
+            }
+        };
+        domainCache.addEventListener(domainCacheListener, false);
+    }
+
+    /**
+     * Terminate caches and listeners.
+     */
+    public void terminate()
+    {
+        // distributed cache listeners
+        principalCache.removeEventListener(principalCacheListener, false);
+        principalCache.removeEventListener(principalCacheListener, true);
+        permissionCache.removeEventListener(permissionCacheListener, false);
+        permissionCache.removeEventListener(permissionCacheListener, true);
+        domainCache.removeEventListener(domainCacheListener, false);
+        domainCache.removeEventListener(domainCacheListener, true);
+
+        // clear caches
+        clear();
+    }
+
+    @Override
+    public Object getPrincipal(Long id)
+    {
+        EhCacheDistributedElementImpl cacheElementImpl = (EhCacheDistributedElementImpl)principalCache.get(id);
+        return ((cacheElementImpl != null) ? cacheElementImpl.getContent() : null);
+    }
+
+    @Override
+    public void putPrincipal(Long id, Object principal)
+    {
+        principalCache.put(new EhCacheDistributedElementImpl(id, (DistributedCacheObject) principal));
+    }
+
+    @Override
+    public void evictPrincipal(Long id)
+    {
+        evictFromDistributedCache(principalCache, id);
+    }
+
+    @Override
+    public Object getPermission(Long id)
+    {
+        EhCacheDistributedElementImpl cacheElementImpl = (EhCacheDistributedElementImpl)permissionCache.get(id);
+        return ((cacheElementImpl != null) ? cacheElementImpl.getContent() : null);
+    }
+
+    @Override
+    public void putPermission(Long id, Object permission)
+    {
+        permissionCache.put(new EhCacheDistributedElementImpl(id, (DistributedCacheObject) permission));
+    }
+
+    @Override
+    public void evictPermission(Long id)
+    {
+        evictFromDistributedCache(permissionCache, id);
+    }
+
+    @Override
+    public Object getDomain(Long id)
+    {
+        EhCacheDistributedElementImpl cacheElementImpl = (EhCacheDistributedElementImpl)domainCache.get(id);
+        return ((cacheElementImpl != null) ? cacheElementImpl.getContent() : null);
+    }
+
+    @Override
+    public void putDomain(Long id, Object domain)
+    {
+       domainCache.put(new EhCacheDistributedElementImpl(id, (DistributedCacheObject) domain));
+    }
+
+    @Override
+    public void evictDomain(Long id)
+    {
+        evictFromDistributedCache(domainCache, id);
+    }
+
+    @Override
+    public Object getPrincipalQuery(String key)
+    {
+        JSPMQueryEhCacheElementImpl cacheElementImpl = (JSPMQueryEhCacheElementImpl)principalQueryCache.get(key);
+        return ((cacheElementImpl != null) ? cacheElementImpl.getImplElement().getObjectValue() : null);
+    }
+
+    @Override
+    public void putPrincipalQuery(String key, Long principalId, Long permissionId, Long domainId, Object query)
+    {
+        principalQueryCache.put(newJSPMQueryEhCacheElementImpl(key, principalId, null, permissionId, domainId, null,
+                query));
+    }
+
+    @Override
+    public Object getAssociationQuery(String key)
+    {
+        JSPMQueryEhCacheElementImpl cacheElementImpl = (JSPMQueryEhCacheElementImpl)associationQueryCache.get(key);
+        return ((cacheElementImpl != null) ? cacheElementImpl.getImplElement().getObjectValue() : null);
+    }
+
+    @Override
+    public void putAssociationQuery(String key, Long principalId, Long [] otherPrincipalIds, Long domainId,
+                                    Long otherDomainId, Object query)
+    {
+        associationQueryCache.put(newJSPMQueryEhCacheElementImpl(key, principalId, otherPrincipalIds, null, domainId,
+                otherDomainId, query));
+    }
+
+    @Override
+    public Object getPasswordCredentialQuery(String key)
+    {
+        JSPMQueryEhCacheElementImpl cacheElementImpl = (JSPMQueryEhCacheElementImpl)passwordCredentialQueryCache.get(key);
+        return ((cacheElementImpl != null) ? cacheElementImpl.getImplElement().getObjectValue() : null);
+    }
+
+    @Override
+    public void putPasswordCredentialQuery(String key, Long principalId, Long domainId, Object query)
+    {
+        passwordCredentialQueryCache.put(newJSPMQueryEhCacheElementImpl(key, principalId, null, null, domainId, null,
+                query));
+    }
+
+    @Override
+    public Object getPermissionQuery(String key)
+    {
+        JSPMQueryEhCacheElementImpl cacheElementImpl = (JSPMQueryEhCacheElementImpl)permissionQueryCache.get(key);
+        return ((cacheElementImpl != null) ? cacheElementImpl.getImplElement().getObjectValue() : null);
+    }
+
+    @Override
+    public void putPermissionQuery(String key, Long principalId, Long [] otherPrincipalIds, Long permissionId,
+                                   Long domainId, Object query)
+    {
+        permissionQueryCache.put(newJSPMQueryEhCacheElementImpl(key, principalId, otherPrincipalIds, permissionId,
+                domainId, null, query));
+    }
+
+    @Override
+    public Object getDomainQuery(String key)
+    {
+        JSPMQueryEhCacheElementImpl cacheElementImpl = (JSPMQueryEhCacheElementImpl)domainQueryCache.get(key);
+        return ((cacheElementImpl != null) ? cacheElementImpl.getImplElement().getObjectValue() : null);
+    }
+
+    @Override
+    public void putDomainQuery(String key, Long domainId, Object query)
+    {
+        permissionQueryCache.put(newJSPMQueryEhCacheElementImpl(key, null, null, null, domainId, null, query));
+    }
+
+    @Override
+    public int size()
+    {
+        // compute size from sum of all cache sizes
+        int size = 0;
+        size += principalCache.getSize();
+        size += permissionCache.getSize();
+        size += domainCache.getSize();
+        size += principalQueryCache.getSize();
+        size += associationQueryCache.getSize();
+        size += passwordCredentialQueryCache.getSize();
+        size += permissionQueryCache.getSize();
+        size += domainQueryCache.getSize();
+        return size;
+    }
+
+    @Override
+    public void clear()
+    {
+        // clear all caches
+        principalCache.clear();
+        permissionCache.clear();
+        domainCache.clear();
+        principalQueryCache.clear();
+        associationQueryCache.clear();
+        passwordCredentialQueryCache.clear();
+        permissionQueryCache.clear();
+        domainQueryCache.clear();
+    }
+
+    /**
+     * Construct new query cache element with dependent instance
+     * cache ids.
+     *
+     * @param key cache key
+     * @param principalId dependent principal id, ANY_ID, or null
+     * @param otherPrincipalIds dependent principal ids or null
+     * @param permissionId dependent permission id, ANY_ID, or null
+     * @param domainId dependent domain id, ANY_ID, or null
+     * @param otherDomainId dependent domain id, ANY_ID, or null
+     * @param element cache element value
+     * @return new cache element
+     */
+    private static JSPMQueryEhCacheElementImpl newJSPMQueryEhCacheElementImpl(String key, Long principalId,
+                                                                              Long [] otherPrincipalIds,
+                                                                              Long permissionId, Long domainId,
+                                                                              Long otherDomainId, Object element)
+    {
+        JSPMQueryEhCacheElementImpl cacheElementImpl = new JSPMQueryEhCacheElementImpl(key, element);
+        if (principalId != null)
+        {
+            if ((otherPrincipalIds != null) && (otherPrincipalIds.length > 0))
+            {
+                long [] principalIds = new long[otherPrincipalIds.length+1];
+                principalIds[0] = principalId;
+                for (int i = 0, limit = otherPrincipalIds.length; (i < limit); i++)
+                {
+                    principalIds[i+1] = otherPrincipalIds[i];
+                }
+                cacheElementImpl.setPrincipalIds(principalIds);
+            }
+            else
+            {
+                cacheElementImpl.setPrincipalIds(new long[]{principalId});
+            }
+        }
+        else if ((otherPrincipalIds != null) && (otherPrincipalIds.length > 0))
+        {
+            long [] principalIds = new long[otherPrincipalIds.length];
+            for (int i = 0, limit = otherPrincipalIds.length; (i < limit); i++)
+            {
+                principalIds[i] = otherPrincipalIds[i];
+            }
+            cacheElementImpl.setPrincipalIds(principalIds);
+
+        }
+        if (permissionId != null)
+        {
+            cacheElementImpl.setPermissionIds(new long[]{permissionId});
+        }
+        if (domainId != null)
+        {
+            if (otherDomainId != null)
+            {
+                cacheElementImpl.setDomainIds(new long[]{domainId, otherDomainId});
+            }
+            else
+            {
+                cacheElementImpl.setDomainIds(new long[]{domainId});
+            }
+        }
+        else if (otherDomainId != null)
+        {
+            cacheElementImpl.setDomainIds(new long[]{otherDomainId});
+        }
+        return cacheElementImpl;
+    }
+
+    /**
+     * Evict with notification from distributed instance cache.
+     * Notification is sent even if instance is not in the cache
+     * so that eviction is done in distributed peers.
+     *
+     * @param cache distributed instance cache
+     * @param id instance id to evict and notify
+     */
+    private static void evictFromDistributedCache(EhCacheDistributedImpl cache, Long id)
+    {
+        // force remove to notify local and remote listeners
+        if (!cache.remove(id))
+        {
+            cache.put(new EhCacheDistributedElementImpl(id, (DistributedCacheObject) CACHE_NULL));
+            cache.remove(id);
+        }
+    }
+}

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/cache/JSPMQueryCacheElement.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/cache/JSPMQueryCacheElement.java?rev=1678139&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/cache/JSPMQueryCacheElement.java (added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/cache/JSPMQueryCacheElement.java Thu May  7 06:48:06 2015
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.security.spi.impl.cache;
+
+import net.sf.ehcache.Element;
+
+import java.io.Serializable;
+
+/**
+ * JSPMQueryCacheElement - JetspeedSecurityPersistenceManager query cache Element
+ *
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id: $
+ */
+public class JSPMQueryCacheElement extends Element
+{
+    /**
+     * Cache element wildcard dependent id.
+     */
+    public static final long ANY_ID = 0L;
+
+    private static final long serialVersionUID = 1L;
+
+    // dependent instance ids
+    private long [] principalIds;
+    private long [] permissionIds;
+    private long [] domainIds;
+
+    /**
+     * Construct new cache element.
+     *
+     * @param key cache element key
+     * @param value cache element value
+     */
+    public JSPMQueryCacheElement(Serializable key, Serializable value)
+    {
+        super(key, value);
+    }
+
+    /**
+     * Construct new cache element.
+     *
+     * @param key cache element key
+     * @param value cache element value
+     */
+    public JSPMQueryCacheElement(Serializable key, Object value)
+    {
+        super(key, value);
+    }
+
+    public long [] getPrincipalIds()
+    {
+        return principalIds;
+    }
+
+    public void setPrincipalIds(long [] principalIds)
+    {
+        this.principalIds = principalIds;
+    }
+
+    public long [] getPermissionIds()
+    {
+        return permissionIds;
+    }
+
+    public void setPermissionIds(long [] permissionIds)
+    {
+        this.permissionIds = permissionIds;
+    }
+
+    public long [] getDomainIds()
+    {
+        return domainIds;
+    }
+
+    public void setDomainIds(long [] domainIds)
+    {
+        this.domainIds = domainIds;
+    }
+}

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/cache/JSPMQueryEhCacheElementImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/cache/JSPMQueryEhCacheElementImpl.java?rev=1678139&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/cache/JSPMQueryEhCacheElementImpl.java (added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/cache/JSPMQueryEhCacheElementImpl.java Thu May  7 06:48:06 2015
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.security.spi.impl.cache;
+
+import net.sf.ehcache.Element;
+import org.apache.jetspeed.cache.impl.EhCacheElementImpl;
+
+import java.io.Serializable;
+
+/**
+ * JSPMQueryEhCacheElementImpl - JetspeedSecurityPersistenceManager query EhCacheElementImpl
+ *
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id: $
+ */
+public class JSPMQueryEhCacheElementImpl extends EhCacheElementImpl
+{
+    /**
+     * Construct new EhCache element variant.
+     *
+     * @param element EhCache element
+     */
+    public JSPMQueryEhCacheElementImpl(Element element)
+    {
+        super((JSPMQueryCacheElement)element);
+    }
+
+    /**
+     * Construct new EhCache element variant.
+     *
+     * @param key EhCache element key
+     * @param key EhCache element value
+     */
+    public JSPMQueryEhCacheElementImpl(Serializable key, Serializable value)
+    {
+        super(new JSPMQueryCacheElement(key, value));
+    }
+
+    /**
+     * Construct new EhCache element variant.
+     *
+     * @param key EhCache element key
+     * @param key EhCache element value
+     */
+    public JSPMQueryEhCacheElementImpl(Serializable key, Object value)
+    {
+        super(new JSPMQueryCacheElement(key, value));
+    }
+
+    public long [] getPrincipalIds()
+    {
+        return ((JSPMQueryCacheElement)element).getPrincipalIds();
+    }
+
+    public void setPrincipalIds(long [] principalIds)
+    {
+        ((JSPMQueryCacheElement)element).setPrincipalIds(principalIds);
+    }
+
+    public long [] getPermissionIds()
+    {
+        return ((JSPMQueryCacheElement)element).getPermissionIds();
+    }
+
+    public void setPermissionIds(long [] permissionIds)
+    {
+        ((JSPMQueryCacheElement)element).setPermissionIds(permissionIds);
+    }
+
+    public long [] getDomainIds()
+    {
+        return ((JSPMQueryCacheElement)element).getDomainIds();
+    }
+
+    public void setDomainIds(long [] domainIds)
+    {
+        ((JSPMQueryCacheElement)element).setDomainIds(domainIds);
+    }
+}

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/cache/JSPMQueryEhCacheImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/cache/JSPMQueryEhCacheImpl.java?rev=1678139&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/cache/JSPMQueryEhCacheImpl.java (added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/cache/JSPMQueryEhCacheImpl.java Thu May  7 06:48:06 2015
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.security.spi.impl.cache;
+
+import net.sf.ehcache.Ehcache;
+import net.sf.ehcache.Element;
+import org.apache.jetspeed.cache.CacheElement;
+import org.apache.jetspeed.cache.impl.EhCacheImpl;
+
+/**
+ * JSPMQueryEhCacheImpl - JetspeedSecurityPersistenceManager query EhCacheImpl
+ *
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id: $
+ */
+public class JSPMQueryEhCacheImpl extends EhCacheImpl
+{
+    /**
+     * Construct new query cache supporting principal, permission, and
+     * domain dependency driven eviction.
+     *
+     * @param ehcache backing EhCache
+     */
+    public JSPMQueryEhCacheImpl(Ehcache ehcache)
+    {
+        super(ehcache);
+    }
+
+    @Override
+    public CacheElement get(Object key)
+    {
+        Element element = ehcache.get(key);
+        if (element == null)
+            return null;
+        return new JSPMQueryEhCacheElementImpl(element);
+    }
+
+    @Override
+    public void put(CacheElement element)
+    {
+        JSPMQueryEhCacheElementImpl elementImpl = (JSPMQueryEhCacheElementImpl)element;
+        ehcache.put(elementImpl.getImplElement());
+    }
+
+    /**
+     * Evict cached queries for principal. Operation should be rare, so
+     * implemented using potentially expensive iteration over keys. Should
+     * this become an issue, cache could maintain lookup maps of keys for
+     * principal.
+     *
+     * @param principalId principal id
+     */
+    public void evictPrincipal(long principalId)
+    {
+        // validate id
+        if (principalId <= 0)
+        {
+            return;
+        }
+        // iterate over cache elements
+        for (Object key : getKeys())
+        {
+            JSPMQueryCacheElement element = (JSPMQueryCacheElement)ehcache.get(key);
+            if (element != null)
+            {
+                // evict elements with matching principal
+                if (hasMatchingId(element.getPrincipalIds(), principalId))
+                {
+                    ehcache.removeQuiet(key);
+                }
+            }
+        }
+    }
+
+    /**
+     * Evict cached queries for permission. Operation should be rare, so
+     * implemented using potentially expensive iteration over keys. Should
+     * this become an issue, cache could maintain lookup maps of keys for
+     * permission.
+     *
+     * @param permissionId permission id
+     */
+    public void evictPermission(long permissionId)
+    {
+        // validate id
+        if (permissionId <= 0)
+        {
+            return;
+        }
+        // iterate over cache elements
+        for (Object key : getKeys())
+        {
+            JSPMQueryCacheElement element = (JSPMQueryCacheElement)ehcache.get(key);
+            if (element != null)
+            {
+                // evict elements with matching permission
+                if (hasMatchingId(element.getPermissionIds(), permissionId))
+                {
+                    ehcache.removeQuiet(key);
+                }
+            }
+        }
+    }
+
+    /**
+     * Evict cached queries for domain. Operation should be rare, so
+     * implemented using potentially expensive iteration over keys. Should
+     * this become an issue, cache could maintain lookup maps of keys for
+     * domain.
+     *
+     * @param domainId domain id
+     */
+    public void evictDomain(long domainId)
+    {
+        // validate id
+        if (domainId <= 0)
+        {
+            return;
+        }
+        // iterate over cache elements
+        for (Object key : getKeys())
+        {
+            JSPMQueryCacheElement element = (JSPMQueryCacheElement)ehcache.get(key);
+            if (element != null)
+            {
+                // evict elements with matching domain
+                if (hasMatchingId(element.getDomainIds(), domainId))
+                {
+                    ehcache.removeQuiet(key);
+                }
+            }
+        }
+    }
+
+    /**
+     * Check ids for matching id.
+     *
+     * @param ids ids array to check
+     * @param matchingId id to check
+     * @return matching
+     */
+    private static boolean hasMatchingId(long [] ids, long matchingId)
+    {
+        if (ids == null) {
+            return false;
+        }
+        for (long id : ids)
+        {
+            if ((id == matchingId) || (id == JSPMQueryCacheElement.ANY_ID))
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+}

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/spi/TestJSPMCache.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/spi/TestJSPMCache.java?rev=1678139&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/spi/TestJSPMCache.java (added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/spi/TestJSPMCache.java Thu May  7 06:48:06 2015
@@ -0,0 +1,711 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.security.spi;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.jetspeed.security.AbstractSecurityTestcase;
+import org.apache.jetspeed.security.JetspeedPermission;
+import org.apache.jetspeed.security.JetspeedPrincipal;
+import org.apache.jetspeed.security.JetspeedPrincipalAssociationType;
+import org.apache.jetspeed.security.JetspeedPrincipalType;
+import org.apache.jetspeed.security.PasswordCredential;
+import org.apache.jetspeed.security.SecurityDomain;
+import org.apache.jetspeed.security.SecurityException;
+import org.apache.jetspeed.security.User;
+import org.apache.jetspeed.security.impl.GroupImpl;
+import org.apache.jetspeed.security.impl.PersistentJetspeedPrincipal;
+import org.apache.jetspeed.security.impl.RoleImpl;
+import org.apache.jetspeed.security.impl.SecurityDomainImpl;
+import org.apache.jetspeed.security.impl.UserImpl;
+import org.apache.jetspeed.security.spi.impl.JetspeedSecurityPersistenceManager;
+import org.apache.jetspeed.security.spi.impl.PasswordCredentialImpl;
+import org.apache.jetspeed.security.spi.impl.PersistentJetspeedPermissionImpl;
+import org.apache.jetspeed.security.spi.impl.cache.JSPMCache;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.orm.ojb.PersistenceBrokerTransactionManager;
+import org.springframework.transaction.TransactionDefinition;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.DefaultTransactionDefinition;
+import org.springframework.util.ReflectionUtils;
+
+import java.lang.reflect.Field;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * TestJSPMCache - test JetspeedSecurityPersistenceManager cache
+ *
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id: $
+ */
+public class TestJSPMCache extends AbstractSecurityTestcase
+{
+    private static final Logger log = LoggerFactory.getLogger(TestJSPMCache.class);
+
+    private static final String TEST_DOMAIN_1 = "TEST-DOMAIN-1";
+    private static final String TEST_USER_1 = "TEST-USER-1";
+    private static final String TEST_USER_2 = "TEST-USER-2";
+    private static final String TEST_ROLE_1 = "TEST-ROLE-1";
+    private static final String TEST_ROLE_2 = "TEST-ROLE-2";
+    private static final String TEST_GROUP_1 = "TEST-GROUP-1";
+    private static final String TEST_GROUP_2 = "TEST-GROUP-2";
+    private static final String TEST_PERMISSION_TYPE = "TEST-PERMISSION";
+    private static final String TEST_PERMISSION_1 = "TEST-PERMISSION-1";
+    private static final String TEST_PERMISSION_2 = "TEST-PERMISSION-2";
+
+    private JetspeedSecurityPersistenceManager jspm;
+    private JSPMCache jspmCache;
+    private JetspeedPrincipalType userType;
+    private JetspeedPrincipalType roleType;
+    private JetspeedPrincipalType groupType;
+    private PersistenceBrokerTransactionManager txnManager;
+    private TransactionStatus txn;
+
+    private SecurityDomain defaultDomain;
+    private SecurityDomain testDomain1;
+    private User testUser1;
+    private User testUser2;
+    private JetspeedPrincipal testRole1;
+    private JetspeedPrincipal testRole2;
+    private JetspeedPrincipal testGroup1;
+    private JetspeedPrincipal testGroup2;
+    private JetspeedPermission testPermission1;
+    private JetspeedPermission testPermission2;
+
+    public static Test suite()
+    {
+        return new TestSuite(TestJSPMCache.class);
+    }
+
+    @Override
+    public void setUp() throws Exception
+    {
+        super.setUp();
+        // lookup test components
+        jspm = scm.lookupComponent("org.apache.jetspeed.security.spi.impl.JetspeedSecurityPersistenceManager");
+        assertNotNull(jspm);
+        jspmCache = scm.lookupComponent("org.apache.jetspeed.security.spi.impl.cache.JSPMCache");
+        assertNotNull(jspmCache);
+        userType = scm.lookupComponent("org.apache.jetspeed.security.JetspeedPrincipalType.user");
+        assertNotNull(userType);
+        roleType = scm.lookupComponent("org.apache.jetspeed.security.JetspeedPrincipalType.role");
+        assertNotNull(roleType);
+        groupType = scm.lookupComponent("org.apache.jetspeed.security.JetspeedPrincipalType.group");
+        assertNotNull(groupType);
+        txnManager = scm.lookupComponent("transactionManager");
+        assertNotNull(txnManager);
+    }
+
+    @Override
+    public void tearDown() throws Exception
+    {
+        // remove test domain
+        if (testDomain1 != null)
+        {
+            try
+            {
+                domainStorageManager.removeDomain(testDomain1);
+            }
+            catch (Exception e)
+            {
+            }
+            testDomain1 = null;
+        }
+        // remove all principals and permissions
+        super.tearDown();
+    }
+
+    /**
+     * Test read cache operation for security domains, principals,
+     * password credentials, permissions, and associations.
+     *
+     * @throws Exception
+     */
+    public void testJSPMCache() throws Exception
+    {
+        try
+        {
+            // begin transaction
+            beginTransaction();
+
+            // create domains
+            defaultDomain = jspm.getDomainByName(SecurityDomain.DEFAULT_NAME);
+            assertNotNull(defaultDomain);
+            testDomain1 = new SecurityDomainImpl();
+            ((SecurityDomainImpl) testDomain1).setName(TEST_DOMAIN_1);
+            ((SecurityDomainImpl) testDomain1).setOwnerDomainId(defaultDomain.getDomainId());
+            jspm.addDomain(testDomain1);
+            testDomain1 = jspm.getDomainByName(TEST_DOMAIN_1);
+            assertNotNull(testDomain1);
+
+            // create principals
+            testUser1 = new UserImpl(TEST_USER_1);
+            ((UserImpl) testUser1).setDomainId(testDomain1.getDomainId());
+            testUser1.getSecurityAttributes().getAttribute("user.name", true).setStringValue(TEST_USER_1);
+            jspm.addPrincipal(testUser1, null);
+            testUser1 = (User) jspm.getPrincipal(TEST_USER_1, userType, testDomain1.getDomainId());
+            assertNotNull(testUser1);
+            testUser2 = new UserImpl(TEST_USER_2);
+            ((UserImpl) testUser2).setDomainId(testDomain1.getDomainId());
+            testUser2.getSecurityAttributes().getAttribute("user.name", true).setStringValue(TEST_USER_2);
+            jspm.addPrincipal(testUser2, null);
+            testUser2 = (User) jspm.getPrincipal(TEST_USER_2, userType, testDomain1.getDomainId());
+            assertNotNull(testUser2);
+            testRole1 = new RoleImpl(TEST_ROLE_1);
+            ((RoleImpl) testRole1).setDomainId(testDomain1.getDomainId());
+            jspm.addPrincipal(testRole1, null);
+            testRole1 = jspm.getPrincipal(TEST_ROLE_1, roleType, testDomain1.getDomainId());
+            assertNotNull(testRole1);
+            testRole2 = new RoleImpl(TEST_ROLE_2);
+            ((RoleImpl) testRole2).setDomainId(testDomain1.getDomainId());
+            jspm.addPrincipal(testRole2, null);
+            testRole2 = jspm.getPrincipal(TEST_ROLE_2, roleType, testDomain1.getDomainId());
+            assertNotNull(testRole2);
+            testGroup1 = new GroupImpl(TEST_GROUP_1);
+            ((GroupImpl) testGroup1).setDomainId(testDomain1.getDomainId());
+            jspm.addPrincipal(testGroup1, null);
+            testGroup1 = jspm.getPrincipal(TEST_GROUP_1, groupType, testDomain1.getDomainId());
+            assertNotNull(testGroup1);
+            testGroup2 = new GroupImpl(TEST_GROUP_2);
+            ((GroupImpl) testGroup2).setDomainId(testDomain1.getDomainId());
+            jspm.addPrincipal(testGroup2, null);
+            testGroup2 = jspm.getPrincipal(TEST_GROUP_2, groupType, testDomain1.getDomainId());
+            assertNotNull(testGroup2);
+
+            // create password credentials
+            PasswordCredential testUser1Password = new PasswordCredentialImpl(testUser1, TEST_USER_1);
+            jspm.storePasswordCredential(testUser1Password);
+            testUser1Password = jspm.getPasswordCredential(testUser1);
+            assertNotNull(testUser1Password);
+            PasswordCredential testUser1HistoricalPassword = new PasswordCredentialImpl(testUser1, TEST_USER_1);
+            setPasswordCredentialType(testUser1HistoricalPassword, PasswordCredential.TYPE_HISTORICAL);
+            jspm.storePasswordCredential(testUser1HistoricalPassword);
+            List<PasswordCredential> testUser1HistoricalPasswords = jspm.getHistoricPasswordCredentials(testUser1,
+                    testDomain1.getDomainId());
+            assertNotNull(testUser1HistoricalPasswords);
+            assertEquals(1, testUser1HistoricalPasswords.size());
+            testUser1HistoricalPassword = testUser1HistoricalPasswords.get(0);
+            assertNotNull(testUser1HistoricalPassword);
+
+            // create permissions
+            testPermission1 = new PersistentJetspeedPermissionImpl(TEST_PERMISSION_TYPE, TEST_PERMISSION_1);
+            ((PersistentJetspeedPermission) testPermission1).setActions(TEST_PERMISSION_1);
+            jspm.addPermission((PersistentJetspeedPermission) testPermission1);
+            testPermission1 = jspm.getPermissions(TEST_PERMISSION_TYPE, TEST_PERMISSION_1).get(0);
+            assertNotNull(testPermission1);
+            testPermission2 = new PersistentJetspeedPermissionImpl(TEST_PERMISSION_TYPE, TEST_PERMISSION_2);
+            ((PersistentJetspeedPermission) testPermission2).setActions(TEST_PERMISSION_2);
+            jspm.addPermission((PersistentJetspeedPermission) testPermission2);
+            testPermission2 = jspm.getPermissions(TEST_PERMISSION_TYPE, TEST_PERMISSION_2).get(0);
+            assertNotNull(testPermission2);
+
+            // grant principal permissions
+            jspm.grantPermission((PersistentJetspeedPermission) testPermission1, testUser1);
+            jspm.grantPermission((PersistentJetspeedPermission) testPermission2, testGroup1);
+            jspm.grantPermission((PersistentJetspeedPermission) testPermission1, testRole2);
+            jspm.grantPermission((PersistentJetspeedPermission) testPermission2, testUser2);
+
+            // create principal associations
+            jspm.addAssociation(testGroup1, testRole1, JetspeedPrincipalAssociationType.IS_MEMBER_OF);
+            jspm.addAssociation(testGroup2, testRole2, JetspeedPrincipalAssociationType.IS_MEMBER_OF);
+            jspm.addAssociation(testUser1, testRole1, JetspeedPrincipalAssociationType.IS_MEMBER_OF);
+            jspm.addAssociation(testUser2, testRole2, JetspeedPrincipalAssociationType.IS_MEMBER_OF);
+            jspm.addAssociation(testUser1, testGroup1, JetspeedPrincipalAssociationType.IS_MEMBER_OF);
+            jspm.addAssociation(testUser2, testGroup2, JetspeedPrincipalAssociationType.IS_MEMBER_OF);
+
+            // commit transaction
+            commitTransaction();
+
+            // clear cache after creates
+            jspmCache.clear();
+
+            // begin transaction
+            beginTransaction();
+
+            // test principal cache queries
+            int cacheSize = jspmCache.size();
+            jspm.getPrincipalId(TEST_USER_1, userType.getName(), testDomain1.getDomainId());
+            try
+            {
+                jspm.getPrincipalId("NOT-A-USER", userType.getName(), testDomain1.getDomainId());
+                fail("Expected SecurityException for missing principalId");
+            }
+            catch (SecurityException se)
+            {
+            }
+            assertEquals(2, jspmCache.size() - cacheSize);
+            jspm.getPrincipalId(TEST_USER_1, userType.getName(), testDomain1.getDomainId());
+            try
+            {
+                jspm.getPrincipalId("NOT-A-USER", userType.getName(), testDomain1.getDomainId());
+                fail("Expected SecurityException for missing principalId");
+            }
+            catch (SecurityException se)
+            {
+            }
+            assertEquals(2, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            assertTrue(jspm.principalExists(testGroup1));
+            PersistentJetspeedPrincipal notAGroup = new GroupImpl("NOT-A-GROUP");
+            notAGroup.setDomainId(testDomain1.getDomainId());
+            setPrincipalId(notAGroup, new Long(-1L));
+            assertFalse(jspm.principalExists(notAGroup));
+            assertEquals(2, jspmCache.size() - cacheSize);
+            assertTrue(jspm.principalExists(testGroup1));
+            assertFalse(jspm.principalExists(notAGroup));
+            assertEquals(2, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            assertNotNull(jspm.getPrincipal(testUser1.getId()));
+            assertNull(jspm.getPrincipal(new Long(-1L)));
+            assertEquals(2, jspmCache.size() - cacheSize);
+            assertNotNull(jspm.getPrincipal(testUser1.getId()));
+            assertNull(jspm.getPrincipal(new Long(-1L)));
+            assertEquals(2, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            assertNotNull(jspm.getPrincipal(TEST_USER_1, userType, testDomain1.getDomainId()));
+            assertNull(jspm.getPrincipal("NOT-A-USER", userType, testDomain1.getDomainId()));
+            assertEquals(2, jspmCache.size() - cacheSize);
+            assertNotNull(jspm.getPrincipal(TEST_USER_1, userType, testDomain1.getDomainId()));
+            assertNull(jspm.getPrincipal("NOT-A-USER", userType, testDomain1.getDomainId()));
+            assertEquals(2, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            List<String> principalNames = jspm.getPrincipalNames("", userType, testDomain1.getDomainId());
+            assertNotNull(principalNames);
+            assertEquals(2, principalNames.size());
+            principalNames = jspm.getPrincipalNames("NOT-", userType, testDomain1.getDomainId());
+            assertNotNull(principalNames);
+            assertEquals(0, principalNames.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            principalNames = jspm.getPrincipalNames("", userType, testDomain1.getDomainId());
+            assertNotNull(principalNames);
+            assertEquals(2, principalNames.size());
+            principalNames = jspm.getPrincipalNames("NOT-", userType, testDomain1.getDomainId());
+            assertNotNull(principalNames);
+            assertEquals(0, principalNames.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            List<JetspeedPrincipal> principals = jspm.getPrincipals("", userType, testDomain1.getDomainId());
+            assertNotNull(principals);
+            assertEquals(2, principals.size());
+            principals = jspm.getPrincipals("NOT-", userType, testDomain1.getDomainId());
+            assertNotNull(principals);
+            assertEquals(0, principals.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            principals = jspm.getPrincipals("", userType, testDomain1.getDomainId());
+            assertNotNull(principals);
+            assertEquals(2, principals.size());
+            principals = jspm.getPrincipals("NOT-", userType, testDomain1.getDomainId());
+            assertNotNull(principals);
+            assertEquals(0, principals.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            principals = jspm.getPrincipalsByAttribute("user.name", TEST_USER_1, userType, testDomain1.getDomainId());
+            assertNotNull(principals);
+            assertEquals(1, principals.size());
+            principals = jspm.getPrincipalsByAttribute("user.name", "NOT-A-USER", userType, testDomain1.getDomainId());
+            assertNotNull(principals);
+            assertEquals(0, principals.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            principals = jspm.getPrincipalsByAttribute("user.name", TEST_USER_1, userType, testDomain1.getDomainId());
+            assertNotNull(principals);
+            assertEquals(1, principals.size());
+            principals = jspm.getPrincipalsByAttribute("user.name", "NOT-A-USER", userType, testDomain1.getDomainId());
+            assertNotNull(principals);
+            assertEquals(0, principals.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            assertTrue(jspm.principalExists(TEST_GROUP_2, groupType, testDomain1.getDomainId()));
+            assertFalse(jspm.principalExists("NOT-A-GROUP", groupType, testDomain1.getDomainId()));
+            assertEquals(3, jspmCache.size() - cacheSize);
+            assertTrue(jspm.principalExists(TEST_GROUP_2, groupType, testDomain1.getDomainId()));
+            assertFalse(jspm.principalExists("NOT-A-GROUP", groupType, testDomain1.getDomainId()));
+            assertEquals(3, jspmCache.size() - cacheSize);
+
+            // test association cache queries
+            cacheSize = jspmCache.size();
+            List<JetspeedPrincipal> associatedFrom = jspm.getAssociatedFrom(TEST_USER_1, userType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedFrom);
+            assertEquals(1, associatedFrom.size());
+            associatedFrom = jspm.getAssociatedFrom(TEST_USER_1, userType, userType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedFrom);
+            assertEquals(0, associatedFrom.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            associatedFrom = jspm.getAssociatedFrom(TEST_USER_1, userType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedFrom);
+            assertEquals(1, associatedFrom.size());
+            associatedFrom = jspm.getAssociatedFrom(TEST_USER_1, userType, userType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedFrom);
+            assertEquals(0, associatedFrom.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            List<JetspeedPrincipal> associatedTo = jspm.getAssociatedTo(TEST_ROLE_2, userType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedTo);
+            assertEquals(1, associatedTo.size());
+            associatedTo = jspm.getAssociatedTo(TEST_ROLE_2, roleType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedTo);
+            assertEquals(0, associatedTo.size());
+            assertEquals(3, jspmCache.size() - cacheSize);
+            associatedTo = jspm.getAssociatedTo(TEST_ROLE_2, userType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedTo);
+            assertEquals(1, associatedTo.size());
+            associatedTo = jspm.getAssociatedTo(TEST_ROLE_2, roleType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedTo);
+            assertEquals(0, associatedTo.size());
+            assertEquals(3, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            associatedFrom = jspm.getAssociatedFrom(testUser2.getId(), userType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedFrom);
+            assertEquals(1, associatedFrom.size());
+            associatedFrom = jspm.getAssociatedFrom(testUser2.getId(), userType, userType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedFrom);
+            assertEquals(0, associatedFrom.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            associatedFrom = jspm.getAssociatedFrom(testUser2.getId(), userType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedFrom);
+            assertEquals(1, associatedFrom.size());
+            associatedFrom = jspm.getAssociatedFrom(testUser2.getId(), userType, userType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedFrom);
+            assertEquals(0, associatedFrom.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            associatedTo = jspm.getAssociatedTo(testRole1.getId(), userType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedTo);
+            assertEquals(1, associatedTo.size());
+            associatedTo = jspm.getAssociatedTo(testRole1.getId(), roleType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedTo);
+            assertEquals(0, associatedTo.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            associatedTo = jspm.getAssociatedTo(testRole1.getId(), userType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedTo);
+            assertEquals(1, associatedTo.size());
+            associatedTo = jspm.getAssociatedTo(testRole1.getId(), roleType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedTo);
+            assertEquals(0, associatedTo.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            List<String> associatedNamesFrom = jspm.getAssociatedNamesFrom(TEST_USER_1, userType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedNamesFrom);
+            assertEquals(1, associatedNamesFrom.size());
+            associatedNamesFrom = jspm.getAssociatedNamesFrom(TEST_USER_1, userType, userType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedNamesFrom);
+            assertEquals(0, associatedNamesFrom.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            associatedNamesFrom = jspm.getAssociatedNamesFrom(TEST_USER_1, userType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedNamesFrom);
+            assertEquals(1, associatedNamesFrom.size());
+            associatedNamesFrom = jspm.getAssociatedNamesFrom(TEST_USER_1, userType, userType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedNamesFrom);
+            assertEquals(0, associatedNamesFrom.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            List<String> associatedNamesTo = jspm.getAssociatedNamesTo(TEST_ROLE_2, userType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedNamesTo);
+            assertEquals(1, associatedNamesTo.size());
+            associatedNamesTo = jspm.getAssociatedNamesTo(TEST_ROLE_2, roleType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedNamesTo);
+            assertEquals(0, associatedNamesTo.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            associatedNamesTo = jspm.getAssociatedNamesTo(TEST_ROLE_2, userType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedNamesTo);
+            assertEquals(1, associatedNamesTo.size());
+            associatedNamesTo = jspm.getAssociatedNamesTo(TEST_ROLE_2, roleType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedNamesTo);
+            assertEquals(0, associatedNamesTo.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            associatedNamesFrom = jspm.getAssociatedNamesFrom(testUser2.getId(), userType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedNamesFrom);
+            assertEquals(1, associatedNamesFrom.size());
+            associatedNamesFrom = jspm.getAssociatedNamesFrom(testUser2.getId(), userType, userType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedNamesFrom);
+            assertEquals(0, associatedNamesFrom.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            associatedNamesFrom = jspm.getAssociatedNamesFrom(testUser2.getId(), userType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedNamesFrom);
+            assertEquals(1, associatedNamesFrom.size());
+            associatedNamesFrom = jspm.getAssociatedNamesFrom(testUser2.getId(), userType, userType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedNamesFrom);
+            assertEquals(0, associatedNamesFrom.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            associatedNamesTo = jspm.getAssociatedNamesTo(testRole1.getId(), userType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedNamesTo);
+            assertEquals(1, associatedNamesTo.size());
+            associatedNamesTo = jspm.getAssociatedNamesTo(testRole1.getId(), roleType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedNamesTo);
+            assertEquals(0, associatedNamesTo.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            associatedNamesTo = jspm.getAssociatedNamesTo(testRole1.getId(), userType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedNamesTo);
+            assertEquals(1, associatedNamesTo.size());
+            associatedNamesTo = jspm.getAssociatedNamesTo(testRole1.getId(), roleType, roleType,
+                    JetspeedPrincipalAssociationType.IS_MEMBER_OF, testDomain1.getDomainId(), testDomain1.getDomainId());
+            assertNotNull(associatedNamesTo);
+            assertEquals(0, associatedNamesTo.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+
+            // test password credential cache queries
+            cacheSize = jspmCache.size();
+            testUser1Password = jspm.getPasswordCredential(testUser1);
+            assertNotNull(testUser1Password);
+            PasswordCredential testUser2Password = jspm.getPasswordCredential(testUser2);
+            assertNotNull(testUser2Password);
+            assertEquals(1, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            testUser1Password = jspm.getPasswordCredential(TEST_USER_1, testDomain1.getDomainId());
+            assertNotNull(testUser1Password);
+            testUser2Password = jspm.getPasswordCredential(TEST_USER_2, testDomain1.getDomainId());
+            assertNull(testUser2Password);
+            assertEquals(2, jspmCache.size() - cacheSize);
+            testUser1Password = jspm.getPasswordCredential(TEST_USER_1, testDomain1.getDomainId());
+            assertNotNull(testUser1Password);
+            testUser2Password = jspm.getPasswordCredential(TEST_USER_2, testDomain1.getDomainId());
+            assertNull(testUser2Password);
+            assertEquals(2, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            testUser1HistoricalPasswords = jspm.getHistoricPasswordCredentials(testUser1, testDomain1.getDomainId());
+            assertNotNull(testUser1HistoricalPasswords);
+            assertEquals(1, testUser1HistoricalPasswords.size());
+            List<PasswordCredential> testUser2HistoricalPasswords = jspm.getHistoricPasswordCredentials(testUser2,
+                    testDomain1.getDomainId());
+            assertNotNull(testUser2HistoricalPasswords);
+            assertEquals(0, testUser2HistoricalPasswords.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            testUser1HistoricalPasswords = jspm.getHistoricPasswordCredentials(testUser1, testDomain1.getDomainId());
+            assertNotNull(testUser1HistoricalPasswords);
+            assertEquals(1, testUser1HistoricalPasswords.size());
+            testUser2HistoricalPasswords = jspm.getHistoricPasswordCredentials(testUser2, testDomain1.getDomainId());
+            assertNotNull(testUser2HistoricalPasswords);
+            assertEquals(0, testUser2HistoricalPasswords.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+
+            // test permission cache queries
+            cacheSize = jspmCache.size();
+            List<PersistentJetspeedPermission> permissions = jspm.getPermissions();
+            assertNotNull(permissions);
+            assertEquals(2, permissions.size());
+            assertEquals(1, jspmCache.size() - cacheSize);
+            permissions = jspm.getPermissions();
+            assertNotNull(permissions);
+            assertEquals(2, permissions.size());
+            assertEquals(1, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            permissions = jspm.getPermissions(TEST_PERMISSION_TYPE, TEST_PERMISSION_1);
+            assertNotNull(permissions);
+            assertEquals(1, permissions.size());
+            permissions = jspm.getPermissions(TEST_PERMISSION_TYPE, "NOT-A-PERMISSION");
+            assertNotNull(permissions);
+            assertEquals(0, permissions.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            permissions = jspm.getPermissions(TEST_PERMISSION_TYPE, TEST_PERMISSION_1);
+            assertNotNull(permissions);
+            assertEquals(1, permissions.size());
+            permissions = jspm.getPermissions(TEST_PERMISSION_TYPE, "NOT-A-PERMISSION");
+            assertNotNull(permissions);
+            assertEquals(0, permissions.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            assertTrue(jspm.permissionExists(testPermission2));
+            assertFalse(jspm.permissionExists(new PersistentJetspeedPermissionImpl(TEST_PERMISSION_TYPE,
+                    "NOT-A-PERMISSION")));
+            assertEquals(2, jspmCache.size() - cacheSize);
+            assertTrue(jspm.permissionExists(testPermission2));
+            assertFalse(jspm.permissionExists(new PersistentJetspeedPermissionImpl(TEST_PERMISSION_TYPE,
+                    "NOT-A-PERMISSION")));
+            assertEquals(2, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            permissions = jspm.getPermissions((PersistentJetspeedPrincipal) testUser1);
+            assertNotNull(permissions);
+            assertEquals(1, permissions.size());
+            permissions = jspm.getPermissions((PersistentJetspeedPrincipal) testRole1);
+            assertNotNull(permissions);
+            assertEquals(0, permissions.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            permissions = jspm.getPermissions((PersistentJetspeedPrincipal) testUser1);
+            assertNotNull(permissions);
+            assertEquals(1, permissions.size());
+            permissions = jspm.getPermissions((PersistentJetspeedPrincipal) testRole1);
+            assertNotNull(permissions);
+            assertEquals(0, permissions.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            principals = jspm.getPrincipals((PersistentJetspeedPermission) testPermission1, null,
+                    testDomain1.getDomainId());
+            assertNotNull(principals);
+            assertEquals(2, principals.size());
+            principals = jspm.getPrincipals((PersistentJetspeedPermission) testPermission1, groupType.getName(),
+                    testDomain1.getDomainId());
+            assertNotNull(principals);
+            assertEquals(0, principals.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            principals = jspm.getPrincipals((PersistentJetspeedPermission) testPermission1, null,
+                    testDomain1.getDomainId());
+            assertNotNull(principals);
+            assertEquals(2, principals.size());
+            principals = jspm.getPrincipals((PersistentJetspeedPermission) testPermission1, groupType.getName(),
+                    testDomain1.getDomainId());
+            assertNotNull(principals);
+            assertEquals(0, principals.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+
+            // test domain cache queries
+            cacheSize = jspmCache.size();
+            assertNotNull(jspm.getDomain(testDomain1.getDomainId()));
+            assertNull(jspm.getDomain(new Long(-1L)));
+            assertEquals(2, jspmCache.size() - cacheSize);
+            assertNotNull(jspm.getDomain(testDomain1.getDomainId()));
+            assertNull(jspm.getDomain(new Long(-1L)));
+            assertEquals(2, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            assertNotNull(jspm.getDomainByName(TEST_DOMAIN_1));
+            assertNull(jspm.getDomainByName("NOT-A-DOMAIN"));
+            assertEquals(2, jspmCache.size() - cacheSize);
+            assertNotNull(jspm.getDomainByName(TEST_DOMAIN_1));
+            assertNull(jspm.getDomainByName("NOT-A-DOMAIN"));
+            assertEquals(2, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            Collection<SecurityDomain> domains = jspm.getAllDomains();
+            assertNotNull(domains);
+            assertEquals(3, domains.size());
+            assertEquals(1, jspmCache.size() - cacheSize);
+            domains = jspm.getAllDomains();
+            assertNotNull(domains);
+            assertEquals(3, domains.size());
+            assertEquals(1, jspmCache.size() - cacheSize);
+            cacheSize = jspmCache.size();
+            domains = jspm.getDomainsOwnedBy(defaultDomain.getDomainId());
+            assertNotNull(domains);
+            assertEquals(1, domains.size());
+            domains = jspm.getDomainsOwnedBy(testDomain1.getDomainId());
+            assertNotNull(domains);
+            assertEquals(0, domains.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+            domains = jspm.getDomainsOwnedBy(defaultDomain.getDomainId());
+            assertNotNull(domains);
+            assertEquals(1, domains.size());
+            domains = jspm.getDomainsOwnedBy(testDomain1.getDomainId());
+            assertNotNull(domains);
+            assertEquals(0, domains.size());
+            assertEquals(2, jspmCache.size() - cacheSize);
+
+            // commit transaction
+            commitTransaction();
+        }
+        finally
+        {
+            rollbackTransaction();
+        }
+    }
+
+    /**
+     * Begin transaction on current thread.
+     */
+    private void beginTransaction()
+    {
+        txn = txnManager.getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED));
+    }
+
+    /**
+     * Commit transaction on current thread.
+     */
+    private void commitTransaction()
+    {
+        if (txn != null)
+        {
+            txnManager.commit(txn);
+            txn = null;
+        }
+    }
+
+    /**
+     * Rollback transaction on current thread.
+     */
+    private void rollbackTransaction()
+    {
+        try
+        {
+            if (txn != null)
+            {
+                txnManager.rollback(txn);
+                txn = null;
+            }
+        }
+        catch (Exception e)
+        {
+            txn = null;
+        }
+    }
+
+    /**
+     * Force set principal id via reflection for test.
+     *
+     * @param principal principal to modify
+     * @param id principal id to set
+     */
+    private static void setPrincipalId(PersistentJetspeedPrincipal principal, Long id)
+    {
+        Field idField = ReflectionUtils.findField(principal.getClass(), "id");
+        ReflectionUtils.makeAccessible(idField);
+        ReflectionUtils.setField(idField, principal, id);
+    }
+
+    /**
+     * Force set password credential type via reflection for test.
+     *
+     * @param passwordCredential password credential to modify
+     * @param type password credential type to set
+     */
+    private static void setPasswordCredentialType(PasswordCredential passwordCredential, Short type)
+    {
+        Field typeField = ReflectionUtils.findField(passwordCredential.getClass(), "type");
+        ReflectionUtils.makeAccessible(typeField);
+        ReflectionUtils.setField(typeField, passwordCredential, type);
+    }
+}

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/resources/cache-test.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/resources/cache-test.xml?rev=1678139&r1=1678138&r2=1678139&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/resources/cache-test.xml (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/resources/cache-test.xml Thu May  7 06:48:06 2015
@@ -330,4 +330,105 @@
         <constructor-arg><ref bean="ehPageManagerPrincipalPropertiesPathCache"/></constructor-arg>
     </bean>
     
+    <!-- Jetspeed Security Persistence Manager Caches -->
+    <bean id="ehJSPMPrincipalCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
+        <meta key="j2:cat" value="default or cache"/>
+        <property name="cacheManager" ref="cacheManager"/>
+        <property name="cacheName" value="jspmPrincipalCache"/>
+    </bean>
+
+    <bean id="ehJSPMPermissionCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
+        <meta key="j2:cat" value="default or cache"/>
+        <property name="cacheManager" ref="cacheManager"/>
+        <property name="cacheName" value="jspmPermissionCache"/>
+    </bean>
+
+    <bean id="ehJSPMDomainCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
+        <meta key="j2:cat" value="default or cache"/>
+        <property name="cacheManager" ref="cacheManager"/>
+        <property name="cacheName" value="jspmDomainCache"/>
+    </bean>
+
+    <bean id="ehJSPMPrincipalQueryCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
+        <meta key="j2:cat" value="default or cache"/>
+        <property name="cacheManager" ref="cacheManager"/>
+        <property name="cacheName" value="jspmPrincipalQueryCache"/>
+    </bean>
+
+    <bean id="ehJSPMAssociationQueryCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
+        <meta key="j2:cat" value="default or cache"/>
+        <property name="cacheManager" ref="cacheManager"/>
+        <property name="cacheName" value="jspmAssociationQueryCache"/>
+    </bean>
+
+    <bean id="ehJSPMPasswordCredentialQueryCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
+        <meta key="j2:cat" value="default or cache"/>
+        <property name="cacheManager" ref="cacheManager"/>
+        <property name="cacheName" value="jspmPasswordCredentialQueryCache"/>
+    </bean>
+
+    <bean id="ehJSPMPermissionQueryCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
+        <meta key="j2:cat" value="default or cache"/>
+        <property name="cacheManager" ref="cacheManager"/>
+        <property name="cacheName" value="jspmPermissionQueryCache"/>
+    </bean>
+
+    <bean id="ehJSPMDomainQueryCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
+        <meta key="j2:cat" value="default or cache"/>
+        <property name="cacheManager" ref="cacheManager"/>
+        <property name="cacheName" value="jspmDomainQueryCache"/>
+    </bean>
+
+    <bean id="jspmPrincipalCache" class="org.apache.jetspeed.cache.impl.EhCacheDistributedImpl">
+        <meta key="j2:cat" value="default or cache"/>
+        <constructor-arg><ref bean="ehJSPMPrincipalCache"/></constructor-arg>
+    </bean>
+
+    <bean id="jspmPermissionCache" class="org.apache.jetspeed.cache.impl.EhCacheDistributedImpl">
+        <meta key="j2:cat" value="default or cache"/>
+        <constructor-arg><ref bean="ehJSPMPermissionCache"/></constructor-arg>
+    </bean>
+
+    <bean id="jspmDomainCache" class="org.apache.jetspeed.cache.impl.EhCacheDistributedImpl">
+        <meta key="j2:cat" value="default or cache"/>
+        <constructor-arg><ref bean="ehJSPMDomainCache"/></constructor-arg>
+    </bean>
+
+    <bean id="jspmPrincipalQueryCache" class="org.apache.jetspeed.security.spi.impl.cache.JSPMQueryEhCacheImpl">
+        <meta key="j2:cat" value="default or cache"/>
+        <constructor-arg><ref bean="ehJSPMPrincipalQueryCache"/></constructor-arg>
+    </bean>
+    
+    <bean id="jspmAssociationQueryCache" class="org.apache.jetspeed.security.spi.impl.cache.JSPMQueryEhCacheImpl">
+        <meta key="j2:cat" value="default or cache"/>
+        <constructor-arg><ref bean="ehJSPMAssociationQueryCache"/></constructor-arg>
+    </bean>
+
+    <bean id="jspmPasswordCredentialQueryCache" class="org.apache.jetspeed.security.spi.impl.cache.JSPMQueryEhCacheImpl">
+        <meta key="j2:cat" value="default or cache"/>
+        <constructor-arg><ref bean="ehJSPMPasswordCredentialQueryCache"/></constructor-arg>
+    </bean>
+
+    <bean id="jspmPermissionQueryCache" class="org.apache.jetspeed.security.spi.impl.cache.JSPMQueryEhCacheImpl">
+        <meta key="j2:cat" value="default or cache"/>
+        <constructor-arg><ref bean="ehJSPMPermissionQueryCache"/></constructor-arg>
+    </bean>
+
+    <bean id="jspmDomainQueryCache" class="org.apache.jetspeed.security.spi.impl.cache.JSPMQueryEhCacheImpl">
+        <meta key="j2:cat" value="default or cache"/>
+        <constructor-arg><ref bean="ehJSPMDomainQueryCache"/></constructor-arg>
+    </bean>
+
+    <bean id="org.apache.jetspeed.security.spi.impl.cache.JSPMCache" class="org.apache.jetspeed.security.spi.impl.cache.JSPMCacheImpl"
+          init-method="initialize" destroy-method="terminate">
+        <meta key="j2:cat" value="default or cache"/>
+        <constructor-arg><ref bean="jspmPrincipalCache"/></constructor-arg>
+        <constructor-arg><ref bean="jspmPermissionCache"/></constructor-arg>
+        <constructor-arg><ref bean="jspmDomainCache"/></constructor-arg>
+        <constructor-arg><ref bean="jspmPrincipalQueryCache"/></constructor-arg>
+        <constructor-arg><ref bean="jspmAssociationQueryCache"/></constructor-arg>
+        <constructor-arg><ref bean="jspmPasswordCredentialQueryCache"/></constructor-arg>
+        <constructor-arg><ref bean="jspmPermissionQueryCache"/></constructor-arg>
+        <constructor-arg><ref bean="jspmDomainQueryCache"/></constructor-arg>
+    </bean>
 </beans>

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-sso/src/test/resources/cache-test.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-sso/src/test/resources/cache-test.xml?rev=1678139&r1=1678138&r2=1678139&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-sso/src/test/resources/cache-test.xml (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-sso/src/test/resources/cache-test.xml Thu May  7 06:48:06 2015
@@ -334,4 +334,105 @@
           class="org.apache.jetspeed.sso.StubPortletPreferences">
     </bean>
 
+    <!-- Jetspeed Security Persistence Manager Caches -->
+    <bean id="ehJSPMPrincipalCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
+        <meta key="j2:cat" value="default or cache"/>
+        <property name="cacheManager" ref="cacheManager"/>
+        <property name="cacheName" value="jspmPrincipalCache"/>
+    </bean>
+
+    <bean id="ehJSPMPermissionCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
+        <meta key="j2:cat" value="default or cache"/>
+        <property name="cacheManager" ref="cacheManager"/>
+        <property name="cacheName" value="jspmPermissionCache"/>
+    </bean>
+
+    <bean id="ehJSPMDomainCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
+        <meta key="j2:cat" value="default or cache"/>
+        <property name="cacheManager" ref="cacheManager"/>
+        <property name="cacheName" value="jspmDomainCache"/>
+    </bean>
+
+    <bean id="ehJSPMPrincipalQueryCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
+        <meta key="j2:cat" value="default or cache"/>
+        <property name="cacheManager" ref="cacheManager"/>
+        <property name="cacheName" value="jspmPrincipalQueryCache"/>
+    </bean>
+
+    <bean id="ehJSPMAssociationQueryCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
+        <meta key="j2:cat" value="default or cache"/>
+        <property name="cacheManager" ref="cacheManager"/>
+        <property name="cacheName" value="jspmAssociationQueryCache"/>
+    </bean>
+
+    <bean id="ehJSPMPasswordCredentialQueryCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
+        <meta key="j2:cat" value="default or cache"/>
+        <property name="cacheManager" ref="cacheManager"/>
+        <property name="cacheName" value="jspmPasswordCredentialQueryCache"/>
+    </bean>
+
+    <bean id="ehJSPMPermissionQueryCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
+        <meta key="j2:cat" value="default or cache"/>
+        <property name="cacheManager" ref="cacheManager"/>
+        <property name="cacheName" value="jspmPermissionQueryCache"/>
+    </bean>
+
+    <bean id="ehJSPMDomainQueryCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
+        <meta key="j2:cat" value="default or cache"/>
+        <property name="cacheManager" ref="cacheManager"/>
+        <property name="cacheName" value="jspmDomainQueryCache"/>
+    </bean>
+
+    <bean id="jspmPrincipalCache" class="org.apache.jetspeed.cache.impl.EhCacheDistributedImpl">
+        <meta key="j2:cat" value="default or cache"/>
+        <constructor-arg><ref bean="ehJSPMPrincipalCache"/></constructor-arg>
+    </bean>
+
+    <bean id="jspmPermissionCache" class="org.apache.jetspeed.cache.impl.EhCacheDistributedImpl">
+        <meta key="j2:cat" value="default or cache"/>
+        <constructor-arg><ref bean="ehJSPMPermissionCache"/></constructor-arg>
+    </bean>
+
+    <bean id="jspmDomainCache" class="org.apache.jetspeed.cache.impl.EhCacheDistributedImpl">
+        <meta key="j2:cat" value="default or cache"/>
+        <constructor-arg><ref bean="ehJSPMDomainCache"/></constructor-arg>
+    </bean>
+
+    <bean id="jspmPrincipalQueryCache" class="org.apache.jetspeed.security.spi.impl.cache.JSPMQueryEhCacheImpl">
+        <meta key="j2:cat" value="default or cache"/>
+        <constructor-arg><ref bean="ehJSPMPrincipalQueryCache"/></constructor-arg>
+    </bean>
+    
+    <bean id="jspmAssociationQueryCache" class="org.apache.jetspeed.security.spi.impl.cache.JSPMQueryEhCacheImpl">
+        <meta key="j2:cat" value="default or cache"/>
+        <constructor-arg><ref bean="ehJSPMAssociationQueryCache"/></constructor-arg>
+    </bean>
+
+    <bean id="jspmPasswordCredentialQueryCache" class="org.apache.jetspeed.security.spi.impl.cache.JSPMQueryEhCacheImpl">
+        <meta key="j2:cat" value="default or cache"/>
+        <constructor-arg><ref bean="ehJSPMPasswordCredentialQueryCache"/></constructor-arg>
+    </bean>
+
+    <bean id="jspmPermissionQueryCache" class="org.apache.jetspeed.security.spi.impl.cache.JSPMQueryEhCacheImpl">
+        <meta key="j2:cat" value="default or cache"/>
+        <constructor-arg><ref bean="ehJSPMPermissionQueryCache"/></constructor-arg>
+    </bean>
+
+    <bean id="jspmDomainQueryCache" class="org.apache.jetspeed.security.spi.impl.cache.JSPMQueryEhCacheImpl">
+        <meta key="j2:cat" value="default or cache"/>
+        <constructor-arg><ref bean="ehJSPMDomainQueryCache"/></constructor-arg>
+    </bean>
+
+    <bean id="org.apache.jetspeed.security.spi.impl.cache.JSPMCache" class="org.apache.jetspeed.security.spi.impl.cache.JSPMCacheImpl"
+          init-method="initialize" destroy-method="terminate">
+        <meta key="j2:cat" value="default or cache"/>
+        <constructor-arg><ref bean="jspmPrincipalCache"/></constructor-arg>
+        <constructor-arg><ref bean="jspmPermissionCache"/></constructor-arg>
+        <constructor-arg><ref bean="jspmDomainCache"/></constructor-arg>
+        <constructor-arg><ref bean="jspmPrincipalQueryCache"/></constructor-arg>
+        <constructor-arg><ref bean="jspmAssociationQueryCache"/></constructor-arg>
+        <constructor-arg><ref bean="jspmPasswordCredentialQueryCache"/></constructor-arg>
+        <constructor-arg><ref bean="jspmPermissionQueryCache"/></constructor-arg>
+        <constructor-arg><ref bean="jspmDomainQueryCache"/></constructor-arg>
+    </bean>
 </beans>

Added: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/cache/JetspeedCacheEventAdapter.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/cache/JetspeedCacheEventAdapter.java?rev=1678139&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/cache/JetspeedCacheEventAdapter.java (added)
+++ portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/cache/JetspeedCacheEventAdapter.java Thu May  7 06:48:06 2015
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.cache;
+
+/**
+ * JetspeedCacheEventAdapter - JetspeedCacheEventListener adapter
+ *
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id: $
+ */
+public class JetspeedCacheEventAdapter implements JetspeedCacheEventListener {
+
+    @Override
+    public void notifyElementRemoved(JetspeedCache cache, boolean local, Object key, Object element) {
+    }
+
+    @Override
+    public void notifyElementAdded(JetspeedCache cache, boolean local, Object key, Object element) {
+    }
+
+    @Override
+    public void notifyElementChanged(JetspeedCache cache, boolean local, Object key, Object element) {
+    }
+
+    @Override
+    public void notifyElementEvicted(JetspeedCache cache, boolean local, Object key, Object element) {
+    }
+
+    @Override
+    public void notifyElementExpired(JetspeedCache cache, boolean local, Object key, Object element) {
+    }
+}

Modified: portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/alternate/credentials/security-spi.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/alternate/credentials/security-spi.xml?rev=1678139&r1=1678138&r2=1678139&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/alternate/credentials/security-spi.xml (original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/alternate/credentials/security-spi.xml Thu May  7 06:48:06 2015
@@ -43,6 +43,9 @@
     <constructor-arg index="1">
       <ref bean="org.apache.jetspeed.security.spi.impl.JetspeedPrincipalLookupManagerFactory"/>
     </constructor-arg>
+    <constructor-arg index="2">
+      <ref bean="org.apache.jetspeed.security.spi.impl.cache.JSPMCache"/>
+    </constructor-arg>
   </bean>
   
   <bean id="org.apache.jetspeed.security.spi.JetspeedSecurityPersistenceManager" parent="baseTransactionProxy">



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message