Example usage for org.springframework.security.access.method MethodSecurityMetadataSource getAttributes

List of usage examples for org.springframework.security.access.method MethodSecurityMetadataSource getAttributes

Introduction

In this page you can find the example usage for org.springframework.security.access.method MethodSecurityMetadataSource getAttributes.

Prototype

public Collection<ConfigAttribute> getAttributes(Method method, Class<?> targetClass);

Source Link

Usage

From source file:org.codehaus.groovy.grails.plugins.springsecurity.acl.ProxyAwareDelegatingMethodSecurityMetadataSource.java

/**
 * {@inheritDoc}/*from   w w w  . jav a2s .co m*/
 * @see org.springframework.security.access.method.MethodSecurityMetadataSource#getAttributes(
 *    java.lang.reflect.Method, java.lang.Class)
 */
public Collection<ConfigAttribute> getAttributes(final Method m, final Class<?> tc) {

    Method method = ProxyUtils.unproxy(m);
    Class<?> targetClass = ProxyUtils.unproxy(tc);

    DefaultCacheKey cacheKey = new DefaultCacheKey(method, targetClass);
    synchronized (_cache) {
        Collection<ConfigAttribute> cached = _cache.get(cacheKey);
        // Check for canonical value indicating there is no config attribute,
        if (cached == NULL_CONFIG_ATTRIBUTE) {
            return null;
        }

        if (cached != null) {
            return cached;
        }

        // No cached value, so query the sources to find a result
        Collection<ConfigAttribute> attributes = null;
        for (MethodSecurityMetadataSource s : _methodSecurityMetadataSources) {
            attributes = s.getAttributes(method, targetClass);
            if (attributes != null && !attributes.isEmpty()) {
                break;
            }
        }

        // Put it in the cache.
        if (attributes == null) {
            _cache.put(cacheKey, NULL_CONFIG_ATTRIBUTE);
            return null;
        }

        if (logger.isDebugEnabled()) {
            logger.debug("Adding security method [" + cacheKey + "] with attributes " + attributes);
        }

        _cache.put(cacheKey, attributes);

        return attributes;
    }
}

From source file:grails.plugin.springsecurity.acl.access.method.ProxyAwareDelegatingMethodSecurityMetadataSource.java

/**
 * {@inheritDoc}/*from  ww  w. j  ava2s .c o  m*/
 * @see org.springframework.security.access.method.MethodSecurityMetadataSource#getAttributes(
 *    java.lang.reflect.Method, java.lang.Class)
 */
public Collection<ConfigAttribute> getAttributes(final Method m, final Class<?> tc) {

    Method method = ProxyUtils.unproxy(m);
    Class<?> targetClass = ProxyUtils.unproxy(tc);

    DefaultCacheKey cacheKey = new DefaultCacheKey(method, targetClass);
    synchronized (cache) {
        Collection<ConfigAttribute> cached = cache.get(cacheKey);
        // Check for canonical value indicating there is no config attribute,
        if (cached == NULL_CONFIG_ATTRIBUTE) {
            return null;
        }

        if (cached != null) {
            return cached;
        }

        // No cached value, so query the sources to find a result
        Collection<ConfigAttribute> attributes = null;
        for (MethodSecurityMetadataSource s : methodSecurityMetadataSources) {
            attributes = s.getAttributes(method, targetClass);
            if (attributes != null && !attributes.isEmpty()) {
                break;
            }
        }

        // Put it in the cache.
        if (attributes == null) {
            cache.put(cacheKey, NULL_CONFIG_ATTRIBUTE);
            return null;
        }

        if (logger.isDebugEnabled()) {
            logger.debug("Adding security method [" + cacheKey + "] with attributes " + attributes);
        }

        cache.put(cacheKey, attributes);

        return attributes;
    }
}