001    /**
002     *   GRANITE DATA SERVICES
003     *   Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S.
004     *
005     *   This file is part of the Granite Data Services Platform.
006     *
007     *   Granite Data Services is free software; you can redistribute it and/or
008     *   modify it under the terms of the GNU Lesser General Public
009     *   License as published by the Free Software Foundation; either
010     *   version 2.1 of the License, or (at your option) any later version.
011     *
012     *   Granite Data Services is distributed in the hope that it will be useful,
013     *   but WITHOUT ANY WARRANTY; without even the implied warranty of
014     *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
015     *   General Public License for more details.
016     *
017     *   You should have received a copy of the GNU Lesser General Public
018     *   License along with this library; if not, write to the Free Software
019     *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
020     *   USA, or see <http://www.gnu.org/licenses/>.
021     */
022    package org.granite.messaging.service.security;
023    
024    import org.springframework.security.intercept.AbstractSecurityInterceptor;
025    import org.springframework.security.intercept.InterceptorStatusToken;
026    import org.springframework.security.intercept.ObjectDefinitionSource;
027    import org.springframework.security.intercept.web.FilterInvocation;
028    import org.springframework.security.intercept.web.FilterInvocationDefinitionSource;
029    
030    
031    public abstract class AbstractSpringSecurityInterceptor extends AbstractSecurityInterceptor {
032            
033            private FilterInvocationDefinitionSource objectDefinitionSource;
034    
035            @Override
036            public Class<? extends Object> getSecureObjectClass() {
037                    return FilterInvocation.class;
038            }
039    
040            @Override
041            public ObjectDefinitionSource obtainObjectDefinitionSource() {
042                    return objectDefinitionSource;
043            }
044            
045            public void setObjectDefinitionSource(FilterInvocationDefinitionSource newSource) {
046                    this.objectDefinitionSource = newSource;
047            }
048            
049            public Object invoke(AbstractSecurityContext securityContext) throws Exception {
050                    FilterInvocation fi = buildFilterInvocation(securityContext);
051                    InterceptorStatusToken token = beforeInvocation(fi);
052                    Object returnedObject = null;
053                    try {
054                            returnedObject = securityContext.invoke();
055                    }
056                    finally {
057                            returnedObject = afterInvocation(token, returnedObject);
058                    }
059                    return returnedObject;
060            }
061            
062            protected abstract FilterInvocation buildFilterInvocation(AbstractSecurityContext securityContext);
063                    
064    }