Search in sources :

Example 16 with Element

use of net.sf.ehcache.Element in project spring-security by spring-projects.

the class EhCacheBasedAclCacheTests method evictCacheSerializable.

@Test
public void evictCacheSerializable() throws Exception {
    when(cache.get(acl.getObjectIdentity())).thenReturn(new Element(acl.getId(), acl));
    myCache.evictFromCache(acl.getObjectIdentity());
    verify(cache).remove(acl.getId());
    verify(cache).remove(acl.getObjectIdentity());
}
Also used : Element(net.sf.ehcache.Element) Test(org.junit.Test)

Example 17 with Element

use of net.sf.ehcache.Element in project spring-security by spring-projects.

the class EhCacheBasedAclCacheTests method putInCacheAclWithParent.

@Test
public void putInCacheAclWithParent() throws Exception {
    Authentication auth = new TestingAuthenticationToken("user", "password", "ROLE_GENERAL");
    auth.setAuthenticated(true);
    SecurityContextHolder.getContext().setAuthentication(auth);
    ObjectIdentity identityParent = new ObjectIdentityImpl(TARGET_CLASS, Long.valueOf(2));
    AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl(new SimpleGrantedAuthority("ROLE_OWNERSHIP"), new SimpleGrantedAuthority("ROLE_AUDITING"), new SimpleGrantedAuthority("ROLE_GENERAL"));
    MutableAcl parentAcl = new AclImpl(identityParent, Long.valueOf(2), aclAuthorizationStrategy, new ConsoleAuditLogger());
    acl.setParent(parentAcl);
    myCache.putInCache(acl);
    verify(cache, times(4)).put(element.capture());
    List<Element> allValues = element.getAllValues();
    assertThat(allValues.get(0).getKey()).isEqualTo(parentAcl.getObjectIdentity());
    assertThat(allValues.get(0).getObjectValue()).isEqualTo(parentAcl);
    assertThat(allValues.get(1).getKey()).isEqualTo(parentAcl.getId());
    assertThat(allValues.get(1).getObjectValue()).isEqualTo(parentAcl);
    assertThat(allValues.get(2).getKey()).isEqualTo(acl.getObjectIdentity());
    assertThat(allValues.get(2).getObjectValue()).isEqualTo(acl);
    assertThat(allValues.get(3).getKey()).isEqualTo(acl.getId());
    assertThat(allValues.get(3).getObjectValue()).isEqualTo(acl);
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) Authentication(org.springframework.security.core.Authentication) Element(net.sf.ehcache.Element) MutableAcl(org.springframework.security.acls.model.MutableAcl) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 18 with Element

use of net.sf.ehcache.Element in project spring-security by spring-projects.

the class EhCacheBasedAclCacheTests method getFromCacheObjectIdentityPopulatesTransient.

@Test
public void getFromCacheObjectIdentityPopulatesTransient() throws Exception {
    when(cache.get(acl.getObjectIdentity())).thenReturn(new Element(acl.getId(), acl));
    myCache.putInCache(acl);
    ReflectionTestUtils.setField(acl, "permissionGrantingStrategy", null);
    ReflectionTestUtils.setField(acl, "aclAuthorizationStrategy", null);
    MutableAcl fromCache = myCache.getFromCache(acl.getObjectIdentity());
    assertThat(ReflectionTestUtils.getField(fromCache, "aclAuthorizationStrategy")).isNotNull();
    assertThat(ReflectionTestUtils.getField(fromCache, "permissionGrantingStrategy")).isNotNull();
}
Also used : Element(net.sf.ehcache.Element) MutableAcl(org.springframework.security.acls.model.MutableAcl) Test(org.junit.Test)

Example 19 with Element

use of net.sf.ehcache.Element in project spring-security by spring-projects.

the class EhCacheBasedAclCacheTests method getFromCacheObjectIdentity.

@Test
public void getFromCacheObjectIdentity() throws Exception {
    when(cache.get(acl.getId())).thenReturn(new Element(acl.getId(), acl));
    assertThat(myCache.getFromCache(acl.getId())).isEqualTo(acl);
}
Also used : Element(net.sf.ehcache.Element) Test(org.junit.Test)

Example 20 with Element

use of net.sf.ehcache.Element in project spring-security by spring-projects.

the class EhCacheBasedAclCache method getFromCache.

public MutableAcl getFromCache(Serializable pk) {
    Assert.notNull(pk, "Primary key (identifier) required");
    Element element = null;
    try {
        element = cache.get(pk);
    } catch (CacheException ignored) {
    }
    if (element == null) {
        return null;
    }
    return initializeTransientFields((MutableAcl) element.getValue());
}
Also used : CacheException(net.sf.ehcache.CacheException) Element(net.sf.ehcache.Element)

Aggregations

Element (net.sf.ehcache.Element)114 Test (org.junit.Test)21 CacheKey (org.apereo.portal.utils.cache.CacheKey)8 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 Cache (net.sf.ehcache.Cache)7 HashSet (java.util.HashSet)6 CacheException (net.sf.ehcache.CacheException)6 MalformedURLException (java.net.MalformedURLException)5 ConfigurationException (javax.naming.ConfigurationException)5 Ehcache (net.sf.ehcache.Ehcache)5 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)5 EntityIdentifier (org.apereo.portal.EntityIdentifier)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 URISyntaxException (java.net.URISyntaxException)4 SQLException (java.sql.SQLException)4 EntityExistsException (javax.persistence.EntityExistsException)4 RouteBuilder (org.apache.camel.builder.RouteBuilder)4 BaseCacheTest (org.apache.camel.component.BaseCacheTest)4